File size: 6,361 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import React from "react";

const GOAL_TYPES = [
  "Retirement",
  "House Down Payment",
  "Education Fund",
  "Emergency Fund",
  "Wealth Building",
  "Debt Payoff",
  "Custom",
];

export default function Sidebar({
  portfolio,
  setPortfolio,
  profile,
  setProfile,
  financialGoal,
  setFinancialGoal,
  onRunAnalysis,
  onRunAgents,
  onRunInsights,
  onSaveSnapshot,
  onExportPDF,
  loading,
  hasAnalysis,
}) {
  const update = (field, value) =>
    setPortfolio((p) => ({ ...p, [field]: value }));

  const updateProfile = (field, value) =>
    setProfile((p) => ({ ...p, [field]: value }));

  const updateGoal = (field, value) =>
    setFinancialGoal((g) => ({ ...g, [field]: value }));

  return (
    <aside className="sidebar">
      <h2>Settings</h2>

      <label>Tickers (comma-separated)</label>
      <input
        value={portfolio.tickers.join(", ")}
        onChange={(e) =>
          update(
            "tickers",
            e.target.value.split(",").map((t) => t.trim().toUpperCase()).filter(Boolean),
          )
        }
      />

      <label>Benchmarks</label>
      <input
        value={portfolio.benchmarks.join(", ")}
        onChange={(e) =>
          update(
            "benchmarks",
            e.target.value.split(",").map((b) => b.trim().toUpperCase()).filter(Boolean),
          )
        }
      />

      <label>Weights (comma-separated)</label>
      <input
        value={portfolio.weights.join(", ")}
        onChange={(e) =>
          update(
            "weights",
            e.target.value.split(",").map((w) => parseFloat(w.trim())).filter((w) => !isNaN(w)),
          )
        }
      />

      <label>Start Date</label>
      <input
        type="date"
        className="date-input"
        value={portfolio.start_date}
        max={new Date().toISOString().split("T")[0]}
        onChange={(e) => update("start_date", e.target.value)}
      />

      <label>Risk-Free Rate</label>
      <input
        type="number"
        step="0.005"
        min="0"
        max="1"
        value={portfolio.rf}
        onChange={(e) => update("rf", parseFloat(e.target.value))}
      />

      <div className="slider-group">
        <div className="slider-header">
          <label>Simulations</label>
          <span className="slider-value">{portfolio.sims.toLocaleString()}</span>
        </div>
        <input
          type="range"
          className="styled-range"
          min="500"
          max="20000"
          step="500"
          value={portfolio.sims}
          onChange={(e) => update("sims", parseInt(e.target.value))}
        />
        <div className="slider-ticks">
          <span>500</span>
          <span>20,000</span>
        </div>
      </div>

      <div className="slider-group">
        <div className="slider-header">
          <label>Horizon (trading days)</label>
          <span className="slider-value">{portfolio.horizon}</span>
        </div>
        <input
          type="range"
          className="styled-range"
          min="21"
          max="756"
          step="21"
          value={portfolio.horizon}
          onChange={(e) => update("horizon", parseInt(e.target.value))}
        />
        <div className="slider-ticks">
          <span>21</span>
          <span>756</span>
        </div>
      </div>

      <hr />
      <h3>Financial Profile</h3>

      <label>Total Assets ($)</label>
      <input
        type="number"
        step="10000"
        min="0"
        value={profile.total_assets}
        onChange={(e) => updateProfile("total_assets", parseFloat(e.target.value))}
      />

      <label>Total Liabilities ($)</label>
      <input
        type="number"
        step="10000"
        min="0"
        value={profile.total_liabilities}
        onChange={(e) =>
          updateProfile("total_liabilities", parseFloat(e.target.value))
        }
      />

      <label>Risk Tolerance</label>
      <select
        value={profile.risk_tolerance}
        onChange={(e) => updateProfile("risk_tolerance", e.target.value)}
      >
        <option>Conservative</option>
        <option>Moderate</option>
        <option>Aggressive</option>
      </select>

      <hr />
      <h3>Financial Goal</h3>

      <label>Goal Type</label>
      <select
        value={financialGoal.goal_type}
        onChange={(e) => updateGoal("goal_type", e.target.value)}
      >
        {GOAL_TYPES.map((g) => (
          <option key={g} value={g}>
            {g}
          </option>
        ))}
      </select>

      <label>Target Amount ($)</label>
      <input
        type="number"
        step="10000"
        min="0"
        value={financialGoal.target_amount}
        onChange={(e) => updateGoal("target_amount", parseFloat(e.target.value) || 0)}
      />

      <label>Time Horizon (years)</label>
      <input
        type="number"
        step="1"
        min="1"
        max="50"
        value={financialGoal.time_horizon_years}
        onChange={(e) => updateGoal("time_horizon_years", parseInt(e.target.value) || 1)}
      />

      <label>Initial Investment ($)</label>
      <input
        type="number"
        step="5000"
        min="0"
        value={financialGoal.initial_investment}
        onChange={(e) => updateGoal("initial_investment", parseFloat(e.target.value) || 0)}
      />

      <label>Monthly Contribution ($)</label>
      <input
        type="number"
        step="100"
        min="0"
        value={financialGoal.monthly_contribution}
        onChange={(e) => updateGoal("monthly_contribution", parseFloat(e.target.value) || 0)}
      />

      <div className="button-group">
        <button className="btn primary" onClick={onRunAnalysis} disabled={!!loading}>
          Run Analysis
        </button>
        <button className="btn" onClick={onRunAgents} disabled={!!loading}>
          Run Agents
        </button>
        <button className="btn" onClick={onRunInsights} disabled={!!loading}>
          Run Insights
        </button>
      </div>

      {hasAnalysis && (
        <div className="button-group" style={{ marginTop: "0.5rem" }}>
          <button className="btn" onClick={onSaveSnapshot} disabled={!!loading}>
            Save Snapshot
          </button>
          <button className="btn" onClick={onExportPDF} disabled={!!loading}>
            Export PDF
          </button>
        </div>
      )}
    </aside>
  );
}