[Blotter-commits] r542 - in pkg/quantstrat: R demo

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 27 05:35:58 CET 2011


Author: bodanker
Date: 2011-01-27 05:35:57 +0100 (Thu, 27 Jan 2011)
New Revision: 542

Modified:
   pkg/quantstrat/R/rules.R
   pkg/quantstrat/demo/maCross.R
Log:
- Attempt to evaluate rule types in the order listed in ?add.rule. Thanks
  to Aleksandr Rudnev for locating the issue.
- Adjust data for splits/dividends in maCross demo.


Modified: pkg/quantstrat/R/rules.R
===================================================================
--- pkg/quantstrat/R/rules.R	2011-01-24 20:45:42 UTC (rev 541)
+++ pkg/quantstrat/R/rules.R	2011-01-27 04:35:57 UTC (rev 542)
@@ -499,7 +499,10 @@
             hold=FALSE
             holdtill=NULL
         }
-        for ( type in names(strategy$rules)){
+        # evaluate the rule types in the order listed in the documentation
+        # thanks to Aleksandr Rudnev for tracking this down (R-SIG-Finance, 2011-01-25)
+        types <- sort(factor(names(strategy$rules), levels=c("pre","risk","order","rebalance","exit","enter","entry","post")))
+        for ( type in types ) {
             switch( type ,
                     pre = {
                         if(length(strategy$rules[[type]])>=1){

Modified: pkg/quantstrat/demo/maCross.R
===================================================================
--- pkg/quantstrat/demo/maCross.R	2011-01-24 20:45:42 UTC (rev 541)
+++ pkg/quantstrat/demo/maCross.R	2011-01-27 04:35:57 UTC (rev 542)
@@ -36,6 +36,9 @@
 # stratMACROSS <- add.rule(strategy = stratMACROSS,name='ruleSignal', arguments = list(sigcol="ma50.gt.ma200",sigval=TRUE, orderqty=100, ordertype='market', orderside='short'),type='exit')
 
 getSymbols(stock.str,from=initDate)
+for(i in stock.str)
+  assign(i, adjustOHLC(get(i),use.Adjusted=TRUE))
+
 start_t<-Sys.time()
 out<-try(applyStrategy(strategy=stratMACROSS , portfolios=portfolio.st))
 end_t<-Sys.time()
@@ -62,4 +65,4 @@
 #
 # $Id$
 #
-###############################################################################
\ No newline at end of file
+###############################################################################



More information about the Blotter-commits mailing list