[Blotter-commits] r359 - pkg/quantstrat/demo

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jul 22 14:22:24 CEST 2010


Author: braverock
Date: 2010-07-22 14:22:24 +0200 (Thu, 22 Jul 2010)
New Revision: 359

Modified:
   pkg/quantstrat/demo/maCross.R
Log:
- add additional commented rules to handle the short side of a stop and reverse trade strategy

Modified: pkg/quantstrat/demo/maCross.R
===================================================================
--- pkg/quantstrat/demo/maCross.R	2010-07-21 16:46:46 UTC (rev 358)
+++ pkg/quantstrat/demo/maCross.R	2010-07-22 12:22:24 UTC (rev 359)
@@ -1,7 +1,7 @@
 #########################################################################################################################################################################
 #A simple moving average strategy to evaluate trade efficiency
 #checks on SMA of 50 days and SMA of 200 days
-#Author: R. Raghuraman("raghu")
+#Author: R. Raghuraman("raghu"), Brian Peterson
 #########################################################################################################################################################################
 
 require(quantstrat)
@@ -30,6 +30,11 @@
 stratMACROSS <- add.rule(strategy = stratMACROSS,name='ruleSignal', arguments = list(data=quote(mktdata),sigcol="ma50.gt.ma200",sigval=TRUE, orderqty=100, ordertype='market', orderside='long'),type='enter')
 stratMACROSS <- add.rule(strategy = stratMACROSS,name='ruleSignal', arguments = list(data=quote(mktdata),sigcol="ma50.lt.ma200",sigval=TRUE, orderqty=-100, ordertype='market', orderside='long'),type='exit')
 
+# if you want a long/short Stops and Reverse MA cross strategy, you'd add two more rules for the short side:
+
+# stratMACROSS <- add.rule(strategy = stratMACROSS,name='ruleSignal', arguments = list(data=quote(mktdata),sigcol="ma50.lt.ma200",sigval=TRUE, orderqty=-100, ordertype='market', orderside='short'),type='enter')
+# stratMACROSS <- add.rule(strategy = stratMACROSS,name='ruleSignal', arguments = list(data=quote(mktdata),sigcol="ma50.gt.ma200",sigval=TRUE, orderqty=100, ordertype='market', orderside='short'),type='exit')
+
 getSymbols(stock.str,from=initDate)
 start_t<-Sys.time()
 out<-try(applyStrategy(strategy=stratMACROSS , portfolios=portfolio.st))



More information about the Blotter-commits mailing list