File size: 4,665 Bytes
9fbb3f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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>
  );
}