def build_main_table(weights, current_weights, exp_rets, prices, betas, spread_map, vol, capital, has_curr, curr): table_rows = "" all_tickers_tbl = sorted(set(weights[abs(weights)>0.005].index) | (set(current_weights[abs(current_weights)>0.005].index) if has_curr and current_weights is not None else set())) for t in all_tickers_tbl: if t != 'CASH' and (t not in exp_rets.index or t not in prices): continue w_tgt = float(weights.get(t, 0)) w_cur = float(current_weights.get(t, 0)) if (has_curr and current_weights is not None) else 0.0 if abs(w_tgt) < 0.005 and abs(w_cur) < 0.005: continue amt = capital * w_tgt if t == 'CASH': # RFR is handled outside if needed, or passed as 0 for CASH in table price = 1.0; sh = amt; er = 0.0; b = 0.0; sp = 0.0; vol_val = 0.0 else: price = prices.get(t, 0); sh = round(amt / price, 4) if price > 0 else 0 er = float(exp_rets.get(t, 0)); b = float(betas.get(t, 1)); sp = spread_map.get(t, 0.0008); vol_val = float(vol.get(t, 0)) dir_bg = "#f85149" if w_tgt < 0 else "#3fb950" ret_col = "#3fb950" if er >= 0 else "#f85149" sp_col = "#f85149" if sp > 0.001 else ("#e3b341" if sp > 0.0004 else "#3fb950") pct_width = min(abs(w_tgt)*100, 100) bg_color = "rgba(63, 185, 80, 0.2)" if w_tgt >= 0 else "rgba(248, 81, 73, 0.2)" w_html = (f'