[R-SIG-Finance] Quantstrat stoplimit orders not triggered

G See gsee000 at gmail.com
Sat Jul 23 02:19:01 CEST 2011


Patch committed to svn 697.

Let me know if there are still issues.

Garrett

Now, with your original test script and data (which are attached for ease of
reference) you can get this:

> ob$FXportf$EURUSD
                    Order.Qty Order.Price Order.Type  Order.Side
Order.Threshold Order.Status Order.StatusTime      Order.Set Txn.Fees
1999-01-04 00:00:00 "0"       NA          "init"      "long"     "0"
    "closed"     "1999-01-04"          "1"       "0"
2010-11-03 11:00:00 "-1000"   "1.3903"    "stoplimit" "long"     "-0.02"
    "closed"     "2010-11-08 02:00:00" NA        "0"
2010-11-03 11:00:00 "1000"    "1.4103"    "market"    "long"     NA
     "closed"     "2010-11-03 15:00:00" NA        "0"
2010-11-03 15:00:00 "-1000"   "1.3923"    "stoplimit" "long"     "-0.02"
    "closed"     "2010-11-07 18:00:00" NA        "0"
2010-11-03 15:00:00 "1000"    "1.4123"    "market"    "long"     NA
     "closed"     "2010-11-03 19:00:00" NA        "0"
2010-11-03 19:00:00 "-1000"   "1.3923"    "stoplimit" "long"     "-0.02"
    "closed"     "2010-11-07 18:00:00" NA        "0"
2010-11-03 19:00:00 "1000"    "1.4123"    "market"    "long"     NA
     "closed"     "2010-11-03 23:00:00" NA        "0"
2010-11-03 23:00:00 "-1000"   "1.3935"    "stoplimit" "long"     "-0.02"
    "closed"     "2010-11-07 18:00:00" NA        "0"
2010-11-03 23:00:00 "1000"    "1.4135"    "market"    "long"     NA
     "closed"     "2010-11-04 03:00:00" NA        "0"
2010-11-04 03:00:00 "-1000"   "1.4025"    "stoplimit" "long"     "-0.02"
    "closed"     "2010-11-05 11:00:00" NA        "0"
2010-11-04 03:00:00 "1000"    "1.4225"    "market"    "long"     NA
     "closed"     "2010-11-04 07:00:00" NA        "0"
2010-11-04 07:00:00 "-1000"   "1.4052"    "stoplimit" "long"     "-0.02"
    "closed"     "2010-11-05 07:00:00" NA        "0"
2010-11-04 07:00:00 "1000"    "1.4252"    "market"    "long"     NA
     "closed"     "2010-11-04 11:00:00" NA        "0"
2010-11-04 11:00:00 "-1000"   "1.4008"    "stoplimit" "long"     "-0.02"
    "closed"     "2010-11-07 18:00:00" NA        "0"
2010-11-04 11:00:00 "1000"    "1.4208"    "market"    "long"     NA
     "closed"     "2010-11-04 15:00:00" NA        "0"
2010-11-04 15:00:00 "-1000"   "1.4012"    "stoplimit" "long"     "-0.02"
    "closed"     "2010-11-07 18:00:00" NA        "0"
2010-11-04 15:00:00 "1000"    "1.4212"    "market"    "long"     NA
     "closed"     "2010-11-04 19:00:00" NA        "0"
2010-11-04 19:00:00 "-1000"   "1.4009"    "stoplimit" "long"     "-0.02"
    "closed"     "2010-11-07 18:00:00" NA        "0"
2010-11-04 19:00:00 "1000"    "1.4209"    "market"    "long"     NA
     "closed"     "2010-11-04 23:00:00" NA        "0"
2010-11-04 23:00:00 "-1000"   "1.3985"    "stoplimit" "long"     "-0.02"
    "closed"     "2010-11-07 18:00:00" NA        "0"
2010-11-04 23:00:00 "1000"    "1.4185"    "market"    "long"     NA
     "closed"     "2010-11-05 03:00:00" NA        "0"
2010-11-05 03:00:00 "-1000"   "1.3901"    "stoplimit" "long"     "-0.02"
    "closed"     "2010-11-08 02:00:00" NA        "0"
2010-11-05 03:00:00 "1000"    "1.4101"    "market"    "long"     NA
     "closed"     "2010-11-05 07:00:00" NA        "0"
> getPortfolio("FXportf")$symbols$EURUSD$txn
                    Txn.Qty Txn.Price Txn.Value Txn.Avg.Cost Pos.Qty
Pos.Avg.Cost Gross.Txn.Realized.PL Txn.Fees Net.Txn.Realized.PL Con.Mult
1999-01-04 00:00:00       0    0.0000       0.0       0.0000       0
0.000000               0.00000        0             0.00000        0
2010-11-03 15:00:00    1000    1.4123    1412.3       1.4123    1000
1.412300               0.00000        0             0.00000        1
2010-11-03 19:00:00    1000    1.4123    1412.3       1.4123    2000
1.412300               0.00000        0             0.00000        1
2010-11-03 23:00:00    1000    1.4135    1413.5       1.4135    3000
1.412700               0.00000        0             0.00000        1
2010-11-04 03:00:00    1000    1.4225    1422.5       1.4225    4000
1.415150               0.00000        0             0.00000        1
2010-11-04 07:00:00    1000    1.4252    1425.2       1.4252    5000
1.417160               0.00000        0             0.00000        1
2010-11-04 11:00:00    1000    1.4208    1420.8       1.4208    6000
1.417767               0.00000        0             0.00000        1
2010-11-04 15:00:00    1000    1.4212    1421.2       1.4212    7000
1.418257               0.00000        0             0.00000        1
2010-11-04 19:00:00    1000    1.4209    1420.9       1.4209    8000
1.418588               0.00000        0             0.00000        1
2010-11-04 23:00:00    1000    1.4185    1418.5       1.4185    9000
1.418578               0.00000        0             0.00000        1
2010-11-05 03:00:00    1000    1.4101    1410.1       1.4101   10000
1.417730               0.00000        0             0.00000        1
2010-11-05 07:00:00   -1000    1.4052   -1405.2       1.4052    9000
1.419122             -12.53000        0           -12.53000        1
2010-11-05 07:00:00    1000    1.4100    1410.0       1.4100   10000
1.418210               0.00000        0             0.00000        1
2010-11-05 11:00:00   -1000    1.4025   -1402.5       1.4025    9000
1.419956             -15.71000        0           -15.71000        1
2010-11-07 18:00:00   -1000    1.3923   -1392.3       1.3923    8000
1.423412             -27.65556        0           -27.65556        1
2010-11-07 18:00:00   -1000    1.3923   -1392.3       1.3923    7000
1.427857             -31.11250        0           -31.11250        1
2010-11-07 18:00:00   -1000    1.3935   -1393.5       1.3935    6000
1.433583             -34.35714        0           -34.35714        1
2010-11-07 18:00:00   -1000    1.4008   -1400.8       1.4008    5000
1.440140             -32.78333        0           -32.78333        1
2010-11-07 18:00:00   -1000    1.4012   -1401.2       1.4012    4000
1.449875             -38.94000        0           -38.94000        1
2010-11-07 18:00:00   -1000    1.4009   -1400.9       1.4009    3000
1.466200             -48.97500        0           -48.97500        1
2010-11-07 18:00:00   -1000    1.3985   -1398.5       1.3985    2000
1.500050             -67.70000        0           -67.70000        1
2010-11-08 02:00:00   -1000    1.3903   -1390.3       1.3903    1000
1.609800            -109.75000        0          -109.75000        1
2010-11-08 02:00:00   -1000    1.3901   -1390.1       1.3901       0
0.000000            -219.70000        0          -219.70000        1
>



On Fri, Jul 22, 2011 at 12:13 PM, G See <gsee000 at gmail.com> wrote:

> I was wondering why you thought the bug I fixed had to do with stoplimits.
>
> I think I understand the problem now.  I'll take a look.
>
> On Fri, Jul 22, 2011 at 11:49 AM, microlino <h.stegmann at onlinehome.de>wrote:
>
>> Thank you, Garrett!
>>
>> However, unfortunately, it still does not work... The result is not
>> different from the original version.
>>
>> As you can see from the orderbook below, a buy order at Close price is
>> placed whenever the signal is TRUE, i.e. after every bar that closes
>> >1.41.
>> Simultaneously, a stoplimit order is placed along with every buy order at
>> the buy price -0.02. So far, so good.
>>
>> What I expect is that every stoplimit order will be closed later through
>> the
>> provided example data set, as price falls further. However, only one of
>> the
>> stoplimit orders is closed, I have highlighted it below. It seems that the
>> stoplimits are closed only if (price < buyprice - 0.02) AND (signal ==
>> TRUE). You can easily see this logic in my example if you use a buy
>> threshold lower than 1.41.
>>
>> Closing of a simple stoplimit should be triggered by price only, at least
>> this is what I think it should do. Are stoplimit orders defined
>> differently
>> in quantstrat, so I need to code another signal that controls the
>> stoplimit
>> orders separately, somehow?
>>
>> Heiko
>>
>> Index Order.Qty Order.Price Order.Type Order.Side Order.Threshold
>> Order.Status Order.StatusTime Order.Set Txn.Fees
>> 1999-01-04 00:00:00 0 NA init long 0 closed 1999-01-04 1 0
>> 2010-11-03 17:00:00 -1000 1.3903 stoplimit long -0.02 open NA NA 0
>> 2010-11-03 17:00:00 1000 1.4103 market long NA closed 2010-11-03 21:00:00
>> NA
>> 0
>> 2010-11-03 21:00:00 -1000 1.3923 stoplimit long -0.02 open NA NA 0
>> 2010-11-03 21:00:00 1000 1.4123 market long NA closed 2010-11-04 01:00:00
>> NA
>> 0
>> 2010-11-04 01:00:00 -1000 1.3923 stoplimit long -0.02 open NA NA 0
>> 2010-11-04 01:00:00 1000 1.4123 market long NA closed 2010-11-04 05:00:00
>> NA
>> 0
>> 2010-11-04 05:00:00 -1000 1.3935 stoplimit long -0.02 open NA NA 0
>> 2010-11-04 05:00:00 1000 1.4135 market long NA closed 2010-11-04 09:00:00
>> NA
>> 0
>> 2010-11-04 09:00:00 -1000 1.4025 stoplimit long -0.02 open NA NA 0
>> 2010-11-04 09:00:00 1000 1.4225 market long NA closed 2010-11-04 13:00:00
>> NA
>> 0
>> *2010-11-04 13:00:00 -1000 1.4052 stoplimit long -0.02 closed 2010-11-05
>> 13:00:00 NA 0*
>> 2010-11-04 13:00:00 1000 1.4252 market long NA closed 2010-11-04 17:00:00
>> NA
>> 0
>> 2010-11-04 17:00:00 -1000 1.4008 stoplimit long -0.02 open NA NA 0
>> 2010-11-04 17:00:00 1000 1.4208 market long NA closed 2010-11-04 21:00:00
>> NA
>> 0
>> 2010-11-04 21:00:00 -1000 1.4012 stoplimit long -0.02 open NA NA 0
>> 2010-11-04 21:00:00 1000 1.4212 market long NA closed 2010-11-05 01:00:00
>> NA
>> 0
>> 2010-11-05 01:00:00 -1000 1.4009 stoplimit long -0.02 open NA NA 0
>> 2010-11-05 01:00:00 1000 1.4209 market long NA closed 2010-11-05 05:00:00
>> NA
>> 0
>> 2010-11-05 05:00:00 -1000 1.3985 stoplimit long -0.02 open NA NA 0
>> 2010-11-05 05:00:00 1000 1.4185 market long NA closed 2010-11-05 09:00:00
>> NA
>> 0
>> 2010-11-05 09:00:00 -1000 1.3901 stoplimit long -0.02 open NA NA 0
>> 2010-11-05 09:00:00 1000 1.4101 market long NA closed 2010-11-05 13:00:00
>> NA
>> 0
>>
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/Quantstrat-stoplimit-orders-not-triggered-tp3673706p3687209.html
>> Sent from the Rmetrics mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> R-SIG-Finance at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R questions
>> should go.
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110722/ceeab78d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Stoploss_Test-01.R
Type: text/x-r
Size: 2689 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110722/ceeab78d/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: EURUSD240.csv
Type: text/csv
Size: 6931 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110722/ceeab78d/attachment-0001.bin>


More information about the R-SIG-Finance mailing list