Quant Science Profile picture
Sep 20 9 tweets 3 min read Read on X
In 10 lines of Python code, I can do a full portfolio optimization.

This is wild. Let me show how: Image
1. Load Python libraries

These are the python packages and functions we'll use. Image
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. Image
3. Create a Benchmark

This is an inverse volatility portfolio that I'll compare my Max Sharpe portfolio against. Image
4. Out-Of-Sample Performance

Use Predict Method to get out-of-sample Portfolio Performance Image
5. Portfolio Composition

The visualizations from skfolio are incredible. Image
6. Cumulative Returns

In 1 line of code, we can get cumulative returns for our portfolio and benchmark. Image
7. Performance Tear Sheet

In 1 line of code, I get a comprehensive performance tear sheet to share with clients. Image
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…
Image

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Quant Science

Quant Science Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @quantscience_

Sep 19
Python is wild for trading.

Example: AutoTrader for automated trading systems.

Let's dive in: Image
AutoTrader is a Python-based trading framework for the development, optimisation and deployment of automated trading systems.

Let's go through a simple MACD algorithmic trade example.
1. Create a strategy as a YAML file: Image
Read 10 tweets
Sep 14
Why do 95% of traders fail?

They don't have a system.

These are the Python libraries we use systematically trade with python: Image
1. Formation:

Market data
- Omega
- OpenBB
- Nasdaq
- Norgate

Math/Stats
- Riskfolio
- Pandas
- Numpy
- Statsmodels Image
2. Testing:

Backtesting
- Event-Based: Zipline Reloaded
- Vector-Based: VectorBT

Risk/Performance
- Transaction-Based: Pyfolio
- Factor-Based: Alphalens Image
Read 6 tweets
Sep 13
If you're just starting with algorithmic trading in python, you need data.

The fastest way to get data: yfinance.

Let me explain: Image
1. Get historical market data

In 1 line of code you can get:
- Stock Information
- Historical Market Data Image
2. Show Actions

You can also get:
- Metadata
- Actions
- Dividends
- Splits
- Capital Gains Image
Read 8 tweets
Sep 1
The must-have machine learning technique for financial market data analysis: Image
Quants use K-Means to cluster stocks based on similarities in features.

They use it for:

• Risk management
• Strategy development
• Portfolio diversification
• Market structure analysis

Here’s how you can too:
First, grab the data for analysis.

This example shows how to grab the tickers of the Dow Jones average and download historical data. Image
Read 8 tweets
Aug 27
Python is wild for trading.

Example: AutoTrader for automated trading systems.

Let's dive in: Image
AutoTrader is a Python-based trading framework for the development, optimisation and deployment of automated trading systems.

Let's go through a simple MACD algorithmic trade example.
1. Create a strategy as a YAML file: Image
Read 10 tweets
Aug 12
Python for algorithmic trading and investment portfolios has never been easier.

Case in point: Correlations for Portfolio Construction Image
1. Start by collecting data and converting to returns on several stocks: Image
2. Use Correlations to expose relationships Image
Read 10 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(