Failed to download data from Yahoo finance using Quantmod
getSymbol()
loads the object in the environment, so to access it you would just call the object name directly.
> library(quantmod)
> getSymbols("^FTSE")
> FTSE
FTSE.Open FTSE.High FTSE.Low FTSE.Close FTSE.Volume FTSE.Adjusted
2007-01-02 6220.8 6312.5 6220.8 6310.9 1074946500 6310.9
2007-01-03 6310.9 6322.0 6296.0 6319.0 1606892700 6319.0
Alternatively, you can use get()
, but get()
requires the object name to be quoted.
> library(quantmod)
> getSymbols("^FTSE")
> get("FTSE")
FTSE.Open FTSE.High FTSE.Low FTSE.Close FTSE.Volume FTSE.Adjusted
2007-01-02 6220.8 6312.5 6220.8 6310.9 1074946500 6310.9
2007-01-03 6310.9 6322.0 6296.0 6319.0 1606892700 6319.0
Started to get error while downloading data from yahoo finance using R
Yahoo made some changes, so you can't access the download without the respective "crumb", see Question few days ago.
Unless you want to manually copy-paste this Download-URL for each stock, I'd highly suggest you to use the quantmod
package. It works, after applying a short fix (which will probably soon be included in a new package version - until then you have to do it manually).
library(quantmod) #probably will need to install the package first
devtools::install_github("joshuaulrich/quantmod", ref="157_yahoo_502") #installing the fix (devtools necessary)
str(getSymbols("EREGL.IS",auto.assign=F,from="2010-01-01",to="2017-02-03")) #Example
#An ‘xts’ object on 2010-01-01/2017-02-03 containing:
# Data: num [1:1851, 1:6] 4.39 4.43 4.42 4.49 4.49 ...
# - attr(*, "dimnames")=List of 2
# ..$ : NULL
# ..$ : chr [1:6] "EREGL.IS.Open" "EREGL.IS.High" "EREGL.IS.Low" #"EREGL.IS.Close" ...
# Indexed by objects of class: [Date] TZ: UTC
# xts Attributes:
#List of 2
# $ src : chr "yahoo"
# $ updated: POSIXct[1:1], format: "2017-05-20 12:11:08"
Does the quantmod link to yahoo stop working?
Referencing this quantmod issue thread, this is a problem originating from Yahoo, and there is a fix in the development version of quantmod. Until that fix is released on CRAN, you can try installing the development version.
As described in the installation instructions in the quantmod readme:
remotes::install_github("joshuaulrich/quantmod", ref="157_yahoo_502")
# or
devtools::install_github("joshuaulrich/quantmod", ref="157_yahoo_502")
Error downloading quantmod data
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.
Related Topics
Create Frequency Tables for Multiple Factor Columns in R
Filling Area Under Curve Based on Value
How to Subset Data in R Without Losing Na Rows
Adding New Columns to a Data.Table By-Reference Within a Function Not Always Working
How to Save Data File into .Rdata
R: += (Plus Equals) and ++ (Plus Plus) Equivalent from C++/C#/Java, etc.
How to Sort a Data Frame by Date
Reproducing Lattice Dendrogram Graph with Ggplot2
Identify All Objects of Given Class for Further Processing
Formatting Reactive Data.Frames in Shiny
Deleting Columns from a Data.Frame Where Na Is More Than 15% of the Column Length
Add Number of Observations Per Group in Ggplot2 Boxplot
Extract Elements Common in All Column Groups