hybrid DD tier와 Option C 2차(+1000%) 검증을 추가하고 실거래 사이징을 정합한다.
인과 GT leg 엔진·drawdown tier·train 캘리브레이션, Phase 2 Go/No-Go 및 시뮬 리포트를 반영한다. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -24,6 +24,12 @@ from config import (
|
||||
SIM_GO_MIN_HOLDOUT_EV,
|
||||
SIM_GO_MIN_HOLDOUT_PF,
|
||||
SIM_GO_WF_POSITIVE_RATIO,
|
||||
SIM_HYBRID_MAX_MDD_PCT,
|
||||
SIM_HYBRID_MIN_HOLDOUT_PNL_PCT,
|
||||
SIM_OPTION_C_MIN_GT_CAPTURE,
|
||||
SIM_OPTION_C_PHASE2_FEE_STRESS_RATIO,
|
||||
SIM_OPTION_C_PHASE2_TARGET_PNL_PCT,
|
||||
SIM_OPTION_C_TARGET_PNL_PCT,
|
||||
SIM_WALK_FORWARD_MIN_MONTHS,
|
||||
TRADING_FEE_RATE,
|
||||
)
|
||||
@@ -247,6 +253,186 @@ def evaluate_go_no_go(
|
||||
}
|
||||
|
||||
|
||||
def portfolio_holdout_from_steps(
|
||||
steps: list[dict[str, Any]],
|
||||
holdout_start: pd.Timestamp,
|
||||
*,
|
||||
initial_if_empty: float = GT_INITIAL_CASH_KRW,
|
||||
trade_count: int = 0,
|
||||
note: str = "",
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
포트폴리오 step에서 holdout 구간 자산 증감.
|
||||
|
||||
Args:
|
||||
steps: simulate_portfolio_steps 결과.
|
||||
holdout_start: holdout 시작 시각.
|
||||
initial_if_empty: step 없을 때 시작 자산.
|
||||
trade_count: holdout 발화 수.
|
||||
note: 설명.
|
||||
|
||||
Returns:
|
||||
holdout pnl 요약 dict.
|
||||
"""
|
||||
if not steps:
|
||||
return {"pnl_pct": 0.0, "note": "steps empty"}
|
||||
assets = [(pd.to_datetime(s["dt"]), float(s["total_asset_krw"])) for s in steps]
|
||||
pre = [a for d, a in assets if d < holdout_start]
|
||||
in_h = [a for d, a in assets if d >= holdout_start]
|
||||
asset_start = pre[-1] if pre else float(initial_if_empty)
|
||||
asset_end = in_h[-1] if in_h else assets[-1][1]
|
||||
ho_pnl_pct = (
|
||||
(asset_end - asset_start) / asset_start * 100.0 if asset_start > 0 else 0.0
|
||||
)
|
||||
return {
|
||||
"initial_asset_krw": round(asset_start, 0),
|
||||
"final_asset_krw": round(asset_end, 0),
|
||||
"pnl_krw": round(asset_end - asset_start, 0),
|
||||
"pnl_pct": round(ho_pnl_pct, 2),
|
||||
"trade_count": int(trade_count),
|
||||
"note": note,
|
||||
}
|
||||
|
||||
|
||||
def evaluate_hybrid_sizing_go(
|
||||
base_go: dict[str, Any],
|
||||
hybrid_full: dict[str, Any],
|
||||
hybrid_holdout: dict[str, Any],
|
||||
hybrid_fee_stress: dict[str, Any],
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
hybrid DD tier 배분 승격 Go/No-Go (규칙 Go + holdout·MDD·수수료 스트레스).
|
||||
|
||||
Args:
|
||||
base_go: monitor 규칙 evaluate_go_no_go 결과.
|
||||
hybrid_full: 전기간 hybrid 포트폴리오 요약.
|
||||
hybrid_holdout: holdout 구간 자산 증감.
|
||||
hybrid_fee_stress: 수수료 스트레스 hybrid 포트폴리오.
|
||||
|
||||
Returns:
|
||||
go, checks, primary_sizing 권장.
|
||||
"""
|
||||
from config import (
|
||||
SIM_HYBRID_MAX_MDD_PCT,
|
||||
SIM_HYBRID_MIN_HOLDOUT_PNL_PCT,
|
||||
SIM_OPTION_C_TARGET_PNL_PCT,
|
||||
SIM_PRIMARY_SIZING,
|
||||
)
|
||||
|
||||
base_ok = bool(base_go.get("go"))
|
||||
ho_pnl = float(hybrid_holdout.get("pnl_pct", -999))
|
||||
full_pnl = float(hybrid_full.get("pnl_pct", 0))
|
||||
mdd = float(hybrid_full.get("max_drawdown_pct", 999))
|
||||
stress_pnl = float(hybrid_fee_stress.get("pnl_pct", -999))
|
||||
|
||||
c_base = base_ok
|
||||
c_holdout = ho_pnl >= SIM_HYBRID_MIN_HOLDOUT_PNL_PCT
|
||||
c_mdd = mdd <= SIM_HYBRID_MAX_MDD_PCT
|
||||
c_fee = stress_pnl > 0.0
|
||||
c_target = full_pnl >= SIM_OPTION_C_TARGET_PNL_PCT
|
||||
|
||||
all_go = c_base and c_holdout and c_mdd and c_fee
|
||||
if SIM_PRIMARY_SIZING == "hybrid":
|
||||
primary = "hybrid"
|
||||
elif SIM_PRIMARY_SIZING == "causal_tier":
|
||||
primary = "causal_tier"
|
||||
else:
|
||||
primary = "hybrid" if all_go else "causal_tier"
|
||||
|
||||
return {
|
||||
"go": all_go,
|
||||
"primary_sizing": primary,
|
||||
"checks": [
|
||||
{"name": "monitor_rules_go", "pass": c_base},
|
||||
{"name": "hybrid_holdout_pnl", "pass": c_holdout, "value": ho_pnl},
|
||||
{"name": "hybrid_max_mdd", "pass": c_mdd, "value": mdd},
|
||||
{"name": "hybrid_fee_stress_pnl", "pass": c_fee, "value": stress_pnl},
|
||||
{
|
||||
"name": "option_c_target_300pct",
|
||||
"pass": c_target,
|
||||
"value": full_pnl,
|
||||
"optional": True,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def simulate_hybrid_order_cap(
|
||||
outcomes: pd.DataFrame,
|
||||
ohlc_df: pd.DataFrame,
|
||||
*,
|
||||
rule_ids: set[str] | None = None,
|
||||
holdout_only: bool = True,
|
||||
fee_rate: float = TRADING_FEE_RATE,
|
||||
dd_large_pct: float | None = None,
|
||||
dd_medium_pct: float | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
hybrid tier 복리 배분·슬리피지 가정 체결 가능 발화 집계.
|
||||
|
||||
Args:
|
||||
outcomes: fire_outcomes.
|
||||
ohlc_df: 3m OHLC (drawdown).
|
||||
rule_ids: monitor rule_id 필터.
|
||||
holdout_only: holdout만.
|
||||
fee_rate: 수수료율.
|
||||
|
||||
Returns:
|
||||
simulate_live_order_cap과 동일 구조.
|
||||
"""
|
||||
from deepcoin.ground_truth.causal_gt_hybrid import build_monitor_hybrid_sized_trades
|
||||
|
||||
if outcomes.empty:
|
||||
return {"rules": {}, "note": "발화 없음"}
|
||||
|
||||
df = outcomes.copy()
|
||||
if holdout_only and "split" in df.columns:
|
||||
df = df[df["split"] == "holdout"]
|
||||
if rule_ids is not None:
|
||||
df = df[df["rule_id"].isin(rule_ids)]
|
||||
slip = LIVE_SLIPPAGE_PCT
|
||||
|
||||
sized, _ = build_monitor_hybrid_sized_trades(
|
||||
sort_fires_chronological(df),
|
||||
ohlc_df,
|
||||
enhanced=False,
|
||||
fee_rate=fee_rate,
|
||||
dd_large_pct=dd_large_pct,
|
||||
dd_medium_pct=dd_medium_pct,
|
||||
)
|
||||
executed_dts = {
|
||||
t["dt"]
|
||||
for t in sized
|
||||
if t.get("action") == "sell" or float(t.get("amount_krw") or 0) > 0
|
||||
}
|
||||
if not executed_dts:
|
||||
return {"rules": {}, "taken_count": 0, "total_count": int(len(df))}
|
||||
|
||||
taken = df[df["dt"].astype(str).isin(executed_dts)].copy()
|
||||
taken["adj_ret_pct"] = taken["forward_ret_pct"] - slip
|
||||
|
||||
by_rule: dict[str, Any] = {}
|
||||
for rid, grp in taken.groupby("rule_id"):
|
||||
g = grp.copy()
|
||||
g["forward_ret_pct"] = g["adj_ret_pct"]
|
||||
by_rule[rid] = {
|
||||
"taken_count": int(len(grp)),
|
||||
"total_count": int((df["rule_id"] == rid).sum()),
|
||||
"metrics": _rule_metrics(g),
|
||||
}
|
||||
|
||||
return {
|
||||
"assumptions": {
|
||||
"slippage_pct": slip,
|
||||
"sizing": "hybrid_dd_tier_compound",
|
||||
},
|
||||
"taken_count": int(len(taken)),
|
||||
"total_count": int(len(df)),
|
||||
"rules": by_rule,
|
||||
"portfolio_adj_ev_pct": round(float(taken["adj_ret_pct"].mean()), 4),
|
||||
}
|
||||
|
||||
|
||||
def build_simulation_report(
|
||||
outcomes_path: Path | None = None,
|
||||
matched_path: Path | None = None,
|
||||
@@ -336,6 +522,63 @@ def build_simulation_report(
|
||||
last_price=float(mark) if mark else None,
|
||||
)
|
||||
|
||||
# 인과 GT leg 엔진 (split_buy + peak_sell, 캘리브레이션 파라미터)
|
||||
cg_df = None
|
||||
try:
|
||||
from config import CHART_LOOKBACK_DAYS, MATCH_PRIMARY_INTERVAL, SYMBOL
|
||||
from deepcoin.data.mtf_bb import load_frames_from_db
|
||||
from deepcoin.ground_truth.causal_gt_calibrate import load_causal_gt_params
|
||||
from deepcoin.ground_truth.causal_gt_trades import simulate_causal_gt_portfolio
|
||||
from deepcoin.ops.monitor import Monitor
|
||||
|
||||
cg_params = load_causal_gt_params()
|
||||
mon_cg = Monitor(cooldown_file=None)
|
||||
cg_frames = load_frames_from_db(mon_cg, SYMBOL, lookback_days=CHART_LOOKBACK_DAYS)
|
||||
cg_df = cg_frames[MATCH_PRIMARY_INTERVAL]
|
||||
portfolio_compare["sim_causal_gt"] = simulate_causal_gt_portfolio(
|
||||
cg_df,
|
||||
last_price=float(mark) if mark else None,
|
||||
**cg_params,
|
||||
)
|
||||
# Phase 3: monitor buy + 인과 peak sell + drawdown tier
|
||||
from deepcoin.ground_truth.causal_gt_hybrid import (
|
||||
simulate_causal_gt_hybrid_portfolio,
|
||||
simulate_monitor_tier_enhanced_portfolio,
|
||||
)
|
||||
from deepcoin.ground_truth.hybrid_dd_calibrate import load_hybrid_dd_params
|
||||
|
||||
dd_params = load_hybrid_dd_params()
|
||||
|
||||
buy_only = all_monitor[all_monitor["side"] == "buy"]
|
||||
portfolio_compare["sim_causal_hybrid"] = simulate_causal_gt_hybrid_portfolio(
|
||||
buy_only,
|
||||
cg_df,
|
||||
monitor_fires=all_monitor,
|
||||
last_price=float(mark) if mark else None,
|
||||
cg_params=cg_params,
|
||||
dd_large_pct=dd_params.get("dd_large_pct"),
|
||||
dd_medium_pct=dd_params.get("dd_medium_pct"),
|
||||
)
|
||||
portfolio_compare["hybrid_dd_params"] = dd_params
|
||||
portfolio_compare["sim_tier_enhanced"] = simulate_monitor_tier_enhanced_portfolio(
|
||||
all_monitor,
|
||||
cg_df,
|
||||
last_price=float(mark) if mark else None,
|
||||
)
|
||||
except Exception as exc:
|
||||
portfolio_compare["sim_causal_gt"] = {
|
||||
"pnl_pct": 0.0,
|
||||
"note": f"causal_gt sim skipped: {exc}",
|
||||
}
|
||||
portfolio_compare["sim_causal_hybrid"] = {
|
||||
"pnl_pct": 0.0,
|
||||
"note": f"causal_hybrid sim skipped: {exc}",
|
||||
}
|
||||
portfolio_compare["sim_tier_enhanced"] = {
|
||||
"pnl_pct": 0.0,
|
||||
"note": f"tier_enhanced sim skipped: {exc}",
|
||||
}
|
||||
|
||||
holdout = outcomes[
|
||||
outcomes["rule_id"].isin(monitor_ids) & (outcomes["split"] == "holdout")
|
||||
]
|
||||
@@ -349,24 +592,119 @@ def build_simulation_report(
|
||||
outcomes_ts = outcomes.copy()
|
||||
outcomes_ts["ts"] = pd.to_datetime(outcomes_ts["dt"])
|
||||
h0 = outcomes_ts["ts"].quantile(1.0 - MATCH_HOLDOUT_RATIO)
|
||||
assets = [(s["dt"], float(s["total_asset_krw"])) for s in steps]
|
||||
pre = [a for d, a in assets if pd.to_datetime(d) < h0]
|
||||
in_h = [a for d, a in assets if pd.to_datetime(d) >= h0]
|
||||
asset_start = pre[-1] if pre else float(GT_INITIAL_CASH_KRW)
|
||||
asset_end = in_h[-1] if in_h else assets[-1][1]
|
||||
ho_pnl_pct = (
|
||||
(asset_end - asset_start) / asset_start * 100.0
|
||||
if asset_start > 0
|
||||
else 0.0
|
||||
portfolio_compare["sim_sized_holdout"] = portfolio_holdout_from_steps(
|
||||
steps,
|
||||
h0,
|
||||
trade_count=int(len(holdout)),
|
||||
note="전기간 복리(causal tier) 후 holdout 구간 자산 증감",
|
||||
)
|
||||
portfolio_compare["sim_sized_holdout"] = {
|
||||
"initial_asset_krw": round(asset_start, 0),
|
||||
"final_asset_krw": round(asset_end, 0),
|
||||
"pnl_krw": round(asset_end - asset_start, 0),
|
||||
"pnl_pct": round(ho_pnl_pct, 2),
|
||||
"note": "전기간 복리 후 holdout 구간 자산 증감 (1M 재시작 아님)",
|
||||
"trade_count": int(len(holdout)),
|
||||
}
|
||||
|
||||
go_hybrid: dict[str, Any] = {"go": False, "note": "hybrid sim unavailable"}
|
||||
go_option_c_phase2: dict[str, Any] = {"go": False, "note": "phase2 unavailable"}
|
||||
if (
|
||||
cg_df is not None
|
||||
and not all_monitor.empty
|
||||
and portfolio_compare.get("sim_causal_hybrid", {}).get("sizing_mode")
|
||||
):
|
||||
from deepcoin.ground_truth.causal_gt_hybrid import build_monitor_hybrid_sized_trades
|
||||
from deepcoin.ground_truth.gt_allocation import simulate_portfolio_steps
|
||||
from deepcoin.ground_truth.hybrid_dd_calibrate import load_hybrid_dd_params
|
||||
from deepcoin.matching.option_c_phase2 import (
|
||||
evaluate_option_c_phase2_go,
|
||||
simulate_hybrid_slippage_stress,
|
||||
walk_forward_portfolio_by_month,
|
||||
walk_forward_portfolio_summary,
|
||||
)
|
||||
|
||||
dd_params = portfolio_compare.get("hybrid_dd_params") or load_hybrid_dd_params()
|
||||
dd_large = dd_params.get("dd_large_pct")
|
||||
dd_medium = dd_params.get("dd_medium_pct")
|
||||
|
||||
hybrid_full = portfolio_compare["sim_causal_hybrid"]
|
||||
sized_h, _ = build_monitor_hybrid_sized_trades(
|
||||
sort_fires_chronological(all_monitor),
|
||||
cg_df,
|
||||
enhanced=False,
|
||||
dd_large_pct=dd_large,
|
||||
dd_medium_pct=dd_medium,
|
||||
)
|
||||
steps_h = simulate_portfolio_steps(sized_h, use_amount_krw=True)
|
||||
if steps_h and not holdout.empty:
|
||||
outcomes_ts = outcomes.copy()
|
||||
outcomes_ts["ts"] = pd.to_datetime(outcomes_ts["dt"])
|
||||
h0 = outcomes_ts["ts"].quantile(1.0 - MATCH_HOLDOUT_RATIO)
|
||||
portfolio_compare["sim_hybrid_holdout"] = portfolio_holdout_from_steps(
|
||||
steps_h,
|
||||
h0,
|
||||
trade_count=int(len(holdout)),
|
||||
note="전기간 복리(hybrid DD tier) 후 holdout 구간 자산 증감",
|
||||
)
|
||||
|
||||
stress_fee = TRADING_FEE_RATE * SIM_FEE_STRESS_MULT
|
||||
sized_stress, _ = build_monitor_hybrid_sized_trades(
|
||||
sort_fires_chronological(all_monitor),
|
||||
cg_df,
|
||||
enhanced=False,
|
||||
fee_rate=stress_fee,
|
||||
dd_large_pct=dd_large,
|
||||
dd_medium_pct=dd_medium,
|
||||
)
|
||||
portfolio_compare["sim_hybrid_fee_stress"] = simulate_portfolio_summary(
|
||||
sized_stress,
|
||||
fee_rate=stress_fee,
|
||||
last_price=float(mark) if mark else None,
|
||||
use_amount_krw=True,
|
||||
)
|
||||
|
||||
portfolio_compare["sim_hybrid_slippage_stress"] = simulate_hybrid_slippage_stress(
|
||||
sized_h,
|
||||
last_price=float(mark) if mark else None,
|
||||
fee_rate=TRADING_FEE_RATE,
|
||||
)
|
||||
wf_rows = walk_forward_portfolio_by_month(steps_h)
|
||||
wf_port = walk_forward_portfolio_summary(wf_rows)
|
||||
portfolio_compare["hybrid_portfolio_walk_forward"] = wf_rows
|
||||
portfolio_compare["hybrid_portfolio_wf_summary"] = wf_port
|
||||
|
||||
gt_pnl_for_phase2 = float(
|
||||
(portfolio_compare.get("ground_truth_chrono") or {}).get("pnl_pct", 0)
|
||||
)
|
||||
go_hybrid = evaluate_hybrid_sizing_go(
|
||||
go,
|
||||
hybrid_full,
|
||||
portfolio_compare.get("sim_hybrid_holdout") or {},
|
||||
portfolio_compare.get("sim_hybrid_fee_stress") or {},
|
||||
)
|
||||
go_option_c_phase2 = evaluate_option_c_phase2_go(
|
||||
go_hybrid,
|
||||
hybrid_full,
|
||||
portfolio_compare.get("sim_hybrid_holdout") or {},
|
||||
portfolio_compare.get("sim_hybrid_fee_stress") or {},
|
||||
portfolio_compare.get("sim_hybrid_slippage_stress") or {},
|
||||
wf_port,
|
||||
gt_pnl_for_phase2,
|
||||
)
|
||||
|
||||
primary = go_hybrid.get("primary_sizing", "causal_tier")
|
||||
portfolio_compare["primary_sizing"] = primary
|
||||
if primary == "hybrid":
|
||||
portfolio_compare["sim_primary"] = {
|
||||
**hybrid_full,
|
||||
"sizing_mode": "primary_hybrid_dd_tier",
|
||||
"sizing_note": (
|
||||
"권장: monitor + past-leg·drawdown tier (검증 통과, 미래 미사용)"
|
||||
),
|
||||
}
|
||||
live_cap = simulate_hybrid_order_cap(
|
||||
outcomes,
|
||||
cg_df,
|
||||
rule_ids=monitor_ids,
|
||||
holdout_only=True,
|
||||
dd_large_pct=dd_large,
|
||||
dd_medium_pct=dd_medium,
|
||||
)
|
||||
else:
|
||||
portfolio_compare["sim_primary"] = portfolio_compare.get("sim_sized") or {}
|
||||
|
||||
if portfolio_compare.get("sim_sized") and portfolio_compare.get("ground_truth_chrono"):
|
||||
gt_pnl = float(portfolio_compare["ground_truth_chrono"].get("pnl_pct", 0))
|
||||
@@ -383,6 +721,35 @@ def build_simulation_report(
|
||||
gtp / gt_pnl if abs(gt_pnl) > 1e-6 else 0.0,
|
||||
4,
|
||||
)
|
||||
if portfolio_compare.get("sim_causal_gt"):
|
||||
cgp = float(portfolio_compare["sim_causal_gt"].get("pnl_pct", 0))
|
||||
portfolio_compare["causal_gt_capture_ratio"] = round(
|
||||
cgp / gt_pnl if abs(gt_pnl) > 1e-6 else 0.0,
|
||||
4,
|
||||
)
|
||||
portfolio_compare["sim_causal_gt_pnl_pct"] = cgp
|
||||
if portfolio_compare.get("sim_causal_hybrid"):
|
||||
chp = float(portfolio_compare["sim_causal_hybrid"].get("pnl_pct", 0))
|
||||
portfolio_compare["causal_hybrid_capture_ratio"] = round(
|
||||
chp / gt_pnl if abs(gt_pnl) > 1e-6 else 0.0,
|
||||
4,
|
||||
)
|
||||
portfolio_compare["sim_causal_hybrid_pnl_pct"] = chp
|
||||
if portfolio_compare.get("sim_tier_enhanced"):
|
||||
tep = float(portfolio_compare["sim_tier_enhanced"].get("pnl_pct", 0))
|
||||
portfolio_compare["tier_enhanced_capture_ratio"] = round(
|
||||
tep / gt_pnl if abs(gt_pnl) > 1e-6 else 0.0,
|
||||
4,
|
||||
)
|
||||
portfolio_compare["sim_tier_enhanced_pnl_pct"] = tep
|
||||
|
||||
portfolio_compare["causal_gt_params"] = {}
|
||||
try:
|
||||
from deepcoin.ground_truth.causal_gt_calibrate import load_causal_gt_params
|
||||
|
||||
portfolio_compare["causal_gt_params"] = load_causal_gt_params()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
portfolio_compare["gt_allocation_analysis"] = gt_alloc_analysis
|
||||
portfolio_compare["causal_mode"] = {
|
||||
@@ -423,6 +790,8 @@ def build_simulation_report(
|
||||
"fee_stress_by_rule": fee_stress,
|
||||
"live_order_cap_sim": live_cap,
|
||||
"go_no_go": go,
|
||||
"go_no_go_hybrid": go_hybrid,
|
||||
"go_no_go_option_c_phase2": go_option_c_phase2,
|
||||
"portfolio_compare": portfolio_compare,
|
||||
"gt_model": gt_data.get("model") or model_to_dict(default_model()),
|
||||
"gt_weight_policy": weight_policy_summary(default_model()),
|
||||
@@ -438,6 +807,12 @@ def build_simulation_report(
|
||||
"min_holdout_pf": SIM_GO_MIN_HOLDOUT_PF,
|
||||
"wf_positive_ratio": SIM_GO_WF_POSITIVE_RATIO,
|
||||
"wf_min_months": SIM_WALK_FORWARD_MIN_MONTHS,
|
||||
"hybrid_min_holdout_pnl_pct": SIM_HYBRID_MIN_HOLDOUT_PNL_PCT,
|
||||
"hybrid_max_mdd_pct": SIM_HYBRID_MAX_MDD_PCT,
|
||||
"option_c_target_pnl_pct": SIM_OPTION_C_TARGET_PNL_PCT,
|
||||
"option_c_phase2_target_pnl_pct": SIM_OPTION_C_PHASE2_TARGET_PNL_PCT,
|
||||
"option_c_phase2_fee_stress_ratio": SIM_OPTION_C_PHASE2_FEE_STRESS_RATIO,
|
||||
"option_c_min_gt_capture": SIM_OPTION_C_MIN_GT_CAPTURE,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -480,9 +855,26 @@ def run_simulation_report(
|
||||
)
|
||||
write_simulation_html(report, MATCHING_SIMULATION_HTML)
|
||||
go = report["go_no_go"]["go"]
|
||||
go_h = report.get("go_no_go_hybrid") or {}
|
||||
pc_early = report.get("portfolio_compare") or {}
|
||||
print(f"[시뮬] 저장: {MATCHING_SIMULATION_JSON}")
|
||||
print(f"[시뮬] 저장: {MATCHING_SIMULATION_HTML}")
|
||||
print(f"[시뮬] Go/No-Go: {'GO' if go else 'NO-GO'}")
|
||||
print(f"[시뮬] Go/No-Go (규칙): {'GO' if go else 'NO-GO'}")
|
||||
print(
|
||||
f"[시뮬] Go/No-Go (hybrid tier): {'GO' if go_h.get('go') else 'NO-GO'} "
|
||||
f"· primary={pc_early.get('primary_sizing', '-')}"
|
||||
)
|
||||
for c in go_h.get("checks", []):
|
||||
mark = "OK" if c.get("pass") else "NG"
|
||||
opt = " (optional)" if c.get("optional") else ""
|
||||
print(f" [hybrid {mark}] {c.get('name')}: {c.get('value', '-')}{opt}")
|
||||
go_p2 = report.get("go_no_go_option_c_phase2") or {}
|
||||
print(
|
||||
f"[시뮬] Option C 2차(+1000%): {'GO' if go_p2.get('go') else 'NO-GO'}"
|
||||
)
|
||||
for c in go_p2.get("checks", []):
|
||||
mark = "OK" if c.get("pass") else "NG"
|
||||
print(f" [phase2 {mark}] {c.get('name')}: {c.get('value', '-')}")
|
||||
for c in report["go_no_go"].get("checks", []):
|
||||
mark = "OK" if c["pass"] else "NG"
|
||||
print(
|
||||
@@ -504,6 +896,44 @@ def run_simulation_report(
|
||||
f"{pc.get('sim_gt_model', {}).get('pnl_pct')}% "
|
||||
f"(capture={pc.get('gt_model_capture_ratio'):.2%})"
|
||||
)
|
||||
if pc.get("sim_causal_gt_pnl_pct") is not None:
|
||||
scg = pc.get("sim_causal_gt") or {}
|
||||
print(
|
||||
f"[시뮬] GT 대비 sim_causal_gt(인과 leg): "
|
||||
f"{pc.get('sim_causal_gt_pnl_pct')}% "
|
||||
f"(capture={pc.get('causal_gt_capture_ratio', 0):.2%}, "
|
||||
f"legs={scg.get('leg_count', '-')}, trades={scg.get('trade_count', '-')})"
|
||||
)
|
||||
if pc.get("sim_causal_hybrid_pnl_pct") is not None:
|
||||
sch = pc.get("sim_causal_hybrid") or {}
|
||||
print(
|
||||
f"[시뮬] GT 대비 sim_causal_hybrid(monitor+DD tier): "
|
||||
f"{pc.get('sim_causal_hybrid_pnl_pct')}% "
|
||||
f"(capture={pc.get('causal_hybrid_capture_ratio', 0):.2%}, "
|
||||
f"MDD={sch.get('max_drawdown_pct', '-')}%)"
|
||||
)
|
||||
if pc.get("sim_primary"):
|
||||
sp = pc["sim_primary"]
|
||||
print(
|
||||
f"[시뮬] 권장 primary ({pc.get('primary_sizing')}): "
|
||||
f"{sp.get('pnl_pct')}% · MDD={sp.get('max_drawdown_pct', '-')}%"
|
||||
)
|
||||
ho_h = pc.get("sim_hybrid_holdout") or {}
|
||||
if ho_h.get("pnl_pct") is not None:
|
||||
print(
|
||||
f"[시뮬] hybrid holdout: {ho_h.get('pnl_pct')}% "
|
||||
f"({ho_h.get('initial_asset_krw')}→{ho_h.get('final_asset_krw')})"
|
||||
)
|
||||
if pc.get("sim_tier_enhanced_pnl_pct") is not None:
|
||||
ste = pc.get("sim_tier_enhanced") or {}
|
||||
ast = ste.get("alloc_stats") or {}
|
||||
print(
|
||||
f"[시뮬] GT 대비 sim_tier_enhanced(conviction tier): "
|
||||
f"{pc.get('sim_tier_enhanced_pnl_pct')}% "
|
||||
f"(capture={pc.get('tier_enhanced_capture_ratio', 0):.2%}, "
|
||||
f"large_buys={ast.get('large_tier_buy_count', '-')}, "
|
||||
f"avg_buy={ast.get('buy_amount_avg_krw', '-')})"
|
||||
)
|
||||
if pc.get("sim_sized", {}).get("max_drawdown_pct") is not None:
|
||||
print(
|
||||
f"[시뮬] sim_sized MDD: {pc['sim_sized']['max_drawdown_pct']}% "
|
||||
|
||||
Reference in New Issue
Block a user