NOTE: I've noticed the free data APIs (alphavantage and yfinance) to download daily price data here in get-ticker-time-series.py are unreliable - especially for tickers from non-US exchanges like the ASX. These free APIs may fail or the data may be incorrect, so accuracy can not be guaranteed and users of this repo should check the data it downloads to verify accuracy.
These scripts takes as input the users’ desired assets which the user has already pre-assigned into their relevant "environments" in the portfolio-settings.yaml file.
- e.g. equities go in the 'rising growth' and the 'falling inflation' environments because that's when they tend to do well, IL-bonds assigned to the 'rising inflation' and 'falling growth' environments, etc.
The algorithm then:
- creates weights for risk-parity of the user's assets within each environment, essentially creating 4 "sub-portfolios", a sub-portfolio for each environment. Then it,
- looks at the overall volatility of each sub-portfolio and creates risk-parity weights between each of the 4 sub-portfolios so each takes on 25% of the risk. Then,
- each asset’s final weight is determined by the sum of [its within environment weights]-multiplied by-[its overall environment weights], and the final ticker weights are output, along with historical performance simulations of a portfolio based on the final ticker weights.
The within- and between-environment risk-parity calculations are performed with the help of a python
version of the riskParityPortfolio package by Ze Vinicius and Daniel Palomar. See a nice vignette here for the riskParityPortfolio
package - I use the "basic convex formulation", which was based on Spinu (2013)'s unique solution.
- python3.7
- free Git Large File Storage (LFS)
- a free alphavantage API key
-
git clone https://github.com/DanielPNewman/all-weather-risk-parity.git
-
cd all-weather-risk-parity
-
pip3 install -r requirements.txt
-
git lfs install
-
git lfs track '*.csv'
-
Set your alphavantage API key as environment variable: ALPHAVANTAGE_KEY
-
Set your desired portfolio and benchmark tickers in the portfolio-settings.yaml file.
- The tickers you use should have enough historical data (e.g. at least 7 years) available for volatility estimates.
-
Run
./build-and-backtest-portfolio.sh
which executes the following scripts: -
See your results! They will be written to the results subdirectory, along with a named copy of the
portfolio-settings
file related to each set of results.
“If you can’t predict the future with much certainty and you don’t know
which particular economic conditions will unfold, then it seems reasonable
to hold a mix of assets that can perform well across all different types of
economic environments. Leverage helps make the impact of the asset
classes similar.”
...quote from Bridgewater’s All-Weather Story)
All-Weather is an approach to asset allocation designed to minimize downside but still perform regardless of the prevailing economic environment, hence the name “all-weather”. The concept was first implemented by Ray Dalio and his team at Bridgewater Associates, now the largest hedge fund in the world. In researching and developing All-Weather, Bridgewater recognized there are primarily two factors driving the value of any asset class - the levels of economic activity (growth) and inflation.
Therefore, the economy can be broadly viewed as having four “environments”. These are:
- Rising growth
- Falling growth
- Rising inflation and
- Falling inflation.
(use portfolio-settings.yaml to assign tickers for each of these evironments)
Throughout history and across geographical regions, distinct asset classes have consistently performed well in each of these four environments. So, there is a season for all assets, but unlike the real weather you never know which seasons are next or when the seasons will change, and worse, two seasons can occur at once! So surprises impact asset prices due to unexpected rises or falls in growth and inflation.
Recognizing this, an All-Weather portfolio essentially comprises four sub-portfolios - one for each economic environment containing assets known to perform well in that environment. Risk is then balanced equally within and between each of the four environments (see calculate-all-weather-ticker-weights.py for risk balancing with and between environments).
An important point to clarify is that the all-weather-like portfolio weights produced by this repo are certainly NOT the same as Bridgewater’s. Bridgewater uses cheap leverage and sophisticated investment instruments to increase returns while still minimizing risk in their All Weather product. The code in this repo does not currently account for leverage and will thus produce portfolios with considerably lower expected returns...but they should still do a good job at reducing the size of drawdowns if one assigns appropriate tickers in portfolio-settings.yaml.
Still working on how the average individual investor can cost-effectively leverage the lower volatility assets (e.g. Treasury bonds) to have the same volatility as equities, thus maintaining risk parity while increasing returns, like Bridgewater can. It will be relatively easy to adapt the code in this repo to accomidate the use of leverage, but the difficult part is finding a way to get cheap leverage that costs as close the risk free interest rate as possible. One way might be through Treasury bond futures. If you have the answer of how to practically do this, expicially for Aussie Treasury bonds, please let me know!
Also, nobody is suggesting the kind of simple All-Weather portfolios produced with the help of this repo are optimal or will maximize returns. They almost certainly won’t! Rather, the design is to protect assets by avoiding large drawdowns during economic upheavals and market downturns, while still providing reasonable returns above the cash interest rate.
Licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
The information, software, and any additional resources contained in this repository are not intended as, and shall not be understood or construed as, financial advice. Past performance is not a reliable indicator of future results and investors may not recover the full amount invested. The authors of this repository accept no liability whatsoever for any loss or damage you may incur. Any opinions expressed in this repository are from the personal research and experience of the authors and are intended as educational material.