---
title: 'Trading Mean Reversion with Kalman Filters'
source: 'https://www.youtube.com/watch?v=BuPil7nXvMU'
video_id: 'BuPil7nXvMU'
date: 2026-09-16
duration_sec: 778
channel: 'Roman Paolucci'
---

# Trading Mean Reversion with Kalman Filters

> Source: [Trading Mean Reversion with Kalman Filters](https://www.youtube.com/watch?v=BuPil7nXvMU)

## Summary

In this video, Roman from QuantGuild introduces a Kalman Filter trading system designed to implement a mean reversion strategy. He bridges the gap between theoretical mean reversion models and practical market application, discussing the Ornstein-Uhlenbeck process, the challenges of non-stationarity, and how the Kalman filter adapts to changing market conditions.

### Key Points

- **Introduction to QuantStrats** [00:00] — Roman, a quantitative researcher and trader, introduces the series focused on quantitative trading strategies, aiming to bridge theory and practice.
- **Theoretical Mean Reversion** [00:41] — The video starts with the Ornstein-Uhlenbeck stochastic process, explaining what mean reversion should look like in theory and for an equity curve.
- **Reality Check: Non-Stationarity** [01:06] — In practice, there is no long-term mean; the Kalman filter is introduced to help solve this problem by adapting to changing means.
- **Estimating the Mean** [02:34] — Since the true mean is unknown, we estimate it from observed data. Trading long below the mean and short above it can generate wealth even if the estimate is not precise.
- **Implication of Estimation** [03:29] — We don't need the precise theoretical mean; appropriate bet sizing and being correct on average can generate wealth, as justified by the law of large numbers.
- **The Problem in Reality** [04:21] — Stock prices do not follow a mean-reverting process; the parameterization changes over time, which can wipe out the equity curve if not handled properly.
- **Choosing the Time Frame** [05:05] — The correct time frame for observing the mean is unclear (5 minutes, 30 minutes, etc.), and the mean must be updated to avoid trading around a stale mean.
- **Kalman Filter as a Solution** [05:34] — The Kalman filter combines knowledge (model assumptions) with experience (observed data) to adapt the mean in real time.
- **Knowledge and Experience** [07:41] — The knowledge is the assumption of mean reversion (Ornstein-Uhlenbeck), and the experience is the live data that drags the mean down, as seen in the green line.
- **Double-Edged Sword** [08:59] — Adaptive models are sensitive to noise; the trader must set the noise level, which dictates how much the mean changes relative to the original model.
- **Generating Trades** [10:18] — There are many ways to generate trades, including backtesting and walk-forward tests, but there is no asymptotic guarantee in practice.
- **Key Takeaways** [11:21] — The mean level changes over time; you need to be reasonably correct on average. There is no free lunch with adaptive models; trust the model or the data, each with trade-offs.

### Conclusion

The video emphasizes that while mean reversion strategies can be profitable in theory, real-world application requires adapting to changing means, and the Kalman filter offers a way to balance model assumptions with live data, but with inherent trade-offs.

## Transcript

Hey guys, Roman here, quantitative researcher and trader, founder of QuantGuild. Welcome to QuantStrats. In this series, we're going to talk about quantitative trading strategies and bridge
the gap between theory and practice. I find oftentimes we will explore a variety of different strategies and models, but very rarely do we actually discuss the implications in our decision making in the live markets.
And that's exactly the goal of this series and exactly what you see here in front of me. This is a Kalman Filter trading system that aims to implement this mean reversion trading strategy in practice.
What we're going to do today is talk about theoretically what mean reversion should look like. We're going to start in the classroom. We'll talk about the Ornstein-Olembach stochastic process, this idea of trading mean reversion,
what it should look like for your equity curve. and then we will branch out to reality. We'll talk about non-stationarity, this idea that there is no long-term mean,
and we'll talk about the implications of the Kalman filter to aid in solving this problem. As we approach the classroom, this Jupiter notebook, to discuss theoretically what mean reversion and trading mean reversion should look like,
and you'd like to access the source code for either this view through notebook or the Kalman filter trading system, I'll leave a link in the description below. I'll also post it to the Quantil library on GitHub, where you can find all of my view through notebooks and associated YouTube
videos, along with all of the source code for my Quant builds. But I must explicitly state, because the Kalman filter system has execution capacity, either in a discretionary or an algorithmic way, you should not trade with this system live, especially if you have no idea
what an Ornstein-Ollenbach process is. Master first your quantitative skills, your math, probability, statistics, and finance so that you can make informed decisions in the face of
uncertainty or target trading and market making roles. What better place to do this than quantguild.com. Over 100 hours of lecture content, an adaptive practice engine, 90 plus quant lessons,
the list goes on. You can get started for free today. Check out quantguild.com. Let's talk about what mean reversion and trading mean reversion should look like in theory. We
don't know what the mean of the stock price process should be. We don't even know what the expected return should be. So what can we do? Well, we can observe some data and estimate a mean. That's what
we're going to do here. I'm going to start by observing the stock price. I'll estimate a mean, and then I'm going to use that to inform my trading decisions. What you're seeing here on the right is trading this mean reversion strategy. Effectively, I'm going long anywhere we're
way below the mean, and I'm going short anywhere we're way above the mean. And you can see my equity curve here is just accumulating P Sure sometimes I lose a trade here and there but for the most part it up and to the right and that is exactly what we like to see But what I want you to notice is in this simulation here I estimated the mean level from observed data It is not precisely
the true theoretical mean of the Ornstein-Ollenbach process. What is the implication of this? Well, the implication is profound. We don't need the precise theoretical meaning to be able to generate
wealth. Effectively, we just need appropriate bet sizing and to be correct on average to be able to generate wealth with this strategy. It can't be that easy, can it? Well, it's not. Academically,
this is justified. In fact, asymptotically, we will be trading in a statistically optimal way. By the law of large numbers, we will approach the long-term mean of this Ornstein-Ollenbach process, and if we trade around that mean, we will be generating wealth in an optimal way, and then it just comes down to optimizing our bet sizing.
All right, what's the problem in reality? The problem in reality is the law of large numbers asymptotically does not converge to the long-run mean. Prices, stock price processes, do not follow an Ornstein-Ollenbach, a mean reverting stochastic process.
Moreover, the parameterization is subject to change over time. So it could revert to a mean for a period, then it can stop, then it can start reverting again, so on and so forth.
that will wipe out this beautiful equity curve that you see here. So the problem effectively now is we can measure a mean, we can observe data, but how do we observe it?
Do we observe it over five minutes, 30 minutes, 30 seconds, one hour daily, monthly? What is the correct time frame? More importantly, when should we update this mean?
If this mean is subject to change over time, we don't want to be trading around a stale mean. That's going to destroy our equity curve. This is exactly the problem that we face in practice.
This is where the Kalman filter can offer a helping hand. We're now ready to approach the Kalman filter trading system. Anytime you follow a trading strategy, you're going to be making assumptions.
Without a crystal ball, there is nothing else that you can do. You can act statistically optimally, statistically suboptimally in the classroom, but even still, there's no guarantee how that is going to function in the real world.
This is effectively poker. You don't have an indicator that's going to help you win every single hand of poker until you run to fold, run not to fold. Statistically, sure, some things are more optimal than others,
but sometimes you lose on the turn and that's the way that it goes. There is no one single indicator, one single model that going to make you a profitable trader That comes from a combination of knowledge and experience So what is it that we looking at here Well effectively the Kalman Filter is trying to do that
It's trying to combine knowledge and experience. What I have here in this live Kalman Filter trading system is an Ornstein-Ollenbach process calibrated to data.
In this case, I'm using one-minute bars. I have a calibration window of 60 bars. and I find that the mean is this gray dashed line. Well, what's the problem with this?
We already talked about this when we were in the Jupyter Notebook in the classroom. That mean is subject to change over time. When do we update it? How much has it changed by since I calibrated the original process?
Those are all very good and important questions. We can even try to answer them with some back tests and walk-forward tests and then we can observe out of sample if we're acting optimally, if there's stability in our decision-making,
but at the end of the day, it's still no guarantee. So what is it right now that we're looking at? What is it that we're trying to do with this Kalman filter? So I mentioned that it's trying to combine knowledge and experience.
What is the knowledge? Well, the knowledge is an assumption component. It is our laws of physics. I'm assuming that the stock price follows a mean reversion process. And when I calibrate that process to this observed data, like we saw in the classroom,
I get my long-term mean to be this gray dashed line. Whether it is or is not, we will never know. But we do know that it is subject to change over time. But how much has it changed since I originally calibrated that process?
Well, the Kalman filter is going to combine that ground truth, that model assumption, with the data that I'm actually observing. That is this green line here.
The green line is the Kalman filter mean. You can see that it has moved the Ornstein-Ollenbach's long-term mean down. Why is that the case?
Well, look at the trend. The trend is dragging that mean down, and the Kalman filter is being informed by the data that it's experienced, the long-term mean level. It is effectively combining the knowledge of the model with the experience of the data that it is seeing in the live market.
Anytime you have a model capable of adapting with the market, it is a double-edged sword. Sure, it's going to be able to adapt in real time. However, the sensitivity to noise is going to be the primary concern and why it is not a free lunch.
Effectively, you as the quant, the trader, the researcher, you are going to have to set how noisy you anticipate the data that you observe to be. This is going to dictate how much the mean level is going to change over time
as you observe new data relative to the fixed parameterization of the laws of physics your original mean reversion model and what I have here is effectively a lever that you can flip to see what it looks like to trust the model more the original
Ornstein-Olebach, which you calibrate to the data originally, or trust the market data more, in which case it's going to adapt much more aggressively. That is the trade-off when you
implement a model capable of adapting to market prices in real time. You never get something for nothing. There is no free lunch. That is your trade-off. Now that we have a reasonable idea of
what's going on in this trading system, how do we actually generate trades and make money with it? Well, I can't tell you how to play your hand of poker. You can't tell me how to play mine. There are a lot of different ways you could go about doing this. Like I said earlier, you can go about
conducting back tests while forward tests to try to find an optimal window, when you should reparameterize your Ornstein-Ohlenbach, what kind of noise you should anticipate in observed market data. There is a quantitative approach to it, but again, there's no asymptotic guarantee like we
have in the classroom. You could go through and jump through all of those hoops, and at the end of the day, when you deploy it live, everything falls apart. Moreover, you could be sitting here trading Apple for the last 10 years and understand qualitatively the dynamics based on macro factors,
political factors, sector factors, the list goes on, and you could use this as a model to inform your decision making, and you could outperform systematic strategies just because you have a
better grasp on the overall climate of the market. Some key takeaways today for you. The mean level that you calibrate for reversion is certainly going to change over time. You just need to be
reasonably correct on average to make money. Just because you calibrate it in one window, it doesn't mean that it is going to be correct. It is subject to change over time. Who knows what the true mean actually is? Moreover, when you deploy models to aid in trying to circumvent this
issue of mean changing over time, like the Kalman filter, there is no free lunch. You can either trust the model more, hold steadfast in the underlying laws of physics that you assume,
and trade aggressively back to that level, or you can trust the data more, in which case you are certainly subject to more whipsawing, you're subject to your assumptions violently changing over time, in which case you are not going to be capable of watching those species play out
or generating any wealth. That's going to do it for this video on trading mean reversion strategies, this QuantStats video. I hope you enjoyed. I hope you learned something.
If you like this video and you want to see more like it in the future, please like, comment, subscribe, share. It helps me out tremendously. It is always greatly appreciated. Check out quantkilled.com to master your quantitative skills before approaching a project like this,
before approaching the markets, or for targeting trading and market-making roles. Other than that, I want to thank you so much for watching, and I will see you in the next video.
