Back to Community
Small mean reverting portfolios

An implementation of paper using the SDP optimization approach.

Loading notebook preview...
12 responses

Hi Pravin,
Do you feel this has a chance of being successful.
or is other words, what is your level of confidence for mean reverting strategies.

This this all 'in-sample' ? It seems to be when I glance at it...

Does it persist? It might be quicker for you to check than for me to go through and figure out all the matrices I have to change. :)

Does it persist? It might be quicker for you to check than for me to go through and figure out all the matrices I have to change. :)

Pravin your the man!
Great example.

I was just wondering would -
be quicker in working out the optimization problem and hence be able to search for portfolios.
Many thanks Pravin,

Hi Pravin,

Regarding your comment "However it requires a lot of computation and does not scale with Quantopian setup" would you please elaborate? Do you run out of memory? I thought that in general, Python can do number crunching as well as Matlab? Or do you need parallel processing/GPU power that is not available on Quantopian?


There are several problems:

  1. Since quantopian does not support CVXPY I have to make do with CVXOPT and my problem formulation is lengthy or not optimized.
  2. If you increase number of stocks to 40+ either the kernel dies or it runs out of memory or it takes hours to complete.

Would it be worth trying a scipy solver? Any of them applicable? See

Regarding the memory utilization, my understanding is that you get 4 GB across all notebooks, so just make sure you have nothing else running.

By the way, in layman's terms, what does your code do? Glancing at the paper, like many in the field, the author very quickly jumps into the arcane without giving an adequate description in terms that your average Joe could follow. Granted, it is an academic paper, so I guess that the style is excusable. In hand-wavey terms, what is the analysis doing and why should we expect it to work?


I don't know how to do semi-definite programming in scipy but I will definitely look into it.

Regarding the paper itself, it appears to be mathematically tractable but if it works in real world is anyone's guess. The gist of the algorithm is as follows:

Assuming a Portfolio of stocks P = summation(weights * Stocks).

Now fit a regressive model such that P(t) = A P(t-1) + Z(t) ----- i.e. Portoflio at time t is a matrix A time portfolio at time t-1 plus some noise at time t

Now if we take the variance of portfolio then

E[P(t)^2] = E[(A P(t-1)^2] + E[Z(t)^2]

Hence if we divide variance at time t-1 by variance at time t we get a measure of predicatability. When small it means that noise dominates and hence it is mean reverting. If it is large it means the model is predictable. Our objective is to minimize this ratio so that noise dominates and the model is mean reverting.

Hope that helps.

My observation is that since the minimization problem relies on estimation of matrix A above and the covariance matrix of portfolio of stocks, their stability is crucial for out of sample performance.

Thanks. --Grant

A few more bug fixes in cvxopt optimization and here is a mean reverting series 60 days out of sample.

Loading notebook preview...