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

Jul 10
There are 137,000 Python libraries.

But you only need 11 for quant finance:
pandas

• Allows quick data cleaning and preprocessing
• Provides DataFrame structure for time-series data
• Enables complex data operations with simple syntax

Use it for:

Manipulating and transforming financial market data. Image
NumPy

• Advanced statistical functions for analysis
• Efficient vectorized operations for large datasets
• Powerful random number generators for simulations

Use it for:

Fast and versatile scientific computing. Image
Read 14 tweets
Jul 7
This Jane Street trader literally explains edge in this book.

Here's what's inside: Image
The author starts by explaining how the professionals and hedge funds think about trading. Image
He then talks about the biggest risk that faces market makers:

Adverse selection.

It's great since most people think of risk as standard (deviation.) Image
Read 8 tweets
Jul 1
10 free Python PDF ebooks for download: Image
Image
Image
Image
Python Data Science Handbook

github.com/terencetachion…Image
Read 13 tweets
Jun 19
OpenBB dropped the $0 cost financial AI agent workstation.

You can get 405 free data sources (and an AI Copilot).

Here's what you missed (in 90-seconds): OpenBB Terminal Pro
In case you're unfamiliar:

OpenBB is the first AI financial workstation that combines data with an AI agent to transform investment research.

• Private (your data is not shared)
• 100s of free data sources
• Custom data backends
• Advanced AI Copilot

How it works:
Set up a custom, local data server with 370 sources of free market data.

No coding required (just double click an icon):
Read 12 tweets
Jun 17
My master's degree completely failed to teach me how to test trading strategies.

So I spent 40 hours looking for Python backtesting libraries.

Then I started using the best ones.

But unlike my quant finance degree, these won't cost you $90,000.

Here they are for free. Poof
Zipline

From Quantopian (acquired by Robinhood) the first to democratize quant trading, comes Zipline. It's a robust, fully-featured backtesting library which features slippage models, robust data handing and rich metrics.

github.com/quantopian/zip…
backtrader

backtrader features live data and trading, filters and multiple data feeds at once.

github.com/mementum/backt…
Read 12 tweets
Jun 15
9 trading strategies everyone should know (with Python code):
Bollinger Bands Pattern Recognition

The mid band is the moving average on the price series.

The upper and lower bands are two moving standard deviations away from the mid band. Image
MACD oscillator

MACD refers to Moving Average Convergence/Divergence.

MACD is a momentum trading strategy.

It assumes momentum has more impact on short-term moving average than long-term moving average. Image
Read 13 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!

:(