PyQuant News 🐍 Profile picture
Apr 13, 2023 14 tweets 4 min read Read on X
The BEST algo trading simulator:

Zipline.

Quantopian had $100,000,000 in algorithmic strategies using Zipline.

300,000 people used Zipline on their platform.

So I spent 100 hours studying the code so I could use it too.

The step-by-step guide to getting started in 5 minutes:
Zipline was maintained by Quantopian before it was acquired in 2020.

Some of the features:

• Easy to use so you can focus on algo development
• Includes life-like slippage and commission models
• Dozens of common performance metrics built-in

Ready to dive in?
Start with the imports.

You’ll use pandas_datareader for index data, matplotlib for charting, and PyFolio for performance analysis. Image
Since you’re building in Jupyter Notebook, load the Zipline “magics.”

Zipline creates data “bundles” for backtesting.

You can build custom bundles to ingest any data you want.

Today, you’ll use the pre-built Quandl bundle to ingest price data between 2000 and 2018 for free. Image
Every Zipline strategy must have an initialize function. This is run at the beginning of the strategy.

Here, you set a counter to track the days, the symbol to trade, and set the commission and slippage models. Image
Every Zipline strategy must also have a handle_data function.

It's run at every “bar.”

handle_data is where your strategy logic lives.

In today’s example, you will build a simple dual-moving average cross-over strategy. Image
To start the backtest, define the start and end dates.

Then, grab some data to act as an index.

This helps you compare your algorithm to a benchmark.

Finally, run the backtest. Image
Now that the backtest is finished, use PyFolio to get a breakdown of the results.

This creates a full tear sheet based on your backtest results. There’s a ton of information here, but here are the highlights: Image
Performance analysis gives you statistical measures of your performance. Image
The FREE 7-day masterclass that will get you up and running with Python for quant finance.

Here's what you get:

• Working code to trade with Python
• Frameworks to get you started TODAY
• Trading strategy formation framework

7 days. Big results.

pythonforquantfinancemasterclass.com
Of course, there’s a cumulative return chart. Image
Detailed risk analysis with rolling volatility, Sharpe ratio, and drawdowns. Image
Now you’re comfortable setting up the Zipline backtesting framework.

By doing so, you can use the most powerful toolset for algorithmic trading.

Zipline has it all.
Get ready to supercharge your algorithmic trading with Zipline.

What to keep this thread handy?

Hop back to the top and retweet the top tweet so you can find it later - and so others can find it too!

Here's the link:

• • •

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

Keep Current with PyQuant News 🐍

PyQuant News 🐍 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 @pyquantnews

Feb 5
10 free Python PDF ebooks for download: Image
Image
Image
Image
Python Data Science Handbook

github.com/terencetachion…Image
Read 13 tweets
Feb 3
RenTec uses Hidden Markov Models in trading.

The technique generated 60% returns per year over 30 years.

One of the co-founders of RenTec's name is in the algorithm!

Here's how it works: Image
A Hidden Markov Model (HMM) is a statistical model used to represent systems that evolve over time with unobservable (hidden) states.

It is widely applied in areas such as natural language processing, speech recognition, and bioinformatics.

And in trading:
HMMs are particularly useful when dealing with sequential data, where the underlying process is governed by probabilities.
Read 9 tweets
Jan 23
Python and Excel:

A potent combination for working with data.

Here are the 17 Python libraries to help you unlock the power.
XlsxWriter

XlsxWriter is a Python module for writing files in the Excel 2007+ XLSX file format.

github.com/jmcnamara/Xlsx…
xlwings

xlwings is a BSD-licensed Python library that makes it easy to call Python from Excel and vice versa.

github.com/xlwings/xlwings
Read 19 tweets
Jan 20
Backtesting options strategies sucks.

• Millions of contracts
• Weekly expirations
• Assignment if ITM

Now, you can backtest options strategies in a few lines of code.

Here’s how (with a link to historical options data): Image
Optopsy is an analysis tool for options trading strategies.

• Generates strategies from raw historic data
• Uncover performance statistics for combos
• 12 strategies built in including strangles

We’ll use 5 years of historic options data on RUT for the analysis.

Let’s go!
First, import the libraries we need.

Optopsy is light with very few dependencies. Image
Read 12 tweets
Jan 10
My PhD professors taught me MATLAB during my master's degree.

So I watched 200 YouTube videos to learn Python

96% of them were a complete waste of time.

But these 8 taught me more than all my PhD professors combined:
Algorithmic Trading Using Python (4.5 hours)

Learn how to perform algorithmic trading using Python in this complete course. Algorithmic trading means using computers to make investment decisions.

Quantitative Stock Price Analysis with Python (25 minutes)

We look at some quantitative analytical methods of stock price changes using Python and pandas.

Read 12 tweets
Dec 31, 2025
17 free Python GitHub repos for quant finance and algo trading:
OpenBB-finance: Investment Research for Everyone, Anywhere.

github.com/OpenBB-finance…
Read 19 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!

:(