Cointegration-/Pairs-Trading

Discussion in 'Trading Journals' started by TopFroxx, Nov 24, 2013.

Thread Status:
Not open for further replies.
  1. TopFroxx

    TopFroxx Well-Known Member

    Joined:
    Jul 13, 2013
    Messages:
    504
    Hi everyone,

    thought i'd start a journal of my semi-automated strategy. so why should it be interesting to journal something that is (more or less) automated? i'll come to that.

    maybe first a little bit about myself. i am a 27 year old phd student from germany and have been trading for about 3 years. i have not traded the whole 3 years, more like 1 1/2 of it, with the last 12 months being the main period of my trading experience. like most here i am also a student of ict, although i think i am not as closely following him as the majority on here. but this kind of manual trading will not be part of this thread, at least not directly.

    so a few words about the strategy:
    during the last two months or so i've developed a quantitative strategy. it is based on the concept of "cointegration". it basically just means, that if two pairs (or more commonly two stocks) are cointegrated, then the spread (difference) between the price movements of those two is mean reverting. a simplified example of how to trade this could be if you found two cointegrated pairs (statistical evalutation using a CADF-test for example) and the spread has widened to a certain amount, then you could "short" the spread. this is done by going long the one pairs and shorting the other pairs in a certain ratio. a typical target would be the closing of the spread, so a spread of 0.

    anyhow, dont want to go into much detail about this. but based on this concept i've developed a strategy that trades 13 pairs (the main ones). i download daily data once a day (duh), and let matlab do its calculations. then once a day i update my portfolio positions (given matlab tells me to change something).
    i've backtested this strategy over the past 12 years and the BACKTEST! results look quite promising. why do i emphasize the word "backtest", well just because it worked in the past doesnt mean it will in the future. what gives me hope though is that 12 years of daily data is quite a lot and also we've had some turbulent times in those years that this strategy survived.
    also i have been forward-testing (live-testing) it for about 6 weeks now and the results are even above the historical average (currently up 24% with 7.4% max drawdown). only time will tell if i really found something of value.

    sooo, after all that, why this thread? isnt it boring to just talk about positions matlab spits out? well, i modified the execution of this strategy, which makes it only semi-automated. i give myself the right to scale in and out of the positions that the computer tells me to take. so far i have scaled out to 0.8 exposure and scaled in up to 1.5 times of the original positions. now you can ask, but how could you possibly determine when to scale in and out with a portfolio of 13 different pairs? first i can and will only change the exposure if at least 70% of the whole portfolio positions can be explained by a maximum of 2 pairs. for this i aggregate each currency (not pair) and match the ones with the biggest position value, giving me one or two currency pairs. now this is where the "indirect" part of ict trading and the whole reason for this thread comes in. i look at the charts of those one or two pairs and try to determine good times to increase or decrease my overall portfolio position.

    what i love about this method is that i have my "bias" given to me by the numbers but at the same time i can use my understanding of the market. also i cant get kicked out by short term fluctuations hitting my SL. forgot to mention: i dont use a fixed set stop loss for my positions with this strategy. i know, i know, you will say this is bad. but with pairs trading you have a more or less hedged position (it should be like that, that's the whole point). i am not saying that there is no risk or not even small risk with this method. it is very risky! BUT: over the past 12 years this strategy had a maximum drawdown of 46% and never came close to a margin call. also i am not using no SL at all. within the calculations of my positions i have set a stop loss for the spread. this means if the spread blows up and it becomes less likely the pairs are any longer cointegrated i will get out of that position, at the end of the day when the new calculations are done! so i have more or less a daily SL, not an intraday one.

    in this thread i will post if/when i have one or two pairs that make for at least 70% of my overall portfolio and then if/when i am increasing/decreasing my exposure. i will try to post a chart every now and then.

    to start things off: attached you find the backtest performance chart. 1000euro starting capital and no increase in positions (which should normally be done with growing capital). with proportional increase in positions the charts will look like crap because the scaling is so bad that you cant see the first half of the period (only as a flat line), thus this chart. what you can also see is that there is a period of about 1 1/2 years near the end with a pretty much flat equity curve, just some sideways action. i hope we dont get a period like that again, but at least it is just flat and not downward sloping ;)

    currently i have 2 pairs that make more than 70% of my portfolio, namely USDJPY long and EURCHF long. my current scaling factor is 1.15, so i am at some moderate increased risk at the moment. will scale back a bit before tomorrow LO, since USDJPY did quite a good job and is at marked resistance. would then scale back in on a retracement to 100.50ish. EURCHF is currently at strong support, but i am not too sure about that one and also the UJ position is a bit bigger than the EURCHF position, so scaling out is my preferred strategy at the moment.

    that's it from me for now, if you have suggestions or questions, feel free :)

    cheers,
    stefan
     

    Attached Files:

  2. jack

    jack Administrator Staff Member

    Joined:
    Mar 29, 2013
    Messages:
    2,368
    Your forward test results are nice so far.

    I'm very interested in stat-arb, cointegration, style strategies... not just in forex, but in equities as well.

    Specifically about FX though, I've observed lot of people attempting to spread currency pairs that end up just creating a synthetic spread without them realizing it... a common example being spreading the GBP/USD against EUR/USD, which basically leaves you with a EUR/GBP synthetic pair that could have been traded much cheaper by executing on the EUR/GBP directly. And many realize that common currency crosses end up being a lot harder to trade than they appear.

    (I see you're currently in pairs that don't mix like this, if I read your post correctly..)

    Which other pairs (outside of USD/JPY and EUR/CHF) do you trade like this?
     
  3. TopFroxx

    TopFroxx Well-Known Member

    Joined:
    Jul 13, 2013
    Messages:
    504
    hey jack, thanks for the reply!
    cointegration style trading has its roots in equities. although i trade it in forex i think it is better suited for equitites.
    the thing about creating synthetic crosses: it is not that easy. one lot eurusd long and one lot gbpusd short do NOT create one lot of eurgbp long position. i have tried that. especially i have tried to merge positions to decrease spread costs and increase profitability (btw. all results, also the backtest chart, include spread (taken from oanda)). this did not work. merging positions does not leave me with the exact exposure to the currencies that i want and that was intended by the strategy. i have even contacted a very sophisticated quant trader that has also confirmed, that merging positions, especially in a portfolio context, is not easy at all. he said i basically have to trial and error and see how different merging techniques will influence the profitability of the strategy. the decreased costs on the one hand and the possibly worse overall portfolio on the other. in the end there was no merging technique that improved performance.
    so yes, i have positions that could be merged in general (e.g. eurusd short and eurchf long currently), but as i said, the benefits dont outweight the costs in this case.

    the pairs of my portfolio are:
    EU,UJ,UCHF,GU,UCAD,EG,EJ,ECHF,AU,GJ,CHFJ,GCHF,NU

    i just realized maybe i wasnt clear. i am currently not only trading uj and eurchf. i have positions in all the 13 pairs! it is just that a synthetic uj (all usd longs vs all yen shorts aggregated) and a synthetic eurchf (all euro longs vs all chf shorts aggregated) make more than 70% of the portfolio.

    ok, now back to the scaling factor. as i said in my earlier post i wanted to scale back to 1 before LO today and i did. as a nice surprise uj and echf both made quite some moves for a sunday night and gave me some extra profit. still think the picture looks good so i keep the factor at 1 and not less. i will scale back in to 1.1 on a pullback to 101.50ish if i am at the charts. possibly increase to 1.25 at the noted 100.50. dont really have the time today because i will be in a meeting.

    cheers,
    stefan
     
  4. TopFroxx

    TopFroxx Well-Known Member

    Joined:
    Jul 13, 2013
    Messages:
    504
    also i forgot to mention: i am an intraday trader. most of the times i will scale up and back down within 24 hours, sometimes up to 48 hours but that doesnt happen too often. my manual ict style trading is the same and that is what i feel comfortable with. it can happen that i scale up my whole portfolio and then less than an hour later i scale it back down because the "main pair" did its 20-50 pip move.
     
  5. Tansen

    Tansen Well-Known Member

    Joined:
    Jun 6, 2013
    Messages:
    888
    Wanted to post this yesterday but I fell asleep
     

    Attached Files:

  6. TopFroxx

    TopFroxx Well-Known Member

    Joined:
    Jul 13, 2013
    Messages:
    504
    i want to like this more often. hahahhaha :-D
     
  7. TopFroxx

    TopFroxx Well-Known Member

    Joined:
    Jul 13, 2013
    Messages:
    504
    scaled up to 1.1 since uj reached the noted 101.50 level
     
  8. TopFroxx

    TopFroxx Well-Known Member

    Joined:
    Jul 13, 2013
    Messages:
    504
    maybe for clarification, you can find my current allocation attached. the numbers are units. fortunately oandas web application based trading allows to trade with units and not lots. thus i can take the portfolio allocation matlab tells me to take with little equity and high precision.
     

    Attached Files:

  9. TopFroxx

    TopFroxx Well-Known Member

    Joined:
    Jul 13, 2013
    Messages:
    504
    just scaled back to 1. picture is looking unclear to me. still have a positive bias on uj, but will wait for a better moment to scale back up. might post a picture later today, no time atm.
     
  10. Tansen

    Tansen Well-Known Member

    Joined:
    Jun 6, 2013
    Messages:
    888
    I've been watching USD/JPY for a while now mainly because the yen has huge long positions vs their short. Just wondering when their going to release it.
     
  11. TopFroxx

    TopFroxx Well-Known Member

    Joined:
    Jul 13, 2013
    Messages:
    504
    sacling factor is 1 still. did not get a retracement on uj, but well, not getting a retracement with this strategy means that i still make money because i am always invested ;)
    my allocation changed a bit over the last two days. about 50% uj long now and 25% e/g long. looking for 101.50 uj to scale back up, e/g i am not so sure about.
     
  12. TopFroxx

    TopFroxx Well-Known Member

    Joined:
    Jul 13, 2013
    Messages:
    504
    just had another look at the charts and scaled back to 0.9. uj is at 102.20 resistance and it looks like a drop to at least 101.70 seems probable. moreover its holiday and i dont expect much action until monday. if it moves at all it will probably retrace a bit. some profit taking for the end of the month maybe. might be a bit greedy to scale back now, but we will see.
     
  13. TopFroxx

    TopFroxx Well-Known Member

    Joined:
    Jul 13, 2013
    Messages:
    504
    scaled back up to 1 earlier. us bonds falling, expecting a stronger dollar today. gbpusd higher high, eurusd lower high. also divergence with usdx. eurgbp at marked support.
     
  14. TopFroxx

    TopFroxx Well-Known Member

    Joined:
    Jul 13, 2013
    Messages:
    504
    good day, uj rallied quite a bit while eg ended BE. scaling back to 0.9 since uj is near old highs. also since it's a week with quite a lot high impact news (especially NFP), there will be a lot of volatility to possibly scale back up on a pullback to 102.60, 101.90.
     
  15. TopFroxx

    TopFroxx Well-Known Member

    Joined:
    Jul 13, 2013
    Messages:
    504
    dnt barrier option at 103.25 breached, scaled back to 0.8 half an hour ago and secured some profits. chart looks like a pullback to 102.70 is imminent.
     
  16. TopFroxx

    TopFroxx Well-Known Member

    Joined:
    Jul 13, 2013
    Messages:
    504
    102.70 reached, scaled back up to 0.9
     
  17. TopFroxx

    TopFroxx Well-Known Member

    Joined:
    Jul 13, 2013
    Messages:
    504
    scaled up to 1.1 at 102.50 yesterday. missed the drop to 102, wasnt at the charts. otherwise would have increased further
     
  18. TopFroxx

    TopFroxx Well-Known Member

    Joined:
    Jul 13, 2013
    Messages:
    504
    scaled back to 1 at 102.80. still think we are going up, but dont want to be greedy and just secure some profits. also possibility (but not that likely imo), that we bounce back down. lows 102.20 area got taken out and price currently at short OTE. enough reason to scale back to 1, but not enough for more.
     
  19. TopFroxx

    TopFroxx Well-Known Member

    Joined:
    Jul 13, 2013
    Messages:
    504
    ok, so scaling back was definitely the right move and we really saw a decent retrace from 102.80. scaled up to 1.15 at 102.10 and up to 1.25 at 101.80. at the same time my second biggest position (E/G) went really well and covered all the potential losses from uj. overall i am in the green for this week, without scaling in and out i would be slightly in the red. (when i do my daily calculations i let matlab calculate the "live" performance as well)

    looking to take some partial profits before NFP today. dont want to go into NFP with increased risk.
     
  20. TopFroxx

    TopFroxx Well-Known Member

    Joined:
    Jul 13, 2013
    Messages:
    504
    and i did. scaled back to 1.1 at 102.20, just 5 minutes prior to NFP. strong numbers, uj went up, scaled back to 1 at 102.80. overall a very good week, especially the scaling part worked nicely.
     
Thread Status:
Not open for further replies.

Share This Page