Trading with automation (with IB)

Discussion in 'Journals' started by fullautotrading, Sep 8, 2015.

  1. Just got back from a meeting to find out the application has been working. During my absence the PNL shoot up to almost 13K. Apparently, the less I mess with it the better it seems to go :)


    PNL_9.png

    I am also watching a couple of other instruments (ZS, ZW, KE, NG, ...), to see whether it is the case to add them to the folio.

    So far, I am liking this non-predictive "layered" (long/short) approach, with "limited load" on each layer. The hedging action seems nice, at least so far. Of course we need to look also for some real wild move to "stress" it, and see how it responds.

    Max maint. margin about 39K (over the elapsed 15 days). The G-L (Gain-Loss) curve has reached 23.3K (somehow it can be interpreted as the current max "potential" profit).

    Code:
     - Current values (received on: Wed 23 Sep 2015 21:20:48:739 [ Wed 23 Sep 2015 15:20:48:739 edt ]) -
    
    AccruedCash                         0.00 USD                      [Min: 0.00, Max: 0.00]
    AccruedDividend                     0.00 USD                      [Min: 0.00, Max: 0.00]
    BuyingPower                10,097,185.98 USD                      [Min: 9,971,782.43, Max: 10,175,058.60]  (6.79 x 1,486,580.10)
    FullAvailableFunds          1,486,580.10 USD                      [Min: 1,485,890.11, Max: 1,526,258.79]
    FullExcessLiquidity         1,497,512.70 USD                      [Min: 1,495,767.36, Max: 1,526,258.79]
    FullInitMarginReq              49,863.00 USD                      [Min: 0.00, Max: 49,863.00]
    FullMaintMarginReq             38,930.40 USD                      [Min: 0.00, Max: 38,930.40]
    NetLiquidation              1,536,443.10 USD                      [Min: 1,522,138.85, Max: 1,537,917.53]
     
    Last edited: Sep 23, 2015
    #31     Sep 23, 2015
  2. I am watching the "recorded" (realtime) volatilities. In the chart below, as a reference I have drawn 2 yellow horizontal lines. One at the level of ES, and the other one at the CL volatility level.

    This should put into some perspective how the various instruments compare wrt to volatility.

    Volatility_1.png

    Note for instance, ZN (which we are not trading), shows low volatility. In fact, looking at the historical prices collected so far, it was immediately apparent that we would have allocated a relatively large lump of $$$ on small volatility (so, instinctively, we skipped it).

    I would go as far as to hypothesize that this "band" might be a sort of "comfort zone" where we have a level of volatility which may be "just right" for our games.

    Note also how the ETFs compare. Generally, they look pretty wild and the evaluation become even worse if we keep in mind that the "trading window" is significantly narrow when compared to futures. So, in practice, they will "feel" more like the "gapping" component is prevalent in the price curve, and that is certainly not good at all for our hedging/scalping games, where instead the profits are maximized when we can take advantage of a large number of fluctuations (while we need to hedge the "vertical" component).

    So, the "dynamics" of the price curve does matter (for this approach).
     
    Last edited: Sep 23, 2015
    #32     Sep 23, 2015
  3. To recap a bit the approach we have been following thus far, what we are currently doing is to work for each instrument, and at a given price level, with max 3 layers, where we initially start 2 layers with opposite long/short ("mild") "position constraints". A third layer is used to provide some extra hedging in the case the first 2 layers take the same-sign position.

    Layers1.png

    There is no intent to "predict" anything, we just let it scalp as much as possible the fluctuations which occur (so the more fluctuations and the larger the trading window, the better), while aiming to "neutralize" as much as possible the "vertical components" of the moves.

    While the game played on each layer implements itself a powerful mechanism of "superposition" of long /short trades to provide a hedging action at layer level, what, in time, became apparent is that overlaying layers is also a necessary additional mechanism.

    The very intuitive reason for that took actually a bit in my mind to become focused, and in essence is the fact that on a single layer one can't really provide the same hedging action as with multiple layers, because in practice this would cause excessive "stop/reverse" action on a layer. In other words, once a layer has taken a certain direction, it can't really be continuously "inverting" it, as this would result (statistically) in an average of sell orders below the avg of buy orders.
     
    Last edited: Sep 24, 2015
    #33     Sep 24, 2015
  4. This morning we are still in good shape after almost 16 solar days and still using just 34.6K maint. margin.

    PNL_10.png

    NKD has turned momentarily positive on all layers, which means that there has been enough scalping activity to make up for the hedging trades (in other words, the "hedging" or "stopping" players could also close). I am still just "watching" ZW, KE, NG.
     
    #34     Sep 24, 2015
  5. Yesterday we had a bit of drawdown (DD), but still looking fine this morning. The moves were hedged fine and, in fact, they resulted in an increase of the Gain-Loss (G-L) curve (the dotted green line), which, as I mentioned earlier, can be roughly interpreted as our current "potential" max PNL. This is generally due to the fact that when you are "losing" (or "loading up", "investing" if you like) on one side, there are always players on the opposite side (those currently hedging) which may be taking profit, thus closing their life cycles. The fact that we are generally limiting the exposure to 2 "packets" (currently: 1 "packet" defined as 1 contract) per layer, helps a lot keeping the situation under control and hedging with the other layers.

    PNL_11.png

    Still trading those 5 instruments:

    Code:
    CL FUT 201511 NYMEX 1000 Light Sweet Crude Oil  [ CLX5 ]
    ES FUT 201512 GLOBEX 50 E-mini S&P 500  [ ESZ5 ]
    NKD FUT 201512 GLOBEX 5 Dollar Denominated Nikkei 225 Index  [ NKDZ5 ]
    SI FUT 201512 NYMEX 5000 NYMEX Silver Index  [ SIZ5 ]
    ZL FUT 201512 ECBOT 60000 Soybean Oil Futures  [ ZL   DEC 15 ]  
    I have been looking at some other instruments, but so far they do not look "convincing". I may possibly be adding ZW or KE.

    FX futures tend to have large "waves" and I don't really like them: not liking the idea of tying large nominal values on the "wrong type of volatility". Anyway, since this is just an "illustration", I may be throwing in a couple of them.
    Many other instruments are just "replications" of what we already have, often with either larger spread or unsuitable volatility.
    Also, the Forex pairs are imho to be avoided: just use the corresponding futures. [There is also a technical reason for that, as the API relay a sort of "virtual position" (I still have to understand the logic in that "madness") instead of the "real" position, and they may even have opposite sign, which may be very misleading, and I have myself lost a lot of real money for that "problem" and the misunderstandings it causes.) ]

    Even these 5 instruments do show correlations (or, more more precisely "codirections", as I like to compute them):

    Codirections.png

    Although there are thousands instruments available out there, when you factor in all you need to consider, what you are left with is just an handful of stuff really suitable for trading (at least with this kind of approach: clearly for pure "bets", directional trading, etc. much more variety is available, even though, again, when we group all the instruments by their "directions", we see that the mkt does not have many uncorrelated "components" after all. There is in fact the saying "all-correlations-go-to-one": http://keplerianfinance.com/2013/06/all-correlations-go-to-one/ which of course is not true in a strict sense, but of course we get what it is meant in practice ...).
     
    Last edited: Sep 25, 2015
    #35     Sep 25, 2015
  6. ok, I have "activated" 2 layers for ZW too. They have already been filled with opposite (long/short) players, so we are momentarily flat in the underlying account.

    Code:
    ZW FUT 201512 ECBOT 5000 Wheat Futures  [ ZW   DEC 15 ]                                        
    ZW_1.png

    so we have 2 Ag futures active at the moment (the other one is ZL DEC 15, which is at the moment shooting up).

    Probably next to be activated is NG.

    Code:
    NG FUT 201512 NYMEX 10000 Henry Hub Natural Gas  [ NGZ5 ]                                       
     
    Last edited: Sep 25, 2015
    #36     Sep 25, 2015
  7. Now, since the two ZW layers have taken both the same sign position, I will add another ZW layer, this time with a "stricter" form of long only constraint (it is not allowed to turn negative due to buy player close). The layer shown on top has taken a "scalp" and therefore since it also had a sell player active, it ends up having a negative position (this is because the long position constraint is "mild" and it allows this behavior):

    ZW_2.png

    Seeing it in action, it appears that is quite effective to limit the layer max exposure to 2 "packets", as this makes easier to contain the drawdown (DD) while waiting for the continuous scalping action to "pull up" the PNL curve. Letting grow the position too much was, apparently, one of the great mistakes we have been doing in the past. (Actually, at this point we could carry the idea to the extreme and even enforce just 1 "packet" per layer. To be verified by simulation.)
     
    Last edited: Sep 25, 2015
    #37     Sep 25, 2015
  8. We end our second week of trading with a remarkably good performance. Obviously, it's way too early for this to mean anything, but anyway I have a general good feeling about this approach and the fact that several sources of problems experienced in the past have been at least identified and partially removed. Probably, as always, there is still room for tuning and improvements, and we will discover that along the way.

    We are currently at $14.3K PNL (max seen $16.9K) and $33.8K G-L (Gain-Loss). Max maint. margin usage has been $38.9K, while the current figure is $23.8K:

    14.3K / 38.9K * 100 = 36.76 %
    33.8K / 38.9K * 100 = 86.88 %

    in about 17 solar days.

    We have been trading a maximum of 6 instruments (ZW added just today), 3 layers each with a max abs. position of 2 contracts per layer, and enforcing various long/short constraints. Total commissions: $ 313.48 for 128 fills (all lmt orders).

    PNL_12.png

    Code:
     - Current values (received on: Fri 25 Sep 2015 23:46:10:883 [ Fri 25 Sep 2015 17:46:10:883 edt ]) -
    
    AccruedCash                         0.00 USD                      [Min: 0.00, Max: 0.00]
    AccruedDividend                     0.00 USD                      [Min: 0.00, Max: 0.00]
    BuyingPower                10,105,025.03 USD                      [Min: 9,971,782.43, Max: 10,175,058.60]  (6.70 x 1,508,582.19)
    FullAvailableFunds          1,508,582.19 USD                      [Min: 1,485,620.10, Max: 1,526,258.79]
    FullExcessLiquidity         1,515,753.75 USD                      [Min: 1,495,767.36, Max: 1,526,258.79]
    FullInitMarginReq              31,057.80 USD                      [Min: 0.00, Max: 49,863.00]
    FullMaintMarginReq             23,886.24 USD                      [Min: 0.00, Max: 38,930.40]
    NetLiquidation              1,539,639.99 USD                      [Min: 1,522,138.85, Max: 1,541,957.06]
     
    Last edited: Sep 25, 2015
    #38     Sep 25, 2015
  9. Nice morning. I just added 2 layers for NGZ5 (Henry Hub Natural Gas). A layer was already under watch so we just "clone" it with tickdata and set the (long/short) position constraints:

    NG_1.png

    PNL curve still looking great:

    PNL_13.png

    Remember that whenever you are fearing gaps during weekend or holidays, you can simply put all the layers in "manual" mode (= suspension of autotrading) and set an "offsetting" order on a manual layer to flatten the overall position. Clearly, this will be undone when mkt reopens. This way we can "suspend" and "resume" our games, without loss of trading information.
     
    Last edited: Sep 28, 2015
    #39     Sep 28, 2015
  10. This morning, we got some DD, mostly due to ES going down and having mostly long players open.

    PNL_14.png

    I am noticing here some little issue with the hedging mechanism, due to to the small size of the positions. In particular, since we size the hedging orders as a fraction of the opposite-side open players, this is a bit problematic when the side to hedge has just size 1 or 2 contracts (and we are actually limiting the max exposure on a layer to 2 "packets").

    This problem clearly goes away (that is, does not show) with ETFs because sizes are usually much larger than that, and it makes sense to compute a fraction of them. Here instead, where the sizes are so small (1-2), there is some issue with sizing the hedging players, and this is also the reason why the local changes in the PNL curve tend to be not very smooth but quite "steep". Clearly, the larger are the packet size we consider (for instance 10 contracts instead of just 1, the smoother and gradual the hedging action can work).

    I am currently thinking how I can improve this part when small packets are involved. Simulations show that simple rounding or assuming a minimum order of 1 (when the order required comes out to be a fraction of 1) won't work, because it would cause excessive (in statistical terms) stopping action on a layer, if done systematically.

    In the meantime I have also added a pair of layers of NQZ5 (which, of course, has large positive correlation with ES).
     
    Last edited: Sep 29, 2015
    #40     Sep 29, 2015