A step-by-step guide to build 3 optimized portfolios with a few lines of Python:

Hereβs how skfolio helps:
β’ Unified library for building optimized portfolios
β’ Built in Python code to take care of the maths
β’ Built on top of scikit-learn to leverage ML
This thread will walk you through how to use it:
β’ Unified library for building optimized portfolios
β’ Built in Python code to take care of the maths
β’ Built on top of scikit-learn to leverage ML
This thread will walk you through how to use it:
Weβll use scikit-learn for creating data splits, skfolio for optimizing the portfolios, and OpenBB for data.
Weβll do our analysis on a list of sector-based ETFs.
Weβll do our analysis on a list of sector-based ETFs.

Download the historic price data, manipulate the DataFrame to use with skfolio, and split the data into training and testing sets.

The next step is to fit different models to the data.
Weβll use skfolio to create three separate portfolios: maximum diversification, equal weighted, and random weighted.
Weβll use skfolio to create three separate portfolios: maximum diversification, equal weighted, and random weighted.

We can use skfolio to predict the portfolio weights for each of the weighting methods.

The result is a visualization of the weights of the sector ETFs for each of the portfolios.

Generate the cumulative returns of each strategy to visualize how they performed over the analysis period.
This is a quick way to easily assess the performance of the portfolios.
This is a quick way to easily assess the performance of the portfolios.

The portfolio with the maximum diversification underperforms both the equally weighted and randomly weighted portfolios.
You might conclude that being heavily weighted in XLU (utilities) was a drag on the overall performance of the strategy.
You might conclude that being heavily weighted in XLU (utilities) was a drag on the overall performance of the strategy.

While skfolio presents a the cumulative returns of each portfolio, we need to apply periodic rebalancing to better represent a real investment strategy.
As a next step, plug skfolio into your favorite backtesting library and rebalance every month.
How do the returns change?
As a next step, plug skfolio into your favorite backtesting library and rebalance every month.
How do the returns change?
To keep this thread handy, just click the link and repost the first tweet.
Then follow me @pyquantnews to get content for algo trading and quant finance 4x daily.
Then follow me @pyquantnews to get content for algo trading and quant finance 4x daily.
View Tweet
Generated by Thread Navigator
Press β + S to quick-export
