🐍 How to measure what's really moving your portfolio


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.

​

You think your stocks are diversified, but you've never actually measured it (here's how)

You pick stocks from different sectors, assume they'll behave independently, and move on.

Then the market drops and everything in your portfolio falls together.

The problem isn't bad stock picks.

The problem is you never had a way to measure whether your stocks were actually independent in the first place.

Studies consistently show that a small number of broad forces (overall market direction, interest rate moves, sector rotation) explain the majority of individual stock returns.

One well-known estimate from academic research puts the figure at roughly 70% of a typical stock's movement coming from factors shared with other stocks.

Most people never measure this, so they carry far more concentrated risk than they realize.

There's a structured way to check whether your portfolio is genuinely spread across different risk drivers or just one big bet wearing different ticker symbols.

Once you can measure that, you can start building tools and dashboards that track where your real risk sits and adjust before the next selloff.

Here's how it works with Python.

Assumes `portfolio_returns` is a pandas DataFrame where each column holds daily percentage returns for one stock.

This code takes your portfolio’s daily returns and finds the few hidden statistical patterns that explain most of the movement.

The printed percentages tell you how concentrated your risk really is.

If the first component explains 50% or more, a single force (usually broad market direction) dominates your portfolio regardless of how many different tickers you own.

The bar chart then shows each stock’s sensitivity to that dominant force.

Stocks with similar bar heights move together.

Stocks with opposite signs genuinely offset each other.

You can use this to spot false diversification and decide which positions to add or remove.

​Getting Started With Python for Quant Finance walks through this exact kind of analysis as part of a complete risk measurement workflow.

It covers how to use tools like PyFolio and AlphaLens to measure worst-case losses, track how quickly an advantage fades, and calculate risk-adjusted returns, so you can build a real dashboard instead of guessing at your exposure.

Inside Getting Started With Python for Quant Finance

  • Step-by-step frameworks that take you from raw price data to a working risk analysis, so you don't waste weeks figuring out which steps come in what order.
  • 40 code templates covering portfolio management and risk measurement that you can modify for your own positions instead of writing everything from scratch.
  • A private community of 1,700+ Python traders where you can ask questions when you get stuck on something like interpreting PCA output or connecting it to your broker.

These resources give you a clear path from "I downloaded some stock data" to "I understand exactly where my portfolio risk comes from and I can track it automatically."

What students are saying:

⭐️ ⭐️ ⭐️ ⭐️ ⭐️
" A top-tier introduction to Python and quant finance. "
– Zac T
​

Your next steps

Start by pulling daily returns for the stocks you actually own and run the PCA code above. Look at how much the first component explains. If it's above 50%, you know your portfolio is less diversified than you thought, and you have a concrete number to work with. From there, a structured program can show you how to hedge out the drivers you don't want and build a monitoring system that flags when your risk concentration changes.

​Build a portfolio you actually understand πŸ‘‰β€‹

Learn how to measure your portfolio's hidden risk drivers, test strategies on historical data, and connect everything to a live broker so your analysis doesn't just sit in a notebook.


​

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...