Quant Science Profile picture
Jun 29 9 tweets 3 min read Read on X
How to use MACD for algorithmic trading Machine Learning.

Let's dive in. 🧵 Image
MACD (Moving Average Convergence Divergence) is most commonly used in Technical Trading.

But, it can be used as part of a factor model.

Let's see how. Image
1. What is MACD?

MACD is a trend-following momentum indicator that shows the relationship between two moving averages of a security's price.

The MACD is calculated by subtracting the long-term exponential moving average (EMA) from the short-term EMA.
2. Components of MACD:

MACD Line: This is calculated by subtracting the 26-period EMA from the 12-period EMA.

Signal Line: This is a 9-period EMA of the MACD Line itself.

MACD Histogram: This is the difference between the MACD line and the Signal line. Image
3. How MACD is used:

The primary method is to look for crossovers between the MACD line and the signal line.

When the MACD line crosses above the signal line, it is a bullish signal.

Conversely, when the MACD line crosses below the signal line, it is a bearish signal. Image
4. Factor model with MACD

We can add MACD as features.

These features power our Machine Learning models.

And allow us to predict: 1D, 5D, 10D, and 21D returns forecasts. Image
🚨 NEW WORKSHOP: How I built an automated algorithmic trading system with Python.

Hedge funds have better tools & faster execution.

That ends on July 9th.

👉 Register here to learn how to compete in an unfair game with Python (500 seats): learn.quantscience.io/become-a-pro-q…Image
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
P.S. - Want to learn Algorithmic Trading Strategies that actually work?

I'm hosting a live workshop. Join here: learn.quantscience.io/qs-register

• • •

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_

Jul 15
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
Jul 14
Stock Prediction AI: Using Machine Learning and Deep Learning to predict stock price movements in Python.

The Python code is 100% free on GitHub.

Let's dive in (bookmark this): Image
1. The Python Machine Learning and Deep Learning Libraries:

- mxnet
- gluon
- sklearn
- xgboost Image
2. Stock Price Data (Train/Test)

The dashed vertical line represents the separation between training and test data.

GS is shown but will use 72 assets.

Daily prices for each asset. Image
Read 13 tweets
Jul 12
🚨BREAKING: A new Python library for algorithmic trading.

Introducing TensorTrade: An open-source Python framework for trading using Reinforcement Learning (AI) Image
TensorTrade is an open source Python framework for building, training, evaluating, and deploying robust trading algorithms using reinforcement learning leveraging:

- numpy
- pandas
- gym
- keras
- tensorflow
Example: Using TensorTrade to Train and Evaluate with Reinforcement Learning

Step 1: Create training and evaluation sets

We'll start by creating a training and evaluation set as CSV files. Image
Read 10 tweets
Jul 11
In investing, your track record is everything.

In 2 minutes, I'll uncover the secrets hedge funds use to track their portfolio performance: 🧵 Image
There are 3 main areas that smart investors care about:

1. Profits (Returns)
2. Risks
3. Drawdowns

Let's break them down using the snapshot:
1. Profitability Insights

Annual Return: 22.44%—strong growth!

CAGR: 23.78%—compounded gains over time.

MAR: 0% (minimum acceptable)—room to beat risk-free rates.

Significance level (5%) sets the risk benchmark.
Read 9 tweets
Jul 10
How to create a Black-Litterman portfolio in Python.

A thread: 🧵 Image
1. What is Black-Litterman?

Black-Litterman starts with market equilibrium returns (from CAPM) and lets you add your views (e.g., “Tesla will outperform”).

It balances both to create optimal weights. No overfitting, just math.
2. How it works

Using skfolio in Python, you:

- Compute market returns (e.g., S&P 500).
- Add views (e.g., 5% outperformance for tech).
- Blend with confidence levels.
- Optimize weights.
Read 10 tweets
Jul 6
This guy made a real-world AI Hedge Fund Team in Python.

Then he made it available for everyone for free.

Here's how he did it (and how you can too). Image
@virattt is doing something incredible.

He's using AI to replicate a hedge fund.

And he's open-sourced it for the world to learn.
@virattt The main components of the project:

1 • agents
2 • tools
3 • backtester 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!

:(