Gain access to exclusive tools that Wall Street's Elite don't want you to have. Don't miss the next issue...
Join 11,500+ Quant Scientists learning one article at a time
Join 11,500+ Quant Scientists learning one article at a time
In this QS Newsletter (get the code), we are kicking the tires on Skfolio, a new Python library for portfolio optimization built on top of Scikit-Learn. Our objective today is to see how to make a Risk Parity portfolio with Skfolio. Today, you learn:
How to make a Risk Parity Portfolio with Skfolio
BONUS: Get the Python Code for EVERYTHING you see in this post
Disclaimer:
The information and educational material provided by Quant Science, LLC are for educational purposes only and should not be considered as financial advice or recommendations to purchase, hold, or sell any securities or other financial instruments. Before you proceed, please review our full disclaimer here.
Quick favor - We're preparing for the next cohort of our new python for algorithmic trading course. If you can spare 60 seconds, we'd love to hear what would help make you a better trader from our course. Click here to enter your 60-second survey.
Skfolio: A new Python package for portfolio optimization (build on top of Scikit Learn)
Want exclusive access to our FULL codebase for this Quant Science tutorial plus dozens more? The code is in the QS0011 Folder. Join here:
Skfolio is a new Python library for portfolio optimization built on top of scikit-learn. It offers a unified interface and tools compatible with scikit-learn to build, fine-tune, and cross-validate portfolio models.
A risk parity portfolio is a type of investment strategy that focuses on allocating risk, rather than capital, equally among different asset classes. Unlike traditional asset allocation strategies that allocate a fixed percentage of capital to each asset class, risk parity approaches allocate based on the risk each asset contributes to the portfolio.
Here's a breakdown of how it works:
Risk Measurement: First, the risk of each asset in the portfolio is measured. This is often done in terms of volatility or some other measure of historical price fluctuation.
Equalizing Risk Contribution: In a risk parity portfolio, assets are weighted not by their market value but by the risk they contribute. The goal is to ensure that each asset class contributes equally to the overall risk profile of the portfolio. For example, if stocks are more volatile than bonds, a smaller proportion of stocks would be included in the portfolio compared to bonds.
Diversification: Risk parity aims to achieve a more effective diversification. By balancing the risk contribution from different asset classes, the strategy aims to reduce the impact of any one asset class performing poorly.
Leverage: Sometimes, risk parity portfolios use leverage to increase the returns of lower-risk assets, aiming to match the higher returns of riskier assets.
Adaptability: These portfolios are often rebalanced regularly to maintain the desired risk allocation, adapting to changes in market conditions and asset volatilities.
The goal with our analysis is to create Risk Parity portfolio using several growth stocks. Get the code: It's in the QS011 folder.
The first step in our analysis is to load the following libraries and setup our analysis parameters. Run this code:
Get the code: It's in the QS011 folder.
The code produces the following data:
Next, we will use scikit learn train_test_split
to create training and testing sets. The Training Set is what will be used to calculate parameters for our Risk Parity Portfolio. The testing set is used to compare to a benchmark. Run this code:
Get the code: It's in the QS011 folder.
To create a risk parity portfolio we use the RiskBudgeting()
function. Run this code:
Get the code: It's in the QS011 folder.
The benchmark will be an Inverse Volatility portfolio. We can create it using the InverseVolatility()
function. Run this code:
Get the code: It's in the QS011 folder.
To estimate whether or not we are generating alpha versus a benchmark, we can predict on the test set and then get metrics like Sharpe Ratio. Run this code:
Get the code: It's in the QS011 folder.
We can perform a number of analyses at this point using skfolio
. Run this code:
Get the code: It's in the QS011 folder.
Skfolio
is a new library. As of this writing, it's still under active development, so it's not ready for prime-time. But we loved how easy it is to use the Scikit-Learn style of workflow for Portfolio Analysis and Optimization. We will continue to monitor progress as the library develops.
Until then we highly recommend Zipline for Backtesting, VectorBT, AlphaLens, Pyfolio, and the Quant Science stack we teach in our Quant Scientist Algorithmic Trading System.
Ready to take your investment game to the next level? Embracing Python for algorithmic trading can be a game-changer for your portfolio. If you're new to Python or want to sharpen your skills for financial analysis, our upcoming Python for Algorithmic Trading Course is the perfect opportunity. See you in our Python Algo-Trading course!
There's nothing worse than going at this alone--
❌ Learning Python is tough.
❌ Learning Trading is tough.
❌ Learning Math & Stats is tough.
It's no wonder why it's easy to feel lost.
And all of this increases the likelihood you will fail (not to mention lose money in the process). Protect your future.
👉 Join 5100+ future Quant Scientists on our Python for Algorithmic Trading Course Waitlist: https://learn.quantscience.io/python-algorithmic-trading-course-waitlist
Gain access to exclusive tools that Wall Street's Elite don't want you to have. Don't miss the next issue...
Join 11,500+ Quant Scientists learning one article at a time
Join 11,500+ Quant Scientists learning one article at a time