def build_data_alerts_html(tn_ratio, n_fragile):
data_alerts_html = ""
if tn_ratio is not None and tn_ratio < 10:
sev_c = "#f85149" if tn_ratio < 5 else "#d29922"
sev_l = "Critical" if tn_ratio < 5 else "Warning"
data_alerts_html += (
f'
'
f'⚠ Spurious Correlation {sev_l} — '
f'T/N={tn_ratio:.1f}x. Need ≥10× observations vs assets.
'
)
if n_fragile > 0:
data_alerts_html += (
f''
f'⚠ Fragile Allocations — {n_fragile} asset(s) had '
f'weight swings >15 pp under ±10% return noise. Stability penalty applied.
'
)
return data_alerts_html
def build_warnings_html(diags):
warn_html = ""
if diags:
items = "".join(f'{d}' for d in diags)
warn_html = (
''
'
⚠ Behavioral Diagnostics
'
f'
'
)
return warn_html
def build_constraint_diag_html(model_info):
relax_log = model_info.get("relaxation_log", [])
binding_cons = model_info.get("display_constraints", [])
_cd_inner = ""
if binding_cons:
_bc_items = "".join(f'{c}' for c in binding_cons)
_cd_inner += (
'Binding Constraints
'
''
'These rules actively limited the optimizer — relaxing them may improve returns:
'
f''
)
if relax_log:
_rl_items = "".join(f'{r}' for r in relax_log)
_cd_inner += (
'Constraint Relaxation History
'
''
'Initial constraints were infeasible — the engine auto-relaxed these rules to find a solution:
'
f''
)
elif not binding_cons:
_cd_inner = (
'All Constraints Satisfied
'
''
'No binding constraints or relaxations required. The optimizer found a clean solution.
'
)
return (
''
'
'
'Constraint Diagnostics
'
f'{_cd_inner}
'
)