# Sharpe Ratio: Calculation, Application, Limitations

Contributor:
QuantInsti
Visit: QuantInsti

Excerpt

William Sharpe introduced a simple formula to help compare different portfolios and help us find the most feasible of them all. Let’s understand its mechanism in this article.

What is Sharpe Ratio?

Sharpe ratio is a measure for calculating risk-adjusted return. It is the ratio of the excess expected return of investment (over risk-free rate) per unit of volatility or standard deviation.

Let us see the formula for Sharpe ratio which will make things much clearer. The sharpe ratio calculation is done in the following manner

`Sharpe Ratio = (Rx – Rf) / StdDev(x)`

Where,
x is the investment
Rx is the average rate of return of x
Rf is the risk-free rate of return
StdDev(x) is the standard deviation of Rx

Sharpe Ratio can be used in many different contexts such as performance measurement, risk management and to test market efficiency. When it comes to strategy performance measurement, as an industry standard, the Sharpe ratio is usually quoted as “annualised Sharpe” which is calculated based on the trading period for which the returns are measured. If there are N trading periods in a year, the annualised Sharpe is calculated as:

`Sharpe Ratio = √N (E(Rx – Rf) / StdDev(x))`

Sharpe ratio in Python

If you would like to find the Sharpe ratio on your own, you can try the following Python code:

# Load the required modules and packages
import numpy as np
import pandas as pd
# Pull NIFTY data from Yahoo finance
# Compute the logarithmic returns using the closing price
returns = np.log(NIFTY[‘Close’] / NIFTY[‘Close’].shift(1))
volatility = returns.std() * np.sqrt(252)
sharpe_ratio = (returns.mean() – 0.05) / volatility
sharpe_ratio

The above program gives the following output: