Most portfolios move with the market whether you want them to or not (here's how to measure it)
You've picked a handful of stocks, maybe built a small portfolio, and you're watching it go up or down each week.
But you don't really know why it's moving.
Is it your stock picks? Or is the whole market just dragging everything in the same direction? Without a way to answer that question, you're making decisions based on a feeling instead of a measurement.
Here's what I mean.
Studies consistently show that broad market forces explain the majority of a typical stock portfolio's movement.
Research by Fama and French found that just two additional forces beyond the overall market, company size and whether a stock looks cheap or expensive relative to its fundamentals, explain a large portion of returns that the market alone can't account for.
Most individual investors never measure these forces and end up surprised when their "diversified" portfolio drops in lockstep with everything else.
There's a structured way to get past this.
Once you can measure which forces are actually moving your portfolio, you can build tools and dashboards that show you exactly where your risk is concentrated.
Then you adjust on purpose instead of reacting after the fact.
Here's a Python example you can use now.
This assumes `factors` is a DataFrame with columns "SMB" and "HML" from the Fama-French dataset, and `active` is a pandas Series of your portfolio's monthly returns minus a benchmark like SPY.
This code takes your portfolio’s returns (after subtracting a benchmark like SPY) and measures how much of the remaining risk comes from two well-known market forces.
The first is company size, meaning whether your portfolio leans toward smaller or larger companies.
The second is investment style, meaning whether it leans toward stocks that look cheap on paper or stocks that are priced for growth.
The regression finds the sensitivity of your returns to each force, and the risk decomposition tells you what percentage of your portfolio’s ups and downs each force actually explains.
Whatever is left over is the “unexplained” portion, risk from individual stock events or other dynamics the model doesn’t capture.
If that unexplained number is large, it means something other than size and style is driving your portfolio, which is useful to know whether you planned for it or not.
Getting Started With Python for Quant Finance walks through this exact kind of risk analysis using tools like PyFolio and AlphaLens. It covers how to measure worst-case losses, how quickly an advantage fades over time, and how to tell whether your portfolio’s risk profile matches the bets you actually intended to make. If you want to go from a single code snippet to a full risk dashboard, the course gives you a clear path to get there.
Inside Getting Started With Python for Quant Finance
- 13 modules with 134 lessons. Step-by-step instruction that builds from pulling market data all the way through measuring portfolio risk, so you don’t have to piece together random tutorials.
- 40 code templates. Pre-built templates for risk measurement and portfolio analysis that you can modify for your own positions instead of writing everything from zero.
- Private community of 1,700+ Python traders. A place to ask questions when you get stuck on something like aligning time series data or interpreting regression output.
These resources are designed to take you from running a single script to maintaining a working portfolio analysis system.
What students are saying
"
A top-tier introduction to Python and quant finance.
"
– Zac T
|
Your next steps
Start by running the code above on your own portfolio.
Replace the three tech stocks with whatever you actually hold and look at the numbers.
Once you can see how much of your risk comes from identifiable forces versus unexplained sources, you’ll have a concrete basis for deciding what to change.
From there, a structured program can take you through building a full risk dashboard and connecting it to a live portfolio.
Build a risk system that shows you what’s actually happening 👉
Measure exactly which forces drive your returns, spot hidden risk before it surprises you, and make position changes based on numbers instead of guesses.