# PQN #036: How the Treynor ratio landed me a \$100 million trading book

In 2014, the tension was high as the trading bench manager called for an all-hands meeting.

Everyone knew something was off.

Only a week prior, regulators had conducted a surprise raid on the London office, with only an hour’s notice, searching for evidence of rogue trading.

As I sat in our Chicago office, I couldn’t help but wonder if it was happening to us too.

But as the details emerged, we all breathed a collective sigh of relief.

It wasn’t a raid—it was something entirely unexpected.

It turned out that our traders were making too much money. Yes, you read that right—too much money.

“Uhh, duh!”

We all knew our traders made a lot of money, but it was one of those unspoken truths that we never really talked about.

Until now.

What happened next would change the course of my career forever:

I was tasked with managing a \$100 million book of credit.

And it all started with a simple ratio.

## Use Python to calculate a stock’s beta against its benchmark. Then use it to compute the Treynor ratio.

The Treynor ratio measures the reward-to-volatility ratio and helps traders understand how much reward they get for each unit of risk.

When used with other risk metrics like the Sharpe ratio, the Treynor ratio helps measure your risk-adjusted returns.

Unlike the Sharpe ratio, the Treynor ratio uses beta against a benchmark to measure risk. In a previous newsletter, you learned how beta is used by quant traders. Beta is a considered systematic risk that cannot be diversified away. Treynor measures the return investors receive for every unit of risk that cannot be diversified away.

### Imports and set up

For today’s newsletter, all you need is data. Import the OpenBB SDK to get it.

`from openbb_terminal.sdk import openbb`
```Now grab the data and compute the returns.

"JPM, SPY",
start_date="2014-01-01",
end_date="2022-12-31"
)

asset_returns = asset.pct_change().dropna()
benchmark_returns = benchmark.pct_change().dropna()
```

This code pulls 8 years of stock price history, extracts the price data, and computes the daily returns. I use SPY as the benchmark, but you can use any benchmark you want.

### Compute the Treynor ratio

Start by computing beta.

```bm_cov = benchmark_returns.rolling(
window=30
).cov(asset_returns)

bm_var = benchmark_returns.rolling(
window=30
).var()

beta = bm_cov / bm_var
```

The beta coefficient is the covariance between the returns of the benchmark and the asset divided by the variance of the benchmark. Using pandas makes it easy to compute it.

And finally, compute the Treynor ratio.

```treynor = (
asset_returns - benchmark_returns
) / beta

treynor.plot()
```

The Treynor ratio is the active return (portfolio returns minus the benchmark return) divided by the beta.

It measures how much return you earn over the benchmark for every unit of risk you take on.

A higher Treynor ratio is better which means the investment is earning a high return compared to the systematic risk it’s taking on.

### Back to the story…

A team of analysts had been crunching numbers trying to get a better understanding of the traders’ performance.

They realized a particular trader’s Treynor ratio had consistently been through the roof.

This led to more digging, and soon they realized that most of the traders had high Treynor ratios.

They dug deeper and discovered that the traders were taking on high-risk trades. Soon, traders were paid based on their risk-adjusted returns, not just their returns.

This was a game-changer for the traders, and their performance only continued to improve. As they grew more confident, they began taking on even more high-risk counterparties, which paid off in spades.

But there was another surprise in store for them.

I landed the book of \$100 million in CVA and the traders were paid not only on their risk-adjusted returns but their credit-adjusted returns as well.

And it all started with the Treynor ratio.