[R-SIG-Finance] Quantstrat - Error while applying strategy

Brian G. Peterson brian at braverock.com
Sat May 5 12:44:22 CEST 2012


>From glancing at your code, it seems that your first major problem is
that your indicator function is not vectorized, and should be.  

Indicators, as described in the documentation, should use vectorized
operations whenever possible.

You are calling your .T3 function once for every row of your data
(ouch), rather than taking advantage of vectorized operations to act on
every row of the market data at once.  Your sapply loop will be
expensive in both time and memory, and appears completely unnecessary.  

You can and should test your indicator function on your market data
outside of quantstrat before trying to include it in a strategy.

Given how your function is constructed, it's also unclear whether you
even need to call it twice, or whether you would also be better off just
giving it both your fast.ma and the slow.ma at the same time, and only
going over the data once.

In short, R is 'taking a lot of time to run' because your indicator
function needs to be rewritten to be efficient.

Regards,

   - Brian

On Fri, 2012-05-04 at 21:49 -0700, bhavna wrote:
> Hi,
> 
> I am facing similar issue and tried the workaround suggested by Soren, but
> still does not seem to work.
> 
> My data is in below format with datetime as index since I am looking at 15
> min bars:
> > nseData[1,]
>                                      Open   High     Low    Close
> 2011-07-26 09:15:00 5704 5708.8 5689.05  5693
> > class(nseData)
> [1] "xts" "zoo"
> 
> Attached is the custom indicator and strategy I am trying to run.
> When I run the applyStrategy command
> out<-try(applyStrategy(strategy=strat,portfolios=portfolio.st,mktdata=nseData))
> 
> R takes lot of time to run. Not sure what is wrong. Even though I am passing
> an xts object to the T3 custom indicator I see errors like below when I do
> not use the .function(i) method
> (ncol(tmp_val) == 1) { : argument is of length zero
> 
> http://r.789695.n4.nabble.com/file/n4610537/TestStrat.txt TestStrat.txt 
> 
> Please advice.
> 
> Thanks,
> Bhavna
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Quantstrat-Error-while-applying-strategy-tp3472438p4610537.html
> Sent from the Rmetrics mailing list archive at Nabble.com.
> 
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.

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



More information about the R-SIG-Finance mailing list