CIOAgent / frontend /src /components /GoalProjection.jsx
bhuvighosh3
Deployment with restored Stress Specialist data
9fbb3f2
Raw History Blame Contribute Delete
5.63 kB
import React from "react";
import {
AreaChart,
Area,
XAxis,
YAxis,
Tooltip,
ResponsiveContainer,
Legend,
ReferenceLine,
} from "recharts";
function dollars(v) {
if (v >= 1_000_000_000) return "$" + (v / 1_000_000_000).toFixed(1) + "B";
if (v >= 1_000_000) return "$" + (v / 1_000_000).toFixed(1) + "M";
if (v >= 1_000) return "$" + (v / 1_000).toFixed(0) + "K";
return "$" + v.toFixed(0);
}
function pct(v) {
return (v * 100).toFixed(1) + "%";
}
export default function GoalProjection({ goalProjection, financialGoal }) {
const {
probability_of_success,
median_outcome,
surplus_or_shortfall,
required_cagr,
method,
yearly_projections,
} = goalProjection;
const target = financialGoal?.target_amount || 1_000_000;
const years = financialGoal?.time_horizon_years || 20;
const goalType = financialGoal?.goal_type || "Retirement";
const isOnTrack = surplus_or_shortfall >= 0;
const tooltipFormatter = (value, name) => {
const labels = {
p90: "90th Percentile",
p50: "Median Path",
p10: "10th Percentile",
};
return [dollars(value), labels[name] || name];
};
return (
<section className="section">
<h2>Goal-Based Planning</h2>
{/* Status Banner */}
<div className={`status-banner ${isOnTrack ? "success" : "error"}`}>
<span>🎯</span>
<strong>{goalType}:</strong> {pct(probability_of_success)} probability of reaching {dollars(target)} in {years} years
</div>
<div className="metrics-row">
<div className="metric-card">
<span className="metric-label">Probability of Success</span>
<span
className="metric-value"
style={{ color: probability_of_success >= 0.7 ? "#22c55e" : probability_of_success >= 0.4 ? "#f59e0b" : "#ef4444" }}
>
{pct(probability_of_success)}
</span>
</div>
<div className="metric-card">
<span className="metric-label">Median Outcome</span>
<span className="metric-value">{dollars(median_outcome)}</span>
</div>
<div className="metric-card">
<span className="metric-label">Surplus / Shortfall</span>
<span
className="metric-value"
style={{ color: isOnTrack ? "#22c55e" : "#ef4444" }}
>
{isOnTrack ? "+" : ""}
{dollars(surplus_or_shortfall)}
</span>
<span className={`status-badge ${isOnTrack ? "on-track" : "off-track"}`}>
{isOnTrack ? "↑ On track" : "↓ Off track"}
</span>
</div>
<div className="metric-card">
<span className="metric-label">Required CAGR</span>
<span className="metric-value">{pct(required_cagr)}</span>
</div>
</div>
<h3 style={{ textAlign: "center", marginTop: "2rem", color: "#64748b", fontSize: "1.5rem" }}>
Projection: {goalType}
</h3>
<ResponsiveContainer width="100%" height={450}>
<AreaChart
data={yearly_projections}
margin={{ top: 20, right: 30, bottom: 20, left: 40 }}
>
<defs>
<linearGradient id="band90" x1="0" y1="0" x2="0" y2="1">
<stop offset="5%" stopColor="#22c55e" stopOpacity={0.2} />
<stop offset="95%" stopColor="#22c55e" stopOpacity={0.05} />
</linearGradient>
</defs>
<XAxis
dataKey="year"
label={{ value: "Years", position: "bottom", offset: 0, fill: "#94a3b8" }}
tick={{ fill: "#94a3b8" }}
/>
<YAxis
tickFormatter={dollars}
label={{
value: "Portfolio Value ($)",
angle: -90,
position: "insideLeft",
offset: -10,
fill: "#94a3b8"
}}
tick={{ fill: "#94a3b8" }}
/>
<Tooltip
contentStyle={{ backgroundColor: "#1e293b", border: "1px solid #475569", borderRadius: "8px" }}
formatter={tooltipFormatter}
labelFormatter={(y) => `Year ${y}`}
/>
<Legend verticalAlign="top" height={36} />
{/* 10th-90th percentile band */}
<Area
type="monotone"
dataKey="p90"
stroke="#22c55e"
strokeOpacity={0.1}
fill="url(#band90)"
name="10th-90th Percentile"
/>
<Area
type="monotone"
dataKey="p10"
stroke="none"
fill="#0f172a"
fillOpacity={1}
name="p10-base"
legendType="none"
/>
{/* Median path */}
<Area
type="monotone"
dataKey="p50"
stroke="#3b82f6"
strokeWidth={3}
fill="none"
name="Median Path"
/>
{/* Target line */}
<ReferenceLine
y={target}
stroke="#ef4444"
strokeDasharray="5 5"
strokeWidth={3}
label={{
value: `Target: ${dollars(target)}`,
position: "insideBottomRight",
fill: "#ef4444",
fontSize: 14,
fontWeight: 600,
offset: 20
}}
/>
</AreaChart>
</ResponsiveContainer>
<details style={{ marginTop: "1rem" }}>
<summary>Simulation Methodology</summary>
<div className="alert info" style={{ marginTop: "0.5rem" }}>
{method}
</div>
</details>
</section>
);
}