Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
df[df.index >= _dt(today.year, today.month, 1)]) * pct
d = today - _td(3*365/12)
metrics['3M %'] = comp_func(
df[df.index >= _dt(d.year, d.month, d.day)]) * pct
d = today - _td(6*365/12)
metrics['6M %'] = comp_func(
df[df.index >= _dt(d.year, d.month, d.day)]) * pct
metrics['YTD %'] = comp_func(df[df.index >= _dt(today.year, 1, 1)]) * pct
d = today - _td(12*365/12)
metrics['1Y %'] = comp_func(
df[df.index >= _dt(d.year, d.month, d.day)]) * pct
metrics['3Y (ann.) %'] = _stats.cagr(
df[df.index >= _dt(today.year-3, today.month, today.day)
], 0., compounded) * pct
metrics['5Y (ann.) %'] = _stats.cagr(
df[df.index >= _dt(today.year-5, today.month, today.day)
], 0., compounded) * pct
metrics['10Y (ann.) %'] = _stats.cagr(
df[df.index >= _dt(today.year-10, today.month, today.day)
], 0., compounded) * pct
metrics['All-time (ann.) %'] = _stats.cagr(df, 0., compounded) * pct
# best/worst
if mode.lower() == 'full':
metrics['~~~'] = blank
metrics['Best Day %'] = _stats.best(df) * pct
metrics['Worst Day %'] = _stats.worst(df) * pct
metrics['Best Month %'] = _stats.best(df, aggregate='M') * pct
s_rf['benchmark'] = rf
metrics['Start Period'] = _pd.Series(s_start)
metrics['End Period'] = _pd.Series(s_end)
metrics['Risk-Free Rate %'] = _pd.Series(s_rf)
metrics['Time in Market %'] = _stats.exposure(df) * pct
metrics['~'] = blank
if compounded:
metrics['Cumulative Return %'] = (
_stats.comp(df) * pct).map('{:,.2f}'.format)
else:
metrics['Total Return %'] = (df.sum() * pct).map('{:,.2f}'.format)
metrics['CAGR%%'] = _stats.cagr(df, rf, compounded) * pct
metrics['Sharpe'] = _stats.sharpe(df, rf)
metrics['Sortino'] = _stats.sortino(df, rf)
metrics['Max Drawdown %'] = blank
metrics['Longest DD Days'] = blank
if mode.lower() == 'full':
ret_vol = _stats.volatility(df['returns']) * pct
if "benchmark" in df:
bench_vol = _stats.volatility(df['benchmark']) * pct
metrics['Volatility (ann.) %'] = [ret_vol, bench_vol]
metrics['R^2'] = _stats.r_squared(df['returns'], df['benchmark'])
else:
metrics['Volatility (ann.) %'] = [ret_vol]
metrics['Calmar'] = _stats.calmar(df)
metrics['Skew'] = _stats.skew(df)
_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
_po.ror = stats.ror
_po.value_at_risk = stats.value_at_risk
_po.var = stats.var
_po.conditional_value_at_risk = stats.conditional_value_at_risk
_po.cvar = stats.cvar
_po.expected_shortfall = stats.expected_shortfall
_po.tail_ratio = stats.tail_ratio
_po.payoff_ratio = stats.payoff_ratio
metrics['YTD %'] = comp_func(df[df.index >= _dt(today.year, 1, 1)]) * pct
d = today - _td(12*365/12)
metrics['1Y %'] = comp_func(
df[df.index >= _dt(d.year, d.month, d.day)]) * pct
metrics['3Y (ann.) %'] = _stats.cagr(
df[df.index >= _dt(today.year-3, today.month, today.day)
], 0., compounded) * pct
metrics['5Y (ann.) %'] = _stats.cagr(
df[df.index >= _dt(today.year-5, today.month, today.day)
], 0., compounded) * pct
metrics['10Y (ann.) %'] = _stats.cagr(
df[df.index >= _dt(today.year-10, today.month, today.day)
], 0., compounded) * pct
metrics['All-time (ann.) %'] = _stats.cagr(df, 0., compounded) * pct
# best/worst
if mode.lower() == 'full':
metrics['~~~'] = blank
metrics['Best Day %'] = _stats.best(df) * pct
metrics['Worst Day %'] = _stats.worst(df) * pct
metrics['Best Month %'] = _stats.best(df, aggregate='M') * pct
metrics['Worst Month %'] = _stats.worst(df, aggregate='M') * pct
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)