Search code examples
rquantmodyahoo-apifinancial

Error downloading quantmod data


I am currently following a financial video and I am at minute 8:02 of the following video. I believe that I am going wrong in regard to downloading the data as the author of the video has done.

I have pasted the code below which you should be able to just run from the Rstudio window without downloading any additional files.

I first import the data using the quantmod package.

library(quantmod)
getSymbols("F", src="yahoo", periodicity = "monthly", from="2007-10-01", to="2012-11-01")
colnames(F) <- c("Open", "High", "Low", "Close", "Volume", "Adj")

Here I am running into a small problem, the video has at Oct 1, 2012 an Open price of 9.89, and an Adj Close price of 9.88. When I look at my data I have downloaded through the quantmod package I have an open on 2012-10-01 as 12.380 and an Adj Close 8.915304. I fully understand that there may be differences in values at the time of downloading the data but why are the values that I have through the quantmod package drastically different.

Further

I went to the Yahoo finance website to cross check the values. Here is the Yahoo link on Oct-01-2012 or as Yahoo has it Sept-30-2012 there is a price of 9.89 for the opening price and an Adj close price of 8.92 which is very close to the values in the video.

Why is the import through quantmod incorrect, its been a long day so I am assuming its something that I have missed.


Solution

  • The quantmod data that is downloaded is adjusted for dividends. Take a look at the daily prices recently, and in October 2017 for the correction for the dividend then:

    aa <- getSymbols("F", src="yahoo", periodicity = "daily", from="2007-10-01", auto.assign = FALSE)
    
    aa["2017-10/"]
    

    Accounting for dividends going back through time causes the variation in the prices on yahoo and in your downloaded xts object. e.g. the OHL prices are adjusted by 15 cents, the size of the dividend in october before the dividend. After the dividend payment, notice how the OHL prices are identical in yahoo and the xts object.

    https://finance.yahoo.com/quote/F/history?period1=1352178000&period2=1509944400&interval=1d&filter=history&frequency=1d

    If you want to return the yahoo data without dividend adjustments, add the adjust parameter set to TRUE in the getSymbols call (which is a passthru parameter to the function getSymbols.yahoo/getSymbols.yahooj):

    a2 <- getSymbols("F", src="yahoo", periodicity = "daily", from="2007-10-01", auto.assign = FALSE, adjust = TRUE)
    head(a2["2012-10"])
               F.Open F.High F.Low  F.Close F.Volume F.Adjusted
    2012-10-01   9.89  10.08  9.88 7.932703 33445600   7.932703
    2012-10-02  10.01  10.05  9.71 7.820863 63630000   7.820863
    2012-10-03   9.82  10.02  9.76 7.940693 51023800   7.940693
    2012-10-04  10.06  10.15  9.96 8.076502 46855500   8.076502
    2012-10-05  10.17  10.28 10.13 8.116439 40693900   8.116439
    2012-10-08  10.06  10.12  9.99 8.028567 25473900   8.028567
    

    As noted on the yahoo website, it seems stock splits are accounted for in the data on their website.