Created
November 9, 2020 09:56
-
-
Save timotewb/ac534acb1634b7c7639a79982a8a555d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sharpeRatio(returns, periods, rf=0): | |
# --- Annualised Sharpe Ratio | |
# returns: array, percentage change values in decimals | |
# periods: int, annual periods in returns (e.g. days = 252, months = 12) | |
# rf: decimal, Risk Free Rate generally zero but can be specified as a decimal | |
import numpy as np | |
sr = np.sqrt(periods) * ((np.nanmean(returns) - rf) / np.nanstd(returns)) | |
# --- if value is +-inf then set to Nan | |
if sr == np.inf or sr == -np.inf: | |
sr = np.nan | |
return sr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment