Sharpe ratio and Sortino ratio

Financial Trading in Python

Chelsea Yang

Data Science Instructor

Which strategy performs better?

$$

Strategy 1:
  • Return: 15%
  • Volatility (standard deviation): 30%

$$

Strategy 2:
  • Return: 10%
  • Volatility (standard deviation): 8%
Financial Trading in Python

Risk-adjusted return

  • Make performance comparable among different strategies
  • A ratio that describes risk involved in obtaining the return

Risk vs. reward

Financial Trading in Python

Sharpe ratio

$$ \text{Sharpe Ratio} = (R_p - R_r)/\sigma_p $$

$$

  • $R_p $: Return of a strategy, portfolio, asset, etc.
  • $R_r $: Risk-free rate
  • $\sigma_p $: Standard deviation of the excess return ($R_p-R_f$)

$$

  • The bigger the Sharpe ratio, the more attractive the return
Financial Trading in Python

Now choose again

$$

Strategy 1:
  • Return: 15%
  • Volatility (standard deviation): 30%
  • Sharpe ratio: 15%/30% = 0.5

$$

Strategy 2:
  • Return: 10%
  • Volatility (standard deviation): 8%
  • Sharpe ratio: 10%/8% = 1.25
Financial Trading in Python

Obtain Sharpe ratio from bt backtest

resInfo = bt_result.stats
# Get Sharpe ratios from the backtest stats
print('Sharpe ratio daily: %.2f'% resInfo.loc['daily_sharpe'])
print('Sharpe ratio monthly %.2f'% resInfo.loc['monthly_sharpe'])
print('Sharpe ratio annually %.2f'% resInfo.loc['yearly_sharpe'])
Sharpe ratio daily: 0.49
Sharpe ratio monthly 0.48
Sharpe ratio annually 1.34
Financial Trading in Python

Calculate Sharpe ratio manually

# Obtain annual return
annual_return = resInfo.loc['yearly_mean']

# Obtain annual volatility volatility = resInfo.loc['yearly_vol']
# Calculate Sharpe ratio manually sharpe_ratio = annual_return / volatility print('Sharpe ratio annually %.2f'% sharpe_ratio)
Sharpe ratio annually 1.34
Financial Trading in Python

Limitations of Sharpe ratio

  • Penalize both the "good" and "bad" volatility
  • Upside volatility can skew the ratio downward

Sharpe ratio limitations

Financial Trading in Python

Sortino ratio

$$ \text{Sortino Ratio} = (R_p - R_r)/\sigma_d $$

  • $R_p $: Return of a strategy, portfolio, asset, etc
  • $R_r $: Risk-free rate
  • $\sigma_d $: Downside deviation of the excess return ($R_p-R_f$)

Downside vol

Financial Trading in Python

Obtain Sortino ratio from bt backtest

resInfo = bt_result.stats
# Get Sortino ratio from backtest stats
print('Sortino ratio daily: %.2f'% resInfo.loc['daily_sortino'])
print('Sortino ratio monthly %.2f'% resInfo.loc['monthly_sortino'])
print('Sortino ratio annually %.2f'% resInfo.loc['yearly_sortino'])
Sortino ratio daily: 0.70
Sortino ratio monthly 0.86
Sortino ratio annually 2.29
Financial Trading in Python

Let's practice!

Financial Trading in Python

Preparing Video For Download...