Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
help with algorithm - moving average optimization

In working on implementing the algorithm On-Line Portfolio Selection with Moving Average Reversion, I've encountered a smoothing problem that should lend itself to the new batch transforms (I hope). The idea is to run an algorithm (described in the paper above) to determine the weightings of the securities in a portfolio. The basic algorithm involves computing the moving average over a window of W days. Rather than fixing W, the paper claims that there is a smoothing benefit to computing the individual optimized portfolios for W = 3,4,5,...30 days and the historical performance of each, and then, computing the smoothed portfolio by weighting the individual portfolios based on their historical performance.

So, basically I think that I need to write a loop over W, with mavg(W) in the loop. Is this now feasible? If so, a brief outline of how to do it would be helpful. Once we get code running, we'll share it in this forum.

5 responses

Unfortunately, this isn't possible currently as the only way to use a transform is to use .mavg(INT) and INT can not be a variable.

However, I think you can use the batch-transform here to compute a rolling moving average over 30 days going backwards from which you can extract the 3, 4, 5 etc. I realize that this probably requires more explanation but for now I think this is icing on the cake anyway. If we get the vanilla OLMAR to work that'd be a pretty awesome start!

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.

Thomas,

Thanks. I get the gist of using the rolling moving average...I'll think about it and perhaps get out a pencil and paper to sort out how it would work.

The other way would be just to code in all of the moving averages (e.g. mavg(3), mavg(4), mavg(5),...mavg(30)) with a lot of cutting and pasting. I'm assuming that the Quantopian backtester can handle this, right?

I expect we'll get the vanilla OLMAR working shortly. I think the smoothing technique has merit, because it effectively eliminates a free parameter that would have to be manually tuned otherwise.

@Grant,thanks!

Hello, All
where can read Quantopian lesson?

Zichun,

Which "lesson" are you referring to? The main sources of information for me have been this discussion forum and the help page. Additionally, I do Google searches to figure out Python programming details.