tag:blogger.com,1999:blog-35364652.post1609861677677117721..comments2022-01-18T09:16:21.942-05:00Comments on Quantitative Trading: Out-of-sample test on cointegrating basket of stocksErnie Chanhttp://www.blogger.com/profile/02747099358519893177noreply@blogger.comBlogger26125tag:blogger.com,1999:blog-35364652.post-23513136453104399702011-05-05T07:39:26.634-04:002011-05-05T07:39:26.634-04:00Hi SeanP,
For pairs of ETF's, it is not essent...Hi SeanP,<br />For pairs of ETF's, it is not essential to recompute cointegration every day because their relationships do not change so frequently. Once a month is sufficient. However, for stock pairs, or baskets of ETF's or stocks, they do fall out of cointegration fairly quickly, so daily computation is necessary.<br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-83943757988711480412011-05-05T07:37:11.430-04:002011-05-05T07:37:11.430-04:00Hi Anon,
It is not imperative to set the constant ...Hi Anon,<br />It is not imperative to set the constant offset to the regression to zero, but setting to zero often gives better results out-of-sample because of the reduction of the number of free parameters for fitting.<br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-33510668354511849862011-05-04T10:50:04.426-04:002011-05-04T10:50:04.426-04:00Hi Ernie,
This post is interesting....
Say...Hi Ernie,<br /><br />This post is interesting.... <br /><br />Say if you re-estimated the cointegration relationship everyday. You could do a rolling window estimation (i.e. 3 years or whatever time period works). This way you can assess what is going on with the basket. If you already have an open position you could re-balance it based on the new information about the mean and component weights. <br /><br />Well one hopes that the basket relationship doesnt completely fall apart but by re-estimating the mean and weights everyday you could avoid data fitting problems. Not sure if the added costs of rebalancing would negate the profit potential and make this an unviable trading strategy.<br /><br />I would appreciate your thoughts on this.<br /><br />Thank you.<br /><br />SeanPAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-40215567638938647022011-05-04T10:06:04.781-04:002011-05-04T10:06:04.781-04:00Hi Erinie,
Thank you for the valuable information...Hi Erinie,<br /><br />Thank you for the valuable information on your blog.<br /><br />I had a quick question for you re: basket construction.<br /><br />In the regression is it imperative to drop the constant term? Essentially adding a constant moves the mean to near zero - no? So in that sense a basket may be cointegrated around and bounded by a value far away from zero but by adding the constant allows you to find baskets that could be tradable.<br /><br />I wonder whether by allowing a constant term, the out-of-sample relationship has a greater chance of weakening because you cant take a position in the constant. <br /><br />Appreciate some guidance here. Thank you.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-63662105282084384352010-12-05T09:28:02.384-05:002010-12-05T09:28:02.384-05:00Hi Vanes,
1) Yes and yes, your interpretation is c...Hi Vanes,<br />1) Yes and yes, your interpretation is correct.<br />2) In the table on epchan.com, I specified 1000 shares of XLE against the respective number of shares of its component stocks. You should not trade 1000x this number. Also, XTO is no longer a valid symbol, hence the incorrect closing price.<br />3) I have not tested cointegration of options, mainly because I don't have high quality historical data on options. But as various commentators on my post on options suggest, one should not use options to implement pair trading unless the holding period is very short (< 1 week).<br />4) Yes, but some stocks' options are very illiquid.<br />5) Assuming you have access to unlimited leverage, you should indeed use half-Kelly to figure out your order size. You would need to backtest this strategy and find out the average returns and volatility in order to use Kelly formula.<br /><br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-76616028752256307272010-12-03T22:02:09.258-05:002010-12-03T22:02:09.258-05:00Hi Ernie, thanks for your reply, a continuation to...Hi Ernie, thanks for your reply, a continuation to my earlier question.<br /><br />1. What constitutes 1 unit of the basket? In your live spreads section, you have given the number of shares for each of the 10 stocks in the basket. Is one unit of basket the sum of shares of all 10 stocks? <br /><br />Suppose this sum is 500 and the price of each stock was appx $100, then each unit of the basket will have a price of $50,000?<br /><br />2. If 1 share of XLE is $50 and as given above, 1 unit of basket = $50,000 and we long 1000 units of basket and short 1000 shares of the XLE, the 1000 units of Basket will require a capital of $50,000 x 1000 = $50Million? doesn't sound right.<br /><br />3. If you use options, the co-integration tests done on the equities would not hold anymore since the time series for the options will differ significantly compared to the stocks. In this case, how significant are the co-integration tests between the options on XLE and the underlying stocks?<br /><br />4. You said that you could implement the XLE position as options to boost the return. Could you use options for the stocks in the basket as well?<br /><br />5. If we have a capital of $10 million, how would you choose the trade size on each side? How effective will be Kelly's criterion?<br /><br />Thanks!Vanesnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-2857979276170918472010-11-29T08:46:02.626-05:002010-11-29T08:46:02.626-05:00Hi Vanes,
1) Yes, all the stock components and par...Hi Vanes,<br />1) Yes, all the stock components and parameters in that model are fixed since 2006 when I first created the portfolio. It is not updated and should not be used for live trading -- it is purely for illustration of the method.<br />2) Yes, a multivariate regression was used to find the hedge ratios.<br />3) No, I did not include the code, but you can easily construct it following my detailed steps as outlined in my article posted on the premium content section.<br />Best,<br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-41916208719444157672010-11-28T23:29:16.075-05:002010-11-28T23:29:16.075-05:00Hi Ernie,
I recently subscribed to your blog and...Hi Ernie, <br /><br />I recently subscribed to your blog and like your ideas. I have been looking at this strategy and have a couple questions.<br /><br />1. The live spreads section for XLE strategy contains 4 stocks that are not part of XLE holdings (eg RIG, NE etc). Is it that this spread include previous holdings of XLE and has not be updated in a while?<br /><br />2. Regarding the number of shares for each component in the basket, once you have identified which stocks to choose for the basket using co-integration, how did you figure out the weights for each stock? Did you fit a linear model on the 10 stocks in the basket and then choose the number of shares based on the coefficient of each stock in this linear model?<br /><br />3. Is there any matlab/excel code in your subscription section that sheds light about figuring out the number of shares for each component of the basket?<br /><br />Would appreciate your comments regarding this.Vanesnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-70068343613173157152009-03-01T07:16:00.000-05:002009-03-01T07:16:00.000-05:00Hi David,Even though the stocks are in different s...Hi David,<BR/>Even though the stocks are in different sectors, they may have a relationship that is not immediately apparent. Perhaps it is supplier-customer? Substitutes? If they cointegrate very well, it is worth spending some effort in looking for economic relationships, maybe consulting industry experts.<BR/>ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-36734267125068701902009-03-01T05:35:00.000-05:002009-03-01T05:35:00.000-05:00Hi As a result of following your website and buyin...Hi <BR/><BR/>As a result of following your website and buying your book I have run extensive cointegration tests across lots of stocks.<BR/><BR/>In a suprising number of cases I have found high cointegration, with high critical values, across long time periods for pairs of stocks that are in completely different industries.<BR/><BR/>So from an economic point of view I can't justify trading these pairs since in theory they have nothing in common except being part of the SP500. However, the stats for their cointegration is robust over long periods.<BR/><BR/>Do you have any thoughts on how to approach this type of situation?<BR/><BR/>David<BR/><BR/>PS. Love'd your bookAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-37621477174827090912009-02-10T10:38:00.000-05:002009-02-10T10:38:00.000-05:00Hi anonymous,Cointegration is a long-term phenomen...Hi anonymous,<BR/>Cointegration is a long-term phenomenon and cannot be discovered with a 30 day test period, in my opinion. I recommend at least 1 year.<BR/>ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-50246212729831612012009-02-10T05:57:00.000-05:002009-02-10T05:57:00.000-05:00HiI know this thread is old but hopefully you'll s...Hi<BR/><BR/>I know this thread is old but hopefully you'll see this query.<BR/><BR/>What is your view on the appropriate period to use for a cointegration test?<BR/>I have read other sites that talk about pairs trading and correlation (I know not the same as cointegration). <BR/><BR/>Some authors propose using a back test period equal to what you expect your average future trade length to be.<BR/><BR/>So you might run a rolling cointegration test over say 30 days of data.<BR/><BR/>Is that a good idea or do you like to see a "robust" cointegration holding over a longer period to give you greater confidence going forward.<BR/><BR/>My problem with that is I have run cointegration tests on 1000 days of data and found high cointegration. However, when I re-test on rolling 30 days I get (in some cases) poorer cointegration. So cointegration isn't going to be good for some trade periods.<BR/><BR/>I'm not sure what is the best thing to do?<BR/><BR/>ThanksAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-53192073399453045382007-09-25T21:14:00.000-04:002007-09-25T21:14:00.000-04:00Dear Ernie,I appreciate your prompt response. Ther...Dear Ernie,<BR/><BR/>I appreciate your prompt response. <BR/><BR/>There are way too many issues in any basket trading and you always have to make a choice on what is worth the time spent, and as far as any Statistical Arbitrage strategy is concerned, there is no perfect answer to anyone of them.<BR/><BR/>Your posts are interesting and thought provoking. And given that you have a decent population reading and replying to them, it makes it worth reading.<BR/><BR/>Again, thanks.<BR/><BR/>- Natty VirkAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-22100556509453663122007-09-25T20:44:00.000-04:002007-09-25T20:44:00.000-04:00Dear Natty,Thanks again for your elucidation. Here...Dear Natty,<BR/><BR/>Thanks again for your elucidation. Here are my thoughts:<BR/><BR/>1) Though I have used a fixed basket of stocks against the ETF in my cointegration analysis, I should have updated the basket every month based on the historic ETF composition at the time, as well as using the latest price data. (This is what I did for my pairs portfolio.) I skipped this step because of the lack of historical ETF composition data. Going forward, one should certainly update this basket this way, as you have suggested.<BR/><BR/>2) The cash component is only about 3% of the market value of XLE. Furthermore, this percentage does not fluctuate very much. Therefore I doubt it will introduce much tracking error in the cointegration analysis. <BR/><BR/>3) In any backtest analysis, one always use dividend-adjusted historical prices. Therefore, the historical stock price will not suffer a drop on the ex-date. Going forward, one should update the basket composition on the ex-date.<BR/><BR/>I haven't written anything about technical analysis because I am not a believer in this technique.<BR/><BR/>ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-88504916048655046382007-09-25T18:59:00.000-04:002007-09-25T18:59:00.000-04:00Dear Ernie,My apologies, I wasn't very clear in my...Dear Ernie,<BR/><BR/>My apologies, I wasn't very clear in my post.<BR/><BR/>When I said forward looking analysis, what I meant was the following :<BR/><BR/>1) ETF has been rebalanced at least 20 times in last 5 years hence the returns would have been different if you were holding todays composition of stock for last five years than if you were holding the ETF for last five years. And, theoretically, going forward you are going to hold todays composition.<BR/><BR/>2) ETF has dynamic cash component that causes tracking error, False tracking error.<BR/><BR/>3) ETF pays dividends quarterly where as the underlying stocks pay dividends at different times. ETF's value does not change when a stock goes ex-dividend but the stock decreases in value and vice versa, another cause of false tracking error.<BR/><BR/>So it means that if you hold all the stocks in the current composition of ETF and back test for tracking error, you will perhaps have a huge tracing error. <BR/><BR/>Now, if you use some combination of stocks to track this ETF using its historic returns, all you are doing is backward looking analysis. <BR/><BR/>So, how to tackle this problem.<BR/><BR/>1) Take today's composition of ETF. Create a synthetic return series using todays # of stocks and their respective historic returns divided by its creation unit. This also removes tracking error due to dividend mismatch and cash component.<BR/><BR/>2) Create a tracking basket to track this synthetic return cause going forward this will be the ETF composition (at least for a quarter). Re balance this basket every time ETF re balances.<BR/><BR/>This also eliminates the need to know historic composition of ETF.<BR/><BR/>Please feel free to comment and/or email me at QuantArtistic (AT) gmail (DOT) com <BR/><BR/>Also, i was wondering if you have any posts on technical analysis.<BR/><BR/>Thanks<BR/><BR/>- Natty VirkAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-37315712312614443832007-09-25T08:42:00.000-04:002007-09-25T08:42:00.000-04:00Dear Natty,Thank you for your thoughtful comments....Dear Natty,<BR/><BR/>Thank you for your thoughtful comments. I agree with you that the analysis would be made more solid if I had done it with historical components of XLE. Unfortunately I could not find such data. If you know of such a data source, please share with us!<BR/><BR/>ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-28037287802525059502007-09-24T22:51:00.000-04:002007-09-24T22:51:00.000-04:00Ernie,That is a nice piece of work. But please don...Ernie,<BR/><BR/>That is a nice piece of work. <BR/><BR/>But please dont forget that ETF's have a cash component and it inevitably leaves you with a statistical tracking error.<BR/><BR/>Plus when you try to do a co-integration analysis you are actually ignoring the fact that *unless* you re-create the history of ETF by using current composition you will always have huge out of sample tracking error. This due to the fact that your current composition is also trying to fit the curve to the historical changing composition.<BR/><BR/>In all, I think its a nice piece of work but needs a little more forward looking approach<BR/><BR/>- Natty VirkAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-91937591540089108482007-04-30T09:10:00.000-04:002007-04-30T09:10:00.000-04:00Max,You can find references to various articles in...Max,<BR/><BR/>You can find references to various articles in my previous post http://epchan.blogspot.com/2007/02/in-looking-for-pairs-of-financial.html<BR/><BR/>Best,<BR/>ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-57682362658422412832007-04-29T14:31:00.000-04:002007-04-29T14:31:00.000-04:00Ernie,Thanks for the fast comments on my questions...Ernie,<BR/><BR/>Thanks for the fast comments on my questions. <BR/><BR/>Indeed (with IB) you trade at a discount compared to many brokers in Germany (or elsewhere). <BR/><BR/>Where can I find a copy of the paper you mentioned or do you posses a copy that you can send me?<BR/><BR/>In (4) I was more thinking about how XLE is calculated. There is a huge difference between Dow (price weighted) and S&P (weighted average market capitalization). However, since it tracks s&p energy it should be market cap.<BR/><BR/> Best, <BR/>MaxAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-75355405312577951722007-04-29T11:29:00.000-04:002007-04-29T11:29:00.000-04:00Max,Thank you for your interest in my article.Trad...Max,<BR/><BR/>Thank you for your interest in my article.<BR/><BR/>Trading this basket of 10 stocks vs 1000 shares of XLE costs only $13.25 one way, if your commission is the same as mine (0.5 cent/share) at Interactive Brokers.<BR/><BR/>1) The components of this basket are not determined arbitrarily -- they are based on the process described in a published article as well as my own research. Basically, we pick N number of stocks that historically has the highest cointegration likelihood with XLE.<BR/>Therefore, we can't include XOM or CVX just because they constitute the highest weights in XLE.<BR/><BR/>2) The weights, expressed as number of shares, are determined by a multivariate regression with the prices of XLE. I assume 1,000 shares of XLE on one side.<BR/><BR/>3) http://www.sectorspdr.com/spdr/index.cfm?story=composition&symbol=XLE<BR/>lists all XLE components. But I am not sure about historical components.<BR/><BR/>4) According to http://www.sectorspdr.com/spdr/index.cfm?story=disclosure&symbol=XLE,<BR/>XLE should track the energy index in the Select Sector Indexes. <BR/><BR/>ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-62573386295254406482007-04-29T10:54:00.000-04:002007-04-29T10:54:00.000-04:00http://www.etfconnect.com/select/fundpages/etf_fun...http://www.etfconnect.com/select/<BR/>fundpages/etf_funds.asp?MFID=50829Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-88725796623080149732007-04-29T10:53:00.000-04:002007-04-29T10:53:00.000-04:00Ernie, Nice work and points you are making. If you...Ernie, <BR/><BR/>Nice work and points you are making. If you are planning on creating a basket of 10 stocks and trade it against XLE you might be wiped out (commissions). <BR/><BR/>1. Why aren't you trying to take into consideration just <BR/>Exxon Mobil Corp.XOM 21.7% <BR/>Chevron Corp. CVX 13.0% <BR/>Conocophillips COP 9.1%<BR/><BR/>2. How did you come up with the "weights" each asset has in your basket? Something like... <BR/>XLE = w1*XOM+w2*CVX+w3*COP... where sum(wi)=1? <BR/><BR/>http://www.etfconnect.com/select/fundpages/etf_funds.asp?MFID=50829<BR/><BR/><BR/>3. Do you know a web page where you can look at historical components of XLE? <BR/><BR/>4. What type of "index" basket is XLE? I'm desperately looking for a prospect (computation) of XLE. <BR/><BR/>Thanks for any inputs you might have,<BR/><BR/>MaxAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-80616025202180329262007-04-28T12:40:00.000-04:002007-04-28T12:40:00.000-04:00Checked back and just wanted to respond to this od...Checked back and just wanted to respond to this odd comment:<BR/><BR/><I>"L, you can kill any trading idea by your Scientific Mind..."</I><BR/><BR/>Huh? It is quite obvious that Ernie himself applies a "Scientific Mind" to his ideas. I am merely continuing in the same vein. I wanted to highlight how dangerous it might be to believe a trading idea that's not cross-validated. It is rather <I>easy</I> to come up with a trading idea that looks good in-sample -- simply by construction. We all know about "spurious regression", after all. If the synthetic asset is not substantially mean-reverting out of sample, it is very questionable whether there is an "A) -> B)" process that is profitable.<BR/><BR/>I hope you agree that it is only consistent to apply the same quantitative metrics out of sample that were used to build the idea in-sample.<BR/><BR/>LAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-44376928907438546122007-04-26T16:27:00.000-04:002007-04-26T16:27:00.000-04:00L, Sure, if you wait until the spread reverts back...L, <BR/>Sure, if you wait until the spread reverts back to exactly zero before you exit, you might have to wait forever. But I don't think any real trading strategy would do that. What I discuss here in this blog is not a complete trading strategy: it is a trading idea that can be developed into a complete trading strategy. On one hand, A) there is a cointegration test; on the other hand, B) there is an implementation of a trading strategy based on the cointegration test. It is not that simple to go from A) to B), otherwise every econometrician will become a trader. As every trader know, real trading result is always inferior to backtest result, therefore a sensible trading strategy need to take that into account.<BR/><BR/>Thanks for the discussion!<BR/>ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-53607384555730640272007-04-26T16:02:00.000-04:002007-04-26T16:02:00.000-04:00I guess trading strategy is all about plausible id...I guess trading strategy is all about plausible idea---not proven idea. Anyway it is a game. L, you can kill any trading idea by your Scientific Mind...Anonymousnoreply@blogger.com