Most beginners pick a moving average window that looks good on old data, then watch it fail on new data (here's how to fix that)
You've probably spent time tweaking a moving average, trying 20 days, then 30, then 50, looking for the one that makes your strategy look profitable.
Each time you change the number, the results shift.
You're not learning anything about the market.
You're just fitting your analysis to the past.
Studies consistently show that most retail traders lose money, and a big reason is building strategies around parameters that only worked on historical data.
When you pick the moving average window that looks best in a backtest (a simulation of how a strategy would have performed on past prices), you're almost guaranteed to be disappointed when you trade it live.
The strategy didn't find a real pattern.
It found a coincidence.
The good news?
There's a way to get past this.
Instead of guessing at parameters, you can use methods that adapt automatically to new data as it arrives.
That removes one of the biggest sources of false confidence in early-stage trading research, and it's a skill that translates directly into building strategies you can actually trust with real money.
Here's a Python example you can use now.
Assumes `prices` is a pandas Series of daily closing prices with a datetime index, and that `KalmanFilter` has been imported from `pykalman`.
This code produces a smoothed price series that updates itself with every new data point.
Unlike a traditional moving average where you have to pick a fixed number of days, the Kalman filter decides at each step how much to trust the new price versus its running estimate.
The ratio between the two covariance parameters (observation_covariance and transition_covariance) is the only thing you set, and it controls how smooth the output is.
A higher ratio means the filter treats more of the daily price movement as noise and smooths more aggressively.
You can use this smoothed series anywhere you’d normally use a moving average, as a trend indicator or as a baseline to measure how far the current price has moved from its recent average.
Getting Started With Python for Quant Finance walks through this exact kind of workflow, from pulling market data to testing whether a trading idea actually makes money on data it hasn’t seen before.
The course covers how to avoid the common traps that make strategies look good in testing but fall apart in live trading.
Inside Getting Started With Python for Quant Finance
- 40 code templates. Instead of writing a Kalman filter or a backtest (a historical simulation of a strategy) from scratch, you start with working code and modify it for your own ideas.
- Step-by-step strategy workflow. The course follows a structured process for designing tests and running simulations, so you don’t waste weeks tweaking parameters that don’t matter.
- Private community of 1,700+ Python traders. When you get stuck on something like choosing the right covariance ratio, you can ask people who’ve already solved the same problem.
These resources are designed to take you from “I have a trading idea” to “I’ve tested it properly and know whether it works.”
What students are saying
"
A top-tier introduction to Python and quant finance.
"
– Zac T
|
Your next steps
Start by replacing one moving average in your current analysis with the Kalman filter code above and compare the two side by side.
Once you see how adaptive smoothing works on real prices, the natural next step is learning how to test whether that smoother actually improves a trading strategy on data it hasn't seen.
A structured curriculum gets you there faster than piecing together random tutorials, and you'll finish with a working strategy tested on years of historical data.
Build trading strategies you can actually trust 👉
Learn a complete workflow for going from a raw trading idea to a tested, automated strategy, using the same tools and methods that professional trading teams rely on.