[R-SIG-Finance] does quantmod::adjustOHLC adust for dividends?

Joshua Ulrich josh.m.ulrich at gmail.com
Fri Jun 2 17:34:41 CEST 2017


On Fri, Jun 2, 2017 at 10:29 AM, Vivek Rao <vivekrao4 at yahoo.com> wrote:
> Thank you. I see that the IBM.Open, IBM.High, IBM.Low, and IBM.Close columns
> are adjusted for dividends, and IBM.Adjusted column actually contains the
> raw close.

This is not true.  The IBM.Adjusted column contains the split-adjusted
close.  It's the same as the raw close for this time period though,
because IBM has not had a split since mid-1999.

getSymbols("IBM", from ="1900-01-01")
head(IBM)
           IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume IBM.Adjusted
1962-01-02    578.5    578.5     572  572.0000     387200     7.626667
1962-01-03    572.0    577.0     572  577.0000     288000     7.693333
1962-01-04    577.0    577.0     571  571.2501     256000     7.616667
1962-01-05    570.5    570.5     559  560.0000     363200     7.466667
1962-01-08    559.5    559.5     545  549.5001     544000     7.326667
1962-01-09    552.0    563.0     552  556.0000     491200     7.413333
tail(IBM["1999-05"])
           IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume IBM.Adjusted
1999-05-21  232.750  233.375 229.188  230.3750    6899800     115.1875
1999-05-24  230.312  230.688 221.750  223.7500    8598200     111.8750
1999-05-25  222.500  226.000 221.000  221.1875    9405000     110.5938
1999-05-26  223.000  236.625 221.438  236.2500   16628000     118.1250
1999-05-27  116.688  116.875 112.625  116.0000   10552500     116.0000
1999-05-28  116.000  116.750 114.188  116.0000    6379500     116.0000


> This is fine as long the user knows this -- the naming of the columns could
> suggest
> the reverse.
>
> Before Yahoo changed its data format, when I used getYahooData from package
> TTR to get data, the fields returned were
> Open,High,Low,Close,Volume,Unadj.Close,Div,Split,Adj.Div . I think the label
> "Unadj.Close" for the raw close
> is more descriptive.
>
> Vivek Rao
>
> ________________________________
> From: Joshua Ulrich <josh.m.ulrich at gmail.com>
> To: Ilya Kipnis <ilya.kipnis at gmail.com>
> Cc: Vivek Rao <vivekrao4 at yahoo.com>; "r-sig-finance at r-project.org"
> <r-sig-finance at r-project.org>
> Sent: Friday, June 2, 2017 10:51 AM
> Subject: Re: [R-SIG-Finance] does quantmod::adjustOHLC adust for dividends?
>
> On Fri, Jun 2, 2017 at 9:47 AM, Ilya Kipnis <ilya.kipnis at gmail.com> wrote:
>> That's a function of yahoo data no longer adjusting for dividends.
>>
> No, it isn't.
>
>> On Fri, Jun 2, 2017 at 10:45 AM, Vivek Rao via R-SIG-Finance <
>> r-sig-finance at r-project.org> wrote:
>>
>>> (I tried sending this message before joining the group, but it was held
>>> for moderation.)
>>>
>>> It appears that the adjustOHLC function of the quantmod package does not
>>> create an .Adjusted field
>>> that reflects dividends.
>>>
>>> The code
>>>
>>> library("quantmod")
>>> sym <- "IBM"
>>> START.DATE = "2016-01-01"
>>> div <- getDividends(sym,auto.assign=FALSE,from=START.DATE)
>>> xx <- getSymbols(sym, from=START.DATE, src="yahoo", auto.assign=FALSE)
>>> xx.a <- adjustOHLC(xx)
>>> xx.uA <- adjustOHLC(xx, use.Adjusted=TRUE)
>
> The issue is that you must set the symbol.name argument if the first
> argument to adjustOHLC() is not named the same as the symbol being
> adjusted.
>
> This works:
>
> xx.a2 <- adjustOHLC(xx, symbol.name = sym)
> head(xx.a2)
>           IBM.Open IBM.High  IBM.Low IBM.Close IBM.Volume IBM.Adjusted
> 2016-01-04 128.3440 128.6942 127.0568  128.6753    5229400      135.95
> 2016-01-05 129.4420 129.5650 127.6342  128.5807    3924800      135.85
> 2016-01-06 127.1893 128.3251 126.4700  127.9371    4310900      135.17
> 2016-01-07 126.5457 127.7951 125.3437  125.7507    7025800      132.86
> 2016-01-08 126.0535 126.6593 124.2931  124.5865    4762700      131.63
> 2016-01-11 124.7568 126.6593 124.7095  126.1009    4974400      133.23
>
>>> cat("\ndiv\n")
>>> print(head(div))
>>> cat("\nxx\n")
>>> print(head(xx))
>>> cat("\nxx.a\n")
>>> print(head(xx.a))
>>> cat("\nxx.uA\n")
>>> print(head(xx.uA))
>>>
>>> produces the output below. I'd expect that IBM.Adjusted field to have
>>> different values
>>> at the beginning of the period, depending on whether one adjusts for
>>> dividends.
>>>
>>> div
>>> IBM.div
>>> 2016-02-08    1.3
>>> 2016-05-06    1.4
>>> 2016-08-08    1.4
>>> 2016-11-08    1.4
>>> 2017-02-08    1.4
>>> 2017-05-08    1.5
>>>
>>> xx
>>> IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume IBM.Adjusted
>>> 2016-01-04  135.60  135.97  134.24    135.95    5229400      135.95
>>> 2016-01-05  136.76  136.89  134.85    135.85    3924800      135.85
>>> 2016-01-06  134.38  135.58  133.62    135.17    4310900      135.17
>>> 2016-01-07  133.70  135.02  132.43    132.86    7025800      132.86
>>> 2016-01-08  133.18  133.82  131.32    131.63    4762700      131.63
>>> 2016-01-11  131.81  133.82  131.76    133.23    4974400      133.23
>>>
>>> xx.a
>>> IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume IBM.Adjusted
>>> 2016-01-04  135.60  135.97  134.24    135.95    5229400      135.95
>>> 2016-01-05  136.76  136.89  134.85    135.85    3924800      135.85
>>> 2016-01-06  134.38  135.58  133.62    135.17    4310900      135.17
>>> 2016-01-07  133.70  135.02  132.43    132.86    7025800      132.86
>>> 2016-01-08  133.18  133.82  131.32    131.63    4762700      131.63
>>> 2016-01-11  131.81  133.82  131.76    133.23    4974400      133.23
>>>
>>> xx.uA
>>> IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume IBM.Adjusted
>>> 2016-01-04  135.60  135.97  134.24    135.95    5229400      135.95
>>> 2016-01-05  136.76  136.89  134.85    135.85    3924800      135.85
>>> 2016-01-06  134.38  135.58  133.62    135.17    4310900      135.17
>>> 2016-01-07  133.70  135.02  132.43    132.86    7025800      132.86
>>> 2016-01-08  133.18  133.82  131.32    131.63    4762700      131.63
>>> 2016-01-11  131.81  133.82  131.76    133.23    4974400      133.23
>>>
>>> Vivek Rao
>>>
>>> _______________________________________________
>>> 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.
>>>
>>
>>        [[alternative HTML version deleted]]
>
>>
>> _______________________________________________
>> 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 2017 | www.rinfinance.com
>
>
>



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com
R/Finance 2017 | www.rinfinance.com



More information about the R-SIG-Finance mailing list