# How to calculate Sharpe Ratio from $returns? I have a pairs strategy that I am trying to calculate the sharpe ratio for. Currently I am using python for my analysis and calculation. I have a dataframe that contains the cumulative returns in$'s for each day. I am confused on how to convert this information into something that I can calculate the sharpe ratio from.

Could anyone point me in the right direction on how to use cumulative returns (in \$'s) to find the sharpe ratio? Any help is appreciated! Thanks

Let's say your cumulative return series is $$\{R_i \mid i=0,1,...,N-1\}$$ of length $$N$$ days.

There's 3 conventional ways to do this at this stage. You may convert the cumulative dollar return curve into arithmetic returns:

$$\displaystyle{r_i}= \dfrac{R_i-R_{i-1}}{R_{i-1}}$$

Or dollar returns:

$$\displaystyle{r_i=R_i-R_{i-1}}$$

Then take the ratio:

$$\displaystyle{SR_{1d} = \dfrac{E\{r_i\}-r_f}{std\{r_i\}} }$$

where the risk-free rate $$r_f$$ is often taken to be $$0$$. Finally, you annualize it:

$$\displaystyle{SR_{1y}=SR \cdot \sqrt{252}}$$

Here's an example of how you can do it in Python:

import numpy as np
import pandas as pd

# Simulate cumulative returns of 100 days
N = 100
R = pd.DataFrame(np.random.normal(size=100)).cumsum()

# Approach 1
r = (R - R.shift(1))/R.shift(1)

# Approach 2
r = R.diff()

sr = r.mean()/r.std() * np.sqrt(252)

• I still seem to be getting an abnormally large value for my sharp ratio (~5). I should mention that this is being calculated from returns on a pairs trading strategy. Is there anything that would change because of this, or should I assume that something among my prior calculations is off. Commented May 15, 2018 at 23:54
• It doesn't matter what kind of strategy you're testing this on. 5 isn't unusual, for strategies like that you probably just have wrong slippage assumptions. Commented May 16, 2018 at 1:16
• @madilyn is this python code missing the annualization of the SR? Because I'm getting something ridiculous after converting to an annualized ratio. Commented Nov 15, 2018 at 14:31
• You are right, the last line should read sr = r.mean()/r.std() * np.sqrt(252). Commented Nov 16, 2018 at 3:02
• You should include that in the answer above, some people (myself included) don't always read the comments and might miss it, thanks. Commented Jan 30, 2019 at 5:49

With the other answer, the Sharpe ratio might be positive although the returns are negative. This comes from the fact that geometric mean and arithmetic mean are different.

The following approach could be used:

returns = pd.DataFrame(np.random.normal(size=100))
mean_log_returns = (np.mean(np.log(returns + 1)))
mean_returns = np.exp(mean_log_returns) - 1
std = returns.std()
sharpe_ratio = mean_returns / std * np.sqrt(252)