tag:blogger.com,1999:blog-35364652.post7899335765867782241..comments2024-04-09T09:36:26.041-04:00Comments on Quantitative Trading: Index arbitrage with XLEErnie Chanhttp://www.blogger.com/profile/02747099358519893177noreply@blogger.comBlogger41125tag:blogger.com,1999:blog-35364652.post-47525143995099101252018-01-25T11:07:05.789-05:002018-01-25T11:07:05.789-05:00Hi Beppe,
Again, this has nothing to do with the v...Hi Beppe,<br />Again, this has nothing to do with the version of Matlab you are using. You need to download and install the free package from spatial-econometrics.com and use the johansen function there in order to get identical results as mine.<br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-20428747760596629822018-01-25T09:00:20.129-05:002018-01-25T09:00:20.129-05:00Hi,
I'm following your code IndexArb.m (pg. 9...Hi,<br /><br />I'm following your code IndexArb.m (pg. 97-98 book "Algorithmic Trading:winning strategies..."<br /><br />I'm using Matlab 2016 so I had to change ONLY the code line about johansen test.<br />I've followed the same model you suggested (include intercept but no trend and lags=1).<br />So I substituted your code : "results=johansen(y2, 0, 1); with this:<br />"[h,pValue,stat,cValue,mles]=jcitest(y2, 'model', 'H1*','lags',1);<br /><br />Unfortunately, unlike your results (98 stocks cointegrated with the ETF) I never find a single stock cointegrated with it. It was so strange that I tested every johansen test model .<br />Nothing changed but...the quadratic trend model gave me 290 stocks cointegrated!.<br />But it's clear that something is wrong. I'm sure I'm using the very same time series "inputDataOHLCDaily_stocks_20120424" and "inputData_ETF" as well as the same training date you selected. I mean from 98 to 0 is something that worries me....<br /><br />BeppeBeppenoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-45741135674791935052015-02-05T14:20:54.258-05:002015-02-05T14:20:54.258-05:00It could still be profitable if the basket does no...It could still be profitable if the basket does not exactly replicate the ETF.<br /><br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-41380551992935956202015-02-05T13:29:01.080-05:002015-02-05T13:29:01.080-05:00Hi Ernie,
Love your blog. I have a question. If o...Hi Ernie,<br /><br />Love your blog. I have a question. If one has restrictions on their trading such that they must hold positions for at least a week, would trading a basket of underlying symbols against their ETF still be a profitable strategy, in general?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-46877432720391367512014-10-26T08:13:07.896-04:002014-10-26T08:13:07.896-04:00NT,
The process is the same for any basket, even i...NT,<br />The process is the same for any basket, even if you impose the exclusion constraint. You don't need factor or PCA models.<br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-69500168379491708372014-10-25T16:31:28.933-04:002014-10-25T16:31:28.933-04:00How would this process differ if you wanted to cre...How would this process differ if you wanted to create a basket of goods to pairs trade against a single security with the constraint that basket cannot contain the security in which you want to trade individually? Would you have to come up with a factor model and run a PCA to discover underlying factors that drive correlation? <br /><br />-NT<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-39784584374151945252011-12-15T08:47:24.033-05:002011-12-15T08:47:24.033-05:00Jeet,
Ultimately, you should see the Sharpe ratio ...Jeet,<br />Ultimately, you should see the Sharpe ratio of your strategy, irrespective of with R square you get for linear regression.<br /><br />Often, a poor fit can still result in a profitable strategy.<br /><br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-19749891942529982092011-12-15T06:40:20.901-05:002011-12-15T06:40:20.901-05:001. In co integration relationship for pairs tradin...1. In co integration relationship for pairs trading, we regress S1 ~ S2 without intercept. But we know, regression without intercept increases R square dramatically.<br /><br />How to handle this? R square change dramatically, how can we say that this fitting is not spurious? <br /><br /><br />2.We know, in non stationary time series, R square is not a good measure to check the goodness of fit. What measure I should use for regression equation provided we do not use constant in regression equationJeethttps://www.blogger.com/profile/02873192546028417850noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-44817765303351440412011-11-16T07:56:48.842-05:002011-11-16T07:56:48.842-05:00Joe,
It may. No one can tell in advance, and you s...Joe,<br />It may. No one can tell in advance, and you should just run the experiment yourself. I haven't seen any papers on this technique of find the best basket either.<br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-34982516401784346112011-11-15T20:25:19.097-05:002011-11-15T20:25:19.097-05:00So if I keep the volatility fixed and minimize the...So if I keep the volatility fixed and minimize the convergence time or vice versa, do you think this object function will outperforms linear regression?<br />Are there any paper about this topics?<br /><br />Thank you<br />bottleneck56 at gmail.comluscidhttps://www.blogger.com/profile/15175867564316514271noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-64220081959096531072011-09-23T11:11:35.758-04:002011-09-23T11:11:35.758-04:00Joe,
I am not sure how you can have an objective f...Joe,<br />I am not sure how you can have an objective function that does two things at once (maximize volatility AND minimize convergence time). At most, you can use one criterion as a constraint (fixed to a value), and use the other as objective.<br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-53290476880185899132011-09-23T10:31:44.515-04:002011-09-23T10:31:44.515-04:00Using linear/ridge regression to generate the rati...Using linear/ridge regression to generate the ratio of a basket of stock means the mean square error of basket of stock and the index is minimized.<br /><br />However, the target function should be maximizing the spread volatility while minimizing the convergence time.<br /><br />Are there any study or paper regarding this topics?<br /><br />Thank you(Joe bottleneck56 at gmail.com)luscidhttps://www.blogger.com/profile/15175867564316514271noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-77277677779752497992011-04-18T07:49:15.425-04:002011-04-18T07:49:15.425-04:00Hi Anon,
There are 2 different use of the word &qu...Hi Anon,<br />There are 2 different use of the word "lag". <br /><br />If you mean the lag used as a parameter in the cadf test, then I believe the result is not very sensitive to whether you use lag=0, 1, or 2.<br /><br />However, I think you actually mean "lookback", which is the length of the data set used for the cadf test. In this case, it should be at least 1 year, but 3 years is ideal.<br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-57221526395392988202011-04-17T16:24:41.036-04:002011-04-17T16:24:41.036-04:00Hi Ernie - great job with the blog.
I had a simpl...Hi Ernie - great job with the blog.<br /><br />I had a simple question for you. <br /><br />When you run the cointegration tests what lag should you use? I've been doing a lot of reading about this and its quite debatable. Mean reversion occurs at various time frequencies i.e. minutes, hours, days, weeks, months. So in that sense one could test using various different lags - no? I notice in some of your comments you use a lag=0. I would greatly appreciate some guidance on this issue as it would help me greatly.<br /><br />Kind Regards,<br />SamAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-48884669605910944982011-04-01T20:42:58.832-04:002011-04-01T20:42:58.832-04:00Hi Anon,
IB's commission is about 0.5 cent per...Hi Anon,<br />IB's commission is about 0.5 cent per share, and can be lower for large volume.<br /><br />You can scale your components and the ETF by any amount you like so as to trade round lots.<br /><br />$1 stddev seems pretty reasonable.<br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-8890540717961654572011-03-31T17:58:28.658-04:002011-03-31T17:58:28.658-04:00Hi Ernie -
What commission structure at IB are ...Hi Ernie - <br /><br />What commission structure at IB are you working with? The retail commission structure is about 0.01 per share round trip so I am wondering whether these ETF/basket arb strategies work on that commission structure. <br /><br />I have found a basket of 3 components that is cointegrated with an ETF with the spread oscillating between $1 and -$1. However my regression leads to the following hedge ratio:<br /><br />ETF = 1<br />component_1 = 0.4418<br />component_2 = 1.622<br />component_3 = 0.2292<br /><br />Should I the sum of the hedge ratio on the component side equal 1? I see from your graph of XLE you show 1000 units of XLE versus the same units of the basket.<br /><br />Also - do you think the spread deviation that I have found is too narrow to profit on a retail level? Perhaps I need to find a weaker cointegration to increase profit potential. <br /><br />I greatly appreciate your feedback.ATnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-81921710117566327142010-02-16T19:40:33.176-05:002010-02-16T19:40:33.176-05:00Hi Ernie,
I had a question regarding your stateme...Hi Ernie,<br /><br />I had a question regarding your statement that you can boost this return by using options to implement the XLE position. Is this always true for one side of the cointegrating pair? Could we also substitute options for stocks on both sides of a pair?<br /><br />I didn't think that a cointegration test for equities would also translate into a strategy for options. I thought cointegration tells us about a linear combination of two stock prices while options are bets on individual stock prices. <br /><br />ThanksAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-41691115203175117832009-10-11T16:31:21.972-04:002009-10-11T16:31:21.972-04:00Anonymous,
Thanks for your kind words on my book.
...Anonymous,<br />Thanks for your kind words on my book.<br /><br />a) Certainly the more stocks you include in your basket, the shorter the half-life. The number of stocks to include depends on your desired holding period. You can backtest the strategy to find that out.<br /><br />b) Yes, hedge ratio is the coefficient from a linear regression.<br /><br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-62846950576918493882009-10-10T15:19:35.920-04:002009-10-10T15:19:35.920-04:00Ernest,
Firstly, great book, it has become an imp...Ernest,<br /><br />Firstly, great book, it has become an important reference for me especially now as I'm attempting to construct a successful ETF pair strategy.<br /><br />Just 2 questions:<br /><br />a) I found it surprising that your basket of 10 stocks that a mean reversion time of 20 days. Considering that XLE only has 40 constituents, intuitively I would think that if you use the top 10 cointegrating stocks, your half-life would be much shorter, to be useful intraday even. My question is, if I'm looking to stat arb intraday, about how many stocks should I be including and/or how highly co-integrated should this basket be with the index?<br /><br />b) In your book you give an example of how to find the hedge ratio in a pair trade in matlab. If I'm using excel, I'm wondering if this is equivalent to doing a linear regression and using the coefficients as the hedge ratio?<br /><br />Thanks!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-48196360638276989252009-07-04T19:43:48.643-04:002009-07-04T19:43:48.643-04:00Ernest,
I thoroughly enjoyed your book, but I wou...Ernest,<br /><br />I thoroughly enjoyed your book, but I would like to bring up my issues with this strategy.<br /><br />If I can again bring up the example of trading a basket of N-1 stocks against an index with N components. The deviations of your basket from the index will be due to the component that you have NOT included in your basket, say component X. I accept that the spread between the index and your basket will be stationary because the component X is in the same sector.<br /><br />The problem that I can't put aside is the chance that the one component that we didn't include in our basket goes through an M&A. I can imagine myself waking up one day to the news that component X is merging with component Y (the leader) and its share price is about to open at a price that will wipe out all of my profits for the last year. This is something that your backtests and cointegration tests will not prepare you for. In your book you discuss the illogicality of using stop losses with mean reversion strategies (which I totally agree with), but at least stop losses put a limit on the amount of money you can lose on any one trade.<br /><br />To sum up, I just think that this strategy lacks some serious risk management. The example is also quite conservative given that you trade a basket of 10 stocks in 33, leaving 23 component X's to stress about.<br /><br />JeffAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-53941571565727716192009-06-09T08:41:13.978-04:002009-06-09T08:41:13.978-04:00Anonymous,
Thanks for your kind words.
Yes, the mo...Anonymous,<br />Thanks for your kind words.<br />Yes, the more stocks you include in a basket, the shorter the half-life of mean-reversion to the corresponding ETF. However, it also implies smaller returns since cointegration is likely to be very tight. It may be a good candidate for high frequency trading.<br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-44370843981931770002009-06-08T19:37:08.834-04:002009-06-08T19:37:08.834-04:00Ernest,
Firstly, I thoroughly enjoyed reading you...Ernest,<br /><br />Firstly, I thoroughly enjoyed reading your recent book on quant trading.<br /><br />A question with regards to the half-life concept above. I'm attempting to implement and intraday index arb strategy, thus I would need to construct a basket with a much shorter half-life. My guess would be that I would actually want to take the 10 most correlated stocks in the index as they should mean-revert quicker than less correlated stocks in the index. I would appreciate your insights on this, my email is: ozel.christo AT gmail.com, thanks!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-35364652.post-4692866951676328502009-06-05T16:41:43.552-04:002009-06-05T16:41:43.552-04:00Hi ezbentley,
I stand by my argument that relative...Hi ezbentley,<br />I stand by my argument that relative weights of the components are important to whether a basket cointegrates with an index, contrary to what you argued.<br /><br />The N-1 stock basket can cointegrate with an index, but the 1 stock basket will not, because in the 1 stock basket, that stock suddenly has weight of 1. <br />ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-77471111744265336092009-06-04T17:41:25.460-04:002009-06-04T17:41:25.460-04:00Hi Ernest,
I am still unable to resolve the parad...Hi Ernest,<br /><br />I am still unable to resolve the paradox brought up by the reader "L."<br /><br />Let's say the ETF has N components, and you take a smaller subset n to form your baskets. And let's call the other components NOT in the basket e for error.<br /><br />Since cointegration requires a linear combination of two time series to be stationary, you would run cointegration test on the ETF itself and the basket of n stocks. If cointegration does exist, that would mean that the time series of ETF - n stocks(a linear combination, I ignored the constant) is stationary, which will imply that the time series e(=N-n) is also stationary. <br /><br />First of all, I don't see how e, being just stocks, can be stationary. <br /><br />Secondly and more importantly, if e turns out to be stationary for whatever reason, why not just trade e instead of a probably more costly combination of ETF and the basket?<br /><br />I am not sure if weights matter in this argument since e is simply just a "linear combination" of the ETF and the basket. <br /><br />I will appreciate your comment.ezbentleyhttps://www.blogger.com/profile/17414981365550570912noreply@blogger.comtag:blogger.com,1999:blog-35364652.post-282332607360276492009-02-23T10:29:00.000-05:002009-02-23T10:29:00.000-05:00Hi Anonymous,If you believe that AUD cointegrates ...Hi Anonymous,<BR/>If you believe that AUD cointegrates with a basket of currencies, then yes, your trade makes sense.<BR/>ErnieErnie Chanhttps://www.blogger.com/profile/02747099358519893177noreply@blogger.com