🐍 How to measure what's really driving your returns


EXCLUSIVE PARTNER DEAL FOR PYQUANT NEWS READERS:

20% off options-based trading signals

MenthorQ uses the options market to generate trading signals for stocks and futures. Join with an exclusive discount.

Be sure to use the discount code PYQUANTNEWS20.

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.


Jason Strimpel, founder of PyQuant News

Say 👋 on X/Twitter, LinkedIn, or book a call with me. You can always reply to these emails. I check them all

You got this email because you joined the PyQuant Newsletter or bought a product of mine.

You told me your email address is Reader.

Not right? Update your profile.

Want to stop getting these emails? No problem! Unsubscribe from all my emails.

Never investment advice. Use at your own risk. For educational purposes.

113 Cherry St #92768, Seattle, WA 98104

© 2026 PyQuant News, LLC

PyQuant Tips

For finance professionals, coders, and complete beginners. Automate your trading, investing, and data analysis with Python. No jargon, no fancy math, code you can use.

Read more from PyQuant Tips
Decompose time series into trend, seasonality, and noise with Python to build better forecasting models for quant finance.

Most beginners model a whole time series at once (here's why that fails) You sit down with a price chart or an economic indicator, build a model, and the predictions look solid on historical data. Then you feed in new data and the results fall apart. If that sounds familiar, you're not alone. The problem usually isn't your model. It's that you skipped a step professionals never skip. Most financial and economic data contains several patterns layered on top of each other. There's a long-term...

Calculate the Hurst exponent in Python to detect trending or mean-reverting markets. Pick the right trading strategy.

EXCLUSIVE PARTNER DEAL FOR PYQUANT NEWS READERS: 20% off options-based trading signals MenthorQ uses the options market to generate trading signals for stocks and futures. Join with an exclusive discount. Grab your 20% discount with this link 👉 Be sure to use the discount code PYQUANTNEWS20. Most traders use the same strategy no matter what the market is doing (here's how to know when to switch) You've probably found a strategy that looked great on a chart, then watched it bleed money for...

Smooth stock prices in Python with a Kalman filter. Replace arbitrary moving average windows with adaptive estimates.

EXCLUSIVE PARTNER DEAL FOR PYQUANT NEWS READERS: 20% off options-based trading signals MenthorQ uses the options market to generate trading signals for stocks and futures. Join with an exclusive discount. Grab your 20% discount with this link 👉 Be sure to use the discount code PYQUANTNEWS20. 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...