r - 来自 R 中 quantmod 的 getSymbols() 不起作用
问题描述
我尝试getSymbols()
从 R 中著名的库quantmod
中运行,但没有成功。所以我想问如何解决这个问题。
我尝试的代码如下:
library(quantmod)
getSymbols("AAPL")
Error in download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m, :
cannot open URL 'http://ichart.finance.yahoo.com/table.csv?s=AAPL&a=0&b=01&c=2007&d=4&e=30&f=2019&g=d&q=q&y=0&z=AAPL&x=.csv'
In addition: Warning message:
In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m, :
InternetOpenUrl failed: '서버 이름이나 주소를 확인할 수 없습니다.'
getSymbols("AAPL", src="google")
Error in download.file(paste(google.URL, "q=", Symbols.name, "&startdate=", :
cannot open URL 'http://finance.google.com/finance/historical?q=AAPL&startdate=Jan+01,+2007&enddate=May+30,+2019&output=csv'
In addition: Warning message:
In download.file(paste(google.URL, "q=", Symbols.name, "&startdate=", :
cannot open URL 'http://finance.google.com/finance/historical?q=AAPL&startdate=Jan+01,+2007&enddate=May+30,+2019&output=csv': HTTP status was '403 Forbidden'
我曾经在同一个桌面上运行过这个功能(操作系统:Windows 8.1K,x64)。
感谢您告诉我正确的最新版本,所以我尝试像下面这样升级软件包,但失败了。
install.packages("quantmod")
它回答说它仍然调用v0.4-7。
Installing package into ‘C:/Users/fya/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
trying URL 'https://mran.revolutionanalytics.com/snapshot/2016-11-01/bin/windows/contrib/3.3/quantmod_0.4-7.zip'
Content type 'application/zip' length 472947 bytes (461 KB)
downloaded 461 KB
package ‘quantmod’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\***\AppData\Local\Temp\RtmpozsYvx\downloaded_packages
有没有更有效的方法来解决这个问题?
我提到了另一个关于在 R 中升级包的stackoverflow页面:
https://stackoverflow.com/questions/21461649/how-to-update-a-package-in-r
解决方案
CRAN上quantmod的最新版本是0.4-14,所以需要升级。另请注意,Google 财经不再提供任何数据。
您正在使用 MRAN 和 R-3.3.x。MRAN 可能有 quantmod_0.4-14,但它们显然不适用于较旧的 R 版本。并且 CRAN 仅为 R 的最新次要版本(当前为 3.6.x)提供 Windows 二进制文件。
您可以在 R-3.3.x 上安装来自 CRAN 的最新 quantmod,但您必须手动执行一些步骤。从 CRAN下载quantmod_0.4-14然后调用:
install.packages("quantmod_0.4-14.tar.gz", repos = NULL, type = "source")
我认为这应该有效。如果您仍有问题,请发表评论。