Created
February 14, 2019 07:45
-
-
Save xoelop/6ce27b73a3bc6048e555838216f074b1 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
import pandas as pd | |
import numpy as np | |
def ratio(ret1: pd.Series, | |
ret2: pd.Series = 0, | |
ratio: str = 'sharpe', | |
log: bool = True) -> float: | |
"""log: if True, convert ret1 and ret2 to log returns""" | |
if log: | |
ret1 = np.log1p(ret1) | |
ret2 = np.log1p(ret2) | |
ret = ret1 - ret2 | |
if ratio == 'sortino': | |
neg_ret = ret[ret<0] | |
ratio = ret.mean() / neg_ret.std() | |
elif ratio == 'sharpe': | |
ratio = ret.mean() / ret.std() | |
ratio = ratio * np.sqrt(365) | |
return ratio |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment