Back to Community
Is this a good rebalance algorithm or does it need work?

Is this a good algorithm or does it need work? I'm guessing yes. If so, suggestions?

Clone Algorithm
47
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: 541763e51c01cb07e82b965c
There was a runtime error.
4 responses

That code looks good - it's robust to handle late starts instead of hard coding a specific trading time. It also checks for open orders before placing new orders, preventing a long queue of open orders from building up.

It looks like the algo hit a good position in June and is riding that success. The one thing I'd suggest is to run a longer backtest to see a larger window of its historical performance.

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.

Hi Alisa, thank you for your advice. I'll take it into account. :)

Since we're on Quantopian, how about determining that a re-balance is needed algorithmically rather than on pre-determined time periods? For the above algorithm, for example, there are 10 securities rebalanced monthly at $8.95 a trade. That's $1,074 year in trading fees, which is significant even for a $100k portfolio.

Why not only rebalance when the security percentage gets out of whack with it's target? I've attached a version that does that. I've defined "out of whack" as the average being more than 1.5% away from it's target percent, which in this algo is 10%. But you can configure this.

Ideally, the definition of "out of whack" would depend on portfolio size, since trading is proportionately more costly for smaller portfolios than larger portfolios. Also, this could be improved by implementing a partial rebalance -- only rebalancing the securities that need it, rather than rebalancing all of them. I'll do another version that does that, though it's a little complicated because if one security needs rebalancing, you can't do it without touching others to turn up funds or reinvest them.

Clone Algorithm
37
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: 541f428f54230c08a4843a34
There was a runtime error.

Hello Junior,

If you are planning to go live with the algo, you might consider changing the code so that if you stop the algo (for editing), you can set the next re-balance date rather than automatically re-balancing when you re-launch the algo. If you'd recently re-balanced prior to stopping the algo, you'd just be paying another commission to tweak the allocation unnecessarily.

Also, to build on Alan's suggestion, you could also take into account the statistics of the portfolio to determine if re-balancing is indicated. For example, you could set a price z-score threshold rather than a percentage, which would normalize out the differences in variability from stock to stock. I suspect there is some literature on the topic, if you really want to dig into it.

Grant