[Blotter-commits] r1714 - pkg/quantstrat/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Nov 14 16:57:11 CET 2015
Author: bodanker
Date: 2015-11-14 16:57:10 +0100 (Sat, 14 Nov 2015)
New Revision: 1714
Modified:
pkg/quantstrat/R/rules.R
Log:
Check for sigcol before dindex loop
If 'sigcol' either doesn't exist or is named incorrectly, xts throws an
uninformative error. Add a one-time check to ensure sigcol exists in
mktdata before starting the dindex loop.
See R-Forge issue #5101. Thanks to Evelyn Mitchell for the report.
Modified: pkg/quantstrat/R/rules.R
===================================================================
--- pkg/quantstrat/R/rules.R 2015-11-11 19:49:55 UTC (rev 1713)
+++ pkg/quantstrat/R/rules.R 2015-11-14 15:57:10 UTC (rev 1714)
@@ -302,9 +302,15 @@
# check if there's anything to do
if(length(strategy$rules[[type]])>=1){
for (rule in strategy$rules[[type]]){
+ sigcol <- rule$arguments$sigcol
+ sigval <- rule$arguments$sigval
+ # ensure mktdata contains sigcol
+ if (!is.null(sigcol) && !sigcol %in% colnames(mktdata)) {
+ stop("mktdata does not contain 'sigcol': ", sigcol)
+ }
if(isTRUE(rule$path.dep)){ # only apply to path dependent rule
# check for sigcol, sigval, otherwise use all
- if(is.null(rule$arguments$sigcol) | is.null(rule$arguments$sigval) ){
+ if(is.null(sigcol) || is.null(sigval)) {
if(is.null(rule$timespan)) {
assign.dindex(1:length(Dates))
} else {
@@ -312,9 +318,9 @@
}
} else {
if(is.null(rule$timespan)) {
- assign.dindex(c(get.dindex(),which(mktdata[,rule$arguments$sigcol] == rule$arguments$sigval)))
+ assign.dindex(c(get.dindex(),which(mktdata[, sigcol] == sigval)))
} else {
- assign.dindex(c(get.dindex(),which(merge(.xts(,.index(mktdata)),mktdata[rule$timespan,rule$arguments$sigcol]) == rule$arguments$sigval)))
+ assign.dindex(c(get.dindex(),which(merge(.xts(,.index(mktdata)),mktdata[rule$timespan, sigcol]) == sigval)))
}
}
}
More information about the Blotter-commits
mailing list