CIOAgent / frontend /src /components /Rebalancing.jsx
bhuvighosh3
Deployment with restored Stress Specialist data
9fbb3f2
Raw History Blame Contribute Delete
2.99 kB
import React from "react";
export default function Rebalancing({ data }) {
if (!data) return null;
return (
<div className="section">
<h2>Rebalancing Engine</h2>
<div className="metrics-row">
<div className="metric-card">
<span className="metric-label">Status</span>
<span className="metric-value" style={{
color: data.needs_rebalancing ? "var(--warning)" : "var(--success)",
fontSize: "1rem",
}}>
{data.needs_rebalancing ? "Rebalancing Needed" : "On Target"}
</span>
</div>
<div className="metric-card">
<span className="metric-label">Max Drift</span>
<span className="metric-value">{(data.max_drift * 100).toFixed(2)}%</span>
</div>
<div className="metric-card">
<span className="metric-label">Threshold</span>
<span className="metric-value">{(data.drift_threshold * 100).toFixed(0)}%</span>
</div>
<div className="metric-card">
<span className="metric-label">Portfolio Value</span>
<span className="metric-value">${data.portfolio_value.toLocaleString(undefined, { maximumFractionDigits: 0 })}</span>
</div>
</div>
<div className="two-col" style={{ marginTop: "1rem" }}>
<div>
<h3>Position Drift</h3>
<table className="data-table">
<thead><tr><th>Ticker</th><th>Target</th><th>Current</th><th>Drift</th></tr></thead>
<tbody>
{data.positions.map((p, i) => (
<tr key={i}>
<td><strong>{p.ticker}</strong></td>
<td>{(p.target_weight * 100).toFixed(1)}%</td>
<td>{(p.current_weight * 100).toFixed(1)}%</td>
<td style={{
color: Math.abs(p.drift) > data.drift_threshold ? "var(--warning)" : "var(--text-muted)"
}}>
{p.drift > 0 ? "+" : ""}{(p.drift * 100).toFixed(2)}%
</td>
</tr>
))}
</tbody>
</table>
</div>
<div>
<h3>Recommended Trades</h3>
{data.trades.length === 0 ? (
<p className="caption">No trades needed — portfolio is within drift threshold.</p>
) : (
<table className="data-table">
<thead><tr><th>Ticker</th><th>Action</th><th>Shares</th><th>Value</th></tr></thead>
<tbody>
{data.trades.map((t, i) => (
<tr key={i}>
<td><strong>{t.ticker}</strong></td>
<td style={{ color: t.action === "BUY" ? "var(--success)" : "var(--error)" }}>{t.action}</td>
<td>{t.shares}</td>
<td>${t.value.toLocaleString()}</td>
</tr>
))}
</tbody>
</table>
)}
</div>
</div>
</div>
);
}