Quant Science Profile picture
Develop profitable trading strategies, build a systematic trading process, and trade your ideas with Python—even if you’ve never done it before.

Sep 20, 2024, 9 tweets

In 10 lines of Python code, I can do a full portfolio optimization.

This is wild. Let me show how:

1. Load Python libraries

These are the python packages and functions we'll use.

2. Create a Maximum Sharpe Ratio Portfolio

We create a Maximum Sharpe Ratio model and then fit it on the training set.

portfolio_params are parameters passed to the Portfolio returned by the predict method.

3. Create a Benchmark

This is an inverse volatility portfolio that I'll compare my Max Sharpe portfolio against.

4. Out-Of-Sample Performance

Use Predict Method to get out-of-sample Portfolio Performance

5. Portfolio Composition

The visualizations from skfolio are incredible.

6. Cumulative Returns

In 1 line of code, we can get cumulative returns for our portfolio and benchmark.

7. Performance Tear Sheet

In 1 line of code, I get a comprehensive performance tear sheet to share with clients.

Want to learn how to build algorithmic trading strategies in Python (that actually work)?

👉 Join us live for our free training (500 seats): learn.quantscience.io/python-algorit…

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling