Quant Science Profile picture
Mar 22, 2025 8 tweets 3 min read Read on X
According to Ray Dalio, the easiest way to adjust for risk is to seek uncorrelated returns.

Ray's made billions from a simple idea.

Here's how to do it in a few lines of Python code: Image
Step 1: Collect Stock Data

Run this code to download free stock price data from Yahoo Finance. Image
Step 2: Convert Prices to Returns

Using pandas code, we can get returns (just run this code): Image
Step 3: Use Riskfolio's Plot Clusters

This function takes our returns and creates a hierarchical dendrogram based on Pearson correlation of the stock returns. Image
Step 4: Analyze the plot

Select Stocks from different buckets that exhibit lower correlation to others in your portfolio.

Example:

GLD, TSLA, NVDA, AXP would be less correlated than AAPL, MSFT, NVDA, GOOG. Image
Step 5: Become a Quant Scientist

Once you realize that trading with algorithms gives you an edge, the next step is to learn how to exploit that edge.

We want to help.
On March 26th, we are hosting a free workshop to help you get started with algorithmic trading with Python.

Register here (500 seats): learn.quantscience.io/qs-registerImage
That's a wrap! Over the next 24 days, I'm sharing my top 24 algorithmic trading concepts to help you get started.

If you enjoyed this thread:

1. Follow me @quantscience_ for more of these
2. RT the tweet below to share this thread with your audience

• • •

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_

Mar 31
🚨BREAKING: Microsoft open-sourced an AI Quant investment platform in Python

This is what you need to know:

(a thread) Image
1. What is Qlib?

Qlib is an open-source, AI-oriented quantitative investment platform that aims to realize the potential, empower research, and create value using AI technologies in quantitative investment, from exploring ideas to implementing production. Image
2. How it works

Qlib provides an automated quant research workflow that builds the dataset, trains models, backtests, and evaluates the results. Image
Read 8 tweets
Mar 27
12 Python libraries for free market data everyone should know: Image
yfinance

Data for stocks (historic, intraday, fundamental), FX, crypto, and options. Uses Yahoo Finance so any data available through Yahoo is available through yfinance.

github.com/ranaroussi/yfi…
pandas-datareader

pandas-datareader used to be part of the pandas project. Now an independent project. Includes data for stocks, FX, economic indicators, Fama-French factors, and many others.

pandas-datareader.readthedocs.io/en/latest/
Read 17 tweets
Mar 26
A 23-page research paper reveals the number 1 method Hedge Funds use to beat the market:

Time Series Momentum

This is how: 🧵 Image
1. What Is Time Series Momentum?

Time Series Momentum (TSMOM) bets on trends continuing. If a stock’s up, buy more; if down, sell. A 2011 study of 58 assets proved it works! Image
2. The Data Behind the Strategy

The TSMOM paper analyzed equities, currencies & more. T-stats showed consistent profits across 1-month lookbacks! Image
Read 9 tweets
Mar 18
A Bloomberg Terminal costs $30,000 a year.

Here's how to build 90% of it for free.

Wall Street doesn't advertise this. But every function that matters has a free alternative in Python.

Here's the DIY version (with Python): Image
━━━━━━━━━━━━━━━━━
🔹 REAL-TIME PRICES & CHARTS
━━━━━━━━━━━━━━━━━
Bloomberg: GP
Python: yfinance + Plotly

yfinance pulls live and historical price data for any ticker in seconds. Plotly turns it into interactive charts. Add your own indicators, overlays, and alerts. No subscription needed.
━━━━━━━━━━━━━━━━━
🔹 FINANCIAL STATEMENTS & RATIOS
━━━━━━━━━━━━━━━━━
Bloomberg: FA
Python: yfinance + pandas

yfinance exposes full income statements, balance sheets, and cash flow statements directly. Pull any company's financials into a DataFrame, calculate your own ratios, and build custom models — all in a notebook.
Read 11 tweets
Mar 18
This strategy has delivered 18% annual returns since 1926.

No black box. No complex ML model.

Just breakouts, trailing stops, and volatility sizing applied to industry portfolios.

Here's how it works (and link to the 37 page PDF): Image
─────────────────
🔹 THE ENTRIES
─────────────────
A long position triggers when an industry breaks above either:
• A Donchian Channel (20-day high, 40-day lower band)
• A Keltner Channel (20-day EMA ± 1.4× ATR, 40-day lower band)

The asymmetric lookback keeps you invested during sustained trends.
No short positions. When nothing is trending, capital sits in T-bills.
─────────────────
🔹 THE EXITS
─────────────────
Trailing stop = the higher of the 40-day Donchian or Keltner lower band.
Once it moves up, it never moves back down.

Winners run. Losers get cut fast.
Read 9 tweets
Mar 17
Most traders skip the math.

Then wonder why their backtests fail in live trading.

You don't need a math degree. But you need the right foundations.

Here's the complete math & stats roadmap for trading: Image
─────────────────
🔹 STATISTICS & PROBABILITY
─────────────────
• Sample Size & Law of Large Numbers — a 10-trade backtest proves nothing. You need hundreds before trusting your edge.
• Expected Value — the only number that actually matters: (Win% × Avg Win) - (Loss% × Avg Loss)
• Standard Deviation — becomes volatility when applied to returns. Every position sizing formula runs through this.
• Correlation — 3 momentum strategies on correlated assets isn't diversification. It's 3x the risk.
• Conditional Probability — your strategy's win rate changes by market regime. Know when it works.
─────────────────
🔹 LINEAR ALGEBRA
─────────────────
• Vectors & Matrices — your portfolio is a weighted sum of vectors. Risk is matrix multiplication.
• PCA — turns 50 correlated indicators into 5 independent signals. Less noise, more edge.
Read 9 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!

:(