Back to Community
Inverse volatility weighting for traditional stock/bond portfolios

Here is my implementation of so-called naive risk parity where the portfolio weights are calculated as the inverse of volatility of each asset. This is considered naive because (well, among other things) it does not take correlations between assets into account.

Note that CAGR is about 4% and the very high Sharpe which is due to the approach generally favouring bonds

Clone Algorithm
187
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: 5110748e9946fe308ad10c92
This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.
There was a runtime error.
5 responses

So, wondering if this is a bug or a feature (i.e., I'm doing it wrong)

It seems that @batch_transform functions are not handled properly when the arguments change. For example, in the source for this backtest, if one changes the refresh_period to 1 then it only calls get_volatility once per day (rather than what I expect, twice per day, once per security per day).

Also, specifying window_length seems to give a window of size window_length-1

Hi John,

The batch will be called once every refresh period. We combine all the events for all the sids into a pandas datapanel (one frame for prices, another for volume). That way, you can do operations on all the data in one structure. I would say that you should remove the second parameter to get_volatility and then just calculate the volatility in the dataframe. The reason you are only seeing one call instead of two is that batch_transform decorated methods expect to be called just once per handle_data. Calling them multiple times is frying our book-keeping for the moving window. You are not the first person bitten by the api, so we are looking into modifications to make it more clear.

I'm looking into the window_length, you may have found a bug.

thanks for all the feedback,
fawce
thanks,
fawce

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.

Thanks Fawce. I think I understand what you're saying, have written it up - it's attached, let me know if that is consistent. Also, the confusion may arise mainly due to the minmax() batch_transform example in your API docs.

Clone Algorithm
187
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: 5111596b29cfb62d508cc57c
This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.
There was a runtime error.

Also, another couple of bugs/features:

Scrolling the log gets confused for me if I use my mouse wheel. I think this has to do with Mac OS smooth scrolling damping, which might send a rapid succession of up/down movements to damp the movement... it doesn't happen if i use page up/down

The backtest plot disappears after a few runs without any orders, for example, while printing data structures to the log

John,

Yes, that's the intended use. I would suggest making the volatility calculation completely as vector operations, rather than iterating through the columns. You can use the data_frame as though it were a scalar value and it will magically align everything and create a new dataframe of the volatility. It should be quite a bit faster than iterating over everything.

thanks,
fawce