Volatility and measures of risk-adjusted return with Python

Volatility (1)

In this post we see how to compute historical volatility in python, and the different measures of risk-adjusted return based on it. We have also provided the python codes for these measures which might be of help to the readers.

Introduction

Volatility measures the dispersion of returns for a given security. Volatility can be measured by the standard deviation of returns for a security over a chosen period of time. Historic volatility is derived from time series of past price data, whereas, an implied volatility is derived using the market price of a traded derivative instrument like an options contract.

Example: Computing historic volatility for NIFTY

First, we use the log function from numpy to compute the logarithmic returns using NIFTY closing price, and then use the rolling_std function from pandas plus the numpy square root function to compute the annualized volatility. The rolling function uses a window of 252 trading days. Each of the days in the selected lookback period is assigned an equal weight. The user can choose a longer or a shorter period as per his need.

volatility chart

 

Measures of risk-adjusted return based on volatility

Sharpe ratio

The Sharpe ratio which was introduced in 1966 by Nobel laureate William F. Sharpe is a measure for calculating risk-adjusted return. The Sharpe ratio is the average return earned in excess of the risk-free rate per unit of volatility.

Following is the code to compute the Sharpe ratio in python. The inputs required are the returns from the investment, and the risk-free rate (rf).

Information ratio (IR)

The information ratio is an extension of the Sharpe ratio which replaces the risk-free rate of return with the returns of a benchmark portfolio. It measures a trader’s ability to generate excess returns relative to a benchmark.

Following is the code to compute the Information ratio in python. The inputs required are the returns from the investment, and the benchmark returns.

Modigliani ratio (M2 ratio)

The Modigliani ratio measures the returns of the portfolio, adjusted for the risk of the portfolio relative to that of some benchmark. To calculate the M2 ratio, we first calculate the Sharpe ratio and then multiply it with the annualized standard deviation of a chosen benchmark. We then add the risk-free rate to the derived value to give M2 ratio.

Following is the code to compute the Modigliani ratio in python. The inputs required are the returns from the investment, benchmark returns, and the risk-free rate.

 

Next Steps

In our coming posts we will cover other risk measures, and the measures of risk-adjusted returns. You can also catch our other blogs available under the Risk and portfolio management category.

To understand Risk Management in Financial Institutions, have a look at the blogpost. The key requirement in successful options trading involves understanding and implementing options pricing models. In this post, a brief understanding about Greeks is given, which will help in creating and understanding the pricing models.

Leave a Reply

Your email address will not be published. Required fields are marked *