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.
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.
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.
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.
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.
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:
Performance analysis gives you statistical measures of your performance.
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.
Detailed risk analysis with rolling volatility, Sharpe ratio, and drawdowns.
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:
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.