{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Sharpe Ratio - Introduction\n", "\n", "\n", "Sharpe Ratio is the most common metric used to measure risk in finance.\n", "\n", "The formula is \n", "\n", "> (return on portfolio - risk free rate)/standard deviation of the excess return on the portfolio\n", "\n", "There are tons of resources on the internet about sharpe ratio.\n", "\n", "[This investopedia page](https://www.investopedia.com/terms/s/sharperatio.asp) is a good introduction.\n", "\n", "In this series of articles, we take a deep dive into the sharpe ratio and its variations and usage.\n", "\n", "We assume the risk free rate to be zero, then the formula simply becomes mean returns divided by the standard deviation of returns. The following terms are used interchangebly throughout this article\n", "\n", " * mean returns/average returns/mu\n", " * standard deviation of returns/deviation/sigma\n", "\n", "We would be working on the NSE Nifty 50 index data" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import empyrical as ep\n", "from typing import Tuple\n", "import seaborn as sns\n", "sns.set()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "tags": [ "parameters" ] }, "outputs": [], "source": [ "# Parameters \n", "# useful when running as a papermill notebook\n", "\n", "filename:str = '/tmp/nifty.csv'\n", "periods:Tuple[str] = ('W','M','Y')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | open | \n", "high | \n", "low | \n", "close | \n", "daily_return | \n", "
---|---|---|---|---|---|
date | \n", "\n", " | \n", " | \n", " | \n", " | \n", " |
2000-01-03 | \n", "1482.15 | \n", "1592.90 | \n", "1482.15 | \n", "1592.2 | \n", "NaN | \n", "
2000-01-04 | \n", "1594.40 | \n", "1641.95 | \n", "1594.40 | \n", "1638.7 | \n", "0.029205 | \n", "
2000-01-05 | \n", "1634.55 | \n", "1635.50 | \n", "1555.05 | \n", "1595.8 | \n", "-0.026179 | \n", "
2000-01-06 | \n", "1595.80 | \n", "1639.00 | \n", "1595.80 | \n", "1617.6 | \n", "0.013661 | \n", "
2000-01-07 | \n", "1616.60 | \n", "1628.25 | \n", "1597.20 | \n", "1613.3 | \n", "-0.002658 | \n", "