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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Apr 6 15:09:42 CEST 2013


Author: braverock
Date: 2013-04-06 15:09:42 +0200 (Sat, 06 Apr 2013)
New Revision: 1425

Modified:
   pkg/quantstrat/demo/macd.R
Log:
- fix labels to work with new match.names, clean up indentation
- convert commented risk exits to use order chains

Modified: pkg/quantstrat/demo/macd.R
===================================================================
--- pkg/quantstrat/demo/macd.R	2013-04-03 22:26:38 UTC (rev 1424)
+++ pkg/quantstrat/demo/macd.R	2013-04-06 13:09:42 UTC (rev 1425)
@@ -56,26 +56,62 @@
 strategy(strat.st, store=TRUE)
 
 #one indicator
-add.indicator(strat.st, name = "MACD", arguments = list(x=quote(Cl(mktdata))) )
+add.indicator(strat.st, name = "MACD", 
+			  arguments = list(x=quote(Cl(mktdata))),
+			  label='_' 
+)
 
 #two signals
-add.signal(strat.st,name="sigThreshold",arguments = list(column="signal",relationship="gt",threshold=0,cross=TRUE),label="signal.gt.zero")
-add.signal(strat.st,name="sigThreshold",arguments = list(column="signal",relationship="lt",threshold=0,cross=TRUE),label="signal.lt.zero")
+add.signal(strat.st,name="sigThreshold",
+		   arguments = list(column="signal._",
+				   			relationship="gt",
+							threshold=0,
+							cross=TRUE),
+		   label="signal.gt.zero"
+)
+   
+add.signal(strat.st,name="sigThreshold",
+		   arguments = list(column="signal._",
+				            relationship="lt",
+							threshold=0,
+							cross=TRUE),
+	       label="signal.lt.zero"
+)
 
 ####
 # add rules
 
 # entry
-add.rule(strat.st,name='ruleSignal', arguments = list(sigcol="signal.gt.zero",sigval=TRUE, orderqty=100, ordertype='market', orderside='long', threshold=NULL),type='enter',label='enter',storefun=FALSE)
+add.rule(strat.st,name='ruleSignal', 
+		 arguments = list(sigcol="signal.gt.zero",
+				         sigval=TRUE, 
+						 orderqty=100, 
+						 ordertype='market', 
+						 orderside='long', 
+						 threshold=NULL),
+	     type='enter',
+		 label='enter',
+		 storefun=FALSE
+)
 
 #alternatives for risk stops:
 # simple stoplimit order, with threshold multiplier
-add.rule(strat.st,name='ruleSignal', arguments = list(sigcol="signal.gt.zero",sigval=TRUE, orderqty='all', ordertype='stoplimit', orderside='long', threshold=-.05,tmult=TRUE, orderset='exit2'),type='risk',label='risk',storefun=FALSE)
+#add.rule(strat.st,name='ruleSignal', arguments = list(sigcol="signal.gt.zero",sigval=TRUE, orderqty='all', ordertype='stoplimit', orderside='long', threshold=-.05,tmult=TRUE, orderset='exit2'),type='chain', parent='enter', label='risk',storefun=FALSE)
 # alternately, use a trailing order, also with a threshold multiplier
-#add.rule(strat.st,name='ruleSignal', arguments = list(sigcol="signal.gt.zero",sigval=TRUE, orderqty='all', ordertype='stoptrailing', orderside='long', threshold=-.15,tmult=TRUE, orderset='exit2'),type='risk',label='trailingexit')
+#add.rule(strat.st,name='ruleSignal', arguments = list(sigcol="signal.gt.zero",sigval=TRUE, orderqty='all', ordertype='stoptrailing', orderside='long', threshold=-1,tmult=FALSE, orderset='exit2'),	type='chain', parent='enter', label='trailingexit')
 
 # exit
-add.rule(strat.st,name='ruleSignal', arguments = list(sigcol="signal.lt.zero",sigval=TRUE, orderqty='all', ordertype='market', orderside='long', threshold=NULL,orderset='exit2'),type='exit',label='exit')
+add.rule(strat.st,name='ruleSignal', 
+		 arguments = list(sigcol="signal.lt.zero",
+				          sigval=TRUE, 
+						  orderqty='all', 
+						  ordertype='market', 
+						  orderside='long', 
+						  threshold=NULL,
+						  orderset='exit2'),
+         type='exit',
+		 label='exit'
+)
 
 #end rules
 ####
@@ -96,7 +132,7 @@
 plot(add_MACD(fast=fastMA, slow=slowMA, signal=signalMA,maType="EMA"))
 
 #look at the order book
-getOrderBook('macd')
+obook<-getOrderBook('macd')
 
 ###############################################################################
 # R (http://r-project.org/) Quantitative Strategy Model Framework



More information about the Blotter-commits mailing list