#!/usr/bin/env python3
"""
AntLevee Research — Bayesian Forensic Financial Statement Audit Engine
======================================================================
Applies exact Bayesian likelihood-ratio updating and Theorem 3
(Frechet-Hoeffding correlated-signal bounds) to 8 primary-filing signals
extracted verbatim from Anthropic, PBC's Form 424B4 (filed 19 Nov 2026).

Hypotheses Tested:
  - H0 (Null): Organic high-margin enterprise software economics
               (reported 85.5% implied GM, $6.57B OCF, immaterial off-BS obligations).
  - H1 (Alt.): Structurally disguised, channel-grossed-up, capital-subsidised
               compute arbitrage regime (requires restatement of margins, OCF,
               credit-loss reserves, below-line supplier equity subsidies & off-BS liabilities).

Note on Epistemic Hygiene:
  - All ratios (44% vs 52% CSP share, $4,104M vs $4,231M bilateral offset, 1.362% allowance,
    74.42% compute outside CoR, -$11,008M G-2 loss, $451.2B leases / $156.2B VIEs / $4.7B
    unaccrued Note 13 guarantees, 2-member Audit Committee + 1 vacancy) are exact primary facts
    from Form 424B4.
  - Individual signal likelihoods (P(S_k | H0) vs P(S_k | H1)) are explicitly parametrised
    forensic weights; we therefore report three correlation regimes (Global Comonotonic Floor,
    4-Domain Frechet-Hoeffding Bound, and Naive Independent Ceiling) plus a 50%-haircut
    conservative likelihood stress test across base-rate priors pi0 in {0.05, 0.10, 0.25, 0.50}.
"""
from __future__ import annotations

import json
import math
from pathlib import Path

ROOT = Path(__file__).resolve().parent
OUT_JSON = ROOT / "antlevee_bayesian_accounting_audit.json"


# ---- Primary Filing Inputs (Form 424B4, 19 Nov 2026) ----------------------------------------
FILING_INPUTS = {
    "rev_9m26_m": 33242.0,
    "rev_q3_26_m": 16956.0,
    "rev_ye25_m": 4585.0,
    "ar_net_ye24_m": 95.0,
    "allowance_ye24_m": 5.0,
    "ar_net_ye25_m": 909.0,
    "allowance_ye25_m": 17.0,
    "ar_net_q3_26_m": 7892.0,
    "allowance_q3_26_m": 109.0,
    "writeoffs_9m26_m": 2.0,
    "csp_rev_share_9m26": 0.44,
    "csp_ar_share_q3_26": 0.52,
    "csp_payables_q3_26_m": 4231.0,
    "customer_e_ar_share": 0.13,
    "q3_days": 92.0,
    "cor_note8_9m26_m": 4812.0,
    "excess_compute_rnd_m": 13996.0,
    "sm_9m26_m": 6619.0,
    "sm_9m25_m": 530.0,
    "partner_financing_loss_income_stmt_m": -11008.0,
    "partner_financing_loss_level3_m": -13356.0,
    "partner_financing_settled_g2_m": 11810.0,
    "warrant_rights_asset_m": 1128.0,
    "warrant_rights_gain_9m26_m": 783.0,
    "reported_gaap_oi_m": -1260.0,
    "nongaap_adj_oi_m": 4081.0,
    "proforma_9m_rsu_service_p28_m": 7487.0,
    "rsu_unrecognized_backlog_m": 39400.0,
    "total_award_backlog_m": 41500.0,
    "ocf_9m26_m": 6569.0,
    "interest_income_9m26_m": 2359.0,
    "core_fcf_mid_m": 1206.0,
    "leases_uncommenced_m": 451200.0,
    "leases_on_bs_op_pv_m": 2810.0,
    "leases_on_bs_fin_pv_m": 1674.0,
    "leases_on_bs_undiscounted_m": 6174.0,  # 4,224 operating + 1,950 finance (p. F-35)
    "non_consolidated_vie_uncommenced_m": 156200.0,
    "note13_dev_reimbursement_guar_m": 4200.0,
    "note13_power_guar_m": 500.0,
    "rent_npa_2025_m": 10000.0,
    "rent_npa_2026_9pct_pik_m": 42000.0,
    "audit_committee_sitting": 2,
    "audit_committee_vacancies": 1,
}


def compute_exact_ratios(d: dict) -> dict:
    ar_gross_ye24 = d["ar_net_ye24_m"] + d["allowance_ye24_m"]
    ar_gross_ye25 = d["ar_net_ye25_m"] + d["allowance_ye25_m"]
    ar_gross_q3 = d["ar_net_q3_26_m"] + d["allowance_q3_26_m"]

    allow_rate_ye24 = d["allowance_ye24_m"] / ar_gross_ye24
    allow_rate_ye25 = d["allowance_ye25_m"] / ar_gross_ye25
    allow_rate_q3 = d["allowance_q3_26_m"] / ar_gross_q3

    csp_ar_m = d["ar_net_q3_26_m"] * d["csp_ar_share_q3_26"]
    direct_ar_m = d["ar_net_q3_26_m"] * (1.0 - d["csp_ar_share_q3_26"])
    csp_rev_q3_m = d["rev_q3_26_m"] * d["csp_rev_share_9m26"]
    direct_rev_q3_m = d["rev_q3_26_m"] * (1.0 - d["csp_rev_share_9m26"])

    csp_dso = csp_ar_m / (csp_rev_q3_m / d["q3_days"])
    direct_dso = direct_ar_m / (direct_rev_q3_m / d["q3_days"])
    bilateral_csp_offset_ratio = csp_ar_m / d["csp_payables_q3_26_m"]

    # Reserve deficit if Q3 2026 gross AR restored to YE25 (1.836%), 2.5%, or YE24 (5.00%)
    reserve_gap_at_ye25_rate_m = ar_gross_q3 * allow_rate_ye25 - d["allowance_q3_26_m"]
    reserve_gap_at_2_5pct_m = ar_gross_q3 * 0.025 - d["allowance_q3_26_m"]
    reserve_gap_at_ye24_rate_m = ar_gross_q3 * allow_rate_ye24 - d["allowance_q3_26_m"]

    total_compute_disclosed_m = d["cor_note8_9m26_m"] + d["excess_compute_rnd_m"]
    outside_cor_share = d["excess_compute_rnd_m"] / total_compute_disclosed_m

    leases_on_bs_pv_m = d["leases_on_bs_op_pv_m"] + d["leases_on_bs_fin_pv_m"]
    uncommenced_to_onbs_pv_x = d["leases_uncommenced_m"] / leases_on_bs_pv_m
    off_bs_lease_share = d["leases_uncommenced_m"] / (d["leases_uncommenced_m"] + d["leases_on_bs_undiscounted_m"])

    unaccrued_note13_guar_m = d["note13_dev_reimbursement_guar_m"] + d["note13_power_guar_m"]
    customer_e_ar_m = d["ar_net_q3_26_m"] * d["customer_e_ar_share"]
    sm_yoy_multiple = d["sm_9m26_m"] / d["sm_9m25_m"]

    return {
        "ar_gross_q3_26_m": round(ar_gross_q3, 1),
        "ar_9m_growth_multiple": round(d["ar_net_q3_26_m"] / d["ar_net_ye25_m"], 2),
        "allowance_rate_ye24_pct": round(allow_rate_ye24 * 100.0, 2),
        "allowance_rate_ye25_pct": round(allow_rate_ye25 * 100.0, 3),
        "allowance_rate_q3_26_pct": round(allow_rate_q3 * 100.0, 3),
        "allowance_rate_q3_26_net_pct": round((d["allowance_q3_26_m"] / d["ar_net_q3_26_m"]) * 100.0, 3),
        "reserve_gap_ye25_rate_m": round(reserve_gap_at_ye25_rate_m, 1),
        "reserve_gap_2_5pct_m": round(reserve_gap_at_2_5pct_m, 1),
        "reserve_gap_ye24_rate_m": round(reserve_gap_at_ye24_rate_m, 1),
        "csp_ar_q3_26_m": round(csp_ar_m, 2),
        "direct_ar_q3_26_m": round(direct_ar_m, 2),
        "customer_e_ar_m": round(customer_e_ar_m, 2),
        "csp_dso_days": round(csp_dso, 2),
        "direct_dso_days": round(direct_dso, 2),
        "csp_vs_direct_dso_gap_days": round(csp_dso - direct_dso, 2),
        "bilateral_csp_ar_to_ap_pct": round(bilateral_csp_offset_ratio * 100.0, 2),
        "excess_compute_outside_cor_pct": round(outside_cor_share * 100.0, 2),
        "sm_yoy_multiple": round(sm_yoy_multiple, 2),
        "leases_on_bs_pv_m": leases_on_bs_pv_m,
        "uncommenced_to_onbs_pv_x": round(uncommenced_to_onbs_pv_x, 2),
        "off_bs_undiscounted_lease_share_pct": round(off_bs_lease_share * 100.0, 2),
        "unaccrued_note13_guar_m": unaccrued_note13_guar_m,
        "interest_share_of_ocf_pct": round((d["interest_income_9m26_m"] / d["ocf_9m26_m"]) * 100.0, 2),
    }


# ---- 8 Primary-Filing Signals Grouped into 4 Structural Domains -----------------------------
# Strictly separates independent accounting/governance choices across 4 domains while applying
# Frechet-Hoeffding 100% comonotonic correlation within each domain (Theorem 3 discipline).
SIGNALS = [
    {
        "id": "S1",
        "domain": "D1_Revenue_Channel_WC",
        "domain_label": "Revenue Recognition & Channel Working Capital",
        "name": "Bilateral CSP Gross-Up & 50.6d vs 36.7d Channel DSO Asymmetry",
        "primary_fact": "CSP marketplaces = 44% of 9M26 rev yet 52% of Net AR ($4,103.8M vs $4,231.0M CSP Payables = 97.0% bilateral mirror; 50.6d CSP DSO vs 36.7d Direct DSO; +14.44% channel gross-up).",
        "locator": "Form 424B4 pp. 165, F-5, F-16, F-21, F-38",
        "p_h1": 0.85,
        "p_h0": 0.12,
    },
    {
        "id": "S2",
        "domain": "D1_Revenue_Channel_WC",
        "domain_label": "Revenue Recognition & Channel Working Capital",
        "name": "Credit-Loss Allowance Cut to 1.362% Amid 8.68x AR Surge & Customer E (13% AR)",
        "primary_fact": "Net AR jumped 8.68x ($909M -> $7,892M) and Customer E hit 13% ($1,026.0M), yet bad-debt allowance was cut 5.00% -> 1.836% -> 1.362% ($2M write-offs) despite 80% Top-1% VC customer mix.",
        "locator": "Form 424B4 pp. 60, F-5, F-15, F-18; Ramp Nov 2026",
        "p_h1": 0.78,
        "p_h0": 0.16,
    },
    {
        "id": "S3",
        "domain": "D2_Cost_Subsidy_Classification",
        "domain_label": "Cost, Equity-Subsidy & SBC Classification",
        "name": "Auditor Switch -> Functional P&L Removal + 3-Way Compute Shifting (74.4% in R&D, Free Compute in S&M)",
        "primary_fact": "30 Oct 2025 switch from Grant Thornton to EY removed Gross Profit from P&L face; 74.42% ($13,996M) of compute sits in R&D and free-user compute is bundled inside S&M ($6,619M, 12.49x YoY).",
        "locator": "Form 424B4 pp. 348, F-2, F-4, F-7, F-40 (Note 8)",
        "p_h1": 0.88,
        "p_h0": 0.08,
    },
    {
        "id": "S4",
        "domain": "D2_Cost_Subsidy_Classification",
        "domain_label": "Cost, Equity-Subsidy & SBC Classification",
        "name": "-$11,008M (-$13,356M L3) Partner-Financing G-2 Subsidy Buried Below Operating Income",
        "primary_fact": "Selling 57.9M Series G-2 shares to Google/Amazon at $25.91/sh (68.8% below $83 IPO) generated -$13,356M Level 3 loss (-$11,008M in Other Expense) + $1,128M Level 3 Warrant asset.",
        "locator": "Form 424B4 pp. F-30 to F-32, F-38, F-39",
        "p_h1": 0.82,
        "p_h0": 0.14,
    },
    {
        "id": "S5",
        "domain": "D2_Cost_Subsidy_Classification",
        "domain_label": "Cost, Equity-Subsidy & SBC Classification",
        "name": "ASC 718 RSU Cliff Deferral ($0 vs $7.49B Pro Forma 9M) & Nov 9 One-Day Vest Acceleration",
        "primary_fact": "$0 RSU recognised in -$1.26B reported GAAP OI vs $7.487B pro forma 9M RSU service cost (-$8.747B normalized OI; $39.4B RSU backlog; Nov 9 vest tweak unlocked 67M RSUs on Day 1).",
        "locator": "Form 424B4 pp. 28, 162-163, 182, F-53 to F-54, F-66",
        "p_h1": 0.72,
        "p_h0": 0.28,
    },
    {
        "id": "S6",
        "domain": "D3_CashFlow_OffBS_Engineering",
        "domain_label": "Cash-Flow Optical Wedges & Off-BS VIE/Lease/Guarantee Stack",
        "name": "ASC 230 Deposit-Interest OCF Wedge (35.9%) & $3.28B CSP Payables Stretch (+9.9d DPO)",
        "primary_fact": "$2,359M financing-cash interest (35.91% of $6,569M OCF) + $2,865M timing inflows mask $1,082M-$1,330M core FCF (0.31x $4,281M Day-1 RSU tax bill).",
        "locator": "Form 424B4 pp. F-7, F-12, F-38, F-40",
        "p_h1": 0.84,
        "p_h0": 0.15,
    },
    {
        "id": "S7",
        "domain": "D3_CashFlow_OffBS_Engineering",
        "domain_label": "Cash-Flow Optical Wedges & Off-BS VIE/Lease/Guarantee Stack",
        "name": "100.6x Uncommenced Leases ($451.2B), $156.2B VIE Exclusion ('Remarketing'), $4.7B Unaccrued Guarantees",
        "primary_fact": "98.6% of leases off-BS; $156.2B VIEs excluded via Meta-style 'remarketing' claim; $52B rent-financing NPAs; Note 13 hides $4.2B developer + $0.5B power guarantees accrued at 'not material'.",
        "locator": "Form 424B4 pp. F-35, F-36, F-43, F-60 (Note 13)",
        "p_h1": 0.90,
        "p_h0": 0.06,
    },
    {
        "id": "S8",
        "domain": "D4_Governance_Audit_Gate",
        "domain_label": "Governance & Audit Oversight Gate",
        "name": "2-Member Audit Committee + 1 Vacancy Under Nasdaq Exemption Alongside 0.079% Control Wedge",
        "primary_fact": "Enters Nasdaq with 2 Audit Committee members + 1 vacant seat under phase-in exemption while 0%-equity LTBT controls 4/7 board seats and Class F locks 50.1% votes down to 0.079% equity.",
        "locator": "Form 424B4 pp. 14-16, 113, 253-266, 298",
        "p_h1": 0.65,
        "p_h0": 0.22,
    },
]


def bayes_post(prior: float, bf: float) -> float:
    odds = (prior / (1.0 - prior)) * bf
    return odds / (1.0 + odds)


def evaluate_regimes(signals: list[dict], scale_down: float = 1.0) -> dict:
    """
    Evaluate Bayes factors and posteriors under three strict correlation assumptions.
    scale_down in (0, 1] attenuates log(BF_k) linearly for sensitivity testing:
    when scale_down = 0.50, BF_k(attenuated) = sqrt(BF_k).
    Uses canonical 2-decimal signal BFs (bf_base) raised to scale_down without intermediate
    re-rounding so Python, JSON, static SVGs, and client-side JS match to 0.01 precision.
    """
    enriched = []
    by_domain: dict[str, list[dict]] = {}
    for s in signals:
        bf_base = round(s["p_h1"] / s["p_h0"], 2)
        bf_eff = bf_base ** scale_down
        row = {
            "id": s["id"],
            "domain": s["domain"],
            "name": s["name"],
            "locator": s["locator"],
            "p_h1": s["p_h1"],
            "p_h0": s["p_h0"],
            "bf": round(bf_eff, 2),
            "_bf_exact": bf_eff,
            "log10_bf": round(math.log10(bf_eff), 3),
        }
        enriched.append(row)
        by_domain.setdefault(s["domain"], []).append(row)

    # 1. Global Comonotonic Floor (single-envelope lower bound max_i BF_i)
    global_floor_bf = max(r["_bf_exact"] for r in enriched)

    # 2. Within-Domain Envelope Selection under Cross-Domain Orthogonality (prod_d max_{i in D_d} BF_i)
    domain_maxima = {}
    fh_domain_bf = 1.0
    for dom, items in by_domain.items():
        dom_max = max(items, key=lambda x: x["_bf_exact"])
        domain_maxima[dom] = {"dominant_signal": dom_max["id"], "bf": dom_max["bf"]}
        fh_domain_bf *= dom_max["_bf_exact"]

    # 3. 3-Domain Financial-Statement-Only Envelope (D1, D2, D3 using S1-S7; excludes S8 equity tape)
    acc_domains = [
        d for d in (
            "D1_Revenue_Channel_WC",
            "D2_Cost_Subsidy_Classification",
            "D3_CashFlow_OffBS_Engineering",
        )
        if d in domain_maxima
    ]
    fh_3domain_bf = 1.0
    for d in acc_domains:
        fh_3domain_bf *= float(domain_maxima[d]["bf"])

    # 4. Strictly Discretionary Presentation Subset (S1 x S3 = 77.88x without S8; S1 x S3 x S8 = 229.75x)
    disc_acc_ids = {"S1", "S3"}
    disc_acc_bf = 1.0
    for r in enriched:
        if r["id"] in disc_acc_ids:
            disc_acc_bf *= r["_bf_exact"]

    disc_ids = {"S1", "S3", "S8"}
    disc_bf = 1.0
    for r in enriched:
        if r["id"] in disc_ids:
            disc_bf *= r["_bf_exact"]

    # 5. Naive Independent Ceiling: product of all 8 BFs (shown solely as anti-pattern)
    indep_bf = 1.0
    for r in enriched:
        indep_bf *= r["_bf_exact"]

    for r in enriched:
        r.pop("_bf_exact", None)

    # 6. Common-Cause Inter-Domain Correlation Sensitivity on 3-Domain S1-S7 (BF_corr(rho) = BF_3^((1/(1+2*rho))))
    rho_grid = [0.00, 0.30, 0.50, 0.60, 1.00]
    corr_grid = []
    for rho in rho_grid:
        bf_corr = fh_3domain_bf ** (1.0 / (1.0 + 2.0 * rho)) if rho < 1.0 else global_floor_bf
        corr_grid.append({
            "rho": rho,
            "composite_bf": round(bf_corr, 2),
            "posterior_at_5pct_prior_pct": round(bayes_post(0.05, bf_corr) * 100.0, 2),
            "posterior_at_10pct_prior_pct": round(bayes_post(0.10, bf_corr) * 100.0, 2),
            "posterior_at_25pct_prior_pct": round(bayes_post(0.25, bf_corr) * 100.0, 2),
            "posterior_at_50pct_prior_pct": round(bayes_post(0.50, bf_corr) * 100.0, 2),
        })

    priors = [0.05, 0.10, 0.25, 0.50]
    posterior_grid = []
    for p0 in priors:
        posterior_grid.append({
            "prior_h1": p0,
            "posterior_global_comonotonic_floor_pct": round(bayes_post(p0, global_floor_bf) * 100.0, 2),
            "posterior_discretionary_only_s1_s3_pct": round(bayes_post(p0, disc_acc_bf) * 100.0, 2),
            "posterior_discretionary_only_s1_s3_s8_pct": round(bayes_post(p0, disc_bf) * 100.0, 2),
            "posterior_3domain_accounting_s1_s7_pct": round(bayes_post(p0, fh_3domain_bf) * 100.0, 2),
            "posterior_4domain_frechet_hoeffding_pct": round(bayes_post(p0, fh_domain_bf) * 100.0, 2),
            "posterior_naive_independent_pct": round(bayes_post(p0, indep_bf) * 100.0, 4),
        })

    return {
        "likelihood_attenuation": scale_down,
        "aggregation_specification": "Within-domain single-signal envelope selection (max BF_i) across 3 accounting-only domains (S1-S7 -> 1,168.20x) and 4 domains (S1-S8 -> 3,446.19x), plus common-cause correlation penalty BF^(1/(1+2*rho))",
        "signals": enriched,
        "domain_maxima": domain_maxima,
        "composite_bf": {
            "global_comonotonic_floor": round(global_floor_bf, 2),
            "discretionary_only_s1_s3": round(disc_acc_bf, 2),
            "discretionary_only_s1_s3_s8": round(disc_bf, 2),
            "three_domain_accounting_only_s1_s7": round(fh_3domain_bf, 2),
            "four_domain_frechet_hoeffding": round(fh_domain_bf, 2),
            "naive_independent_ceiling": round(indep_bf, 2),
        },
        "common_cause_correlation_grid": corr_grid,
        "posterior_grid": posterior_grid,
    }


def main() -> None:
    ratios = compute_exact_ratios(FILING_INPUTS)
    base_regimes = evaluate_regimes(SIGNALS, scale_down=1.0)
    conservative_50pct = evaluate_regimes(SIGNALS, scale_down=0.5)

    # Posterior expected economic values at 10% skeptical prior using 3-Domain Accounting S1-S7 (primary non-circular) and 4-Domain FH
    fh3_10 = next(r for r in base_regimes["posterior_grid"] if r["prior_h1"] == 0.10)["posterior_3domain_accounting_s1_s7_pct"] / 100.0
    fh_10 = next(r for r in base_regimes["posterior_grid"] if r["prior_h1"] == 0.10)["posterior_4domain_frechet_hoeffding_pct"] / 100.0
    rho30_10 = next(r for r in base_regimes["common_cause_correlation_grid"] if r["rho"] == 0.30)["posterior_at_10pct_prior_pct"] / 100.0
    expected_9m = {
        "post_weight_10pct_prior_3domain_s1_s7": round(fh3_10, 4),
        "post_weight_10pct_prior_3domain_rho_0_30": round(rho30_10, 4),
        "post_weight_10pct_prior": round(fh_10, 4),
        "gross_margin_reported_pct": 85.52,
        "gross_margin_restated_50pct_compute_pct": 46.45,
        "gross_margin_restated_65pct_mid_compute_pct": 40.14,
        "gross_margin_posterior_expected_pct": round(85.52 * (1.0 - fh3_10) + 46.45 * fh3_10, 2),
        "gross_margin_posterior_expected_4domain_pct": round(85.52 * (1.0 - fh_10) + 46.45 * fh_10, 2),
        "op_income_reported_m": -1260.0,
        "op_income_normalized_p28_m": -8747.0,
        "op_income_posterior_expected_m": round(-1260.0 * (1.0 - fh3_10) + (-8747.0) * fh3_10, 1),
        "core_fcf_reported_ocf_m": 6569.0,
        "core_fcf_restated_mid_m": 1206.0,
        "core_fcf_after_fin_lease_principal_m": 994.0,
        "core_fcf_posterior_expected_m": round(6569.0 * (1.0 - fh3_10) + 1206.0 * fh3_10, 1),
    }

    payload = {
        "audit_date": "2026-11-21",
        "source_filing": "Anthropic, PBC Form 424B4 (filed 19 Nov 2026, acc. 0001628280-26-074944)",
        "primary_inputs": FILING_INPUTS,
        "exact_ratios": ratios,
        "bayesian_regimes_base": base_regimes,
        "bayesian_regimes_conservative_half_logbf": conservative_50pct,
        "bayesian_posterior_expected_statements_at_10pct_prior": expected_9m,
    }
    OUT_JSON.write_text(json.dumps(payload, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")

    print("=== AntLevee Bayesian Financial Statement Presentation Audit (Form 424B4) ===")
    print(f"S1 Bilateral CSP Mirror: ${ratios['csp_ar_q3_26_m']:.1f}M CSP AR vs ${FILING_INPUTS['csp_payables_q3_26_m']:.1f}M CSP AP ({ratios['bilateral_csp_ar_to_ap_pct']:.2f}%) | DSO: CSP {ratios['csp_dso_days']:.1f}d vs Direct {ratios['direct_dso_days']:.1f}d")
    print(f"S2 Credit-Loss Allowance: YE24 {ratios['allowance_rate_ye24_pct']:.2f}% -> YE25 {ratios['allowance_rate_ye25_pct']:.3f}% -> Q3'26 {ratios['allowance_rate_q3_26_pct']:.3f}% (AR {ratios['ar_9m_growth_multiple']}x; Customer E ${ratios['customer_e_ar_m']:.1f}M)")
    print(f"S3/S7 Off-BS Stack: {ratios['excess_compute_outside_cor_pct']:.2f}% compute in R&D | Uncommenced leases {ratios['uncommenced_to_onbs_pv_x']}x on-BS PV | $156.2B VIEs excluded | ${ratios['unaccrued_note13_guar_m']:.0f}M Note 13 guarantees at ~0")
    p10 = next(r for r in base_regimes["posterior_grid"] if r["prior_h1"] == 0.10)
    c10 = next(r for r in conservative_50pct["posterior_grid"] if r["prior_h1"] == 0.10)
    r30 = next(r for r in base_regimes["common_cause_correlation_grid"] if r["rho"] == 0.30)
    r50 = next(r for r in base_regimes["common_cause_correlation_grid"] if r["rho"] == 0.50)
    print(f"Base BF: Global Floor {base_regimes['composite_bf']['global_comonotonic_floor']}x | 3-Domain S1-S7 {base_regimes['composite_bf']['three_domain_accounting_only_s1_s7']:,.2f}x ({p10['posterior_3domain_accounting_s1_s7_pct']}%) | rho=0.30: {r30['composite_bf']}x ({r30['posterior_at_10pct_prior_pct']}%) | rho=0.50: {r50['composite_bf']}x ({r50['posterior_at_10pct_prior_pct']}%) | 4-Domain FH {base_regimes['composite_bf']['four_domain_frechet_hoeffding']:,.2f}x ({p10['posterior_4domain_frechet_hoeffding_pct']}%)")
    print(f"Conservative 50%-Haircut (10% prior): Global Floor {c10['posterior_global_comonotonic_floor_pct']}% | 3-Domain S1-S7 {c10['posterior_3domain_accounting_s1_s7_pct']}% | 4-Domain FH {c10['posterior_4domain_frechet_hoeffding_pct']}%")


if __name__ == "__main__":
    main()
