[Blotter-commits] r1432 - pkg/quantstrat/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Apr 14 23:53:14 CEST 2013
Author: bodanker
Date: 2013-04-14 23:53:14 +0200 (Sun, 14 Apr 2013)
New Revision: 1432
Modified:
pkg/quantstrat/R/rules.R
Log:
- fix chain rule execution logic
Modified: pkg/quantstrat/R/rules.R
===================================================================
--- pkg/quantstrat/R/rules.R 2013-04-13 17:30:44 UTC (rev 1431)
+++ pkg/quantstrat/R/rules.R 2013-04-14 21:53:14 UTC (rev 1432)
@@ -630,19 +630,17 @@
chain = {
if(!is.null(closed.orders))
{
+ # determine which closed orders are chained to an entry
chain.rules <- strategy$rules[[type]]
- for(parent in closed.orders[,'Rule'])
- {
- # there should be a nicer way to do this in R :-) JH
- rules <- list()
- for(rule in chain.rules) {
- if(!is.null(rule$parent) && rule$parent == parent)
- rules = c(rules, list(rule))
- }
- if(length(rules) > 0)
- {
- ruleProc(rules, timestamp=timestamp, path.dep=path.dep, mktdata=mktdata, portfolio=portfolio, symbol=symbol, ruletype=type, mktinstr=mktinstr, parameters=list('chain.price'=as.numeric(closed.orders$Order.Price), ...))
- }
+ chain.rule.names <- sapply(chain.rules, '[[', 'parent')
+ closed.with.chain <- which(closed.orders$Rule %in% chain.rule.names)
+ # put rules/prices in same order
+ rules <- chain.rules[closed.with.chain]
+ chain.price <- closed.orders$Order.Price[closed.with.chain]
+ # loop over each rule and call ruleProc()
+ for(i in seq_along(closed.with.chain)) {
+ # call ruleProc in a loop, since it doesn't look like chain.price would be subset correctly
+ ruleProc(rules[i], timestamp=timestamp, path.dep=path.dep, mktdata=mktdata, portfolio=portfolio, symbol=symbol, ruletype=type, mktinstr=mktinstr, parameters=list(chain.price=as.numeric(chain.price[i]), ...))
}
}
},
More information about the Blotter-commits
mailing list