Fully automated futures trading

Discussion in 'Journals' started by globalarbtrader, Feb 11, 2015.

  1. Yes, eithier that or I'm doing a poor job of understanding it. Perhaps you could give an example. I genuinely don't understand what a "missed trade" is (or at least what you mean by one).

    GAT
     
    #281     Feb 8, 2016
  2. jj1111

    jj1111

    So maybe in your code, if you have something like, "oil is 32.50 bid at 32.60, I would like to sell oil at 32.55, but since I expect to do no better than 32.50, I won't take the trade." When in fact, the odds are high that placing orders at 32.55 would result in you getting filled more often than not? I'm assuming (and think I read) you cross only.

    I know it's a crude example (I'm here all week!)
     
    #282     Feb 8, 2016
  3. That's nothing. I once spent two days trading crude oil related puns with a guy on twitter. By the end they were at least 10 times worse than that.

    Okay, so my trading system doesn't work in the way you describe - it's not event driven. It works something like this:

    - periodically check the price in the market. I do this hourly, but daily woud be fine as well (when I clean up my code I'll move to daily closing prices only).
    - recalculate the optimal position, plus and minus a buffer around that.
    - at some point (which could easily be the next day) a seperate order management process will check my current position and compare it to the optimal. If the current position is outside the optimal buffer then I issue a trade. At this point I'll check the market price, but this is purely to benchmark my algo. It doesn't affect the trade.
    - a seperate execution algo will then do the trade, whatever the price, although it will try and get the best price it can.
    - if for some reason the trade fails, then if the original price capturing process gets a new price before we try and do the trade again, then and only then will the price movement be reflected in the trade we want to do. This is rare however.

    They key point is that there is no feedback between the price in the market or executed price and what trade I want to do. I can do this because (a) I'm fairly small, so my positions are quite discrete; it usually takes a reasonable move to make it worth doing even one lot in many markets (b) I'm trading slowly, average holding period several weeks or longer (c) because of the buffering which reduces trades that don't add alpha.

    Consider this example

    Code:
    [code:SOYBEAN, ismanual:False, clientid:1, balancecomment:, orderid:8524, brokerorderid:8524, sample_price:878.625, brokeraccount:U1228709, commission:0.0, brokerpermid:10265674, filledtrade:-2, isforcetype:, contractid:201611, sample_datetime:2016-02-08 12:32:10, submit_price:878.625, exchange:ECBOT, filledprice:878.5, broker:IB, isbalancing:False, side_price:878.5, submit_datetime:2016-02-08 12:32:25, cancelled:False, submit_trade:-2, filled_datetime:2016-02-08 12:31:16 ; ]
    
    
    At 12:32.10 I got a price of 878.625 for soybeans (the mid of 50 and 75). Nine seconds later my order management module picks up on that. That sounds glacial to the HFT guys but remember it could easily be the next day.

    Code:
    2016-02-08 12:32:19 INFO    : trading      : (trademarket, SOYBEAN) Detected change in optplusbuffer, from -0.913993840024 to -2.57742239718 (update)
    2016-02-08 12:32:19 INFO    : trading      : (trademarket, SOYBEAN) Detected change in optminusbuffer, from -2.23505975636 to -3.92032195712 (update)
    2016-02-08 12:32:19 INFO    : trading      : (trademarket, SOYBEAN) Detected change in refprice, from 885.75 to 878.625 (update)
    2016-02-08 12:32:20 INFO    : trading      : (trademarket, SOYBEAN) Detected change in optimal, from -1.57452679819 to -3.24887217715 (update)
    2016-02-08 12:32:20 INFO    : trading      : (trademarket, SOYBEAN) Detected change in limited_trades, from 0 to -2 (update)
    
    The optimal has moved from between -0.91 and -2.23; to between -2.6 and -3.2. Since we are short one contract, we need to sell 2.0.

    Code:
    
    2016-02-08 12:32:23 INFO    : trading      : Order of -2 for SOYBEAN 201611 (issue_an_order)2016-02-08 12:32:25 INFO    : trading      : Trying to place order of -2 for SOYBEAN 201611 (place_new_order)
    2016-02-08 12:32:25 INFO    : trading      : Next orderid is 8524 (add_new_order)
    2016-02-08 12:32:30 INFO    : trading      : Added algo used Easy for 8524 (add_algo_used)2016-02-08 12:32:31 INFO    : trading      : (algo, NA) Initial value of limit_price is 878.75 (update)
    2016-02-08 12:32:31 INFO    : trading      : (algo, NA) Initial value of side_price is 878.5 (update)
    
    The market is still at 878.5 - 878.75, 21 seconds after the original quote. I offer two at 75's.

    Code:
    
    2016-02-08 12:32:31 INFO    : trading      : (algo, NA) Initial value of Mode is Passive (update)
    2016-02-08 12:32:31 INFO    : trading      : (algo, NA) Initial value of offside_price is 878.75 (update)
    2016-02-08 12:32:32 INFO    : trading      : Added algo dict value for 8524.000000 Limit of string  or value 878.750000 (_add_value)
    2016-02-08 12:32:34 INFO    : trading      : Placed order for SOYBEAN 201611 of -2 with order id 8524 (place_new_IB_order)
    2016-02-08 12:32:35 INFO    : trading      : (algo, NA) Detected change in message, from StartingPassive to Order book imbalance of 99999.990000 developed compared to 5.000000, switching to aggressive for 8524
    878.500000 (update_value)2016-02-08 12:32:36 INFO    : trading      : (algo, NA) Detected change in limit_price, from 878.75 to 878.5 (update)
    
    There's a lot more volume on the offer now, so I'm going to hit the bid instead at 50's.

    Code:
    
    {'orderid': '8524', 'account': 'U1228709', 'exchange': 'ECBOT', 'symbol': 'ZS', 'permid': 10265674, 'execid': '00010a26.56b7cce9.01.01', 'clientid': '1', 'expiry': '20161114', 'price': 878.5, 'qty': 1, 'side': 'SLD', 'times': '20160208  12:31:16'}
    2016-02-08 12:32:38 INFO    : trading      : Received fill size -1 for brokerid 8524  code SOYBEAN expiry 20161114 contractid 201611 (action_fill)
    2016-02-08 12:32:38 INFO    : trading      : Fill done size -1 out of -2 for brokerid 8524 orderid 8524 at price 878.500000 (action_fill)
    
    We get a fill at 50's

    Code:
    2016-02-08 12:32:40 INFO    : trading      : (algo, NA) Detected change in side_price, from 878.5 to 878.25 (update)
    2016-02-08 12:32:40 INFO    : trading      : Updated algo dict  for 8524.000000, ValidSidePrice with string  or value 878.250000 (update_value)
    2016-02-08 12:32:40 INFO    : trading      : (algo, NA) Detected change in message, from tick no action 8524 SOYBEAN 201611 to Adverse price move in aggressive mode for 8524 SOYBEAN 201611 (update)
    2016-02-08 12:32:41 INFO    : trading      : (algo, NA) Detected change in limit_price, from 878.5 to 878.25 (update)
    
    The large order has indeed pushed the bid down to 878.25. We chase it down by lowering our offer to 25's but fortunately:

    Code:
    {'orderid': '8524', 'account': 'U1228709', 'exchange': 'ECBOT', 'symbol': 'ZS', 'permid': 10265674, 'execid': '00010a26.56b7ccea.01.01', 'clientid': '1', 'expiry': '20161114', 'price': 878.5, 'qty': 2, 'side': 'SLD', 'times': '20160208  12:31:16'}
    2016-02-08 12:32:43 INFO    : trading      : Received fill size -2 for brokerid 8524  code SOYBEAN expiry 20161114 contractid 201611 (action_fill)
    2016-02-08 12:32:43 INFO    : trading      : Fill done size -2 out of -2 for brokerid 8524 orderid 8524 at price 878.500000 (action_fill)
    2016-02-08 12:32:45 INFO    : trading      : Postion in SOYBEAN 201611 changed from -1 to -3 because of trade -2 id 8524 (add_fill)2016-02-08 12:35:23 INFO    : trading      : (trademarket, SOYBEAN) Detected change in priced_status, from Order_submitted to Nothing to trade (update)
    
    Our earlier order of 50's executes first.

    This is way more detail than you need but the key point is that the price is moving around the whole time but I'm doing nothing about it in terms of modifying my trade. I don't have low latency capacity anyway so this wouldn't be possible as well as being pointless.

    In the end for this particular example we execute where we'd expect to if I'd hit the bid onthe original original sample price; but I couldn't care less if I do or not. I do monitor this statistic (execution versus sample) and break it down into its components (delay to issue order, bid-ask spread, execution algo effect); but the delay part although sometimes large is mostly random and certainly doesn't do more than 1-2bp to my bottom line even if all my trades were delayed until the next days close. I focus like a laser beam on the second two components.

    I hope this all makes sense; I'm aware I've gone well away from the original query.

    GAT
     
    Last edited: Feb 8, 2016
    #283     Feb 8, 2016
    dratsum likes this.
  4. Hi GAT, when estimating costs as per chapter 12, how do you estimate bid/ask spreads? Do you download time series of very short frequencies of the bid and ask (say every 5 minutes) over a couple of years to get an average? Can you provide any pointers on estimating the bid/ask spread? Thanks!
     
    #284     Feb 9, 2016
  5. I sample the price hourly

    I also have a sample of bid/ask every time I go to trade.

    So maybe 10 observations a day, over which I then take an average.

    GAT
     
    #285     Feb 9, 2016
  6. I understand that this approach makes sense for comparing your expected slippage vs actual. How do you sample the bid/ask spread for the input into how costs affect your trading rules during the construction/bootstrapping phase?
     
    #286     Feb 9, 2016
  7. Exactly the same way
     
    #287     Feb 9, 2016
  8. Hi GAT, for your use of Sharpe ratios, are you excluding the risk-free rate in all of your calculations and just dividing returns by standard deviation, or are your dividing excess returns by standard deviation? If you are including the risk-free rate, what are you using? Also, are your returns geometric or arithmetic returns?
     
    #288     Feb 9, 2016
  9. I use arithmetic returns.

    I don't include a risk free rate because when trading futures it's a reasonable approximation to assume you don't need cash to do it (I use 35% of my account value for margin on average). And right now interest rates are effectively zero anyway (this is what I'd get on my margin).

    GAT
     
    #289     Feb 10, 2016
    AvantGarde likes this.
  10. Hi GAT, in your optimisation techniques, are you seeking the global minimum variance portfolio (minimised standard deviation for given level of return) or the 'tangency' portfolio (best Sharpe ratio) assuming risk-free rate is zero?
     
    #290     Feb 10, 2016