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

Dec 15
Missiles, robots, and traffic.

Nothing to do with quant finance, right?

Quants use the Kalman filter to predict future observations of hidden variables.

You can use it too-with Python.

Without the explosions: Image
A quick primer on the Kalman filter if you’re unfamiliar:

• Invented to track missiles in space
• Uses noisy data to improve at each time step
• Traders use it to uncover the “true state” of a time series

Python makes it dead simple to use the Kalman filter.

Here’s how:
First, you need data.

Use the OpenBB SDK to get it.

OpenBB is a leading open-source investment research software platform for accessing and analyzing financial market data.

Here’s an intro:
Read 13 tweets
Dec 9
Save your $90,000 and skip the quant finance degree.

Dive into 17 code repos that will teach you more than all your professors at school.

All without costing you $90,000: Image
OpenBB

Workspace for investment research for everyone.

github.com/OpenBB-finance…
PyQL

QuantLib's Python port.

github.com/enthought/pyql
Read 22 tweets
Dec 2
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 8 tweets
Nov 30
Quants use the volatility surface to price exotic options, calibrate models, and find mispricings.

You can build your own volatility surface with Python: Image
First, get the options chain data. Image
Then, inspect the volatility skew. Image
Read 10 tweets
Nov 27
During my master's degree, I read 65 books on quant finance.

Most of them were useless.

But these 4 are still on my shelf 10 years later.

And they should be on yours too: Image
Linear and Nonlinear Programming by David G Luenberger and Yin Ye

What you learn:

Optimization theory and its applications, covering both linear and nonlinear programming with a focus on practical problem-solving techniques. Image
Pricing Derivative Securities by TW Epps

What you learn:

How to price various derivative securities using mathematical models and the limitations and assumptions of these models. Image
Read 7 tweets
Nov 17
Some market data costs $1,400 per month.

The oil that makes the world's financial markets operate.

Unaffordable for 99% of us.

A profit center for countless Wall Street firms.

Fight back.

Here are the 12 Python libraries that give it to you free:
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 16 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!

:(