Build the Treynor ratio in Python to separate skill from market exposure.

By PyQuant News

Published: 2026-06-20

URL: https://pyquantnews.substack.com/p/big-returns-dont-mean-good-trading


Each week, I send out one Python tutorial to help you get started with algorithmic trading, market data analysis, and quant finance. Upgrade to a paid plan to access the Python code notebooks, Discord community, and code support.


Most traders think performance means making money.

That’s only half the picture. A trader who earns 20% by betting everything on one position isn’t performing the same as a trader who earns 15% with careful, measured risk. The difference between those two traders only shows up when you measure returns relative to the risk taken.

Without that measurement, you can’t tell skill from luck, and you’ll keep repeating strategies that feel profitable but are actually fragile.

A ratio that changed everything

Early in my career, a team of analysts started digging into why certain traders were making so much money. What they found wasn’t just high returns. It was high returns paired with high risk. Once the firm started measuring performance against the risk each trader was taking, everything changed.

Most beginners skip this step entirely. They look at total return and assume bigger is better.

Professionals don’t evaluate strategies by return alone. They divide the return by the risk to see if the performance is actually worth it.

What you’ll build today

In this post, you’ll use Python to calculate a stock’s risk relative to a benchmark, then use that to compute a ratio that tells you how much return you’re getting for each unit of risk you can’t avoid.

Let’s go.