[Blotter-commits] r1628 - pkg/quantstrat/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Aug 2 15:13:46 CEST 2014


Author: bodanker
Date: 2014-08-02 15:13:46 +0200 (Sat, 02 Aug 2014)
New Revision: 1628

Modified:
   pkg/quantstrat/R/rules.R
Log:
- Fix bug 5802 in applyRules; thanks to Jonathan Owen for the report


Modified: pkg/quantstrat/R/rules.R
===================================================================
--- pkg/quantstrat/R/rules.R	2014-08-01 16:04:04 UTC (rev 1627)
+++ pkg/quantstrat/R/rules.R	2014-08-02 13:13:46 UTC (rev 1628)
@@ -492,8 +492,15 @@
     holdtill=first(time(Dates))-1 # TODO FIXME make holdtill default more robust?
     mktinstr<-getInstrument(symbol)
     curIndex<-1
-    if(nrow(mktdata)>1) freq <- periodicity(mktdata)  # run once and pass to ruleOrderProc
-    else if (indexClass(mktdata) == 'Date') freq='daily'
+    if(nrow(mktdata)>1)
+        freq <- periodicity(mktdata)  # run once and pass to ruleOrderProc
+    else {
+        # For applyStrategy.rebalancing, which could run on a 1-row subset of mktdata
+        # This should work for all index classes in ruleOrderProc's default switch expression
+        freq <- structure(list(difftime = structure(NA, units="secs", class="difftime"), 
+            frequency=1, start=start(mktdata), end=end(mktdata), units="secs", 
+            scale="seconds", label="second"), class="periodicity")
+    }
     
     # do order price subsetting outside of nextIndex and curIndex loop
     # this avoids repeated [.xts calls; and mktPrices is never altered, so copies aren't made



More information about the Blotter-commits mailing list