Download frontend/src/components/Frontier.jsx from bhuvi3/CIOAgent: direct link, hf CLI and curl.
- Browser
- Download file 4.67 kB
-
https://huggingface.co/spaces/bhuvi3/CIOAgent/resolve/main/frontend/src/components/Frontier.jsx
- Command line
-
hf download hf://spaces/bhuvi3/CIOAgent/frontend/src/components/Frontier.jsx
-
curl -L -o Frontier.jsx https://huggingface.co/spaces/bhuvi3/CIOAgent/resolve/main/frontend/src/components/Frontier.jsx
4.67 kB
| import React from "react"; | |
| import { | |
| ScatterChart, | |
| Scatter, | |
| XAxis, | |
| YAxis, | |
| Tooltip, | |
| ResponsiveContainer, | |
| Legend, | |
| ZAxis, | |
| } from "recharts"; | |
| function pct(v) { | |
| return (v * 100).toFixed(2) + "%"; | |
| } | |
| export default function Frontier({ | |
| frontier, | |
| currentPerformance, | |
| tickers, | |
| weights, | |
| }) { | |
| const points = frontier.frontier_points.map((p) => ({ | |
| volatility: p.volatility * 100, | |
| return: p.return * 100, | |
| sharpe: p.sharpe, | |
| })); | |
| const maxS = frontier.max_sharpe; | |
| const minV = frontier.min_vol; | |
| const cur = currentPerformance; | |
| const specialPoints = [ | |
| { | |
| volatility: cur.annual_volatility * 100, | |
| return: cur.annual_return * 100, | |
| name: "Current", | |
| }, | |
| ]; | |
| const maxSharpePoint = [ | |
| { | |
| volatility: maxS.annual_volatility * 100, | |
| return: maxS.annual_return * 100, | |
| name: "Max Sharpe", | |
| }, | |
| ]; | |
| const minVolPoint = [ | |
| { | |
| volatility: minV.annual_volatility * 100, | |
| return: minV.annual_return * 100, | |
| name: "Min Vol", | |
| }, | |
| ]; | |
| return ( | |
| <section className="section"> | |
| <h2>Efficient Frontier</h2> | |
| <ResponsiveContainer width="100%" height={400}> | |
| <ScatterChart margin={{ top: 10, right: 30, bottom: 10, left: 10 }}> | |
| <XAxis | |
| dataKey="volatility" | |
| name="Volatility" | |
| unit="%" | |
| type="number" | |
| label={{ value: "Annual Volatility (%)", position: "bottom" }} | |
| /> | |
| <YAxis | |
| dataKey="return" | |
| name="Return" | |
| unit="%" | |
| type="number" | |
| label={{ | |
| value: "Annual Return (%)", | |
| angle: -90, | |
| position: "insideLeft", | |
| }} | |
| /> | |
| <ZAxis range={[15, 15]} /> | |
| <Tooltip | |
| formatter={(val) => val.toFixed(2) + "%"} | |
| cursor={{ strokeDasharray: "3 3" }} | |
| /> | |
| <Legend /> | |
| <Scatter | |
| name="Random Portfolios" | |
| data={points} | |
| fill="#a5b4fc" | |
| opacity={0.4} | |
| /> | |
| <Scatter | |
| name="Current Portfolio" | |
| data={specialPoints} | |
| fill="#ef4444" | |
| shape="star" | |
| > | |
| <ZAxis range={[200, 200]} /> | |
| </Scatter> | |
| <Scatter | |
| name="Max Sharpe" | |
| data={maxSharpePoint} | |
| fill="#eab308" | |
| shape="diamond" | |
| > | |
| <ZAxis range={[150, 150]} /> | |
| </Scatter> | |
| <Scatter | |
| name="Min Volatility" | |
| data={minVolPoint} | |
| fill="#06b6d4" | |
| shape="square" | |
| > | |
| <ZAxis range={[150, 150]} /> | |
| </Scatter> | |
| </ScatterChart> | |
| </ResponsiveContainer> | |
| <h3>Portfolio Comparison</h3> | |
| <table className="data-table"> | |
| <thead> | |
| <tr> | |
| <th>Portfolio</th> | |
| <th>Annual Return</th> | |
| <th>Annual Volatility</th> | |
| <th>Sharpe Ratio</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <tr> | |
| <td>Current</td> | |
| <td>{pct(cur.annual_return)}</td> | |
| <td>{pct(cur.annual_volatility)}</td> | |
| <td>{cur.sharpe_ratio.toFixed(2)}</td> | |
| </tr> | |
| <tr> | |
| <td>Max Sharpe</td> | |
| <td>{pct(maxS.annual_return)}</td> | |
| <td>{pct(maxS.annual_volatility)}</td> | |
| <td>{maxS.sharpe_ratio.toFixed(2)}</td> | |
| </tr> | |
| <tr> | |
| <td>Min Volatility</td> | |
| <td>{pct(minV.annual_return)}</td> | |
| <td>{pct(minV.annual_volatility)}</td> | |
| <td>{minV.sharpe_ratio.toFixed(2)}</td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| <details> | |
| <summary>Optimal Portfolio Weights</summary> | |
| <table className="data-table"> | |
| <thead> | |
| <tr> | |
| <th>Ticker</th> | |
| <th>Current</th> | |
| <th>Max Sharpe</th> | |
| <th>Min Vol</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| {tickers.map((t, i) => ( | |
| <tr key={t}> | |
| <td>{t}</td> | |
| <td>{(weights[i] * 100).toFixed(1)}%</td> | |
| <td> | |
| {maxS.weights[t] != null | |
| ? (maxS.weights[t] * 100).toFixed(1) + "%" | |
| : "—"} | |
| </td> | |
| <td> | |
| {minV.weights[t] != null | |
| ? (minV.weights[t] * 100).toFixed(1) + "%" | |
| : "—"} | |
| </td> | |
| </tr> | |
| ))} | |
| </tbody> | |
| </table> | |
| </details> | |
| </section> | |
| ); | |
| } | |