Algo Trading

A Python Package for Optimal Mean Reversion Trading

From portfolio construction to optimal execution

Tim Leung, Ph.D.
Quantitative Investing
3 min readSep 18, 2020

--

A Deep Dive into Pairs Trading. Photo by NOAA on Unsplash

In this new python package called Machine Learning Financial Laboratory (mlfinlab) developed by Hudson & Thames, there is a module that automatically solves for the optimal trading strategies (entry & exit price thresholds) when the underlying assets/portfolios have mean-reverting price dynamics.

It covers a few mean-reverting models, including the Ornstein-Uhlenbeck (OU) model. The trading model and computations are based on the results from this journal article.

The module includes three main steps:

Model Fitting:

Source: MLfinlab documentation
Source: MLfinlab documentation
Source: MLfinlab documentation

Determining the Optimal Entry & Exit Levels

--

--

Tim Leung, Ph.D.
Quantitative Investing

Endowed Chair Professor of Applied Math, Director of the Computational Finance & Risk Management (CFRM) Program at University of Washington in Seattle