def build_resiliency_html(sens_report, stress_report): sens_rows = "" if "report" in sens_report: s_report = sens_report["report"] else: s_report = sens_report for t, data in s_report.items(): if data['max'] > 0.01 or data['min'] < -0.01: fragile = data['spread'] > 0.15 s_col = "#f85149" if fragile else "#3fb950" sens_rows += ( f"{t}" f"{data['optimal']*100:.1f}%" f"{data['min']*100:.1f}%" f"{data['max']*100:.1f}%" f"{'[!] Fragile' if fragile else 'Stable'}" ) stress_rows = "" for s in stress_report: c = "#f85149" if s['impact'] < -0.05 else ("#e3b341" if s['impact'] < 0 else "#3fb950") stress_rows += ( f"{s['scenario']}{s['trigger']}" f"{s['impact']*100:+.2f}%" ) resiliency_html = f"""

Systemic Resiliency & Allocation Stability

Crash Scenarios

{stress_rows}
ScenarioTriggerImpact

Sensitivity (±10% noise)

{sens_rows}
TickerOptimalMinMaxStatus
""" return resiliency_html