def record(dst: str):
import pickle
dates = pd.date_range(start='2020-01-01', end='2020-12-31', freq='B')
np.random.seed(42)
returns = pd.Series(np.random.normal(0.001, 0.02, len(dates)), index=dates)
np.random.seed(43)
benchmark_returns = pd.Series(np.random.normal(0.0005, 0.015, len(dates)), index=dates)
# the following requires returns only
unary_ops = ['adjusted_sortino', 'autocorr_penalty', 'avg_loss', 'avg_return', 'avg_win', 'best', 'cagr', 'calmar', 'common_sense_ratio', 'comp', 'compsum', 'conditional_value_at_risk', 'consecutive_losses', 'consecutive_wins', 'cpc_index', 'cvar', 'distribution', 'drawdown_details', 'expected_return', 'expected_shortfall', 'exposure', 'gain_to_pain_ratio', 'geometric_mean', 'ghpr', 'implied_volatility', 'kelly_criterion', 'kurtosis', 'max_drawdown', 'monthly_returns', 'omega', 'outlier_loss_ratio', 'outlier_win_ratio', 'outliers', 'payoff_ratio', 'pct_rank', 'probabilistic_adjusted_sortino_ratio', 'probabilistic_ratio', 'probabilistic_sharpe_ratio', 'probabilistic_sortino_ratio', 'profit_factor', 'profit_ratio', 'rar', 'recovery_factor', 'remove_outliers', 'risk_of_ruin', 'risk_return_ratio', 'rolling_sharpe', 'rolling_sortino', 'rolling_volatility', 'ror', 'serenity_index', 'sharpe', 'skew', 'smart_sharpe', 'smart_sortino', 'sortino', 'tail_ratio', 'to_drawdown_series', 'ulcer_index', 'ulcer_performance_index', 'upi', 'validate_input', 'value_at_risk', 'var', 'volatility', 'win_loss_ratio', 'win_rate', 'worst']
# the following requires benchmark also
binary_ops = [
"compare",
"greeks",
"information_ratio",
"r2",
"r_squared",
"treynor_ratio"
]
# need speical handling, or not a stats
excluded = ["rolling_greeks", "safe_concat"]
results = {}
for name in dir(qs.stats):
if name[0] == '_':
continue
func = getattr(qs.stats, name)
if name in unary_ops:
results[name] = func(returns)
elif name in binary_ops:
results[name] = func(returns, benchmark_returns)
else:
print("no handled", name)
data= {
"returns": returns,
"benchmark": benchmark_returns,
"results": results,
"unary_ops": unary_ops
}
with open(dst, "wb") as f:
pickle.dump(data, f)