[R-SIG-Finance] quantstrat order execution

Samo Pahor samo.pahor at gmail.com
Thu Jul 19 21:48:50 CEST 2012


Hi,

I am trying to "persuade" quantstrat, working with daily data, to execute
orders at the close on the day that signal is telling "short" and
exit(cover short) a day after "move to cash" signal is generated.
Unfortunately, quantstrat does is not easily presuaded to do this...

I have searched all possible lists and e-mails but it seems to me that
either quantstrat was not designed for delaying order execution on daily
data with prefer option column or there is a bug in quantstrat or my
understanding is limited(again)... I tried to play with all possible
combinations of delay (-1, 0, 1) and prefer (Open, PreviousOpen) arguments
but without success (following discussion here
https://stat.ethz.ch/pipermail/r-sig-finance/2011q3/008356.html and here
https://stat.ethz.ch/pipermail/r-sig-finance/2012q2/010224.html)... Am I
missing something here or I do not understand something about quantstrat?

I have prepared a reproducible example (based on Jan Humme excellent
demos). It also contains expected result and actual result from quantstrat.
Please see attached R script file. Looking at OrderBook, txns and maktdata
it just does not make sense to me...

> print(getOrderBook(p))
$qs.test
$qs.test$VXX
           Order.Qty Order.Price Order.Type Order.Side Order.Threshold
Order.Status Order.StatusTime      Prefer  Order.Set Txn.Fees
Rule
2009-01-30 "0"       NA          "init"     "long"     "0"
"closed"     "2009-01-30"          ""      ""        "0"
""
2009-02-10 "-1"      "418.4"     "market"   "short"    NA
"closed"     "2009-02-11 00:00:00" "Close" NA        "-1.9"
"EnterSHORT"
2009-02-12 "all"     "421"       "market"   "short"    NA
"closed"     "2009-02-12 00:00:00" "NextO" NA        "-1.9"
"ExitShort2CASH"


attr(,"class")
[1] "order_book"
>
> txns <- getTxns(p, "VXX")
> txns
           Txn.Qty Txn.Price Txn.Fees Txn.Value Txn.Avg.Cost
Net.Txn.Realized.PL
2009-01-30       0      0.00      0.0      0.00         0.00
0.00
2009-02-11      -1    412.28     -1.9   -412.28       412.28
-1.90
2009-02-12       1    411.04     -1.9    411.04       411.04
-0.66
>
> mktdata["2009-02-10/2009-02-12"]
           VXX.Open VXX.High VXX.Low VXX.Close VXX.Volume VXX.Adjusted
PreviousC  NextO signal cash long short
2009-02-10    404.0   422.64  395.12    418.40      64200       418.40
397.32 416.20     -1    0    0     1
2009-02-11    416.2   419.32  408.40    412.28      21500       412.28
418.40 421.00      0    1    0     0
2009-02-12    421.0   432.00  411.04    411.04      25500       411.04
412.28 412.96      0    0    0     0


I would appreciate any hints on how to accomplish what I want.

Best,
Samo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120719/9ff766a5/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: quantstrat_test.R
Type: application/octet-stream
Size: 6338 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120719/9ff766a5/attachment.obj>


More information about the R-SIG-Finance mailing list