我想做的事情相当容易,但我无法弄清楚。我想我可以做类似于这里概述的事情
我有一个由 .xts 返回的 xts OHLC 对象的股票代码字符向量getSymbols
。我想遍历符号中的每个代码并将符号传递给以adjustOHLC
调整拆分:
symbols = c("FCX", "SPY")
for(symbol in symbols){
return(adjustOHLC(symbol,adjust =c("split"), use.Adjusted=FALSE))
}
似乎adjustOHLC
没有抓住变量“符号”的值:
debug: div <- getDividends(symbol.name)
Browse[2]> symbol.name
[1] "symbol"
Browse[2]>
Error in download.file(paste(yahoo.URL, Symbol.name, "&a=", from.m, "&b=", :
cannot open URL 'http://ichart.finance.yahoo.com/table.csv?s=symbol&a=0&b=01&c=1970&d=3&e=14&f=2012&g=v&ignore=.csv'
In addition: Warning message:
In download.file(paste(yahoo.URL, Symbol.name, "&a=", from.m, "&b=", :
cannot open: HTTP status was '404 Not Found'
如果我使用get(symbols)
,我会得到相同的结果(我在本文顶部显示的链接中使用了类似的方法):
for(symbol in symbols){
return(adjustOHLC(get(symbol),adjust =c("split"), use.Adjusted=FALSE))
}
debug: div <- getDividends(symbol.name)
Browse[2]> symbol.name
[1] "get(symbol)"
Browse[2]>
Error in download.file(paste(yahoo.URL, Symbol.name, "&a=", from.m, "&b=", :
cannot open URL 'http://ichart.finance.yahoo.com/table.csv?s=get(symbol)&a=0&b=01&c=1970&d=3&e=14&f=2012&g=v&ignore=.csv'
In addition: Warning message:
In download.file(paste(yahoo.URL, Symbol.name, "&a=", from.m, "&b=", :
cannot open: HTTP status was '404 Not Found'
我想我也可以利用lapply
它来加快速度,但我认为我首先遇到了上述问题。
lapply(symbols, function(x) adjustOHLC(x, adjust=c("split"), use.Adjusted=FALSE) )
似乎很容易 - 如果这太微不足道了,我深表歉意。感谢帮助。