[R-SIG-Finance] Speed issue issue with periodReturn

Brian G. Peterson brian at braverock.com
Thu Jul 30 02:42:06 CEST 2009


Ian Coe wrote:
> Hi,
>   I noticed that the periodReturn function seems to a take non-trivial
> amount of time to compute weekly returns. 
>
>   The calls below all compute the log returns from 1/1/2007 to now and
> they take slightly different amounts of time.
>
>   I'd like to be able to compute weekly returns as fast as possible.
> Does anyone have suggestions for minimizing the processing time?
> Different data type?  Different function to call?  
>
> Thanks,
> Ian  
>
>
>   
>> yhoo=getSymbols("GOOG",source="yahoo",from = "01-01-2004")
>> system.time(weeks<-periodReturn(GOOG,period="weekly",type='log',
>>     
> subset="2007::"))
>    user  system elapsed 
>    0.06    0.00    0.06 
>   
>> yhoo=getSymbols("GOOG",source="yahoo",from = "01-01-2007")
>> system.time(weeks<-periodReturn(GOOG,period="weekly",type='log',
>>     
> subset="2007::"))
>    user  system elapsed 
>    0.04    0.00    0.07
>   
>> yhoo=getSymbols("GOOG",source="yahoo")
>> system.time(weeks<-periodReturn(GOOG,period="weekly",type='log'))
>>     
>    user  system elapsed 
>    0.05    0.00    0.05
>
>   
Ian,

1/20th of a second for WEEKLY aggregated returns on 2+ years of data 
doesn't seem outrageous.  So might gain a tiny bit by calling log() 
directly, but I doubt it.  I could of course be wrong, but the tiny time 
difference seems trivial, not "non-trivial".  Perhaps you need to 
investigate use of foreach and doMC for your larger problem?

Regards,

   - Brian


-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list