Hi,👋 we have updated the app and fixed multiple bugs. We are lacking funds, request to free user not to use Adblock. Ads are non intrusive. 😊

@quantscience_: How to make a simple algorithm...

@quantscience_
12 views Jun 21, 2026
Advertisement
1
How to make a simple algorithmic trading strategy with a 472% return using Python.

A thread. 🧵
Media image
2
This strategy takes advantage of "flow effects", which is how certain points in time influence the value of an asset.

This strategy uses a simple temporal shift to determine when trades should exit relative to their entry for monthly boundary conditions.
Media image
3
The signals for when to go short, when to cover shorts, when to go long, and when to close longs are all linked to these recurring monthly cycles.

This periodic "flow" of signals—month-in, month-out—creates a systematic pattern.
Media image
4
1. Load the libraries and data

Import these libraries. Then run the code to ingest price data on TLT.
Media image
5
2. Generate Signals

We'll first set up an empty data frame to track the long/short signals.

Then we create short entry signals on each new month's 1st and 5th day.

Similarly, we make long signals 7 days and 1 day before the end of each month.
Media image
6
3. Run this code to get the Trade PnL

Use vbt.Portfolio.from_signals().
Media image
7
Use pf.stats() to return the portfolio stats summary tear sheet.
Media image
8
🚨Want to learn Algorithmic Trading Strategies (that actually work)?

On June 25th, we are hosting a free workshop to help you get started with algorithmic trading with Python.

Register here (500 seats): learn.quantscience.io/join
Media image
9
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
10
P.S. - Want Algorithmic Trading with Python tutorials every Sunday?

Register here to join our Sunday Quant Scientist Newsletter (it's free): learn.quantscience.io/quant-scientis…
Actions
Visual Editor Carousel Maker NEW
Update Thread
What You Can Do
  • Download as PDF
  • Save to Notion
  • Export as Markdown
  • Visual Editor
  • LinkedIn & Instagram Carousel Maker
Create Free Account

Includes 7-day Premium trial

Advertisement