Back to Community
WSJ Example Algorithm

The Wall Street Journal published an example quantitative strategy walk-though today, and we're posting the same strategy here so you can play around with it. A version of this was originally developed by our lecturer Max for use in the lecture series.

This example strategy is meant to convey all the different components of a professional quantitative trading algorithm, from universe selection to alpha definition to portfolio optimization. Lectures on various parts of the process can be found here:

https://www.quantopian.com/lectures#Universe-Selection
https://www.quantopian.com/lectures#Factor-Analysis

Because this is a simplified strategy for use as a walkthrough, you shouldn't take the performance here as representative. Instead think about it as a template for learning more and filling it out with your own ideas.

Clone Algorithm
589
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 59232d19c931f1619e6423c9
There was a runtime error.
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.

9 responses

Great PR! I think you've posted elsewhere, but what is the thinking about the weighted estimate of beta. 33% = 1.0, 66% = linear regression?

It's listed here:
https://www.lib.uwo.ca/business/betasbydatabasebloombergdefinitionofbeta.html

The idea is that your historical snapshot of beta will give you some information about it, but you should also have a strong prior that everything tends to 1.0. Think of it as a poor man's bayesian model incorporating some weight on recent behavior and some weight on everything being 1.0.

I've replaced beta with volatility in some of my efforts. While some of a stock's volatility may be idiosyncratic, mostly it's related to beta, and is a more stable parameter to estimate.

Q had a built in Factor called AnnualizedVolatilty which can replace RollingLinearRegressionOfReturns in Delaney's example.

Yup figuring out causality is a really interesting problem. If A causes B and you try to regulate B, you'll often fail. A needs to be regulated for B to be kept in check. Of course in reality it's all a complicated web of causality and not that simple. Would be really interesting to see an empirical comparison of residuals when using historical beta and historical vol to forecast future beta.

Ps a model with 66% historic beta and 33% beta 1.0, is probably the same as a capital allocation to two models, one estimating beta, and one assuming 1.0. You can run these two side by side in one algo by creating two alphas, then adding their signals.

Yup I think the math boils out in the wash, but doing them together likely saves some amount of computing time.

Well here's some good news, return is higher, 61% instead of 46% when compared to the amount risked. A maximum of just 750k of the 1M was exchanged for long or put at risk in the form of shorting, and it means the template can be regarded as 15% further above the benchmark than what we see, by this measure of what was used. Also with more of the available cash put to work, alpha etc will be higher. Not familiar with order_optimal_portfolio() I can only say that increasing max gross leverage to around 1.25 or so is one way to utilize more of the initial value and see that.

On line 81, shouldn't zscore be called before the ranking? It looks like the order of operations is reversed.

Good catch! zscore should be called before ranking. rank returns an integral float, however, so calling zscore on it will not impact the algorithm here. If we were dealing with multiple factors, this would have been a more concerning bug as we would want to standardize all of our factors before ranking or performing any sort of aggregation so we could fairly compare them. In this case, it's definitely a typo, but it will have no effect. Thanks for pointing it out!

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.