Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# dd
metrics['~~~~'] = blank
for ix, row in dd.iterrows():
metrics[ix] = row
metrics['Recovery Factor'] = _stats.recovery_factor(df)
metrics['Ulcer Index'] = _stats.ulcer_index(df, rf)
# win rate
if mode.lower() == 'full':
metrics['~~~~~'] = blank
metrics['Avg. Up Month %'] = _stats.avg_win(df, aggregate='M') * pct
metrics['Avg. Down Month %'] = _stats.avg_loss(df, aggregate='M') * pct
metrics['Win Days %%'] = _stats.win_rate(df) * pct
metrics['Win Month %%'] = _stats.win_rate(df, aggregate='M') * pct
metrics['Win Quarter %%'] = _stats.win_rate(df, aggregate='Q') * pct
metrics['Win Year %%'] = _stats.win_rate(df, aggregate='A') * pct
if "benchmark" in df:
metrics['~~~~~~~'] = blank
greeks = _stats.greeks(df['returns'], df['benchmark'])
metrics['Beta'] = [str(round(greeks['beta'], 2)), '-']
metrics['Alpha'] = [str(round(greeks['alpha'], 2)), '-']
# prepare for display
for col in metrics.columns:
try:
metrics[col] = metrics[col].astype(float).round(2)
if display or "internal" in kwargs:
metrics[col] = metrics[col].astype(str)
except Exception:
pass
if (display or "internal" in kwargs) and "%" in col:
metrics['Best Year %'] = _stats.best(df, aggregate='A') * pct
metrics['Worst Year %'] = _stats.worst(df, aggregate='A') * pct
# dd
metrics['~~~~'] = blank
for ix, row in dd.iterrows():
metrics[ix] = row
metrics['Recovery Factor'] = _stats.recovery_factor(df)
metrics['Ulcer Index'] = _stats.ulcer_index(df, rf)
# win rate
if mode.lower() == 'full':
metrics['~~~~~'] = blank
metrics['Avg. Up Month %'] = _stats.avg_win(df, aggregate='M') * pct
metrics['Avg. Down Month %'] = _stats.avg_loss(df, aggregate='M') * pct
metrics['Win Days %%'] = _stats.win_rate(df) * pct
metrics['Win Month %%'] = _stats.win_rate(df, aggregate='M') * pct
metrics['Win Quarter %%'] = _stats.win_rate(df, aggregate='Q') * pct
metrics['Win Year %%'] = _stats.win_rate(df, aggregate='A') * pct
if "benchmark" in df:
metrics['~~~~~~~'] = blank
greeks = _stats.greeks(df['returns'], df['benchmark'])
metrics['Beta'] = [str(round(greeks['beta'], 2)), '-']
metrics['Alpha'] = [str(round(greeks['alpha'], 2)), '-']
# prepare for display
for col in metrics.columns:
try:
metrics[col] = metrics[col].astype(float).round(2)
if display or "internal" in kwargs:
metrics[col] = metrics[col].astype(str)
metrics['Worst Year %'] = _stats.worst(df, aggregate='A') * pct
# dd
metrics['~~~~'] = blank
for ix, row in dd.iterrows():
metrics[ix] = row
metrics['Recovery Factor'] = _stats.recovery_factor(df)
metrics['Ulcer Index'] = _stats.ulcer_index(df, rf)
# win rate
if mode.lower() == 'full':
metrics['~~~~~'] = blank
metrics['Avg. Up Month %'] = _stats.avg_win(df, aggregate='M') * pct
metrics['Avg. Down Month %'] = _stats.avg_loss(df, aggregate='M') * pct
metrics['Win Days %%'] = _stats.win_rate(df) * pct
metrics['Win Month %%'] = _stats.win_rate(df, aggregate='M') * pct
metrics['Win Quarter %%'] = _stats.win_rate(df, aggregate='Q') * pct
metrics['Win Year %%'] = _stats.win_rate(df, aggregate='A') * pct
if "benchmark" in df:
metrics['~~~~~~~'] = blank
greeks = _stats.greeks(df['returns'], df['benchmark'])
metrics['Beta'] = [str(round(greeks['beta'], 2)), '-']
metrics['Alpha'] = [str(round(greeks['alpha'], 2)), '-']
# prepare for display
for col in metrics.columns:
try:
metrics[col] = metrics[col].astype(float).round(2)
if display or "internal" in kwargs:
metrics[col] = metrics[col].astype(str)
except Exception:
# dd
metrics['~~~~'] = blank
for ix, row in dd.iterrows():
metrics[ix] = row
metrics['Recovery Factor'] = _stats.recovery_factor(df)
metrics['Ulcer Index'] = _stats.ulcer_index(df, rf)
# win rate
if mode.lower() == 'full':
metrics['~~~~~'] = blank
metrics['Avg. Up Month %'] = _stats.avg_win(df, aggregate='M') * pct
metrics['Avg. Down Month %'] = _stats.avg_loss(df, aggregate='M') * pct
metrics['Win Days %%'] = _stats.win_rate(df) * pct
metrics['Win Month %%'] = _stats.win_rate(df, aggregate='M') * pct
metrics['Win Quarter %%'] = _stats.win_rate(df, aggregate='Q') * pct
metrics['Win Year %%'] = _stats.win_rate(df, aggregate='A') * pct
if "benchmark" in df:
metrics['~~~~~~~'] = blank
greeks = _stats.greeks(df['returns'], df['benchmark'])
metrics['Beta'] = [str(round(greeks['beta'], 2)), '-']
metrics['Alpha'] = [str(round(greeks['alpha'], 2)), '-']
# prepare for display
for col in metrics.columns:
try:
metrics[col] = metrics[col].astype(float).round(2)
if display or "internal" in kwargs:
metrics[col] = metrics[col].astype(str)
except Exception:
pass
"""
from pandas.core.base import PandasObject as _po
_po.compsum = stats.compsum
_po.comp = stats.comp
_po.expected_return = stats.expected_return
_po.geometric_mean = stats.geometric_mean
_po.ghpr = stats.ghpr
_po.outliers = stats.outliers
_po.remove_outliers = stats.remove_outliers
_po.best = stats.best
_po.worst = stats.worst
_po.consecutive_wins = stats.consecutive_wins
_po.consecutive_losses = stats.consecutive_losses
_po.exposure = stats.exposure
_po.win_rate = stats.win_rate
_po.avg_return = stats.avg_return
_po.avg_win = stats.avg_win
_po.avg_loss = stats.avg_loss
_po.volatility = stats.volatility
_po.implied_volatility = stats.implied_volatility
_po.sharpe = stats.sharpe
_po.sortino = stats.sortino
_po.cagr = stats.cagr
_po.rar = stats.rar
_po.skew = stats.skew
_po.kurtosis = stats.kurtosis
_po.calmar = stats.calmar
_po.ulcer_index = stats.ulcer_index
_po.ulcer_performance_index = stats.ulcer_performance_index
_po.upi = stats.upi
_po.risk_of_ruin = stats.risk_of_ruin