GithubHelp home page GithubHelp logo

loochao / all-weather-risk-parity Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mirca/all-weather-risk-parity

0.0 1.0 0.0 7.81 MB

create all-weather risk parity weights and back-test

Python 98.85% Shell 1.15%

all-weather-risk-parity's Introduction

Create all-weather risk parity weights and back-test

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.

Overview

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:

  1. 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,
  2. 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,
  3. 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.

Prerequisites

How to use:

  1. git clone https://github.com/DanielPNewman/all-weather-risk-parity.git

  2. cd all-weather-risk-parity

  3. pip3 install -r requirements.txt

  4. git lfs install

  5. git lfs track '*.csv'

  6. Set your alphavantage API key as environment variable: ALPHAVANTAGE_KEY

  7. 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.
  8. Run ./build-and-backtest-portfolio.sh which executes the following scripts:

  9. 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.

WTF is an "All-Weather" portfolio anyway?

“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:

  1. Rising growth
  2. Falling growth
  3. Rising inflation and
  4. 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.

Licence

License: CC BY-SA 4.0

Licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)

Disclaimer

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.

all-weather-risk-parity's People

Contributors

danielpnewman avatar mdjnewman avatar dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.