On Apr 9, 2015, at 2:25 PM, James Toll <james at jtoll.com> wrote:
On Apr 6, 2015, at 11:59 AM, Samuel Wilson <samuelcoltwilson at gmail.com> wrote:
I'm trying to create a script that takes a list of equity tickers (60-80
tickers each day), and downloads their prices and puts them into
data.frames.
I realize your question was answered, but is there a particular reason you want to make this a data.frame? If I?m not mistaken, the performance should be better if left as xts (i.e. matrix). Might I suggest creating a list of xts?
Given your tickers:
tickers<-c("GLD","DBC", "EEM", "EFV","EFG","BND","TLT","SHY","IWF","IWD","IWC","IWO","IWN","VNQ")
Something like:
library(parallel)
library(quantmod)
library(xts)
getData <- function (symbols, ...) {
result <- mclapply(symbols, function(x) getSymbols(x, auto.assign = FALSE, ...))
names(result) <- symbols
return(result)
}
output <- getData(tickers)
output$GLD["2015-04?]
However, I want to build a generic engine
using for.next loops, because the list of tickers will change each day.
Rather than for loops, write functions to do what you need, and then you can take advantage of the parallel apply functions like mclapply.
mclapply(tickers, function(x) last(output[[x]]))
Just a suggestion.
James