Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Exponentially Weighted Moving Average & Standard Deviation in Pipeline

Scott shared the details of algorithm profiling that he recently completed on an algorithm using the new Pipeline API. This resulted in the addition of two new built in factors that are now available for use.

  • Exponentially weighted moving average (EWMA) - which allows you to calculate a moving average while weighting the importance of the data based on recency
  • Exponentially weighted moving standard deviation (EWMSTD) - which allows you to see the variance in the EWMA

The attached backtest was the backtest shared with us by Simon Thornington which resulted in the addition of these two new built in factors. I thought it relevant to share and have updated it to use the two new factors. Simon asked that I give a nod to Systematic Trading: A unique new method for designing trading and investing systems since most of the naive risk parity sizing etc came from his book.

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.

12 responses

I would just like to point out that I am not trading this algo or anything, but it has a good starting point for the sort of naive risk parity position sizing Rob Carver describes in his book!

Thank you for interesting algo. I am reading Carver’s book as well and like his approach of determining the position size based on desired volatily, underlying volatility and the forecast.
But It looks like the poor performance (negative Sharp) of the algo comes from under-investment. The algo invests only 0.008 of the capital or $8000 out of $1M.
In think the idea in Carver’s book was to volatility adjust the positions to reach the optimal volatility of the total portfolio. So if volatility of S&P is 12.8%, the algo should invest 100% into equities to reach e.g. 0.008 daily or 12.8% annualized. In your algo, the volatility of the portfolio is close to 0.

If you have found an error, please share the fixed algo!

Simon, unfortunately i couldn't make the algo work as desired :(
On the side note, the volatility adjusted position sizing, described in Carver's book works, makes more sense then applied with low correlated instrument. For now, Q doesn't allow futures trading, but one should achieve similar results with futures proxies ETFs which would replicate the diversified asset classes (equity , commodities, bonds, etc).
It would be great if someone applied the logic from Carvers' book to a trend follow algo here https://www.quantopian.com/posts/trend-follow-algo

The book is pretty clear, what is the issue implementing his methodology? I am using it for a couple of systems, but I can't post them.

I agree that the book explains very well the methodology, it's just me lacking python skills to implement it on Q.
Do you use it with Quantopian and ETFs as proxies or running on a different platform with futures?

One thing I'm not clear on looking at this algo is how the forecast scalars were calculated.
In the algo it says "from research".
In Robert's book he also just says "these are numbers which I've found from multiple tests" but I would love to know how I could work them out myself.

Here is Carver's explanation how to calculate the forecast scalar http://qoppac.blogspot.ca/2016/01/pysystemtrader-estimated-forecast.html

I used bootstrapped simulations for most of those numbers. I shared that technique in a research notebook last year.

Thanks Simon and Maxim.

Thanks guys

I tried cloning this algo and got 2 errors that impede having the algo do a build.:
100 Warning Undefined name 'update_universe'
121 Warning Local variable 'std' is assigned to but never used

Being a neophyte here, could someone point out how to fix them?