PyQuant News 🐍
PyQuant News 🐍

@pyquantnews

13 Tweets 4 reads Jan 19, 2023
Missles, 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:
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:
After you grab the OpenBB SDK, import pykalman.
It's your “dead-simple” way of building a Kalman filter in Python.
Now, the fun part:
Data.
Get it with the OpenBB SDK:
This code just *touches* on the full functionality of the OpenBB SDK.
You can download data for stocks, options, economics, and more.
The Kalman filter is an algorithm that uses noisy data over time to estimate the parameters of a system.
It needs a few inputs to get set up:
• Transition matrix
• Observation matrix
• Initial mean and covariance
• Observation and transition covariances
Getting the filtered series is two lines of code.
You can plot the filtered price series to compare it to a simple 30-day moving average.
Notice the Kalman filter starts with an estimate far away from the prices.
Obviously wrong.
That’s because we seeded the algorithm with a matrix of 1s.
Within only a few time steps it corrects and more accurately models the average price.
To see it more clearly, you can grab the last 200 days of data.
Filtering price data with the Kalman filter reveals the "true" average price.
Pair the Kalman filter with the OpenBB SDK and you have a powerful analysis tool.
• Import the libraries
• Use OpenBB SDK for data
• Build the filter with pykalman
No missiles.
Just a better time series analysis.
You can use the Kalman filter for smoothing the Sharpe ratio, volatility, and other rolling metrics.
Want to keep this guide handy?
Hop back to the top and retweet the top tweet so you can find it later!
Here's the link:
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

Loading suggestions...