Skip to content

Commit

Permalink
Added Treynor ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
ranaroussi committed Apr 23, 2022
1 parent bb7a33f commit beb1b14
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
@@ -1,6 +1,10 @@
Change Log
===========

0.0.52
------
- Added Treynor ratio

0.0.51
------
- Added max consecutive wins/losses to full report
Expand Down
1 change: 1 addition & 0 deletions quantstats/__init__.py
Expand Up @@ -99,6 +99,7 @@ def extend_pandas():
_po.monthly_returns = stats.monthly_returns
_po.pct_rank = stats.pct_rank

_po.treynor_ratio = stats.treynor_ratio
_po.probabilistic_sharpe_ratio = stats.probabilistic_sharpe_ratio
_po.probabilistic_sortino_ratio = stats.probabilistic_sortino_ratio
_po.probabilistic_adjusted_sortino_ratio = stats.probabilistic_adjusted_sortino_ratio
Expand Down
1 change: 1 addition & 0 deletions quantstats/reports.py
Expand Up @@ -561,6 +561,7 @@ def metrics(returns, benchmark=None, rf=0., display=True,
metrics['Beta'] = [str(round(greeks['beta'], 2)), '-']
metrics['Alpha'] = [str(round(greeks['alpha'], 2)), '-']
metrics['Correlation'] = [str(round(df['benchmark'].corr(df['returns']) * pct, 2))+'%', '-']
metrics['Treynor Ratio'] = [str(round(_stats.treynor_ratio(df['returns'], df['benchmark'], win_year, rf)*pct, 2))+'%', '-']

# prepare for display
for col in metrics.columns:
Expand Down
18 changes: 18 additions & 0 deletions quantstats/stats.py
Expand Up @@ -428,6 +428,24 @@ def probabilistic_adjusted_sortino_ratio(series, rf=0., periods=252, annualize=F
annualize=annualize, smart=smart)


def treynor_ratio(returns, benchmark, periods=252., rf=0.):
"""
Calculates the Treynor ratio
Args:
* returns (Series, DataFrame): Input return series
* benchmatk (String, Series, DataFrame): Benchmark to compare beta to
* periods (int): Freq. of returns (252/365 for daily, 12 for monthly)
"""
if isinstance(returns, _pd.DataFrame):
returns = returns[returns.columns[0]]

beta = greeks(returns, benchmark, periods=periods).to_dict().get('beta', 0)
if beta == 0:
return 0
return (comp(returns) - rf) / beta


def omega(returns, rf=0.0, required_return=0.0, periods=252):
"""
Determines the Omega ratio of a strategy.
Expand Down
2 changes: 1 addition & 1 deletion quantstats/version.py
@@ -1 +1 @@
version = "0.0.51"
version = "0.0.52"

0 comments on commit beb1b14

Please sign in to comment.