Financial Trading in Python
Chelsea Yang
Data Science Instructor
$$
$$
$$ \text{Sharpe Ratio} = (R_p - R_r)/\sigma_p $$
$$
$$
$$
$$
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
# 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
$$ \text{Sortino Ratio} = (R_p - R_r)/\sigma_d $$
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