adjustOHLC.R issues
On Mon, Apr 11, 2016 at 8:48 PM, Ernie Stokely <wizardchef at gmail.com> wrote:
OK, I am prepared for the stones that will be thrown at me for being naive, but here goes anyway. Most of the references on adjusting OHLC values for splits and dividends say to use the following adjustment: K = Ca/C Om = K * O Hm = K * H Lm = K * L Cm = K * C = Ca where: Ca = adjusted close, OHLC are the unadjusted values, and OmHmLmCm are the modified (adjusted) values of OHLC.
The adjusted close from Yahoo used to only have 2 decimal places, so what you describe would have been subject to massive loss of accuracy when there were many adjustments. That's the entire reason I wrote TTR::adjRatios and why quantmod::adjustOHLC exists. That said, they provide more decimal places now, and adjustOHLC provides a use.Adjusted argument, so you could have used the adjustments you describe above by calling: adjustOHLC(VTI, use.Adjusted=TRUE).
If I use adjustOHLC() in quantmod to do the adjustment I find these are not the equations being used. For example, for VTI here is the unadjusted OHLCadjC data read from Yahoo: VTI.Open VTI.High VTI.Low VTI.Close VTI.Volume VTI.Adjusted 2006-03-01 128.15 128.90 127.79 128.70 216400 52.56795 2006-03-02 128.50 128.76 128.01 128.61 148800 52.53119 2006-03-03 128.26 129.43 128.20 128.40 323200 52.44541 2006-03-06 128.64 128.64 127.27 127.46 279800 52.06147 2006-03-07 127.15 127.31 126.65 126.94 218400 51.84907 2006-03-08 126.72 127.49 126.20 127.30 491800 51.99612 If I apply adjustOHLC() to these data I get: VTI.Open VTI.High VTI.Low VTI.Close VTI.Volume VTI.Adjusted 2006-03-01 59.15007 59.49625 58.98391 59.40394 216400 52.56795 2006-03-02 59.31162 59.43163 59.08545 59.36240 148800 52.53119 2006-03-03 59.20084 59.74088 59.17315 59.26546 323200 52.44541 2006-03-06 59.37624 59.37624 58.74389 58.83159 279800 52.06147 2006-03-07 58.68851 58.76235 58.45772 58.59158 218400 51.84907 2006-03-08 58.49003 58.84544 58.25001 58.75774 491800 51.99612
Works fine for me using the latest quantmod and TTR on CRAN:
R> getSymbols("VTI", from="2006-03-01")
[1] "VTI"
R> first(VTI)
VTI.Open VTI.High VTI.Low VTI.Close VTI.Volume VTI.Adjusted
2006-03-01 128.15 128.9 127.79 128.7 216400 52.56795
R> first(adjustOHLC(VTI))
VTI.Open VTI.High VTI.Low VTI.Close VTI.Volume VTI.Adjusted
2006-03-01 52.3433 52.64964 52.19626 52.56795 216400 52.56795
Perhaps you're using an older version of one/both packages?
Obviously, VTI.Adjusted (Ca) is not equal to VTI.Close (Cm) as required by the formula above. I have a colleague who has been trading for 40 years and he says this is an erroneous result (that Cm must equal Ca). When I explore the package reference file for adjustOHLC() I see this paragraph: "New columns are derived by taking the ratio of adjusted value to original Close, and multiplying by the difference of the respective column and the original Close. This is then added to the modified Close column to arrive at the remaining ?adjusted? Open, High, Low column values." I am not quite sure how to translate this verbal description into an equation, but it doesn't sound like the same correction I see recommended elsewhere and described at the beginning of this note. Can someone shed some light on this discrepancy or send me a link to more enlightenment? Thanks in advance.
Yahoo describes their adjusted close column here: https://help.yahoo.com/kb/finance/SLN2311.html
Ernie
_______________________________________________ R-SIG-Finance at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com R/Finance 2016 | www.rinfinance.com