exp23: weight optimization (EQUAL лучше всех) exp24: realistic backtest с retrain (retrain вреден) exp25: порт на backtrader, retrain modes comparison exp26: ablation study ADA — shape_confirm #1 фактор exp26b: direction accuracy = 51% (random) exp26c: trailing stop WR edge vs random = 0pp exp26d: amplitude prediction — r=0.164 для ADA (Q4/Q1=1.5x) Главный вывод: формула Ремизова = детектор волатильности, не predictor направления. Прибыльность = trailing stop asymmetry + amplitude filter. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
531 lines
20 KiB
Python
531 lines
20 KiB
Python
"""Exp24: Realistic backtest matching production algorithm.
|
|
|
|
Differences from exp22/23 backtest:
|
|
1. adaptive_corr_threshold: adjusts 0.4-0.8 based on per-asset win rate
|
|
2. retrain: finetune model after 3 consecutive losses or regime change
|
|
3. exit_price = bar_close (not 50% slippage) — matches prod market order
|
|
4. confidence filter ≥ 1.5
|
|
5. All other logic matches executor.py exactly
|
|
"""
|
|
import sys
|
|
from pathlib import Path
|
|
from dataclasses import dataclass, field
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent.parent / "src"))
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
import numpy as np
|
|
import torch
|
|
|
|
from remizov_trader.core import model as model_mod, signals, risk
|
|
from remizov_trader.config import ModelConfig
|
|
from common.metrics import save_results
|
|
from common.dataset import load_or_fetch
|
|
|
|
TOTAL_CAPITAL = 254.0
|
|
TRAILING_STOP = True
|
|
TRAIN_RATIO = 0.3
|
|
SHIFT = 7
|
|
MIN_CONFIDENCE = 1.5
|
|
|
|
INTEREST_RATE_DAILY = 0.0002
|
|
COMMISSION = 0.001
|
|
MARKET_ORDER_BUFFER = 0.02
|
|
|
|
COLLATERAL_VALUE_RATIO = {
|
|
"BTC-USD": 0.98, "ETH-USD": 0.95, "SOL-USD": 0.90,
|
|
"ADA-USD": 0.90, "DOGE-USD": 0.90,
|
|
}
|
|
SPOT_IM_RATE = {k: 0.05 for k in COLLATERAL_VALUE_RATIO}
|
|
|
|
CORRELATED_GROUPS = [
|
|
{"BTC-USD", "ETH-USD"},
|
|
]
|
|
|
|
PROD_ASSETS = [
|
|
{"ticker": "BTC-USD", "tf": "4h", "ws": 32, "leverage": 2, "weight": 0.200, "K": 3},
|
|
{"ticker": "ETH-USD", "tf": "2h", "ws": 64, "leverage": 2, "weight": 0.200, "K": 2},
|
|
{"ticker": "ADA-USD", "tf": "4h", "ws": 64, "leverage": 2, "weight": 0.200, "K": 3},
|
|
{"ticker": "DOGE-USD", "tf": "4h", "ws": 48, "leverage": 2, "weight": 0.200, "K": 2},
|
|
{"ticker": "SOL-USD", "tf": "2h", "ws": 128, "leverage": 2, "weight": 0.200, "K": 2},
|
|
]
|
|
|
|
|
|
@dataclass
|
|
class AssetState:
|
|
"""Per-asset state tracking, mirrors DB assets table."""
|
|
wins: int = 0
|
|
trades_count: int = 0
|
|
consecutive_losses: int = 0
|
|
last_atr_regime: str = "normal"
|
|
signals_since_retrain: int = 0
|
|
|
|
|
|
@dataclass
|
|
class Position:
|
|
ticker: str
|
|
direction: int
|
|
entry_price: float
|
|
entry_date: str
|
|
stop_price: float
|
|
stop_dist: float
|
|
best_price: float
|
|
pos_size: float
|
|
pos_value: float
|
|
margin_locked: float
|
|
borrowed: float
|
|
haircut_loss: float
|
|
spot_im: float
|
|
k_used: int
|
|
entry_bar: int
|
|
|
|
|
|
def calc_available_balance(free_usdc, open_positions):
|
|
return free_usdc - sum(p.haircut_loss + p.spot_im for p in open_positions.values())
|
|
|
|
|
|
def calc_account_imr(free_usdc, open_positions):
|
|
total_equity = free_usdc + sum(p.margin_locked for p in open_positions.values())
|
|
if total_equity <= 0:
|
|
return 1.0
|
|
return sum(p.margin_locked + p.spot_im for p in open_positions.values()) / total_equity
|
|
|
|
|
|
def calc_required_capital(pos_value, leverage, ticker):
|
|
margin_needed = pos_value / leverage
|
|
borrowed = pos_value - margin_needed
|
|
cvr = COLLATERAL_VALUE_RATIO.get(ticker, 0.80)
|
|
haircut = (1.0 - cvr) * pos_value
|
|
spot_im = borrowed * SPOT_IM_RATE.get(ticker, 0.15)
|
|
buffer = pos_value * MARKET_ORDER_BUFFER
|
|
return {
|
|
"margin_needed": margin_needed, "borrowed": borrowed,
|
|
"haircut": haircut, "spot_im": spot_im, "buffer": buffer,
|
|
"total_frozen": margin_needed + haircut + spot_im + buffer,
|
|
}
|
|
|
|
|
|
def check_correlation_conflict(open_positions, ticker, direction):
|
|
for g in CORRELATED_GROUPS:
|
|
if ticker not in g:
|
|
continue
|
|
for other in g:
|
|
if other != ticker and other in open_positions:
|
|
if open_positions[other].direction == direction:
|
|
return True
|
|
return False
|
|
|
|
|
|
def get_atr_regime(prices, idx):
|
|
"""Classify ATR regime — matches executor._get_atr_regime."""
|
|
atr14 = risk.compute_atr(prices, idx, period=14)
|
|
atr50 = risk.compute_atr(prices, idx, period=50)
|
|
ratio = atr14 / atr50 if atr50 > 0 else 1.0
|
|
if ratio < 0.7:
|
|
return "low"
|
|
if ratio > 1.5:
|
|
return "high"
|
|
return "normal"
|
|
|
|
|
|
def retrain_model(mdl, prices, ws, shift):
|
|
"""Finetune model on recent data — matches executor._retrain."""
|
|
data = signals.prepare_windows(prices, ws, shift)
|
|
if len(data) < 20:
|
|
return mdl
|
|
recent = data[-200:]
|
|
windows = np.array([d["norm_input"] for d in recent])
|
|
targets = np.array([d["norm_target"] for d in recent])
|
|
model_mod.train(mdl, windows, targets, epochs=20, lr=0.003 * 0.3)
|
|
return mdl
|
|
|
|
|
|
def run_simulation(config_name, assets_cfg, asset_data, events):
|
|
tf_hours = {"1h": 1, "2h": 2, "4h": 4, "6h": 6, "12h": 12, "1d": 24}
|
|
free_usdc = TOTAL_CAPITAL
|
|
open_positions = {}
|
|
all_trades = []
|
|
per_asset_trades = {t: [] for t in asset_data}
|
|
last_stop_date = {}
|
|
asset_states = {a["ticker"]: AssetState() for a in assets_cfg}
|
|
skipped = {"margin": 0, "cooldown": 0, "corr": 0, "short": 0, "imr": 0,
|
|
"low_conf": 0, "retrain": 0}
|
|
peak_equity = TOTAL_CAPITAL
|
|
max_drawdown = 0.0
|
|
total_interest = 0.0
|
|
|
|
weights = {a["ticker"]: a["weight"] for a in assets_cfg}
|
|
|
|
for date, ticker, window in events:
|
|
if ticker not in weights:
|
|
continue
|
|
ad = asset_data[ticker]
|
|
prices = ad["prices"]
|
|
price_idx = window["price_idx"]
|
|
current_price = float(prices[price_idx])
|
|
leverage = ad["leverage"]
|
|
weight = weights[ticker]
|
|
asset_k = ad["K"]
|
|
state = asset_states[ticker]
|
|
|
|
# --- Check open position ---
|
|
if ticker in open_positions:
|
|
pos = open_positions[ticker]
|
|
bar_hours = tf_hours.get(ad["tf"], 4)
|
|
|
|
check_from = max(pos.entry_bar + 1, price_idx - SHIFT + 1)
|
|
for bar_idx in range(check_from, price_idx + 1):
|
|
if bar_idx >= len(prices):
|
|
break
|
|
bar_close = float(prices[bar_idx])
|
|
|
|
if TRAILING_STOP:
|
|
pos.best_price, pos.stop_price = risk.update_trailing_stop(
|
|
bar_close, pos.best_price, pos.stop_price,
|
|
pos.stop_dist, pos.direction)
|
|
|
|
stopped = risk.is_stopped(bar_close, pos.stop_price, pos.direction)
|
|
|
|
if stopped:
|
|
# exit_price = bar_close — matches prod (market order at close)
|
|
exit_price = bar_close
|
|
bars_held = bar_idx - pos.entry_bar
|
|
pnl_gross = pos.pos_size * (exit_price - pos.entry_price) * pos.direction
|
|
commission_cost = pos.pos_value * COMMISSION * 2
|
|
hold_hours = bars_held * bar_hours
|
|
trade_interest = pos.borrowed * INTEREST_RATE_DAILY * hold_hours / 24
|
|
total_interest += trade_interest
|
|
pnl_net = pnl_gross - commission_cost - trade_interest
|
|
|
|
free_usdc += pos.margin_locked + pnl_net
|
|
del open_positions[ticker]
|
|
|
|
exit_date = str(ad["dates"][bar_idx]) if bar_idx < len(ad["dates"]) else date
|
|
trade = {"ticker": ticker, "pnl_net": pnl_net,
|
|
"exit_reason": "stop", "bars_held": bars_held,
|
|
"equity_at_entry": pos.margin_locked}
|
|
all_trades.append(trade)
|
|
per_asset_trades[ticker].append(trade)
|
|
last_stop_date[ticker] = exit_date
|
|
|
|
# Update asset state — matches executor
|
|
state.trades_count += 1
|
|
win = pnl_net > 0
|
|
if win:
|
|
state.wins += 1
|
|
state.consecutive_losses = 0
|
|
else:
|
|
state.consecutive_losses += 1
|
|
|
|
total_equity = free_usdc + sum(
|
|
p.margin_locked for p in open_positions.values())
|
|
peak_equity = max(peak_equity, total_equity)
|
|
dd = (peak_equity - total_equity) / peak_equity if peak_equity > 0 else 0
|
|
max_drawdown = max(max_drawdown, dd)
|
|
break
|
|
|
|
# --- Retrain check — matches executor._should_retrain ---
|
|
current_regime = get_atr_regime(prices, price_idx)
|
|
should_retrain = False
|
|
retrain_reason = ""
|
|
if state.consecutive_losses >= 3:
|
|
should_retrain = True
|
|
retrain_reason = f"{state.consecutive_losses}_losses"
|
|
elif state.last_atr_regime and current_regime != state.last_atr_regime:
|
|
should_retrain = True
|
|
retrain_reason = f"regime_{state.last_atr_regime}_to_{current_regime}"
|
|
|
|
if should_retrain:
|
|
# Retrain on prices up to current point
|
|
prices_up_to = prices[:price_idx + 1]
|
|
ad["model"] = retrain_model(ad["model"], prices_up_to, ad["ws"], SHIFT)
|
|
state.consecutive_losses = 0
|
|
state.signals_since_retrain = 0
|
|
skipped["retrain"] += 1
|
|
|
|
state.last_atr_regime = current_regime
|
|
|
|
# --- New signal ---
|
|
if ticker not in open_positions and price_idx >= ad["ws"] + asset_k:
|
|
if ticker in last_stop_date:
|
|
from datetime import date as d
|
|
days_since = (d.fromisoformat(date[:10]) -
|
|
d.fromisoformat(last_stop_date[ticker][:10])).days
|
|
bar_h = tf_hours.get(ad["tf"], 4)
|
|
if days_since * 24 // bar_h < SHIFT:
|
|
skipped["cooldown"] += 1
|
|
continue
|
|
|
|
w = prices[price_idx - ad["ws"] - asset_k:price_idx - asset_k].copy()
|
|
confirm = prices[price_idx - asset_k:price_idx].copy()
|
|
mu, std = w.mean(), w.std()
|
|
if std < 1e-10:
|
|
continue
|
|
|
|
norm_input = (w - mu) / std
|
|
pred = model_mod.predict(ad["model"], norm_input)
|
|
pred_new = pred[-SHIFT:]
|
|
|
|
# Regime adaptive stop_mult — matches executor
|
|
_, stop_mult = risk.regime_adaptive_params(prices, price_idx, asset_k)
|
|
|
|
# Adaptive corr threshold — matches executor
|
|
corr_thresh = risk.adaptive_corr_threshold(
|
|
0.5, state.wins, state.trades_count)
|
|
|
|
corr, confirmed = signals.check_shape_confirmation(
|
|
pred_new, confirm, mu, std, asset_k, corr_thresh)
|
|
|
|
state.signals_since_retrain += 1
|
|
|
|
if not confirmed:
|
|
continue
|
|
|
|
# Confidence filter — matches executor
|
|
atr = risk.compute_atr(prices, price_idx)
|
|
if MIN_CONFIDENCE > 0 and atr > 0:
|
|
pred_denorm = pred_new * std + mu
|
|
amplitude = float(np.max(pred_denorm) - np.min(pred_denorm))
|
|
confidence = abs(corr) * (amplitude / atr)
|
|
if confidence < MIN_CONFIDENCE:
|
|
skipped["low_conf"] += 1
|
|
continue
|
|
|
|
direction = signals.get_direction(pred_new, asset_k)
|
|
if direction is None:
|
|
continue
|
|
if direction == -1:
|
|
skipped["short"] += 1
|
|
continue
|
|
|
|
if check_correlation_conflict(open_positions, ticker, direction):
|
|
skipped["corr"] += 1
|
|
continue
|
|
if len(open_positions) >= len(assets_cfg):
|
|
continue
|
|
|
|
imr = calc_account_imr(free_usdc, open_positions)
|
|
if imr >= (leverage - 1) / leverage:
|
|
skipped["imr"] += 1
|
|
continue
|
|
|
|
total_equity = free_usdc + sum(
|
|
p.margin_locked for p in open_positions.values())
|
|
pos_value = total_equity * weight * leverage
|
|
if pos_value < 5.0:
|
|
continue
|
|
|
|
req = calc_required_capital(pos_value, leverage, ticker)
|
|
available = calc_available_balance(free_usdc, open_positions)
|
|
|
|
if available < req["total_frozen"]:
|
|
cvr = COLLATERAL_VALUE_RATIO.get(ticker, 0.80)
|
|
im_rate = SPOT_IM_RATE.get(ticker, 0.15)
|
|
freeze_per_dollar = (1/leverage + (1 - cvr)
|
|
+ (1 - 1/leverage) * im_rate + MARKET_ORDER_BUFFER)
|
|
max_pv = available / freeze_per_dollar
|
|
if max_pv < 5.0:
|
|
skipped["margin"] += 1
|
|
continue
|
|
pos_value = max_pv
|
|
req = calc_required_capital(pos_value, leverage, ticker)
|
|
|
|
pos_size = pos_value / current_price
|
|
stop_dist = max(atr * stop_mult * 0.5, current_price * 0.005)
|
|
|
|
free_usdc -= req["margin_needed"]
|
|
open_positions[ticker] = Position(
|
|
ticker=ticker, direction=direction,
|
|
entry_price=current_price, entry_date=date,
|
|
stop_price=current_price - direction * stop_dist,
|
|
stop_dist=stop_dist, best_price=current_price,
|
|
pos_size=pos_size, pos_value=pos_value,
|
|
margin_locked=req["margin_needed"],
|
|
borrowed=req["borrowed"],
|
|
haircut_loss=req["haircut"],
|
|
spot_im=req["spot_im"],
|
|
k_used=asset_k, entry_bar=price_idx,
|
|
)
|
|
|
|
# Close remaining
|
|
for ticker, pos in list(open_positions.items()):
|
|
ad = asset_data[ticker]
|
|
last_price = float(ad["prices"][-1])
|
|
bars_held = ad["test_data"][-1]["price_idx"] - pos.entry_bar
|
|
bar_hours = tf_hours.get(ad["tf"], 4)
|
|
pnl_gross = pos.pos_size * (last_price - pos.entry_price) * pos.direction
|
|
commission_cost = pos.pos_value * COMMISSION * 2
|
|
trade_interest = pos.borrowed * INTEREST_RATE_DAILY * bars_held * bar_hours / 24
|
|
pnl_net = pnl_gross - commission_cost - trade_interest
|
|
free_usdc += pos.margin_locked + pnl_net
|
|
all_trades.append({"ticker": ticker, "pnl_net": pnl_net,
|
|
"exit_reason": "end", "bars_held": bars_held,
|
|
"equity_at_entry": pos.margin_locked})
|
|
per_asset_trades[ticker].append(all_trades[-1])
|
|
|
|
final_equity = free_usdc
|
|
total_pnl = final_equity - TOTAL_CAPITAL
|
|
wins = [t for t in all_trades if t["pnl_net"] > 0]
|
|
|
|
sharpe = 0.0
|
|
if len(all_trades) > 1:
|
|
returns = np.array([t["pnl_net"] / t["equity_at_entry"]
|
|
for t in all_trades if t["equity_at_entry"] > 0])
|
|
if len(returns) > 1 and np.std(returns) > 0:
|
|
from datetime import date as d
|
|
first = d.fromisoformat(events[0][0][:10])
|
|
last = d.fromisoformat(events[-1][0][:10])
|
|
years = max((last - first).days / 365.25, 0.1)
|
|
tpy = len(all_trades) / years
|
|
sharpe = float(np.mean(returns) / np.std(returns) * np.sqrt(tpy))
|
|
|
|
asset_pnl = {}
|
|
for ticker, trades in per_asset_trades.items():
|
|
if trades:
|
|
pnl = sum(t["pnl_net"] for t in trades)
|
|
w = [t for t in trades if t["pnl_net"] > 0]
|
|
asset_pnl[ticker] = {"pnl": round(pnl, 2), "trades": len(trades),
|
|
"wins": len(w), "wr": round(len(w)/len(trades)*100, 1)}
|
|
|
|
return {
|
|
"config": config_name,
|
|
"final_equity": round(final_equity, 2),
|
|
"total_pnl": round(total_pnl, 2),
|
|
"total_ret": round(total_pnl / TOTAL_CAPITAL * 100, 1),
|
|
"sharpe": round(sharpe, 2),
|
|
"max_dd": round(max_drawdown * 100, 1),
|
|
"trades": len(all_trades),
|
|
"wins": len(wins),
|
|
"wr": round(len(wins)/len(all_trades)*100, 1) if all_trades else 0,
|
|
"skipped": skipped,
|
|
"per_asset": asset_pnl,
|
|
"retrains": skipped["retrain"],
|
|
}
|
|
|
|
|
|
def main():
|
|
results_dir = Path(__file__).parent / "results"
|
|
|
|
print(f"{'='*80}")
|
|
print("EXP24: REALISTIC BACKTEST (matches prod algorithm)")
|
|
print(f"{'='*80}")
|
|
print(f"Capital: ${TOTAL_CAPITAL} | conf≥{MIN_CONFIDENCE} | close-only | TE=OFF")
|
|
print(f"Exit: bar_close (market order) | adaptive_corr | retrain on 3L/regime")
|
|
print()
|
|
|
|
dataset = load_or_fetch("default")
|
|
asset_data = {}
|
|
|
|
for a in PROD_ASSETS:
|
|
ticker, tf, ws = a["ticker"], a["tf"], a["ws"]
|
|
asset_k = a.get("K", 2)
|
|
print(f" {ticker} ({tf}, ws={ws}, K={asset_k})...", end=" ", flush=True)
|
|
|
|
if ticker not in dataset:
|
|
print("not in dataset"); continue
|
|
prices = dataset[ticker]["prices"]
|
|
dates = dataset[ticker]["dates"]
|
|
|
|
if len(prices) < ws + asset_k + SHIFT + 30:
|
|
print("not enough data"); continue
|
|
|
|
data = signals.prepare_windows(prices, ws, SHIFT)
|
|
if len(data) < 30:
|
|
print(f"only {len(data)} windows"); continue
|
|
|
|
n_train = max(int(len(data) * TRAIN_RATIO), 20)
|
|
test_data = data[n_train:]
|
|
|
|
model_cfg = ModelConfig(window_size=ws, n_steps=20, total_time=0.5,
|
|
shift=SHIFT, epochs=200, finetune_epochs=50, lr=0.003)
|
|
|
|
# Train fresh model (no cache — retrain modifies it)
|
|
train_data = data[:n_train]
|
|
torch.manual_seed(42); np.random.seed(42)
|
|
mdl = model_mod.create_model(model_cfg)
|
|
windows_arr = np.array([d["norm_input"] for d in train_data])
|
|
targets_arr = np.array([d["norm_target"] for d in train_data])
|
|
model_mod.train(mdl, windows_arr, targets_arr, 200, 0.003)
|
|
|
|
asset_data[ticker] = {
|
|
"prices": prices, "dates": dates, "tf": tf,
|
|
"model": mdl, "test_data": test_data,
|
|
"ws": ws, "K": asset_k,
|
|
"leverage": a["leverage"],
|
|
}
|
|
print(f"{len(prices)} bars, {len(test_data)} test")
|
|
|
|
events = []
|
|
for ticker, ad in asset_data.items():
|
|
for d in ad["test_data"]:
|
|
price_idx = d["price_idx"]
|
|
date = str(ad["dates"][price_idx])
|
|
events.append((date, ticker, d))
|
|
events.sort(key=lambda x: x[0])
|
|
print(f"\n Events: {len(events)} | Range: {events[0][0]} → {events[-1][0]}")
|
|
|
|
# --- Run configs ---
|
|
CONFIGS = {
|
|
"PROD_ALGO": PROD_ASSETS, # equal weights, full prod algorithm
|
|
}
|
|
|
|
# Also test without confidence filter for comparison
|
|
print(f"\n{'='*80}")
|
|
|
|
all_results = []
|
|
|
|
# 1. Full prod algorithm with conf≥1.5
|
|
print("\n [1] PROD_ALGO (conf≥1.5, adaptive_corr, retrain)...")
|
|
r1 = run_simulation("PROD_ALGO", PROD_ASSETS, asset_data, events)
|
|
all_results.append(r1)
|
|
print(f" PnL=${r1['total_pnl']:+.0f} Sharpe={r1['sharpe']:.2f} "
|
|
f"DD={r1['max_dd']:.1f}% Trades={r1['trades']} WR={r1['wr']:.1f}% "
|
|
f"Retrains={r1['retrains']}")
|
|
|
|
# Per-asset
|
|
print(f" Per-asset:")
|
|
for t in [a["ticker"] for a in PROD_ASSETS]:
|
|
if t in r1["per_asset"]:
|
|
pa = r1["per_asset"][t]
|
|
print(f" {t:10s} PnL=${pa['pnl']:+.0f} trades={pa['trades']} "
|
|
f"W={pa['wins']} WR={pa['wr']:.1f}%")
|
|
else:
|
|
print(f" {t:10s} no trades")
|
|
print(f" Skipped: {r1['skipped']}")
|
|
|
|
# 2. Retrain fresh models for no-confidence comparison
|
|
print("\n Retraining models for no-conf baseline...")
|
|
for a in PROD_ASSETS:
|
|
ticker = a["ticker"]
|
|
ws = a["ws"]
|
|
prices = dataset[ticker]["prices"]
|
|
data = signals.prepare_windows(prices, ws, SHIFT)
|
|
n_train = max(int(len(data) * TRAIN_RATIO), 20)
|
|
train_data = data[:n_train]
|
|
torch.manual_seed(42); np.random.seed(42)
|
|
mdl = model_mod.create_model(ModelConfig(window_size=ws, n_steps=20,
|
|
total_time=0.5, shift=SHIFT, epochs=200, finetune_epochs=50, lr=0.003))
|
|
windows_arr = np.array([d["norm_input"] for d in train_data])
|
|
targets_arr = np.array([d["norm_target"] for d in train_data])
|
|
model_mod.train(mdl, windows_arr, targets_arr, 200, 0.003)
|
|
asset_data[ticker]["model"] = mdl
|
|
|
|
# Summary
|
|
print(f"\n{'='*80}")
|
|
print("SUMMARY")
|
|
print(f"{'='*80}")
|
|
print(f"{'Config':<16s} {'PnL':>7s} {'Shrp':>5s} {'DD%':>5s} {'Trds':>5s} "
|
|
f"{'WR%':>5s} {'Retr':>4s}")
|
|
for r in all_results:
|
|
print(f" {r['config']:<14s} ${r['total_pnl']:>+6.0f} {r['sharpe']:>5.2f} "
|
|
f"{r['max_dd']:>4.1f}% {r['trades']:>5d} {r['wr']:>4.1f}% "
|
|
f"{r['retrains']:>4d}")
|
|
|
|
save_data = {"results": all_results}
|
|
path = save_results(save_data, results_dir, "exp24_realistic")
|
|
print(f"\nSaved: {path}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|