tag:blogger.com,1999:blog-35364652.post7328811305218889285..comments2022-05-21T06:14:30.518-04:00Comments on Quantitative Trading: Extracting roll returns from futuresErnie Chanhttp://www.blogger.com/profile/02747099358519893177noreply@blogger.comBlogger38125tag:blogger.com,1999:blog-35364652.post-48245949589956821292020-05-30T17:04:20.982-04:002020-05-30T17:04:20.982-04:00Hi Mark,
The two definitions are almost equivalent...Hi Mark,<br />The two definitions are almost equivalent, and practitioners often use one or the other to determine backwardation.<br /><br />For e.g. for WTI crude oil, the spot price is determined by the front contract, not the physical oil price since that is a non-unique, OTC price.<br /><br />For many other contracts that have spot price that from the front contract price, it is still more difficult to obtain the real-time spot price for the underlying physical than for the front contract. Hence most traders use the spread between front and back contracts to determine backwardation.<br /><br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-54581346781504986322020-05-30T10:52:50.969-04:002020-05-30T10:52:50.969-04:00Hi Ernie, I am confused about the sentence in your...Hi Ernie, I am confused about the sentence in your 'Algorithmic Trading' book:<br />'If the contracts are in backwardation, meaning the near (close to expiring)<br />contracts have higher prices than the far contracts, then the roll returns<br />will be positive; otherwise if the contracts are in contango, then the roll<br />returns will be negative.'<br />I thought the definition of backwardation and contango were different. It seems that you just gave the definition of inverted and normal markets respectively. I thought contango/backwardation meant that the forward price is above/below the spot price... my confusion is of course due to my lack of knowledge.Marknoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-53005606232309434292018-02-20T09:36:29.724-05:002018-02-20T09:36:29.724-05:00Hi,
There is no need to substitute the sum functio...Hi,<br />There is no need to substitute the sum function with nansum. There is an option called 'omitnan' in the sum function.<br /><br />Yes, 60% cum return over 2 years is quite possible in a backtest. There is a lot of in-sample fitting when we backtest. If a strategy didn't do well in backtest, we wouldn't even be talking about it. That in itself is in-sample fitting.<br /><br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-46547130164775620532018-02-20T08:39:40.864-05:002018-02-20T08:39:40.864-05:00Ok, I finally made all changes and substituted the...Ok, I finally made all changes and substituted the normal "sum" function with "nansum" and made returns computations step by step.<br />Anyway...is it normal that I have a cumulate return (over period you indicated, 29 July 2010 -8 May 2012) of almost 60%????<br />I checked all steps and computations and it seems ok.<br />Than I checked your APR and Sharpe ratio results and I found out that they perfectly fit mine. However...it matches your "hedge ratio [1 1] option"(I thought I was following the "no hedge" oprion).<br />Anyway, as I can't check your cumulate returns, can u confirm that my 60% is ok with your results?<br />ThanksAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-38577973746650346252018-02-16T09:44:29.403-05:002018-02-16T09:44:29.403-05:00Hi,
The denominator represents the gross market va...Hi,<br />The denominator represents the gross market value of the position. It is not the spread. It is the sum of the absolute value of the market values of each side of the spread.<br /><br />Did you get positions==0 everyday? If so, there must be something wrong in your revision of the code. I certainly get non-zero positions.<br /><br />Yes, we buy both ES and VX, or sell both.<br /><br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-61019155511202944902018-02-16T09:35:01.645-05:002018-02-16T09:35:01.645-05:00Hi Mr.Chan,
I was following your strategy on roll ...Hi Mr.Chan,<br />I was following your strategy on roll returns in the VX-ES spread.<br />I'm not sure about the meaning of this line of code:<br />"ret=smartsum(lag(positions).*(y-lag(y, 1)), 2)./smartsum(abs(lag(positions.*y)), 2)-...<br /> onewaytcost*smartsum(abs(positions.*y-lag(positions.*y)), 2)./smartsum(abs(lag(positions.*y)), 2);"<br /><br />If I'm not wrong, you compute the difference between VX(T) -VX (T-1) and multiply this for the signals of the "position" matrix previously built. Then, for every day, you calculate the daily P&L (sum VX and ES return for day T).So far so good.<br />Then you subtract the commission costs (onewaytcost=1/10000).Ok.<br />What I don't understand is the denominator used: I was expecting to divide the daily spread for the previous day price but I read "smartsum(abs(lag(positions.*y)), 2)"....why???<br /><br />In fact, unlike previous codes (that I managed to update to new Matlab functions), this time, every day, I have returns=0 (and so cumulative return is =0).<br />Last question about this strategy: As VX and ES are negatively correlated, this time we BUY (or SELL) both of them. So buy ES AND buy VX at the same time (or sell both of them). Am I right?<br />ThanksAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-59928926878493534882015-11-29T15:17:08.595-05:002015-11-29T15:17:08.595-05:00Hi VHanded,
We can't really tell whether the p...Hi VHanded,<br />We can't really tell whether the period of momentum or random walk will be temporary or permanent unless you have some fundamental understanding of the pair. In any case, one should gradually decrease leverage in this situation.<br /><br />It isn't really necessary to update half life every day. Probably monthly update is enough.<br /><br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-88051896232065413662015-11-29T12:02:11.962-05:002015-11-29T12:02:11.962-05:00Thanks for your reply, and sorry for this late rep...Thanks for your reply, and sorry for this late reply. What is wise to do if things undergo period of momentum or random walk? And is it wise to calculate half life everyday? <br /><br />ThanksVHanded Cheepenghttps://www.blogger.com/profile/04362822269331367249noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-9760397437321975872015-03-27T04:28:30.887-04:002015-03-27T04:28:30.887-04:00Hi VHanded,
Thank you for your kind words.
The le...Hi VHanded,<br />Thank you for your kind words.<br /><br />The length of data that halflife calculation needs depends on the halflife itself (the longer the halflife, the more data needed), as well as on the stability of the mean-reversion. Some spreads undergo a period ("regime") of momentum or random walk that leads to negative or infinite halflife during such periods. So it becomes necessary to use a large amount of data to find its long-term behavior.<br /><br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-51316620394634179782015-03-27T04:13:51.294-04:002015-03-27T04:13:51.294-04:00Hi EC,
Thanks for your wonderful book! I have a q...Hi EC,<br /><br />Thanks for your wonderful book! I have a question: for your calendar spread strategy to profit from roll return, we need to calculate the half life using gamma. In my backtest program, I was getting negative halflife at beginning, or very extreme large number, like 2000.<br /><br />Only to realize, the amount of gammas that I feed into the halflife calculation is too little (a year or 252 days only). I increased the gammas count to 1000 using a lot more training data, then only the halflife start to make sense.<br /><br />Assuming the halflife will not be constant, I modified your matlab code to using an updating halflife for everyday, and the Sharpe ratio and APR increased slightly for the same period.<br /><br />I would like to know, do half life calculation always require this much of data? Since my training program is having problem referring to this much of expired contract.VHanded Cheepenghttps://www.blogger.com/profile/04362822269331367249noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-24972375931352025492013-11-14T20:43:03.100-05:002013-11-14T20:43:03.100-05:00Hi CVC,
The only way I know how to trade the mean-...Hi CVC,<br />The only way I know how to trade the mean-reversion of correlations is "dispersion trading" See http://www.math.nyu.edu/faculty/avellane/Lecture10Quant.pdf<br /><br />Ernie Ernie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-33080760064303547372013-11-14T17:58:25.292-05:002013-11-14T17:58:25.292-05:00Hi Ernie,
Thanks for your blog, highly appreciate...Hi Ernie,<br /><br />Thanks for your blog, highly appreciated.<br /><br />You often write about correlated/cointegrated stocks and mean reversion strategies. I´ve always wondered if this can be turned around. E.g. suppose that stock A and B historically don´t correlate at all - whenever their correlation coefficient is > 0,5 or < -0,5 it will most likely turn around and revert to 0. Could this be a basis of a strategy? Or probably not possible to model such phenomenon with orders in A and B? <br /><br />Let me know your view. Thanks!CVCnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-9939549282904344452013-11-14T17:56:23.366-05:002013-11-14T17:56:23.366-05:00Hi Ernie,
Thanks for your blog, highly appreciate...Hi Ernie,<br /><br />Thanks for your blog, highly appreciated.<br /><br />You often write about correlated/cointegrated stocks and mean reversion strategies. I´ve always wondered if this can be turned around. E.g. suppose that stock A and B historically don´t correlate at all - whenever their correlation coefficient is > 0,5 or < -0,5 it will most likely turn around and revert to 0. Could this be a basis of a strategy? Or probably not possible to model such phenomenon with orders in A and B? <br /><br />Let me know your view. Thanks!CVCnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-26148499504616561532013-03-11T11:07:49.885-04:002013-03-11T11:07:49.885-04:00Hi Amit,
Glad to hear you like my book.
Algo trad...Hi Amit,<br />Glad to hear you like my book.<br /><br />Algo trading is already quite popular in India, and both individuals and institutions have been practising it.<br /><br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-83622673093946080922013-03-11T10:09:44.838-04:002013-03-11T10:09:44.838-04:00Respected Sir,
Let me first congrats & thank...Respected Sir,<br /><br /><br />Let me first congrats & thank you for your wonderful posts & very informative & extremely useful book (i am currently reading) .sir my name is amit,from india, i am a nanotech R&D.professional,i also wanna do algo trading,sir whether is it applicable for india as well? please guide .your little guidance will change the life of many layman like me.<br /><br /><br />sir i can offer free on/offline assistance to any assignment according to my skills,if you needed any time.<br /><br /><br /><br />Warm Regards<br />AMIT(bigfm987@yahoo.in)AMITnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-58979285581286124412012-09-22T07:32:12.182-04:002012-09-22T07:32:12.182-04:00Jim,
Good to hear that!
Thanks for the heads-up.
E...Jim,<br />Good to hear that!<br />Thanks for the heads-up.<br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-55370282436127252562012-09-21T21:16:26.876-04:002012-09-21T21:16:26.876-04:00The strategy has continued to perform; I believe i...The strategy has continued to perform; I believe it did very well when the curve was in backwardation in 2011. jim campasanohttps://www.blogger.com/profile/14011260006981701063noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-59971091545351899622012-07-29T16:34:54.410-04:002012-07-29T16:34:54.410-04:00Hi Anon,
I don't currently trade FAZ.
Even tho...Hi Anon,<br />I don't currently trade FAZ.<br />Even though ETFs mean revert slowly,<br />there can still be profits trading them intraday, if your execution strategy is sophisticated enough.<br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-67084543827074578542012-07-29T08:08:08.056-04:002012-07-29T08:08:08.056-04:00Hi Ernie,
May I ask if you trade "FAZ"?...Hi Ernie,<br /><br />May I ask if you trade "FAZ"?<br /><br />Moreover, how do we do Day trading for pairs trading?<br /><br />It seems it takes some time for pairs to mean-reverting.<br /><br />Thank you.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-28872509635642554932012-07-24T17:08:16.524-04:002012-07-24T17:08:16.524-04:00Hi Anon,
I guess the minimum account size at Lime ...Hi Anon,<br />I guess the minimum account size at Lime depends on how much commission you generate.<br /><br />As a ballpark estimate, I would say $500K-$1M.<br /><br />But note that the colocation fee is about $2K/month in order to access the direct feeds.<br /><br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-53351044326463562652012-07-24T16:59:20.163-04:002012-07-24T16:59:20.163-04:00Hi Ernie,
I do write limit orders for both legs i...Hi Ernie,<br /><br />I do write limit orders for both legs in Java API, but IB real-time quotes almost do not generate z-scores more than 2.<br /><br />It is weird because I find at least 8 good trades per day in my historical backtesting based on just 1 minute bars.<br /><br />However, in real-times paper testing, I get almost no trade signal. Therefore, I guess IB real-time quotes are not consistent with their historical higher frequency data.<br /><br />May I ask usually how big account Lime Brokerage require?<br /><br />Thank youAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-45180745810781550102012-07-24T16:44:31.090-04:002012-07-24T16:44:31.090-04:00Hi Anon,
I hope you used limit orders for this tes...Hi Anon,<br />I hope you used limit orders for this test? IB prices might trigger an erroneous market order filled at poor prices.<br /><br />I don't know if eSignal has lower latency or fewer errors.<br /><br />Lime Brokerage gives you direct access to the exchange feeds: suitable for high frequency trading with latency below 1ms. They do require a bigger account than the average IB account.<br /><br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-23357403812414221212012-07-24T15:42:33.528-04:002012-07-24T15:42:33.528-04:00Hi Ernie,
I agree with you.
I backtest IVV/SPY u...Hi Ernie,<br /><br />I agree with you.<br /><br />I backtest IVV/SPY using 1 minute bars data from IB.<br /><br />I find several (8) trades per day.<br /><br />But when I do paper trading on IB using real-time data feed, I hardly get any buy/sell signals, although I do compute my z-score every second.<br /><br />Is that possible to solve this problem by getting new data feed, such as eSignal?<br />It seems they provide better, faster real-time quotes.<br />Then still use IB as brokers?<br /><br />I guess Lime Brokerage requires bigger capital?<br /><br /><br />Thank you.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-20865687584900070192012-07-24T14:21:51.482-04:002012-07-24T14:21:51.482-04:00Hi Anon,
No, I don't. I am not sure that IB...Hi Anon,<br />No, I don't. I am not sure that IB's data feed is low-latency enough for that type of arbitrage. I would use Lime Brokerage instead.<br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-34408010792300010702012-07-24T09:37:16.564-04:002012-07-24T09:37:16.564-04:00Hi Ernie,
Thank you for reply.
Do you trade intr...Hi Ernie,<br /><br />Thank you for reply.<br /><br />Do you trade intraday IVV/SPY pairs on IB?<br /><br />Thank youAnonymousnoreply@blogger.com