math-backend / report_builders /html_fixed_income.py
engineportf's picture
Upload folder using huggingface_hub
558db1e verified
Raw
History Blame Contribute Delete
1.38 kB
def build_fixed_income_html(model_info, cfg, weights):
fixed_income_html = ""
port_dur = model_info.get("portfolio_duration", 0.0)
bond_meta = cfg.get("bond_metadata", {})
bonds_in_port = [t for t in weights.index if t in bond_meta and abs(weights.get(t, 0)) > 0.001]
if bonds_in_port or port_dur > 0.01:
fi_rows = ""
for t in bonds_in_port:
w_pct = weights.get(t, 0) * 100
meta = bond_meta[t]
dur = meta.get("modified_duration", 0.0)
cpn = meta.get("coupon", 0.0)
fi_rows += (
f"<tr><td><strong>{t}</strong></td>"
f"<td>{w_pct:.1f}%</td>"
f"<td>{dur:.2f} yrs</td>"
f"<td>{cpn*100:.2f}%</td></tr>\n"
)
fixed_income_html = (
f'<p class="st">Fixed Income Profile</p>'
f'<div class="mg"><div class="mc"><div class="ml">Portfolio Duration</div>'
f'<div class="mv">{port_dur:.2f} yrs</div></div></div>'
)
if fi_rows:
fixed_income_html += (
f'<div class="cc" style="overflow-x:auto"><table><thead><tr>'
f'<th>Bond</th><th>Weight</th><th>Duration</th><th>Coupon</th>'
f'</tr></thead><tbody>{fi_rows}</tbody></table></div>'
)
return fixed_income_html