Message-ID: <FB2DAD25-50E6-498E-B0A6-9F9935286D0D@gmail.com>
Date: 2015-04-10T02:00:02Z
From: Samuel Wilson
Subject: I know I should be able to figure this out...
In-Reply-To: <902B9551-7665-46AB-BC52-EF957BF46233@jtoll.com>
Wow, that?s a cool idea, I?ll try it!
I had already written them as function anyway.
Sam
Sent with Unibox
> 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
>
>
>
>
>
>
>
>
>
>
>
>
>
>
[[alternative HTML version deleted]]