Skip to content

Sharpe Ratio does not take risk-free rate as a parameter #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
afzalmushtaque opened this issue May 20, 2020 · 5 comments · Fixed by #281
Closed

Sharpe Ratio does not take risk-free rate as a parameter #71

afzalmushtaque opened this issue May 20, 2020 · 5 comments · Fixed by #281
Labels
enhancement New feature or request

Comments

@afzalmushtaque
Copy link

afzalmushtaque commented May 20, 2020

Backtesting.py Line #954

s.loc['Sharpe Ratio'] = mean_return / (returns.std() or np.nan)

Expected Behavior

s.loc['Sharpe Ratio'] = (mean_return - risk_free_return) / (returns.std() or np.nan)

Actual Behavior

s.loc['Sharpe Ratio'] = mean_return / (returns.std() or np.nan)

Additional info

Sharpe Ratio

@kernc
Copy link
Owner

kernc commented May 20, 2020

With interest rates effectively zero or negative, and with short-term bond yields close to zero, assuming the risk-free rate at 0% was an honest, intended, and not unreasonable simplification.

Does your Sharpe change significantly if you amend it so?

@afzalmushtaque
Copy link
Author

Yes it does. Risk free rate here in India is ~6%.

@kernc
Copy link
Owner

kernc commented May 21, 2020

As a quick workaround, might this fix your Sharpe?

def adjusted_sharpe(stats, riskfree_rate=.06):
    mean_return = stats['Avg. Trade [%]'] / 100
    return stats['Sharpe Ratio'] / mean_return * (mean_return - riskfree_rate)

You can also use it to optimize: Backtest.optimize(..., maximize=adjusted_sharpe)

@afzalmushtaque
Copy link
Author

afzalmushtaque commented May 21, 2020

Haha thanks for going the extra mile but that's pretty much what I am already doing. Not a deal breaker for me. However most users kind of expect a risk-free-rate parameter for a Sharpe function coming from other quant packages so I guess adding it would avoid some confusion and time spent scouring through the source code to ensure it hasn't been hardcoded to something like 2%.

@kernc
Copy link
Owner

kernc commented Aug 3, 2021

It is since v0.3.2 possible to use backtesting.lib.compute_stats and recompute the statistics with a custom risk-free rate:

stats = Backtest(GOOG, MyStrategy).run()
new_stats = compute_stats(stats=stats, data=GOOG, risk_free_rate=.02)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants