[R] inbuilt crossover function for backtesting

Joshua Ulrich josh.m.ulrich at gmail.com
Mon Aug 10 03:13:15 CEST 2015


On Sun, Aug 9, 2015 at 3:46 AM, boredstoog via R-help
<r-help at r-project.org> wrote:
> I am trying to built a simple moving average cross over strategy for
> backtesting. I have installed TTR and quantmod, quantstrat for that purpose.
> >From TTR package we can get functions for sma,bolinger band and other
> indicators. I want to know whether any inbuilt crossover function (not
> greater '>' or lesser '<') is available for R.
>
help.search("crossover") would have lead you to quantstrat::sigCrossover.

require(quantstrat)
getSymbols("SPY")
SPY$sma10 <- SMA(Cl(SPY),10)
SPY$sma30 <- SMA(Cl(SPY),30)
buy <- sigCrossover("buy", SPY, c("sma10","sma30"), "gt")
sell <- sigCrossover("sell", SPY, c("sma30","sma10"), "lt")

> Example
>
> sma10<-SMA(close,10)
> sma30<-SMA(close,30)
>
> buy<-Crossover(sma10,sma30)
> sell<-Crossover(sma30,sma10)
>
>
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/inbuilt-crossover-function-for-backtesting-tp4710918.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com



More information about the R-help mailing list