Using the maCross.R demo, if you change the applyStrategy line to include prefer=Open
, like this
out<-try(applyStrategy(strategy=stratMACROSS , portfolios=portfolio.st, prefer='Open'))
You will get execution when you open the next line.
> head(txns) Txn.Qty Txn.Price Txn.Fees Txn.Value Txn.Avg.Cost Net.Txn.Realized.PL 1999-12-31 0e+00 0.000000 0 0.0 0.000000 0 2001-06-27 1e+05 11.863950 0 1186395.0 11.863950 0 2001-09-07 -1e+05 8.709491 0 -870949.1 8.709491 -315446 2002-01-07 1e+05 11.808210 0 1180821.0 11.808210 0 2002-07-10 -1e+05 8.814099 0 -881409.9 8.814099 -299411 2003-05-16 1e+05 9.255447 0 925544.7 9.255447 0 > head(AAPL['2001-06-26/']) AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted 2001-06-26 11.61595 11.82995 11.45171 11.82 9742200 11.82 2001-06-27 11.86395 11.94859 11.20180 11.62 13361800 11.62 2001-06-28 11.47604 11.90421 11.42127 11.72 12443200 11.72 2001-06-29 11.78421 12.50142 11.55510 11.58 18406800 11.58 2001-07-02 11.77054 12.06431 11.52159 11.90 8216000 11.90 2001-07-03 11.70569 12.03929 11.70071 11.87 4019400 11.87
And check that the signals are sent to the panel before the execution line
> .strategy$order_book.macross$macross$AAPL Order.Qty Order.Price Order.Type Order.Side Order.Threshold Order.Status Order.StatusTime Prefer Order.Set Txn.Fees Rule 1999-12-31 "0" NA "init" "long" "0" "closed" "1999-12-31" "" "" "0" "" 2001-06-26 "1e+05" "11.6159494736842" "market" "long" NA "closed" "2001-06-27 00:00:00" "Open" NA "0" "ruleSignal.rule" 2001-09-06 "-1e+05" "9.15846501128668" "market" "long" NA "closed" "2001-09-07 00:00:00" "Open" NA "0" "ruleSignal.rule" 2002-01-04 "1e+05" "11.6158125791473" "market" "long" NA "closed" "2002-01-07 00:00:00" "Open" NA "0" "ruleSignal.rule" 2002-07-09 "-1e+05" "9.0088819167142" "market" "long" NA "closed" "2002-07-10 00:00:00" "Open" NA "0" "ruleSignal.rule" 2003-05-15 "1e+05" "9.25531233315537" "market" "long" NA "closed" "2003-05-16 00:00:00" "Open" NA "0" "ruleSignal.rule" 2006-06-21 "-1e+05" "57.4905184929139" "market" "long" NA "closed" "2006-06-22 00:00:00" "Open" NA "0" "ruleSignal.rule" 2006-09-25 "1e+05" "73.498195379538" "market" "long" NA "closed" "2006-09-26 00:00:00" "Open" NA "0" "ruleSignal.rule" 2008-03-06 "-1e+05" "124.074175969569" "market" "long" NA "closed" "2008-03-07 00:00:00" "Open" NA "0" "ruleSignal.rule" 2008-05-16 "1e+05" "189.299382795011" "market" "long" NA "closed" "2008-05-19 00:00:00" "Open" NA "0" "ruleSignal.rule" 2008-09-23 "-1e+05" "131.28867076632" "market" "long" NA "closed" "2008-09-24 00:00:00" "Open" NA "0" "ruleSignal.rule" 2009-05-13 "1e+05" "122.684122520713" "market" "long" NA "closed" "2009-05-14 00:00:00" "Open" NA "0" "ruleSignal.rule"
Note that this is not the way prefer
supposed to be used (at least not the way it is documented). In addition, I'm not sure what and how it will change when the signals light up.
source share