What I want to do is fairly easy but I haven't been able to figure it out. I thought I could do something similar to that outlined here
I have a character vector of tickers that are xts OHLC objects returned by getSymbols
. I want to loop through each ticker in symbols and pass the symbol to adjustOHLC
to adjust for splits:
symbols = c("FCX", "SPY")
for(symbol in symbols){
return(adjustOHLC(symbol,adjust =c("split"), use.Adjusted=FALSE))
}
It seems adjustOHLC
does not grab the value of the variable 'symbol':
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'
If I use get(symbols)
I get the same result (similar approach was used in the link I show at the top of this post):
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'
I thought I could also make use of lapply
to make this faster but think I'm stuck with the above issue first.
lapply(symbols, function(x) adjustOHLC(x, adjust=c("split"), use.Adjusted=FALSE) )
Seems easy enough - I apologize if this is so trivial. Appreciate the help.