Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
mean reversion with variance threshold - help needed

I attempted to implement one of the solutions in this paper http://www.iip.ist.i.kyoto-u.ac.jp/member/cuturi/Papers/coinstat_final.pdf. I managed to use cvxopt to minimize predictability as explained in this paper with a lower bound on variance.

The difference between historical portfolio values and estimated values is stationary (checked using adfuller). Question is how do I implement a trading strategy around it? Attached is a naive implementation but I am sure its not right.

Could someone experienced with mean reversion help me implement a strategy around this stationary series?

19 responses

Hi... this looks like an interesting strategy. How about trying to 'optimize' or hone in on more optimal values for triggering the trade? I see you have hardcoded 1.2 for the standards deviations to trigger trades? Besides trying to optimize on the standard devs to enter on you can try to optimize the number of standard devs at which to exit the trade. Maybe you only enter trades at +/- 2.0 std devs, and then exit them after just a bit of mean reversions to 1.0 std devs?

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Thanks Justin. I realized that the paper assumes that prices follow a stationary VAR process and my estimation of Ahat is incorrect. I guess I first need to find a stationary basket using cointegration techniques before doing the optimization with cvxopt. They mention Box Tiao procedure for cointegration. I need to find a free internet resource about this method before improving this algo. Also it is not difference between portfolio and estimates that will be stationary but the portfolio values itself must be stationary. Duh.. me so dumb.

Keep at it, I would love to see this cardinality-constrained portfolio construction working!

Thanks Simon.

Satyapravin
Here's a good example of using Johansen's test for cointegration of baskets of securities using a very commonly used python library. It may be easier to implement in your strategy than Box Tiao.
http://nbviewer.ipython.org/github/mapsa/seminario-doc-2014/blob/master/cointegration-example.ipynb

Hello Satyapravin,

I'll take a crack at reading and digesting the paper you referenced. Do you have access to the Q research platform yet? My understanding is that you can simply submit any ol' algo to the contest, and "Presto!" you get access. Or you can request access and be put in a queue.

Regarding developing a trading strategy, the integration of the research platform and the backtester/trading API is almost non-existent, so I don't see a path to set up any kind of online/automated approach (e.g. where daily you would automatically identify new baskets of securities and feed them to the trading API overnight). However, manually, you can download entire notebooks in various formats (IPython, Python, & HTML). So, if you performed analysis, you could download it, and then massage it into a format compatible with fetcher. So, the idea would be to run a periodic screening analysis in the research platform, to find your security baskets, and then get them into the trading platform via fetcher for backtesting and trading (or you could copy and paste, but that would require stopping the algo, if it is running live).

One open question is whether the research platform, in its current manifestation, could be used for screening. I think that if one is careful not to create a memory leak, it could work (I was able to loop over all ~ 20,000 securities in the database, computing some simple summary statistics of each, overwriting the memory as each new security was loaded).

If I understand correctly, the basic approach here is to synthesize a trading pair, by creating two security baskets. So, it is a matter of picking the number of securities in each basket, N and M, the securities, and their weights. It might be worth a head scratch to sort out the overall difficulty of the computing problem, particularly as N and M become large. Presently, the research platform has no parallel computing capability. In theory, one can run multiple notebooks in parallel (each launched manually), but the RAM is shared in some fashion (you can't actually see what's going on under the hood, in terms of utilization of available computing resources). To pair down the problem a bit, it is possible to pluck out a subset of securities from the data base. For example, say you wanted to look at only ETFs for you baskets. It is a matter of pasting in a list of the ETF symbols, and the analyzing only those securities in the Q database.

Grant

Hi Satyapravin Bezwada,
I have emailed the author Marco in regards to the paper.
He has sent me the matlab code but it is way over my head and hard to read.
I can forward it to you if this helps.

Regards,
Andrew

Ah excellent thanks. Please forward me the code. My email address is pravin[dot][email protected]

Me too please! [email protected]

cool cool.
Ok will send it now to you both :).

I managed to club these two papers into one algo using cvxopt. However most times mean reversion fails out of sample. I will post results shortly.

http://www.iip.ist.i.kyoto-u.ac.jp/member/cuturi/Papers/coinstat_final.pdf
http://arxiv.org/pdf/0708.3048.pdf

awesome!!.. yer the latest papers seems to hold some promise but identifying the signal is difficult.
He seems to have something to do with the Portmanteau Criterion but this maths is to advanced for me :).

6 month result. code is ugly but hopefully when Q supports module CVXPY things will get simpler and faster.

@Andrew - do you know any other papers of interest that are worth reading?

Hi Satyapravin,
A couple of papers are below :)-
http://web4.cs.ucl.ac.uk/staff/C.Bracegirdle/BayesianConditionalCointegration.php

but more interesting is here full phd which is here -

http://web4.cs.ucl.ac.uk/staff/C.Bracegirdle/PhDThesis.php..

Maybe these could lead to some interesting algorithms :)..
thoughts.....

Thanks Andrew. That makes an interested read for the weekend. Maybe something useful comes out of it :)

Pravin - did you ever end up trading anything like this?

No I discontinued it. Working on A.N. Burgess paper whose statistical arbitrage approach is more appealing.

Ah cool, his papers have been on my list for a while, I read the FTSE 100 one a while ago, but he has some older ones from the mid-90s too.