fix: 年化用回测区间年数(修复交易聚集爆炸)+资本基数统一913k
This commit is contained in:
+10
-1
@@ -680,7 +680,7 @@ def has_breakout_dna(bars, i, lookback=10):
|
||||
return False
|
||||
|
||||
|
||||
def run_backtest(strategy_version, start_date, end_date, capital=1000000, save=True, universe='all', period_tag='2y'):
|
||||
def run_backtest(strategy_version, start_date, end_date, capital=913000, save=True, universe='all', period_tag='2y'):
|
||||
strat = get_strategy(strategy_version)
|
||||
cfg = strat['config']
|
||||
entry_cfg, exit_cfg = cfg['entry'], cfg['exit']
|
||||
@@ -1044,6 +1044,10 @@ def run_backtest(strategy_version, start_date, end_date, capital=1000000, save=T
|
||||
|
||||
summary = calc_summary(trades, capital)
|
||||
if summary:
|
||||
# 年化统一用回测区间年数(修复交易聚集导致年化爆炸)
|
||||
_y0 = datetime.strptime(start_date, '%Y-%m-%d')
|
||||
_y1 = datetime.strptime(end_date, '%Y-%m-%d')
|
||||
_bt_years = max((_y1 - _y0).days / 365.0, 0.5)
|
||||
# 信念缩放(通用,2026-07-29验证全策略+7~16pp):动量基因票默认×2.5
|
||||
boost_k = cfg.get('exit', {}).get('dna_boost', 2.5)
|
||||
for t in trades:
|
||||
@@ -1054,6 +1058,11 @@ def run_backtest(strategy_version, start_date, end_date, capital=1000000, save=T
|
||||
summary['sizing_slots'] = slots
|
||||
# 全参与可行仓位(公平基线:单仓≥5万地板,消除上车运气)
|
||||
summary['portfolio_full'] = portfolio_sim_full(trades, capital)
|
||||
# cagr 统一用回测区间年数覆盖(portfolio_sim里按交易跨度算的会爆炸)
|
||||
_tr = summary['portfolio'].get('total_return_pct', 0) / 100
|
||||
_tf = summary['portfolio_full'].get('total_return_pct', 0) / 100
|
||||
summary['portfolio']['cagr_pct'] = round((((1 + _tr) ** (1 / _bt_years)) - 1) * 100, 1)
|
||||
summary['portfolio_full']['cagr_pct'] = round((((1 + _tf) ** (1 / _bt_years)) - 1) * 100, 1)
|
||||
result = {
|
||||
'strategy': strat['version'],
|
||||
'strategy_name': strat['name'],
|
||||
|
||||
Reference in New Issue
Block a user