🐍 Why your risk number counts winning days


Standard deviation counts a 6% day above the mean and a 6% day below it as the same risk

np.std(returns) * np.sqrt(252) is one line, and it produces the volatility figure, the standard measure of how far a price swings from its average, that shows up on nearly every broker screen.

Now picture two equity curves with the same standard deviation, one that jumped 9% in a single week and one that bled about 1% a week for two months.

The measure scores them identically, so a ranking built on it alone can't tell you which fund had the worse month.

The problem has been known for decades.

Harry Markowitz described semivariance, which measures only the returns that fall below your target instead of all of them, in his 1959 book Portfolio Selection, and then noted it cost more to compute than plain variance.

Computing power stopped being the constraint a long time ago, but what keeps variance in place now is comparability, because everyone calculates it the same way, while a downside measure changes with the target you pick, so two people can report different numbers for the same returns.

The risk reports I built ran on a short list of measures, downside deviation and the worst peak-to-trough loss among them, and the notebook that produces them is the same code you schedule to run each morning.

Start by writing them yourself in ten lines, where you have to pick the target and the annualization factor by hand instead of accepting a library's defaults.

Here's a Python example you can use now.

Assumes NumPy is imported as np and returns is a pandas Series or NumPy array of daily percent changes.

Run this on AAPL daily adjusted closes from 2015 through 2024 and the downside deviation lands roughly a third below the standard deviation of the same returns, because the stock spent most of that decade rising.

The two calculations differ in what they subtract.

Downside deviation subtracts your target and discards everything above it, while standard deviation subtracts the mean and keeps both sides, so a 6% up day adds zero to the first sum and about 0.0036 to the second, and it sits in both denominators.

Print the two side by side for every strategy you test, then look at a histogram of the returns before you conclude anything, since the same gap can come from three big rally days or from a long quiet stretch.

The monthly reports I built kept snagging on this, a sample with fewer than about 30 losing days swings hard when one bad day rolls out of the window, so count them before you size anything off it.

Your next steps

Calculate downside deviation and standard deviation for one ticker you already follow, then add a third column with the Sortino ratio, which divides your return above the target by downside deviation to show reward per unit of loss risk.

Once those three numbers run on a single stock, extend the same code across a basket of positions and write the output to a table you refresh daily.

At that point you have a risk table for your own portfolio that updates without you rewriting anything.


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
Every strategy makes 1 of 3 bets: Use Python to tell you which one.

Sort any trading idea into 1 of 3 bets with 4 lines of Python Every strategy makes 1 of 3 bets: Use Python to tell you which one. My master's degree taught me MATLAB. Not Python. Since I didn't want to pay the $2,000 license fee, I watched every YouTube video I could find to teach myself. 96% of them were a complete waste of time. The other 4% buried me in strategy ideas. Statistical arbitrage. Trend and momentum. Pairs trading... Maybe that's you. A head full of trading ideas but nothing...

Use the workbook you already have.

Move from Excel to Python in 3 simple steps Use the workbook you already have. Most finance work still runs on Excel. When I was a derivatives trader, most the $7 billion operation was based on Excel. The process was the same: You build the model, drag the formulas down and refresh it every Monday. Eventually, the sheets got too big and wouldn't even open. The analysis was basic and not that interesting. An actuary in one of my courses said most of his analysis lived in Excel, and "it was...

You don't need a $30,000 terminal to build an AI research desk Let Python pick what matters. Let the agent explain it. A Bloomberg Terminal costs about $30,000 a year. So you do what everyone does: You paste news headlines into ChatGPT. Then a 10-K. Then a chart. Then another chat window. By Friday you have 40 chats, 12 browser tabs, and no idea if any of what ChatGPT came up with works. That's experimenting, which is fine, but the sooner you build a system, the sooner you get results. Every...