math-backend / report_builders /html_resiliency.py
engineportf's picture
Upload folder using huggingface_hub
558db1e verified
Raw
History Blame Contribute Delete
1.82 kB
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"<tr><td><strong>{t}</strong></td>"
f"<td>{data['optimal']*100:.1f}%</td>"
f"<td>{data['min']*100:.1f}%</td>"
f"<td>{data['max']*100:.1f}%</td>"
f"<td style='color:{s_col}'>{'[!] Fragile' if fragile else 'Stable'}</td></tr>"
)
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"<tr><td>{s['scenario']}</td><td>{s['trigger']}</td>"
f"<td style='color:{c};font-weight:bold'>{s['impact']*100:+.2f}%</td></tr>"
)
resiliency_html = f"""
<p class="st">Systemic Resiliency &amp; Allocation Stability</p>
<div class="two">
<div class="cc" style="overflow-x:auto">
<p style="font-size:.8rem;color:#8b949e;margin-bottom:8px"><strong>Crash Scenarios</strong></p>
<table><thead><tr><th>Scenario</th><th>Trigger</th><th>Impact</th></tr></thead>
<tbody>{stress_rows}</tbody></table>
</div>
<div class="cc" style="overflow-x:auto">
<p style="font-size:.8rem;color:#8b949e;margin-bottom:8px"><strong>Sensitivity (±10% noise)</strong></p>
<table><thead><tr><th>Ticker</th><th>Optimal</th><th>Min</th><th>Max</th><th>Status</th></tr></thead>
<tbody>{sens_rows}</tbody></table>
</div>
</div>"""
return resiliency_html