使用 Quantmod 从雅虎财经下载数据失败
Failed to download data from Yahoo finance using Quantmod
我尝试使用 Quantmod
包从 Yahoo finance
下载数据,但未能获得任何数据。
library(quantmod)
> get(getSymbols("^FTSE"))
Error in get(getSymbols("^FTSE")) : object '^FTSE' not found
In addition: Warning message:
^FTSE contains missing values. Some functions will not work if objects contain missing values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to remove or replace them.
如果知道它失败的原因,我们将不胜感激。
下面是我的session信息
> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.2 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
[4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
[7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] quantmod_0.4-14 TTR_0.23-4 xts_0.11-2 zoo_1.8-5
loaded via a namespace (and not attached):
[1] compiler_3.6.0 tools_3.6.0 curl_3.3 grid_3.6.0
[5] lattice_0.20-38
getSymbol()
加载环境中的对象,因此要访问它,您只需直接调用对象名称即可。
> 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
或者,您可以使用 get()
,但 get()
需要引用对象名称。
> 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
我建议将 auto.assign
参数设置为 FALSE
。然后您可以将 getSymbols()
的输出分配给您想要的任何对象。例如:
ftse <- getSymbols("^FTSE", auto.assign = FALSE)
head(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
# 2007-01-04 6319.0 6319.0 6261.0 6287.0 1902875500 6287.0
# 2007-01-05 6287.0 6287.0 6220.1 6220.1 1622439300 6220.1
# 2007-01-08 6220.1 6246.0 6187.0 6194.2 1326700900 6194.2
# 2007-01-09 6194.2 6218.5 6190.4 6196.1 2143699600 6196.1
我尝试使用 Quantmod
包从 Yahoo finance
下载数据,但未能获得任何数据。
library(quantmod)
> get(getSymbols("^FTSE"))
Error in get(getSymbols("^FTSE")) : object '^FTSE' not found
In addition: Warning message:
^FTSE contains missing values. Some functions will not work if objects contain missing values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to remove or replace them.
如果知道它失败的原因,我们将不胜感激。
下面是我的session信息
> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.2 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
[4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
[7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] quantmod_0.4-14 TTR_0.23-4 xts_0.11-2 zoo_1.8-5
loaded via a namespace (and not attached):
[1] compiler_3.6.0 tools_3.6.0 curl_3.3 grid_3.6.0
[5] lattice_0.20-38
getSymbol()
加载环境中的对象,因此要访问它,您只需直接调用对象名称即可。
> 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
或者,您可以使用 get()
,但 get()
需要引用对象名称。
> 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
我建议将 auto.assign
参数设置为 FALSE
。然后您可以将 getSymbols()
的输出分配给您想要的任何对象。例如:
ftse <- getSymbols("^FTSE", auto.assign = FALSE)
head(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
# 2007-01-04 6319.0 6319.0 6261.0 6287.0 1902875500 6287.0
# 2007-01-05 6287.0 6287.0 6220.1 6220.1 1622439300 6220.1
# 2007-01-08 6220.1 6246.0 6187.0 6194.2 1326700900 6194.2
# 2007-01-09 6194.2 6218.5 6190.4 6196.1 2143699600 6196.1