Spaces:
Running
Running
Jimin Huang
commited on
Commit
·
99fcf98
1
Parent(s):
a2b7663
Change settings
Browse files- src/components/CompareChartE.vue +164 -234
src/components/CompareChartE.vue
CHANGED
|
@@ -1,130 +1,95 @@
|
|
| 1 |
<template>
|
| 2 |
-
<div class="live">
|
| 3 |
-
<!--
|
| 4 |
-
<
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
<
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
</
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
<!-- Chart -->
|
| 17 |
-
<
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
<
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
:
|
| 35 |
-
class="card"
|
| 36 |
-
|
| 37 |
-
>
|
| 38 |
-
|
| 39 |
-
<div class="
|
| 40 |
-
|
| 41 |
-
<img v-if="c.logo" :src="c.logo" alt="" />
|
| 42 |
-
<div v-else class="card__logo-fallback"></div>
|
| 43 |
-
<span v-if="c.isWinner" class="card__badge" aria-label="Top performer">👑</span>
|
| 44 |
-
</div>
|
| 45 |
-
|
| 46 |
-
<div class="card__title" :title="c.title">{{ c.title }}</div>
|
| 47 |
-
<div class="card__balance">{{ fmtUSD(c.balance) }}</div>
|
| 48 |
-
</div>
|
| 49 |
-
|
| 50 |
-
<!-- meta row -->
|
| 51 |
-
<div class="card__meta">
|
| 52 |
-
<div class="card__sub ellipsize" :title="c.subtitle">{{ c.subtitle }}</div>
|
| 53 |
-
|
| 54 |
-
<template v-if="c.kind==='agent' && c.gapUsd != null">
|
| 55 |
-
<div class="pill" :class="{ neg: c.gapUsd < 0 && !c.isWinner, pos: c.gapUsd >= 0 || c.isWinner }">
|
| 56 |
-
<span v-if="mode==='usd'">{{ signedMoney(c.gapUsd) }}</span>
|
| 57 |
-
<span v-else>{{ signedPct(c.gapPct) }}</span>
|
| 58 |
-
</div>
|
| 59 |
-
</template>
|
| 60 |
-
|
| 61 |
-
<template v-else>
|
| 62 |
-
<div class="pill pill--neutral">Buy & Hold</div>
|
| 63 |
-
</template>
|
| 64 |
-
</div>
|
| 65 |
-
|
| 66 |
-
<!-- date row -->
|
| 67 |
-
<div class="card__footer">
|
| 68 |
-
<div class="card__sub">EOD {{ c.date ? new Date(c.date).toLocaleDateString() : '–' }}</div>
|
| 69 |
</div>
|
| 70 |
</div>
|
| 71 |
</div>
|
| 72 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
</div>
|
| 74 |
</template>
|
| 75 |
|
| 76 |
<script setup>
|
| 77 |
-
import { ref, computed, onMounted,
|
| 78 |
import AssetTabs from '../components/AssetTabs.vue'
|
| 79 |
import CompareChartE from '../components/CompareChartE.vue'
|
| 80 |
import { dataService } from '../lib/dataService'
|
| 81 |
|
| 82 |
-
/*
|
| 83 |
import { getAllDecisions } from '../lib/dataCache'
|
| 84 |
import { readAllRawDecisions } from '../lib/idb'
|
| 85 |
import { filterRowsToNyseTradingDays } from '../lib/marketCalendar'
|
| 86 |
import { STRATEGIES } from '../lib/strategies'
|
| 87 |
import { computeBuyHoldEquity, computeStrategyEquity } from '../lib/perf'
|
| 88 |
|
| 89 |
-
/*
|
| 90 |
-
const orderedAssets = ['BTC','ETH','MSFT','BMRN','TSLA'] // MRNA removed
|
| 91 |
-
const EXCLUDED_AGENT_NAMES = new Set(['vanilla', 'vinilla']) // case-insensitive
|
| 92 |
-
|
| 93 |
-
// optional logos
|
| 94 |
-
const AGENT_LOGOS = {
|
| 95 |
-
// 'DeepFundAgent': new URL('../assets/images/agents/deepfund.png', import.meta.url).href,
|
| 96 |
-
}
|
| 97 |
-
const ASSET_ICONS = {
|
| 98 |
-
BTC: new URL('../assets/images/assets_images/BTC.png', import.meta.url).href,
|
| 99 |
-
ETH: new URL('../assets/images/assets_images/ETH.png', import.meta.url).href,
|
| 100 |
-
MSFT: new URL('../assets/images/assets_images/MSFT.png', import.meta.url).href,
|
| 101 |
-
BMRN: new URL('../assets/images/assets_images/BMRN.png', import.meta.url).href,
|
| 102 |
-
TSLA: new URL('../assets/images/assets_images/TSLA.png', import.meta.url).href,
|
| 103 |
-
}
|
| 104 |
-
|
| 105 |
-
/* match the chart’s cutoff so numbers align exactly */
|
| 106 |
-
const ASSET_CUTOFF = { BTC: '2025-08-01' }
|
| 107 |
-
|
| 108 |
-
/* ---------- state ---------- */
|
| 109 |
const mode = ref('usd') // 'usd' | 'pct'
|
| 110 |
const asset = ref('BTC')
|
| 111 |
-
const
|
|
|
|
| 112 |
|
| 113 |
-
|
|
|
|
|
|
|
| 114 |
|
| 115 |
-
/*
|
| 116 |
onMounted(async () => {
|
| 117 |
try {
|
| 118 |
if (!dataService.loaded && !dataService.loading) {
|
| 119 |
-
await dataService.load(false)
|
| 120 |
}
|
| 121 |
} catch (e) {
|
| 122 |
console.error('LiveView: dataService.load failed', e)
|
| 123 |
}
|
| 124 |
-
|
| 125 |
-
if (!orderedAssets.includes(asset.value)) asset.value = orderedAssets[0]
|
| 126 |
|
| 127 |
-
//
|
| 128 |
allDecisions = getAllDecisions() || []
|
| 129 |
if (!allDecisions.length) {
|
| 130 |
try {
|
|
@@ -132,30 +97,24 @@ onMounted(async () => {
|
|
| 132 |
if (cached?.length) allDecisions = cached
|
| 133 |
} catch {}
|
| 134 |
}
|
| 135 |
-
await nextTick()
|
| 136 |
})
|
| 137 |
|
| 138 |
-
/*
|
| 139 |
function score(row) {
|
| 140 |
return typeof row.balance === 'number' ? row.balance : -Infinity
|
| 141 |
}
|
| 142 |
-
const fmtUSD = (n) =>
|
| 143 |
-
|
| 144 |
-
const signedPct = (p) => `${(p >= 0 ? '+' : '−')}${Math.abs(p * 100).toFixed(2)}%`
|
| 145 |
|
| 146 |
-
/*
|
| 147 |
-
const
|
| 148 |
-
(
|
| 149 |
if (r.asset !== asset.value) return false
|
| 150 |
const name = (r?.agent_name || '').toLowerCase()
|
| 151 |
return !EXCLUDED_AGENT_NAMES.has(name)
|
| 152 |
})
|
| 153 |
-
)
|
| 154 |
-
|
| 155 |
-
/* Best model per agent (by balance) — from leaderboard rows for winners list */
|
| 156 |
-
const winners = computed(() => {
|
| 157 |
const byAgent = new Map()
|
| 158 |
-
for (const r of
|
| 159 |
const k = r.agent_name
|
| 160 |
const cur = byAgent.get(k)
|
| 161 |
if (!cur || score(r) > score(cur)) byAgent.set(k, r)
|
|
@@ -163,36 +122,44 @@ const winners = computed(() => {
|
|
| 163 |
return [...byAgent.values()]
|
| 164 |
})
|
| 165 |
|
| 166 |
-
/*
|
| 167 |
const winnersForChart = computed(() =>
|
| 168 |
winners.value.map(w => ({
|
| 169 |
-
agent_name:
|
| 170 |
-
asset:
|
| 171 |
-
model:
|
| 172 |
-
strategy:
|
| 173 |
decision_ids: Array.isArray(w.decision_ids) ? w.decision_ids : undefined
|
| 174 |
}))
|
| 175 |
)
|
| 176 |
|
| 177 |
-
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
-
|
|
|
|
|
|
|
| 180 |
async function buildSeq(sel) {
|
| 181 |
-
const { agent_name:
|
| 182 |
const ids = Array.isArray(sel.decision_ids) ? sel.decision_ids : []
|
| 183 |
let seq = ids.length
|
| 184 |
? allDecisions.filter(r => ids.includes(r.id))
|
| 185 |
-
: allDecisions.filter(r => r.agent_name ===
|
| 186 |
|
| 187 |
-
seq.sort((a,
|
| 188 |
|
| 189 |
-
const isCrypto =
|
| 190 |
let filtered = seq
|
| 191 |
if (!isCrypto) {
|
| 192 |
-
filtered = await filterRowsToNyseTradingDays(seq)
|
| 193 |
}
|
| 194 |
|
| 195 |
-
const cutoff = ASSET_CUTOFF[
|
| 196 |
if (cutoff) {
|
| 197 |
const t0 = new Date(cutoff + 'T00:00:00Z')
|
| 198 |
filtered = filtered.filter(r => new Date(r.date + 'T00:00:00Z') >= t0)
|
|
@@ -200,8 +167,8 @@ async function buildSeq(sel) {
|
|
| 200 |
return filtered
|
| 201 |
}
|
| 202 |
|
| 203 |
-
/** async: compute final equity &
|
| 204 |
-
async function
|
| 205 |
const seq = await buildSeq(sel)
|
| 206 |
if (!seq.length) return null
|
| 207 |
|
|
@@ -212,143 +179,106 @@ async function computeEquities(sel) {
|
|
| 212 |
const stratY = computeStrategyEquity(seq, 100000, cfg.fee, cfg.strategy, cfg.tradingMode) || []
|
| 213 |
const bhY = computeBuyHoldEquity(seq, 100000) || []
|
| 214 |
|
| 215 |
-
const
|
| 216 |
-
if (
|
| 217 |
|
| 218 |
return {
|
| 219 |
-
date: seq[
|
| 220 |
-
stratLast: stratY[
|
| 221 |
-
bhLast: bhY[
|
| 222 |
}
|
| 223 |
}
|
| 224 |
|
| 225 |
-
/*
|
| 226 |
-
const
|
| 227 |
-
let computing = false
|
| 228 |
|
|
|
|
|
|
|
| 229 |
watch(
|
| 230 |
-
() => [asset.value,
|
| 231 |
async () => {
|
| 232 |
-
if (!allDecisions.length) {
|
| 233 |
if (computing) return
|
| 234 |
computing = true
|
| 235 |
try {
|
| 236 |
const sels = winnersForChart.value || []
|
| 237 |
-
if (!sels.length) {
|
| 238 |
|
| 239 |
-
// run all perf computations in parallel
|
| 240 |
const perfs = (await Promise.all(
|
| 241 |
-
sels.map(async sel => ({ sel, perf: await
|
| 242 |
)).filter(x => x.perf)
|
| 243 |
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
logo: ASSET_ICONS[assetCode] || null,
|
| 256 |
-
isWinner: false
|
| 257 |
-
}
|
| 258 |
-
|
| 259 |
-
// Agent cards and winner flag
|
| 260 |
-
const agentCards = perfs.map(({ sel, perf }) => {
|
| 261 |
-
const gapUsd = perf.stratLast - perf.bhLast
|
| 262 |
-
const gapPct = perf.bhLast > 0 ? (perf.stratLast / perf.bhLast - 1) : 0
|
| 263 |
-
return {
|
| 264 |
-
key: `agent|${sel.agent_name}|${sel.model}`,
|
| 265 |
-
kind: 'agent',
|
| 266 |
-
title: sel.agent_name,
|
| 267 |
-
subtitle: sel.model,
|
| 268 |
-
balance: perf.stratLast,
|
| 269 |
-
date: perf.date,
|
| 270 |
-
logo: AGENT_LOGOS[sel.agent_name] || null,
|
| 271 |
-
gapUsd, gapPct,
|
| 272 |
-
isWinner: false
|
| 273 |
-
}
|
| 274 |
-
})
|
| 275 |
-
|
| 276 |
-
const maxBal = Math.max(...agentCards.map(c => c.balance ?? -Infinity))
|
| 277 |
-
agentCards.forEach(c => { c.isWinner = c.balance === maxBal })
|
| 278 |
-
|
| 279 |
-
// Top 4 agents + BH
|
| 280 |
-
cards.value = [bhCard, ...agentCards.sort((a,b) => b.balance - a.balance).slice(0,4)]
|
| 281 |
} catch (e) {
|
| 282 |
-
console.error('LiveView: compute
|
| 283 |
-
|
| 284 |
} finally {
|
| 285 |
computing = false
|
| 286 |
}
|
| 287 |
},
|
| 288 |
-
{ immediate: true
|
| 289 |
)
|
| 290 |
</script>
|
| 291 |
|
| 292 |
<style scoped>
|
| 293 |
-
.live { max-width:
|
| 294 |
-
|
| 295 |
-
/*
|
| 296 |
-
.
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
/* empty */
|
| 312 |
-
.empty { padding: 14px; border: 1px dashed #D6DAE1; border-radius: 12px; color: #6B7280; font-size: .92rem; }
|
| 313 |
-
|
| 314 |
-
/* 5 cards in a row */
|
| 315 |
-
.cards5 { display: grid; gap: 12px; grid-template-columns: repeat(5, minmax(0, 1fr)); }
|
| 316 |
-
@media (max-width: 1200px) { .cards5 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
| 317 |
-
@media (max-width: 720px) { .cards5 { grid-template-columns: 1fr; } }
|
| 318 |
-
|
| 319 |
-
/* card */
|
| 320 |
-
.card { display: grid; grid-template-rows: auto auto auto; gap: 8px; padding: 12px 14px; border: 1px solid #EEF1F6; border-radius: 14px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.04); position: relative; }
|
| 321 |
-
.card--bh { outline: 2px dashed rgba(15,23,42,.08); }
|
| 322 |
-
.card--winner { border-color: #16a34a; box-shadow: 0 0 0 3px rgba(22,163,74,.12); }
|
| 323 |
-
|
| 324 |
-
/* header layout: logo | title | balance */
|
| 325 |
-
.card__header { display: grid; grid-template-columns: 52px minmax(0,1fr) auto; align-items: start; gap: 12px; }
|
| 326 |
-
|
| 327 |
-
/* logo */
|
| 328 |
-
.card__logo { width: 44px; height: 44px; border-radius: 999px; background: #F3F4F6; display: grid; place-items: center; overflow: hidden; position: relative; }
|
| 329 |
-
.card__logo img { width: 100%; height: 100%; object-fit: contain; }
|
| 330 |
-
.card__logo-fallback { width: 60%; height: 60%; border-radius: 999px; background: #E5E7EB; }
|
| 331 |
-
.card__badge { position: absolute; right: -6px; top: -6px; font-size: 16px; filter: drop-shadow(0 1px 1px rgba(0,0,0,.15)); }
|
| 332 |
-
|
| 333 |
-
/* title: clamp to 2 lines so balance never overlaps */
|
| 334 |
-
.card__title {
|
| 335 |
-
min-width: 0; font-weight: 800; color: #0F172A;
|
| 336 |
-
white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
|
| 337 |
-
overflow: hidden; line-height: 1.15;
|
| 338 |
}
|
| 339 |
|
| 340 |
-
/*
|
| 341 |
-
.
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
|
| 349 |
-
/*
|
| 350 |
-
.
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
</style>
|
|
|
|
| 1 |
<template>
|
| 2 |
+
<div class="live-view px-4 py-3 space-y-3">
|
| 3 |
+
<!-- Asset tabs (logos, no prices) -->
|
| 4 |
+
<AssetTabs v-model="asset" />
|
| 5 |
+
|
| 6 |
+
<!-- $ / % mode switch -->
|
| 7 |
+
<div class="flex items-center gap-2">
|
| 8 |
+
<button
|
| 9 |
+
class="switch-btn"
|
| 10 |
+
:class="mode==='usd' ? 'switch-btn--active' : ''"
|
| 11 |
+
@click="mode='usd'">
|
| 12 |
+
$
|
| 13 |
+
</button>
|
| 14 |
+
<button
|
| 15 |
+
class="switch-btn"
|
| 16 |
+
:class="mode==='pct' ? 'switch-btn--active' : ''"
|
| 17 |
+
@click="mode='pct'">
|
| 18 |
+
%
|
| 19 |
+
</button>
|
| 20 |
+
</div>
|
| 21 |
|
| 22 |
<!-- Chart -->
|
| 23 |
+
<CompareChartE
|
| 24 |
+
v-if="winnersForChart.length"
|
| 25 |
+
:selected="winnersForChart"
|
| 26 |
+
:visible="true"
|
| 27 |
+
:mode="mode"
|
| 28 |
+
/>
|
| 29 |
+
<div v-else class="empty">
|
| 30 |
+
No data for <strong>{{ asset }}</strong> yet. Check Supabase runs or try another asset.
|
| 31 |
+
</div>
|
| 32 |
+
|
| 33 |
+
<!-- Winner cards (best final equity per agent; computed like the chart) -->
|
| 34 |
+
<div v-if="winnersSorted.length" class="grid gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
|
| 35 |
+
<div
|
| 36 |
+
v-for="row in winnersSorted"
|
| 37 |
+
:key="row.agent_name+'|'+row.asset+'|'+row.model"
|
| 38 |
+
class="card">
|
| 39 |
+
<div class="min-w-0">
|
| 40 |
+
<div class="card-title truncate" :title="row.agent_name">{{ row.agent_name }}</div>
|
| 41 |
+
<div class="card-sub truncate" :title="row.model">{{ row.model }}</div>
|
| 42 |
+
</div>
|
| 43 |
+
<div class="text-right">
|
| 44 |
+
<div class="card-balance">{{ fmtUSD(row.balance) }}</div>
|
| 45 |
+
<div class="card-sub">
|
| 46 |
+
EOD {{ row.end_date ? new Date(row.end_date).toLocaleDateString() : (row.last_nav_ts ? new Date(row.last_nav_ts).toLocaleDateString() : '-') }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
</div>
|
| 48 |
</div>
|
| 49 |
</div>
|
| 50 |
+
</div>
|
| 51 |
+
|
| 52 |
+
<div v-else class="empty">
|
| 53 |
+
No winners for <strong>{{ asset }}</strong> yet.
|
| 54 |
+
</div>
|
| 55 |
</div>
|
| 56 |
</template>
|
| 57 |
|
| 58 |
<script setup>
|
| 59 |
+
import { ref, computed, onMounted, shallowRef, watch } from 'vue'
|
| 60 |
import AssetTabs from '../components/AssetTabs.vue'
|
| 61 |
import CompareChartE from '../components/CompareChartE.vue'
|
| 62 |
import { dataService } from '../lib/dataService'
|
| 63 |
|
| 64 |
+
/* === use the same helpers as the chart === */
|
| 65 |
import { getAllDecisions } from '../lib/dataCache'
|
| 66 |
import { readAllRawDecisions } from '../lib/idb'
|
| 67 |
import { filterRowsToNyseTradingDays } from '../lib/marketCalendar'
|
| 68 |
import { STRATEGIES } from '../lib/strategies'
|
| 69 |
import { computeBuyHoldEquity, computeStrategyEquity } from '../lib/perf'
|
| 70 |
|
| 71 |
+
/* ---- state ---- */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
const mode = ref('usd') // 'usd' | 'pct'
|
| 73 |
const asset = ref('BTC')
|
| 74 |
+
const agents = ref([]) // leaderboard/table rows
|
| 75 |
+
let allDecisions = [] // raw decisions used for perf compute
|
| 76 |
|
| 77 |
+
/* keep chart parity: cut BTC before Aug 1, 2025 */
|
| 78 |
+
const ASSET_CUTOFF = { BTC: '2025-08-01' }
|
| 79 |
+
const EXCLUDED_AGENT_NAMES = new Set(['vanilla', 'vinilla']) // case-insensitive
|
| 80 |
|
| 81 |
+
/* ---- load once ---- */
|
| 82 |
onMounted(async () => {
|
| 83 |
try {
|
| 84 |
if (!dataService.loaded && !dataService.loading) {
|
| 85 |
+
await dataService.load(false) // populates tableRows & cache
|
| 86 |
}
|
| 87 |
} catch (e) {
|
| 88 |
console.error('LiveView: dataService.load failed', e)
|
| 89 |
}
|
| 90 |
+
agents.value = Array.isArray(dataService.tableRows) ? dataService.tableRows : []
|
|
|
|
| 91 |
|
| 92 |
+
// decisions cache for perf (same source the chart uses)
|
| 93 |
allDecisions = getAllDecisions() || []
|
| 94 |
if (!allDecisions.length) {
|
| 95 |
try {
|
|
|
|
| 97 |
if (cached?.length) allDecisions = cached
|
| 98 |
} catch {}
|
| 99 |
}
|
|
|
|
| 100 |
})
|
| 101 |
|
| 102 |
+
/* ---- helpers ---- */
|
| 103 |
function score(row) {
|
| 104 |
return typeof row.balance === 'number' ? row.balance : -Infinity
|
| 105 |
}
|
| 106 |
+
const fmtUSD = (n) =>
|
| 107 |
+
(n ?? 0).toLocaleString(undefined, { style: 'currency', currency: 'USD', maximumFractionDigits: 2 })
|
|
|
|
| 108 |
|
| 109 |
+
/* winners by agent (from leaderboard rows), filtered by asset & excluding vanilla/vinilla */
|
| 110 |
+
const winners = computed(() => {
|
| 111 |
+
const rows = (agents.value || []).filter(r => {
|
| 112 |
if (r.asset !== asset.value) return false
|
| 113 |
const name = (r?.agent_name || '').toLowerCase()
|
| 114 |
return !EXCLUDED_AGENT_NAMES.has(name)
|
| 115 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
const byAgent = new Map()
|
| 117 |
+
for (const r of rows) {
|
| 118 |
const k = r.agent_name
|
| 119 |
const cur = byAgent.get(k)
|
| 120 |
if (!cur || score(r) > score(cur)) byAgent.set(k, r)
|
|
|
|
| 122 |
return [...byAgent.values()]
|
| 123 |
})
|
| 124 |
|
| 125 |
+
/* selections for the chart */
|
| 126 |
const winnersForChart = computed(() =>
|
| 127 |
winners.value.map(w => ({
|
| 128 |
+
agent_name: w.agent_name,
|
| 129 |
+
asset: w.asset,
|
| 130 |
+
model: w.model,
|
| 131 |
+
strategy: w.strategy,
|
| 132 |
decision_ids: Array.isArray(w.decision_ids) ? w.decision_ids : undefined
|
| 133 |
}))
|
| 134 |
)
|
| 135 |
|
| 136 |
+
/* stable key to avoid watcher re-trigger due to new object identities */
|
| 137 |
+
const winnersKey = computed(() => {
|
| 138 |
+
const sels = winnersForChart.value || []
|
| 139 |
+
return sels
|
| 140 |
+
.map(s => `${s.agent_name}|${s.asset}|${s.model}|${s.strategy}|${(s.decision_ids?.length||0)}`)
|
| 141 |
+
.join('||')
|
| 142 |
+
})
|
| 143 |
|
| 144 |
+
/* ========== PERF: compute bottom-card balances exactly like the chart ========== */
|
| 145 |
+
|
| 146 |
+
/** async: build ordered decision seq for a selection (await NYSE filter; apply cutoff) */
|
| 147 |
async function buildSeq(sel) {
|
| 148 |
+
const { agent_name: agentName, asset: assetCode, model } = sel
|
| 149 |
const ids = Array.isArray(sel.decision_ids) ? sel.decision_ids : []
|
| 150 |
let seq = ids.length
|
| 151 |
? allDecisions.filter(r => ids.includes(r.id))
|
| 152 |
+
: allDecisions.filter(r => r.agent_name === agentName && r.asset === assetCode && r.model === model)
|
| 153 |
|
| 154 |
+
seq.sort((a,b) => (a.date > b.date ? 1 : -1))
|
| 155 |
|
| 156 |
+
const isCrypto = assetCode === 'BTC' || assetCode === 'ETH'
|
| 157 |
let filtered = seq
|
| 158 |
if (!isCrypto) {
|
| 159 |
+
filtered = await filterRowsToNyseTradingDays(seq)
|
| 160 |
}
|
| 161 |
|
| 162 |
+
const cutoff = ASSET_CUTOFF[assetCode]
|
| 163 |
if (cutoff) {
|
| 164 |
const t0 = new Date(cutoff + 'T00:00:00Z')
|
| 165 |
filtered = filtered.filter(r => new Date(r.date + 'T00:00:00Z') >= t0)
|
|
|
|
| 167 |
return filtered
|
| 168 |
}
|
| 169 |
|
| 170 |
+
/** async: compute final equity for strategy & B&H using perf helpers */
|
| 171 |
+
async function computeFinals(sel) {
|
| 172 |
const seq = await buildSeq(sel)
|
| 173 |
if (!seq.length) return null
|
| 174 |
|
|
|
|
| 179 |
const stratY = computeStrategyEquity(seq, 100000, cfg.fee, cfg.strategy, cfg.tradingMode) || []
|
| 180 |
const bhY = computeBuyHoldEquity(seq, 100000) || []
|
| 181 |
|
| 182 |
+
const n = Math.min(stratY.length, bhY.length)
|
| 183 |
+
if (!n) return null
|
| 184 |
|
| 185 |
return {
|
| 186 |
+
date: seq[n-1].date,
|
| 187 |
+
stratLast: stratY[n-1],
|
| 188 |
+
bhLast: bhY[n-1],
|
| 189 |
}
|
| 190 |
}
|
| 191 |
|
| 192 |
+
/* winnersSorted used by the simple cards list (values recomputed via perf) */
|
| 193 |
+
const winnersSorted = shallowRef([])
|
|
|
|
| 194 |
|
| 195 |
+
/* serialized async watcher to compute the cards (avoid re-entrancy & identity churn) */
|
| 196 |
+
let computing = false
|
| 197 |
watch(
|
| 198 |
+
() => [asset.value, winnersKey.value], // stable deps
|
| 199 |
async () => {
|
| 200 |
+
if (!allDecisions.length) { winnersSorted.value = []; return }
|
| 201 |
if (computing) return
|
| 202 |
computing = true
|
| 203 |
try {
|
| 204 |
const sels = winnersForChart.value || []
|
| 205 |
+
if (!sels.length) { winnersSorted.value = []; return }
|
| 206 |
|
|
|
|
| 207 |
const perfs = (await Promise.all(
|
| 208 |
+
sels.map(async sel => ({ sel, perf: await computeFinals(sel) }))
|
| 209 |
)).filter(x => x.perf)
|
| 210 |
|
| 211 |
+
const uiRows = perfs.map(({ sel, perf }) => ({
|
| 212 |
+
agent_name: sel.agent_name,
|
| 213 |
+
model: sel.model,
|
| 214 |
+
asset: sel.asset,
|
| 215 |
+
strategy: sel.strategy,
|
| 216 |
+
balance: perf.stratLast, // final strategy equity (matches chart right edge)
|
| 217 |
+
end_date: perf.date,
|
| 218 |
+
last_nav_ts: perf.date
|
| 219 |
+
}))
|
| 220 |
+
|
| 221 |
+
winnersSorted.value = uiRows.sort((a,b) => (b.balance ?? -Infinity) - (a.balance ?? -Infinity))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
} catch (e) {
|
| 223 |
+
console.error('LiveView: perf compute failed', e)
|
| 224 |
+
winnersSorted.value = []
|
| 225 |
} finally {
|
| 226 |
computing = false
|
| 227 |
}
|
| 228 |
},
|
| 229 |
+
{ immediate: true }
|
| 230 |
)
|
| 231 |
</script>
|
| 232 |
|
| 233 |
<style scoped>
|
| 234 |
+
.live-view { max-width: 1400px; margin: 0 auto; }
|
| 235 |
+
|
| 236 |
+
/* toggle buttons */
|
| 237 |
+
.switch-btn {
|
| 238 |
+
padding: 6px 10px;
|
| 239 |
+
border: 1px solid #1f2937; /* gray-800 */
|
| 240 |
+
border-radius: 8px;
|
| 241 |
+
background: #fff;
|
| 242 |
+
font-weight: 700;
|
| 243 |
+
line-height: 1;
|
| 244 |
+
transition: background .12s ease, color .12s ease, transform .06s ease;
|
| 245 |
+
}
|
| 246 |
+
.switch-btn:hover { transform: translateY(-1px); }
|
| 247 |
+
.switch-btn--active {
|
| 248 |
+
background: #111827; /* gray-900 */
|
| 249 |
+
color: #fff;
|
| 250 |
+
border-color: #111827;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
}
|
| 252 |
|
| 253 |
+
/* empty state */
|
| 254 |
+
.empty {
|
| 255 |
+
padding: 12px 14px;
|
| 256 |
+
border: 1px dashed #d1d5db; /* gray-300 */
|
| 257 |
+
border-radius: 12px;
|
| 258 |
+
color: #6b7280; /* gray-500 */
|
| 259 |
+
font-size: 0.9rem;
|
| 260 |
+
}
|
| 261 |
|
| 262 |
+
/* winner cards */
|
| 263 |
+
.card {
|
| 264 |
+
display: flex;
|
| 265 |
+
justify-content: space-between;
|
| 266 |
+
align-items: center;
|
| 267 |
+
gap: 12px;
|
| 268 |
+
padding: 14px 16px;
|
| 269 |
+
border: 1px solid #e5e7eb; /* gray-200 */
|
| 270 |
+
border-radius: 16px;
|
| 271 |
+
box-shadow: 0 1px 2px rgba(0,0,0,0.04);
|
| 272 |
+
background: #fff;
|
| 273 |
+
}
|
| 274 |
+
.card-title { font-weight: 600; }
|
| 275 |
+
.card-sub { font-size: 12px; opacity: 0.65; }
|
| 276 |
+
.card-balance { font-weight: 800; font-size: 18px; line-height: 1.1; }
|
| 277 |
+
|
| 278 |
+
/* small util */
|
| 279 |
+
.truncate {
|
| 280 |
+
overflow: hidden;
|
| 281 |
+
text-overflow: ellipsis;
|
| 282 |
+
white-space: nowrap;
|
| 283 |
+
}
|
| 284 |
</style>
|