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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Oct 30 14:20:08 CET 2015


Author: bodanker
Date: 2015-10-30 14:20:08 +0100 (Fri, 30 Oct 2015)
New Revision: 1706

Modified:
   pkg/quantstrat/R/rules.R
Log:
Fix check to ensure we have valid mktPrice

The current logic throws an error if the first observation of the
mktPrice object is NA, even if that observation isn't being used.

Check for NULL first, since it will almost always be FALSE. Then check
if the length of mktPrice==1 and that one value is NA.

Thanks to Kyle Balkissoon for the report and reproducible example.


Modified: pkg/quantstrat/R/rules.R
===================================================================
--- pkg/quantstrat/R/rules.R	2015-10-30 13:13:24 UTC (rev 1705)
+++ pkg/quantstrat/R/rules.R	2015-10-30 13:20:08 UTC (rev 1706)
@@ -378,7 +378,7 @@
                 mktPrice <- mktPrices[[orderType]]$negQty
         }
         # ensure we have a mktPrice
-        if (is.na(mktPrice) || is.null(mktPrice))
+        if (is.null(mktPrice) || (length(mktPrice) == 1L && is.na(mktPrice)))
             stop("no price discernable for ", orderType, " in applyRules")
 
         # use .firstCross to find the location of the first orderPrice that crosses mktdata[,col]



More information about the Blotter-commits mailing list