Jimin Huang commited on
Commit
fa77219
·
1 Parent(s): 3ac9172

Change settings

Browse files
Files changed (1) hide show
  1. src/components/CompareChartE.vue +6 -22
src/components/CompareChartE.vue CHANGED
@@ -25,7 +25,7 @@ export default defineComponent({
25
  name: 'CompareChartE',
26
  components: { VChart },
27
  props: {
28
- selected: { type: Array, default: () => [] }, // [{agent_name, asset, model, strategy, decision_ids?}]
29
  visible: { type: Boolean, default: true }
30
  },
31
  data(){ return { option: {} } },
@@ -38,7 +38,7 @@ export default defineComponent({
38
  async getAll(){
39
  let all = getAllDecisions() || []
40
  if (!all.length) {
41
- try { const cached = await readAllRawDecisions(); if (cached?.length) all = cached } catch(_) {}
42
  }
43
  return all
44
  },
@@ -48,7 +48,6 @@ export default defineComponent({
48
  const all = await this.getAll()
49
  const groupKeyToSeq = new Map()
50
 
51
- // Build grouped sequences from selected (borrowed from CompareChart.vue)
52
  for (const sel of selected) {
53
  const { agent_name: agent, asset, model } = sel
54
  const ids = Array.isArray(sel.decision_ids) ? sel.decision_ids : []
@@ -63,15 +62,12 @@ export default defineComponent({
63
  const keys = Array.from(groupKeyToSeq.keys())
64
  const labels = keys.length ? (groupKeyToSeq.get(keys[0]).seq || []).map(s => s.date) : []
65
 
66
- // Build ECharts series: strategy lines per selection + asset Buy&Hold once
67
  const series = []
68
  const legend = []
69
  const assets = new Set()
70
-
71
- // Per-agent color hue: reuse your getStrategyColor hue system
72
  const agentColorIndex = new Map()
73
 
74
- for (const [gk, { sel, seq }] of groupKeyToSeq.entries()) {
75
  if (!seq.length) continue
76
  const agent = sel.agent_name
77
  const asset = sel.asset
@@ -80,7 +76,6 @@ export default defineComponent({
80
  const idx = agentColorIndex.get(agent) ?? agentColorIndex.size
81
  agentColorIndex.set(agent, idx)
82
 
83
- // strategy config
84
  const cfg = (STRATEGIES || []).find(s => s.id === sel.strategy) || { strategy: 'long_only', tradingMode: 'aggressive', fee: 0.0005, label: 'Selected' }
85
  const stratSeries = computeStrategyEquity(seq, 100000, cfg.fee, cfg.strategy, cfg.tradingMode)
86
  if (stratSeries?.length) {
@@ -100,9 +95,7 @@ export default defineComponent({
100
  }
101
  }
102
 
103
- // Add Buy&Hold baseline once per asset (in black)
104
  for (const asset of assets) {
105
- // find any seq for this asset to build BH labels
106
  const entry = [...groupKeyToSeq.values()].find(v => v.sel.asset === asset)
107
  if (!entry) continue
108
  const bh = computeBuyHoldEquity(entry.seq, 100000) || []
@@ -128,22 +121,13 @@ export default defineComponent({
128
  : v
129
  },
130
  legend: { type: 'scroll', bottom: 0, data: legend },
131
- xAxis: {
132
- type: 'category',
133
- data: labels,
134
- axisLabel: { formatter: v => v?.slice?.(2) } // compact YY-MM-DD
135
- },
136
  yAxis: {
137
  type: 'value',
138
  scale: true,
139
- axisLabel: {
140
- formatter: v => v.toLocaleString(undefined, { style: 'currency', currency: 'USD', maximumFractionDigits: 0 })
141
- }
142
  },
143
- dataZoom: [
144
- { type: 'inside', throttle: 50 },
145
- { type: 'slider', height: 16, bottom: 22 }
146
- ],
147
  series
148
  }
149
  }
 
25
  name: 'CompareChartE',
26
  components: { VChart },
27
  props: {
28
+ selected: { type: Array, default: () => [] },
29
  visible: { type: Boolean, default: true }
30
  },
31
  data(){ return { option: {} } },
 
38
  async getAll(){
39
  let all = getAllDecisions() || []
40
  if (!all.length) {
41
+ try { const cached = await readAllRawDecisions(); if (cached?.length) all = cached } catch {}
42
  }
43
  return all
44
  },
 
48
  const all = await this.getAll()
49
  const groupKeyToSeq = new Map()
50
 
 
51
  for (const sel of selected) {
52
  const { agent_name: agent, asset, model } = sel
53
  const ids = Array.isArray(sel.decision_ids) ? sel.decision_ids : []
 
62
  const keys = Array.from(groupKeyToSeq.keys())
63
  const labels = keys.length ? (groupKeyToSeq.get(keys[0]).seq || []).map(s => s.date) : []
64
 
 
65
  const series = []
66
  const legend = []
67
  const assets = new Set()
 
 
68
  const agentColorIndex = new Map()
69
 
70
+ for (const [_, { sel, seq }] of groupKeyToSeq.entries()) {
71
  if (!seq.length) continue
72
  const agent = sel.agent_name
73
  const asset = sel.asset
 
76
  const idx = agentColorIndex.get(agent) ?? agentColorIndex.size
77
  agentColorIndex.set(agent, idx)
78
 
 
79
  const cfg = (STRATEGIES || []).find(s => s.id === sel.strategy) || { strategy: 'long_only', tradingMode: 'aggressive', fee: 0.0005, label: 'Selected' }
80
  const stratSeries = computeStrategyEquity(seq, 100000, cfg.fee, cfg.strategy, cfg.tradingMode)
81
  if (stratSeries?.length) {
 
95
  }
96
  }
97
 
 
98
  for (const asset of assets) {
 
99
  const entry = [...groupKeyToSeq.values()].find(v => v.sel.asset === asset)
100
  if (!entry) continue
101
  const bh = computeBuyHoldEquity(entry.seq, 100000) || []
 
121
  : v
122
  },
123
  legend: { type: 'scroll', bottom: 0, data: legend },
124
+ xAxis: { type: 'category', data: labels, axisLabel: { formatter: v => v?.slice?.(2) } },
 
 
 
 
125
  yAxis: {
126
  type: 'value',
127
  scale: true,
128
+ axisLabel: { formatter: v => v.toLocaleString(undefined, { style:'currency', currency:'USD', maximumFractionDigits:0 }) }
 
 
129
  },
130
+ dataZoom: [{ type: 'inside', throttle: 50 }, { type: 'slider', height: 16, bottom: 22 }],
 
 
 
131
  series
132
  }
133
  }