[Blotter-commits] r1678 - pkg/quantstrat/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Feb 1 22:53:08 CET 2015
Author: bodanker
Date: 2015-02-01 22:53:08 +0100 (Sun, 01 Feb 2015)
New Revision: 1678
Modified:
pkg/quantstrat/R/applyStrategy.rebalancing.R
Log:
- Fix bug #5990; and fix unreported bug that caused first rebalance signal
to not be evaluated.
Modified: pkg/quantstrat/R/applyStrategy.rebalancing.R
===================================================================
--- pkg/quantstrat/R/applyStrategy.rebalancing.R 2015-02-01 21:46:09 UTC (rev 1677)
+++ pkg/quantstrat/R/applyStrategy.rebalancing.R 2015-02-01 21:53:08 UTC (rev 1678)
@@ -127,6 +127,8 @@
# combine plist into one sorted index
pindex <- unique(sort(do.call(c, c(plist, use.names=FALSE))))
+ # prepend minimum value, so first rebalance period will be evaluated
+ pindex <- c(.POSIXct(-8520336000, tz=attr(pindex,'tzone')), pindex)
st$rebalance_index<-pindex
#now we need to do the endpoints loop.
@@ -138,7 +140,12 @@
#sret<-ret[[portfolio]][[symbol]]
mktdata<-get(symbol,pos=st)
#now subset
- md_subset<-mktdata[as.POSIXct(index(mktdata))>pindex[i-1]&as.POSIXct(index(mktdata))<=pindex[i]]
+ posix_ix <- as.POSIXct(index(mktdata))
+ # include prior row, in case there is a signal on the last
+ # observation of the rebalance period (#5990)
+ mdi <- seq.int(.firstCross(posix_ix, pindex[i-1], "gt")-1,
+ .firstCross(posix_ix, pindex[i], "gte"))
+ md_subset <- mktdata[mdi,]
if(nrow(md_subset)<1) {
next()
} else {
More information about the Blotter-commits
mailing list