forked from SteppieD/tradinggame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard_simple.html
More file actions
780 lines (703 loc) · 40.6 KB
/
dashboard_simple.html
File metadata and controls
780 lines (703 loc) · 40.6 KB
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Trading Dashboard</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
.profit { color: #16a34a; }
.loss { color: #dc2626; }
.dark .profit { color: #4ade80; }
.dark .loss { color: #f87171; }
.highlight { background: linear-gradient(120deg, #fef3c7 0%, #fde68a 100%); }
.dark .highlight { background: linear-gradient(120deg, #422006 0%, #451a03 100%); }
</style>
</head>
<body class="bg-gray-50 dark:bg-gray-900 transition-colors duration-200">
<div class="container mx-auto px-4 py-6 max-w-7xl">
<!-- Header with Dark Mode Toggle -->
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm p-4 mb-6">
<div class="flex justify-between items-center">
<h1 class="text-2xl font-bold text-gray-800 dark:text-gray-100">TFSA Trading Dashboard</h1>
<div class="flex items-center gap-4">
<span id="updateTime" class="text-sm text-gray-600 dark:text-gray-400">Last Update: Loading...</span>
<button onclick="updatePricesViaAlphaVantage()" class="px-3 py-2 bg-green-600 hover:bg-green-700 text-white rounded-lg text-sm font-medium transition flex items-center gap-2" id="updateBtn">
<span>📊</span>
<span>Update Prices</span>
</button>
<button onclick="toggleDarkMode()" class="p-2 rounded-lg bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 transition">
<span id="darkModeIcon">🌙</span>
</button>
</div>
</div>
</div>
<!-- Performance Chart -->
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm p-6 mb-6">
<h2 class="text-lg font-bold text-gray-800 dark:text-gray-100 mb-4 flex items-center">
<span class="mr-2">📊</span> Portfolio vs Benchmarks
</h2>
<div class="h-64">
<canvas id="performanceChart"></canvas>
</div>
</div>
<!-- 1. POSITION TRACKER -->
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm p-6 mb-6">
<h2 class="text-lg font-bold text-gray-800 dark:text-gray-100 mb-4 flex items-center">
<span class="mr-2">💼</span> Active Positions
</h2>
<div class="overflow-x-auto">
<table class="w-full">
<thead class="bg-gray-50 dark:bg-gray-700 text-sm">
<tr>
<th class="p-3 text-left text-gray-700 dark:text-gray-300">Symbol</th>
<th class="p-3 text-right text-gray-700 dark:text-gray-300">Shares</th>
<th class="p-3 text-right text-gray-700 dark:text-gray-300">Entry</th>
<th class="p-3 text-right text-gray-700 dark:text-gray-300">Current</th>
<th class="p-3 text-right text-gray-700 dark:text-gray-300">Value</th>
<th class="p-3 text-right text-gray-700 dark:text-gray-300">P&L</th>
<th class="p-3 text-right text-gray-700 dark:text-gray-300">%</th>
</tr>
</thead>
<tbody id="positionsTable" class="text-gray-800 dark:text-gray-200">
<!-- Will be populated by JavaScript -->
</tbody>
</table>
</div>
</div>
<!-- REALIZED GAINS -->
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm p-6 mb-6">
<h2 class="text-lg font-bold text-gray-800 dark:text-gray-100 mb-4 flex items-center">
<span class="mr-2">🏆</span> Realized Gains (Closed Trades)
</h2>
<div class="overflow-x-auto">
<table class="w-full">
<thead class="bg-gray-50 dark:bg-gray-700 text-sm">
<tr>
<th class="p-3 text-left text-gray-700 dark:text-gray-300">Symbol</th>
<th class="p-3 text-right text-gray-700 dark:text-gray-300">Shares</th>
<th class="p-3 text-right text-gray-700 dark:text-gray-300">Entry</th>
<th class="p-3 text-right text-gray-700 dark:text-gray-300">Exit</th>
<th class="p-3 text-right text-gray-700 dark:text-gray-300">Profit</th>
<th class="p-3 text-right text-gray-700 dark:text-gray-300">%</th>
<th class="p-3 text-center text-gray-700 dark:text-gray-300">Date</th>
</tr>
</thead>
<tbody id="realizedTable" class="text-gray-800 dark:text-gray-200">
<tr class="border-b dark:border-gray-700">
<td class="p-3 font-bold">FCEL 🔒</td>
<td class="p-3 text-right">97</td>
<td class="p-3 text-right">$4.05</td>
<td class="p-3 text-right">$4.26</td>
<td class="p-3 text-right text-green-600 font-medium">$13.42</td>
<td class="p-3 text-right text-green-600 font-medium">+3.4%</td>
<td class="p-3 text-center text-sm text-gray-600 dark:text-gray-400">Aug 13</td>
</tr>
<tr class="bg-gray-50 dark:bg-gray-700 font-bold">
<td class="p-3">TOTAL REALIZED</td>
<td class="p-3 text-right">-</td>
<td class="p-3 text-right">-</td>
<td class="p-3 text-right">-</td>
<td class="p-3 text-right text-green-600">$13.42</td>
<td class="p-3 text-right text-green-600">+3.4%</td>
<td class="p-3 text-center">-</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- 2. PERFORMANCE SUMMARY -->
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm p-6 mb-6">
<h2 class="text-lg font-bold text-gray-800 dark:text-gray-100 mb-4 flex items-center">
<span class="mr-2">📈</span> Performance Summary
</h2>
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
<div class="bg-gray-50 dark:bg-gray-700 rounded-lg p-4">
<div class="text-sm text-gray-600 dark:text-gray-400">Portfolio Value</div>
<div class="text-2xl font-bold text-gray-800 dark:text-gray-100" id="portfolioValue">$0.00</div>
<div class="text-sm" id="portfolioReturn">+0.00%</div>
</div>
<div class="bg-gray-50 dark:bg-gray-700 rounded-lg p-4">
<div class="text-sm text-gray-600 dark:text-gray-400">Net P&L (after fees)</div>
<div class="text-2xl font-bold" id="todayPnL">$0.00</div>
<div class="text-sm" id="todayPercent">+0.00%</div>
</div>
<div class="bg-gray-50 dark:bg-gray-700 rounded-lg p-4">
<div class="text-sm text-gray-600 dark:text-gray-400">Fees Impact</div>
<div class="text-lg font-bold text-orange-600 dark:text-orange-400" id="totalFees">-$20.85</div>
<div class="text-xs text-gray-600 dark:text-gray-400" id="feeImpact">27% of profits</div>
</div>
<div class="bg-gray-50 dark:bg-gray-700 rounded-lg p-4">
<div class="text-sm text-gray-600 dark:text-gray-400">vs Benchmarks (from Aug 12)</div>
<div class="text-sm mt-1 text-gray-700 dark:text-gray-300">
<span class="font-medium">You:</span> <span id="yourReturn" class="font-bold">-</span>
</div>
<div class="text-sm text-gray-700 dark:text-gray-300">
<span class="font-medium">SPY:</span> <span id="spyReturn">-</span>
<span class="text-xs">(<span id="spyComparison">-</span>)</span>
</div>
<div class="text-sm text-gray-700 dark:text-gray-300">
<span class="font-medium">IWM:</span> <span id="iwmReturn">-</span>
<span class="text-xs">(<span id="iwmComparison">-</span>)</span>
</div>
</div>
</div>
</div>
<!-- 15% Monthly Goal Tracker -->
<div class="bg-gradient-to-r from-green-500 to-blue-500 text-white rounded-lg shadow-sm p-6 mb-6">
<h2 class="text-lg font-bold mb-3">🎯 15% MONTHLY GOAL TRACKER</h2>
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
<div class="bg-white/20 rounded p-3">
<div class="text-sm opacity-90">Current</div>
<div class="text-2xl font-bold">+4.33%</div>
</div>
<div class="bg-white/20 rounded p-3">
<div class="text-sm opacity-90">Need</div>
<div class="text-2xl font-bold">+10.67%</div>
</div>
<div class="bg-white/20 rounded p-3">
<div class="text-sm opacity-90">Days Left</div>
<div class="text-2xl font-bold">28</div>
</div>
<div class="bg-white/20 rounded p-3">
<div class="text-sm opacity-90">Target</div>
<div class="text-2xl font-bold">$1,200</div>
</div>
</div>
<div class="mt-4 bg-white/10 rounded p-2 text-sm">
<strong>Price Targets for 15%:</strong> CHPT→$13.75 | EVGO→$4.45 | FUBO→$4.50 | TDUP→$12.00
</div>
</div>
<!-- 3. NEXT DAY INSTRUCTIONS -->
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm p-6 mb-6">
<h2 class="text-lg font-bold text-gray-800 dark:text-gray-100 mb-4 flex items-center">
<span class="mr-2">🚨</span> TRADING PLAN & STOP ORDERS
</h2>
<!-- ORDERS COMPLETED - UPDATE AT 7 AM -->
<div class="bg-green-600 text-white p-4 rounded-lg mb-4">
<p class="text-lg font-bold mb-2">✅ MORNING ORDERS COMPLETED</p>
<p class="text-sm">TDUP: Filled 19 @ $10.45</p>
<p class="text-sm">FUBO: Filled 55 @ $3.67</p>
<p class="text-sm mt-2 font-bold">⏰ NEXT ACTION: Tighten stops at 7:00 AM PST (see below)</p>
</div>
<div class="bg-yellow-50 dark:bg-yellow-900/20 border-l-4 border-yellow-500 dark:border-yellow-600 p-4 mb-4">
<p class="text-sm font-bold text-gray-800 dark:text-gray-200">📋 EXACT ORDER SEQUENCE:</p>
<ol class="text-xs text-gray-600 dark:text-gray-400 mt-2 ml-4 list-decimal">
<li>Run: python update_prices.py (get fresh prices)</li>
<li>Set CHPT & EVGO trailing stops FIRST</li>
<li>Place TDUP & FUBO limit buy orders</li>
<li>If buy orders fill, set stops immediately</li>
</ol>
</div>
<!-- Existing Position Stops -->
<h3 class="text-md font-semibold text-gray-700 dark:text-gray-300 mb-3">1️⃣ Set Stop-Loss Orders (Existing Positions)</h3>
<div id="stopInstructions" class="space-y-4 mb-6">
<!-- Will be populated by JavaScript -->
</div>
<!-- New Position Orders -->
<h3 class="text-md font-semibold text-gray-700 dark:text-gray-300 mb-3 mt-6">2️⃣ Place Limit Buy Orders (NEW POSITIONS - MUST PLACE AT 6:30 AM)</h3>
<div class="border-2 border-orange-500 dark:border-orange-400 rounded-lg p-2 mb-4 bg-orange-50 dark:bg-orange-900/20">
<p class="text-sm font-bold text-orange-700 dark:text-orange-300">⚠️ These orders CANNOT be placed tonight - CIBC requires market hours!</p>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="border dark:border-gray-700 rounded-lg p-4 bg-green-50 dark:bg-green-900/20">
<div class="flex justify-between items-start mb-2">
<span class="font-bold text-lg">TDUP (ThredUp)</span>
<span class="text-sm bg-green-600 text-white px-2 py-1 rounded">NEW</span>
</div>
<div class="text-sm space-y-1 text-gray-700 dark:text-gray-300">
<div>Current: $10.51</div>
<div class="font-semibold text-green-600 dark:text-green-400">Limit Order: $10.40</div>
<div class="font-semibold">Quantity: 15 shares</div>
<div>Total Cost: $162.95 (incl. fees)</div>
<div class="text-xs mt-2 pt-2 border-t dark:border-gray-600">
✅ Recent earnings beat<br>
🎯 Target: $13.00 (+25%)<br>
🛡️ Stop Loss: $9.57 (-8%)
</div>
</div>
</div>
<div class="border dark:border-gray-700 rounded-lg p-4 bg-green-50 dark:bg-green-900/20">
<div class="flex justify-between items-start mb-2">
<span class="font-bold text-lg">FUBO (fuboTV)</span>
<span class="text-sm bg-green-600 text-white px-2 py-1 rounded">NEW</span>
</div>
<div class="text-sm space-y-1 text-gray-700 dark:text-gray-300">
<div>Current: $3.77</div>
<div class="font-semibold text-green-600 dark:text-green-400">Limit Order: $3.70</div>
<div class="font-semibold">Quantity: 44 shares</div>
<div>Total Cost: $169.75 (incl. fees)</div>
<div class="text-xs mt-2 pt-2 border-t dark:border-gray-600">
✅ First EBITDA positive<br>
🎯 Target: $5.00 (+35%)<br>
🛡️ Stop Loss: $3.33 (-10%)
</div>
</div>
</div>
</div>
<!-- Cash Summary -->
<div class="mt-6 p-4 bg-gray-50 dark:bg-gray-700 rounded-lg">
<h3 class="text-sm font-semibold text-gray-700 dark:text-gray-300 mb-2">💰 Cash Deployment (Option 1 - Balanced)</h3>
<div class="text-sm space-y-1 text-gray-600 dark:text-gray-400">
<div>Available Cash: $414.75</div>
<div>TDUP Order: -$162.95</div>
<div>FUBO Order: -$169.75</div>
<div class="font-semibold text-green-600 dark:text-green-400 pt-1 border-t dark:border-gray-600">Remaining Cash: $82.05 (safety buffer)</div>
</div>
</div>
<!-- 7:00 AM PST STOP ORDERS -->
<div class="mt-6 p-4 bg-red-50 dark:bg-red-900/20 border-2 border-red-500 rounded-lg">
<h3 class="text-lg font-bold text-red-700 dark:text-red-300 mb-3">⏰ 7:00 AM PST - TIGHTEN ALL STOPS</h3>
<div class="text-sm space-y-3 text-gray-700 dark:text-gray-300">
<div class="font-semibold text-red-600 dark:text-red-400">After morning volatility settles, UPDATE these trailing stops:</div>
<div class="bg-white dark:bg-gray-800 p-3 rounded border dark:border-gray-700">
<div class="font-bold">CHPT - Trailing Stop-Limit:</div>
<div class="ml-4 text-sm">
<div>• Trigger Delta: $0.36</div>
<div>• Limit Offset: $0.06</div>
<div>• Quantity: 26 shares</div>
</div>
</div>
<div class="bg-white dark:bg-gray-800 p-3 rounded border dark:border-gray-700">
<div class="font-bold">EVGO - Trailing Stop-Limit:</div>
<div class="ml-4 text-sm">
<div>• Trigger Delta: $0.08</div>
<div>• Limit Offset: $0.02</div>
<div>• Quantity: 82 shares</div>
</div>
</div>
<div class="bg-white dark:bg-gray-800 p-3 rounded border dark:border-gray-700">
<div class="font-bold">TDUP - Stop-Limit (FIXED):</div>
<div class="ml-4 text-sm">
<div>• Stop Price: $9.61</div>
<div>• Limit Price: $9.59</div>
<div>• Quantity: 19 shares</div>
</div>
</div>
<div class="bg-white dark:bg-gray-800 p-3 rounded border dark:border-gray-700">
<div class="font-bold">FUBO - Stop-Limit (FIXED):</div>
<div class="ml-4 text-sm">
<div>• Stop Price: $3.30</div>
<div>• Limit Price: $3.28</div>
<div>• Quantity: 55 shares</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
// Dark mode handling
function initDarkMode() {
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark');
document.getElementById('darkModeIcon').textContent = '☀️';
} else {
document.documentElement.classList.remove('dark');
document.getElementById('darkModeIcon').textContent = '🌙';
}
}
function toggleDarkMode() {
if (document.documentElement.classList.contains('dark')) {
document.documentElement.classList.remove('dark');
localStorage.theme = 'light';
document.getElementById('darkModeIcon').textContent = '🌙';
} else {
document.documentElement.classList.add('dark');
localStorage.theme = 'dark';
document.getElementById('darkModeIcon').textContent = '☀️';
}
// Update chart colors
if (window.performanceChart) {
updateChartTheme();
}
}
// Chart setup
let performanceChart;
function initChart() {
const ctx = document.getElementById('performanceChart').getContext('2d');
// Show actual trading days starting from Aug 12
const labels = ['Aug 12', 'Aug 13', 'Aug 14'];
// Will be dynamically updated based on portfolio data
const portfolioData = [1000, 1000, 1000];
const spyData = [1000, 1000, 1000];
const iwmData = [1000, 1000, 1000];
performanceChart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [
{
label: 'Portfolio',
data: portfolioData,
borderColor: '#10b981',
backgroundColor: 'rgba(16, 185, 129, 0.1)',
borderWidth: 2,
tension: 0.4
},
{
label: 'SPY',
data: spyData,
borderColor: '#3b82f6',
backgroundColor: 'rgba(59, 130, 246, 0.1)',
borderWidth: 1,
tension: 0.4,
borderDash: [5, 5]
},
{
label: 'IWM',
data: iwmData,
borderColor: '#a855f7',
backgroundColor: 'rgba(168, 85, 247, 0.1)',
borderWidth: 1,
tension: 0.4,
borderDash: [5, 5]
}
]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'top',
labels: {
usePointStyle: true,
padding: 15,
color: document.documentElement.classList.contains('dark') ? '#e5e7eb' : '#374151'
}
},
tooltip: {
mode: 'index',
intersect: false,
callbacks: {
label: function(context) {
const value = context.parsed.y;
const percentChange = ((value - 1000) / 1000 * 100).toFixed(2);
return `${context.dataset.label}: $${value.toFixed(2)} (${percentChange >= 0 ? '+' : ''}${percentChange}%)`;
}
}
}
},
scales: {
x: {
grid: {
display: false
},
ticks: {
color: document.documentElement.classList.contains('dark') ? '#9ca3af' : '#6b7280'
}
},
y: {
ticks: {
callback: function(value) {
return '$' + value.toFixed(0);
},
color: document.documentElement.classList.contains('dark') ? '#9ca3af' : '#6b7280'
},
grid: {
color: document.documentElement.classList.contains('dark') ? '#374151' : '#e5e7eb'
}
}
}
}
});
}
function updateChartTheme() {
const isDark = document.documentElement.classList.contains('dark');
performanceChart.options.plugins.legend.labels.color = isDark ? '#e5e7eb' : '#374151';
performanceChart.options.scales.x.ticks.color = isDark ? '#9ca3af' : '#6b7280';
performanceChart.options.scales.y.ticks.color = isDark ? '#9ca3af' : '#6b7280';
performanceChart.options.scales.y.grid.color = isDark ? '#374151' : '#e5e7eb';
performanceChart.update();
}
function updateChartData(currentPortfolioValue, prices) {
if (!performanceChart) return;
// Update portfolio data - CUMULATIVE from $1000 start
const portfolioData = [
1000, // Aug 12 - Initial investment
1036.50, // Aug 13 - After FCEL sale (+3.65%)
currentPortfolioValue // Aug 14 - Current (should be ~1043)
];
// SPY and IWM CUMULATIVE performance
// Starting prices on Aug 12
const spyAug12 = 642.69;
const iwmAug12 = 226.81;
// Aug 13 closing prices (estimates)
const spyAug13 = 643.50; // SPY was up slightly
const iwmAug13 = 228.00; // IWM was up slightly
// Aug 14 current prices from API
const spyAug14 = prices['SPY']?.price || 644.89;
const iwmAug14 = prices['IWM']?.price || 231.22;
// Calculate CUMULATIVE returns as if investing $1000 on Aug 12
const spyData = [
1000, // Aug 12 - Start
1000 * (spyAug13 / spyAug12), // Aug 13 - Cumulative
1000 * (spyAug14 / spyAug12) // Aug 14 - Cumulative
];
const iwmData = [
1000, // Aug 12 - Start
1000 * (iwmAug13 / iwmAug12), // Aug 13 - Cumulative
1000 * (iwmAug14 / iwmAug12) // Aug 14 - Cumulative
];
console.log('Chart Update:', {
portfolio: portfolioData,
spy: spyData,
iwm: iwmData,
portfolioReturn: ((currentPortfolioValue - 1000) / 10).toFixed(2) + '%',
spyReturn: ((spyAug14 / spyAug12 - 1) * 100).toFixed(2) + '%',
iwmReturn: ((iwmAug14 / iwmAug12 - 1) * 100).toFixed(2) + '%'
});
// Update chart datasets
performanceChart.data.datasets[0].data = portfolioData;
performanceChart.data.datasets[1].data = spyData;
performanceChart.data.datasets[2].data = iwmData;
performanceChart.update();
}
// Load and display data
async function loadDashboardData() {
try {
// Load portfolio data
const portfolioResponse = await fetch('data/portfolio.json');
const portfolio = await portfolioResponse.json();
// Load latest prices
const pricesResponse = await fetch('data/latest_prices.json');
const prices = await pricesResponse.json();
// Load stop instructions
const instructionsResponse = await fetch('data/stop_instructions.json');
const instructions = await instructionsResponse.json();
updateDashboard(portfolio, prices, instructions);
} catch (error) {
console.error('Error loading data:', error);
// Use fallback data
updateDashboardWithFallback();
}
}
function updateDashboard(portfolio, prices, instructions) {
// Update time
document.getElementById('updateTime').textContent =
`Last Update: ${new Date().toLocaleTimeString()}`;
// Calculate positions - All active positions
const positions = portfolio.positions.filter(p =>
['CHPT', 'EVGO', 'TDUP', 'FUBO'].includes(p.symbol)
);
let totalValue = 0;
let totalPnL = 0;
let positionsHTML = '';
positions.forEach(pos => {
const currentPrice = prices[pos.symbol]?.price || pos.entry_price;
const value = pos.quantity * currentPrice;
const pnl = value - (pos.quantity * pos.entry_price);
const pnlPercent = (pnl / (pos.quantity * pos.entry_price)) * 100;
totalValue += value;
totalPnL += pnl;
const pnlClass = pnl >= 0 ? 'profit' : 'loss';
const emoji = pnlPercent >= 10 ? '🚀' : pnlPercent >= 5 ? '⭐' : '';
positionsHTML += `
<tr class="border-b dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-700/50">
<td class="p-3 font-bold">${pos.symbol} ${emoji}</td>
<td class="p-3 text-right">${pos.quantity}</td>
<td class="p-3 text-right">$${pos.entry_price.toFixed(4)}</td>
<td class="p-3 text-right">$${currentPrice.toFixed(2)}</td>
<td class="p-3 text-right">$${value.toFixed(2)}</td>
<td class="p-3 text-right ${pnlClass} font-medium">$${pnl.toFixed(2)}</td>
<td class="p-3 text-right ${pnlClass} font-medium">${pnlPercent.toFixed(1)}%</td>
</tr>
`;
});
// Add total row
const totalShares = positions.reduce((sum, p) => sum + p.quantity, 0);
const totalCost = positions.reduce((sum, p) => sum + (p.quantity * p.entry_price), 0);
const totalReturn = (totalPnL / totalCost) * 100;
positionsHTML += `
<tr class="bg-gray-50 dark:bg-gray-700 font-bold">
<td class="p-3">TOTAL ACTIVE</td>
<td class="p-3 text-right">${totalShares}</td>
<td class="p-3 text-right">-</td>
<td class="p-3 text-right">-</td>
<td class="p-3 text-right">$${totalValue.toFixed(2)}</td>
<td class="p-3 text-right ${totalPnL >= 0 ? 'profit' : 'loss'}">$${totalPnL.toFixed(2)}</td>
<td class="p-3 text-right ${totalReturn >= 0 ? 'profit' : 'loss'}">${totalReturn.toFixed(1)}%</td>
</tr>
`;
document.getElementById('positionsTable').innerHTML = positionsHTML;
// Update performance summary
const portfolioValue = portfolio.cash_balance + totalValue;
const portfolioReturn = ((portfolioValue - 1000) / 1000) * 100;
// Update chart with current portfolio value
updateChartData(portfolioValue, prices);
// Fee calculations (6 trades at $6.95 each: 3 buys, 1 sell, 2 new buys)
const totalFees = 41.70;
const netPnL = portfolioValue - 1000; // This is after fees already
const grossPnL = totalPnL; // Position P&L before considering fees
const feePercentOfProfit = grossPnL > 0 ? (totalFees / grossPnL * 100) : 0;
document.getElementById('portfolioValue').textContent = `$${portfolioValue.toFixed(2)}`;
document.getElementById('portfolioReturn').textContent = `${portfolioReturn >= 0 ? '+' : ''}${portfolioReturn.toFixed(2)}%`;
document.getElementById('portfolioReturn').className = portfolioReturn >= 0 ? 'text-sm profit' : 'text-sm loss';
document.getElementById('todayPnL').textContent = `$${netPnL.toFixed(2)}`;
document.getElementById('todayPercent').textContent = `${portfolioReturn >= 0 ? '+' : ''}${portfolioReturn.toFixed(2)}%`;
document.getElementById('todayPnL').className = netPnL >= 0 ? 'text-2xl font-bold profit' : 'text-2xl font-bold loss';
document.getElementById('todayPercent').className = portfolioReturn >= 0 ? 'text-sm profit' : 'text-sm loss';
// Update fee impact
document.getElementById('totalFees').textContent = `-$${totalFees.toFixed(2)}`;
document.getElementById('feeImpact').textContent = `${feePercentOfProfit.toFixed(0)}% of profits`;
// Update benchmark comparison using actual price data
// Calculate cumulative returns from Aug 12
const spyStartPrice = 642.69; // Aug 12 baseline
const iwmStartPrice = 226.81; // Aug 12 baseline
const spyCurrentPrice = prices['SPY']?.price || 644.89;
const iwmCurrentPrice = prices['IWM']?.price || 231.22;
const spyReturn = ((spyCurrentPrice - spyStartPrice) / spyStartPrice) * 100;
const iwmReturn = ((iwmCurrentPrice - iwmStartPrice) / iwmStartPrice) * 100;
const spyDiff = portfolioReturn - spyReturn;
const iwmDiff = portfolioReturn - iwmReturn;
// Update your return display
document.getElementById('yourReturn').textContent = `${portfolioReturn >= 0 ? '+' : ''}${portfolioReturn.toFixed(2)}%`;
document.getElementById('yourReturn').className = portfolioReturn >= 0 ? 'font-bold text-green-600 dark:text-green-400' : 'font-bold text-red-600 dark:text-red-400';
// Update SPY comparison
document.getElementById('spyReturn').textContent = `${spyReturn >= 0 ? '+' : ''}${spyReturn.toFixed(2)}%`;
document.getElementById('spyComparison').textContent = `${spyDiff >= 0 ? 'Beat by ' : 'Trail by '}${Math.abs(spyDiff).toFixed(1)}%`;
document.getElementById('spyComparison').className = spyDiff >= 0 ? 'text-green-600 dark:text-green-400' : 'text-red-600 dark:text-red-400';
// Update IWM comparison
document.getElementById('iwmReturn').textContent = `${iwmReturn >= 0 ? '+' : ''}${iwmReturn.toFixed(2)}%`;
document.getElementById('iwmComparison').textContent = `${iwmDiff >= 0 ? 'Beat by ' : 'Trail by '}${Math.abs(iwmDiff).toFixed(1)}%`;
document.getElementById('iwmComparison').className = iwmDiff >= 0 ? 'text-green-600 dark:text-green-400' : 'text-red-600 dark:text-red-400';
// Update stop instructions
if (instructions && instructions.orders) {
let instructionsHTML = '';
instructions.orders.forEach(order => {
instructionsHTML += `
<div class="border dark:border-gray-700 rounded-lg p-4 hover:bg-gray-50 dark:hover:bg-gray-700/50 transition">
<div class="flex justify-between items-start">
<div>
<span class="font-bold text-lg text-gray-800 dark:text-gray-100">${order.symbol}</span>
<span class="ml-2 text-sm ${order.pnl_pct >= 0 ? 'profit' : 'loss'}">
(+${order.pnl_pct.toFixed(1)}%)
</span>
</div>
<span class="text-2xl">${order.emoji}</span>
</div>
<div class="grid grid-cols-2 gap-4 mt-3 text-sm">
<div>
<span class="text-gray-600 dark:text-gray-400">Trigger Delta:</span>
<span class="font-bold ml-1 text-gray-800 dark:text-gray-200">$${order.trigger_delta.toFixed(2)}</span>
</div>
<div>
<span class="text-gray-600 dark:text-gray-400">Limit Offset:</span>
<span class="font-bold ml-1 text-gray-800 dark:text-gray-200">$${order.limit_offset.toFixed(2)}</span>
</div>
<div class="text-xs text-gray-500 dark:text-gray-500">
Stop at: $${order.stop.toFixed(2)}
</div>
<div class="text-xs text-gray-500 dark:text-gray-500">
Limit at: $${order.limit.toFixed(2)}
</div>
</div>
</div>
`;
});
document.getElementById('stopInstructions').innerHTML = instructionsHTML;
}
}
function updateDashboardWithFallback() {
// Fallback with current known data (updated Aug 14)
const fallbackData = {
portfolio: {
positions: [
{ symbol: 'CHPT', quantity: 26, entry_price: 10.7845 },
{ symbol: 'EVGO', quantity: 82, entry_price: 3.6271 },
{ symbol: 'TDUP', quantity: 19, entry_price: 10.45 },
{ symbol: 'FUBO', quantity: 55, entry_price: 3.67 }
],
cash_balance: 0.45
},
prices: {
'CHPT': { price: 12.05 },
'EVGO': { price: 3.94 },
'TDUP': { price: 10.51 },
'FUBO': { price: 3.76 },
'SPY': { price: 644.89 },
'IWM': { price: 231.22 }
},
instructions: {
orders: [
{ symbol: 'CHPT', trigger_delta: 0.18, limit_offset: 0.06, stop: 10.90, limit: 10.84, pnl_pct: 2.74, emoji: '📍' },
{ symbol: 'EVGO', trigger_delta: 0.08, limit_offset: 0.02, stop: 3.68, limit: 3.66, pnl_pct: 3.66, emoji: '📍' }
]
}
};
updateDashboard(fallbackData.portfolio, fallbackData.prices, fallbackData.instructions);
}
// Function to update prices via Alpha Vantage
async function updatePricesViaAlphaVantage() {
const btn = document.getElementById('updateBtn');
const originalText = btn.innerHTML;
// Show loading state
btn.disabled = true;
btn.innerHTML = '<span>⏳</span><span>Updating...</span>';
btn.classList.add('opacity-75');
try {
// Call the Python script to update prices
const response = await fetch('/api/update-prices', {
method: 'POST'
});
if (!response.ok) {
// Fallback: Show instructions to run manually
alert('Please run this command in terminal:\npython update_prices.py\n\nThen refresh the dashboard.');
} else {
// Reload dashboard data
await loadDashboardData();
// Show success
btn.innerHTML = '<span>✅</span><span>Updated!</span>';
btn.classList.remove('bg-green-600');
btn.classList.add('bg-green-500');
setTimeout(() => {
btn.innerHTML = originalText;
btn.classList.remove('bg-green-500');
btn.classList.add('bg-green-600');
}, 2000);
}
} catch (error) {
// Show manual update instructions
alert('To update prices, run this command:\n\npython update_prices.py\n\nThis uses Alpha Vantage API for real-time data.');
btn.innerHTML = originalText;
} finally {
btn.disabled = false;
btn.classList.remove('opacity-75');
}
}
// Show Alpha Vantage status on load
async function checkAlphaVantageStatus() {
try {
const response = await fetch('data/latest_prices.json');
const data = await response.json();
// Check timestamp freshness
if (data.CHPT && data.CHPT.timestamp) {
const timestamp = new Date(data.CHPT.timestamp);
const now = new Date();
const diffMinutes = (now - timestamp) / 60000;
if (diffMinutes > 15) {
// Data is stale, show warning
const updateBtn = document.getElementById('updateBtn');
updateBtn.classList.remove('bg-green-600');
updateBtn.classList.add('bg-orange-600', 'animate-pulse');
updateBtn.innerHTML = '<span>⚠️</span><span>Prices Stale - Update Now</span>';
}
}
} catch (error) {
console.log('Could not check price freshness');
}
}
// Initialize on page load
initDarkMode();
initChart();
loadDashboardData();
checkAlphaVantageStatus();
// Auto-refresh every 30 seconds
setInterval(loadDashboardData, 30000);
// Check data freshness every 5 minutes
setInterval(checkAlphaVantageStatus, 300000);
</script>
</body>
</html>