Understanding and Implementing Kalman Filter in Python for Pairs Trading

Learn how to implement Kalman Filter in Python to predict the hedge ration between two assets for Pairs Trading

Maurício Cordeiro
Analytics Vidhya

--

Photo by Chris Liverani on Unsplash

For information about the course Introduction to Python for Scientists (available on YouTube) and other articles like this, please visit my website cordmaur.carrd.co.

Introduction

Kalman filter, despite its name, is a two step (prediction and correction) estimator algorithm. Kalman filter is most used in tracking and control systems to provide accurate estimates in the presence of uncertainties, but it can be adapted for use in a number of different applications, from finance to computer vision.

When trying to apply Kalman Filter to a finance topic (in this case, Pairs Trading), I ran into a number of different material on the internet. After a lot of research/study (reference list at the end), I couldn’t find a comprehensive resource with the intuition and the basics math altogether that I could get all the pieces from. There are a lot of online materials, but they are rather too simple or too complex, or they focus on complex examples from control theory, etc.

--

--

Maurício Cordeiro
Analytics Vidhya

Ph.D. Geospatial Data Scientist and water specialist at Brazilian National Water and Sanitation Agency. To get in touch: https://www.linkedin.com/in/cordmaur/