*Last Update: January 7, 2021*

**Portfolio performance metrics** consist of portfolio expected or realized risk premium by unit of risk.

This topic is part of **Investment Portfolio Analysis with Python** course. Feel free to take a look at Course Curriculum.

This **tutorial** has an educational and informational purpose and doesn’t constitute any type of trading or investment advice. All content, including code and data, is presented for personal educational use exclusively and with no guarantee of exactness of completeness. Past performance doesn’t guarantee future results. Please read full Disclaimer.

An example of portfolio performance metrics is **Treynor ratio** [1] which consists of portfolio expected or realized risk premium by unit of systematic market risk.

**1. Formula notation.**

1.1. Ex-ante or expected Treynor ratio formula notation.

Where = ex-ante or expected portfolio returns Treynor ratio, = ex-ante or expected portfolio returns risk premium, = ex-ante or expected portfolio returns market beta, = ex-ante or expected portfolio and market returns covariance, = ex-ante or expected market returns variance, = risk free or benchmark returns can be used.

1.2. Ex-post or realized Treynor ratio formula notation.

Where = ex-post or realized portfolio returns Treynor ratio, = ex-post or realized portfolio returns risk premium, = ex-post or realized portfolio returns mean, = ex-post or realized risk free returns mean, = ex-post or realized portfolio returns market beta, = ex-post or realized portfolio and market returns covariance, = ex-post or realized market returns variance, = risk free or benchmark returns can be used.

1.3. Ex-post or realized Treynor ratio risk free or benchmark returns through time period assumptions formulas notation.

Where = ex-post or realized risk free returns through time period, = number of observations in time period, = constant, = ex-post or realized portfolio returns Treynor ratio, = ex-post or realized portfolio returns risk premium, = ex-post or realized portfolio returns mean, = ex-post or realized risk free returns mean, = ex-post or realized portfolio returns risk premiums market beta, = ex-post or realized portfolio and market returns risk premiums covariance, = ex-post or realized market returns risk premiums variance, = ex-post or realized risk free return, = ex-post or realized portfolio returns market beta, = ex-post or realized portfolio and market returns covariance, = ex-post or realized market returns variance, = risk free or benchmark returns can be used.

**2. Python code example.**

2.1. Import Python packages [2].

```
import numpy as np
import pandas as pd
```

2.2. Treynor ratio performance metric data reading.

- Data: S&P 500® index replicating ETF (ticker symbol: SPY) adjusted close prices and market portfolio [3] monthly arithmetic returns (2007-2016).

`returns = pd.read_csv('Data//Treynor-Ratio-Performance-Metric-Data.txt', index_col='Date', parse_dates=True)`

2.3. Treynor ratio performance metric calculation and output.

- Note: ex-post or realized Treynor ratio calculation and risk-free return assumption not fixed and only included for educational purposes.

```
In:
print('== Treynor Ratio Performance Metric (SPY) ==')
print('')
print('Monthly Treynor Ratio (Rf=0%):', np.round(returns['SPY'].mean() /
(returns.cov().iloc[0, 1]/returns['MKT'].var()), 6))
```

```
Out:
== Treynor Ratio Performance Metric (SPY) ==
Monthly Treynor Ratio (Rf=0%): 0.006608
```

##### 3. References.

[1] Jack L. Treynor. “How to Rate Management of Investment Funds”. *Harvard Business Review*. 1965.

[2] Travis E, Oliphant. *“A guide to NumPy”*. USA: Trelgol Publishing. 2006.

Stéfan van der Walt, S. Chris Colbert and Gaël Varoquaux. “The NumPy Array: A Structure for Efficient Numerical Computation”. *Computing in Science & Engineering*. 2011.

Wes McKinney. “Data Structures for Statistical Computing in Python.” *Proceedings of the 9th Python in Science Conference*. 2010.

[3] Eugene F. Fama and Kenneth F. French. “Common Risk Factors in the Returns on Stocks and Bonds,” *Journal of Financial Economics*. 1993.