-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactor-backtest.html
More file actions
440 lines (419 loc) · 22.8 KB
/
factor-backtest.html
File metadata and controls
440 lines (419 loc) · 22.8 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alpha Factor Lab — 因子研究库</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns@3.0.0/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
<style>
:root {
--bg: #0f1117; --card: #1a1d29; --border: #2a2d3a;
--text: #e4e6eb; --text2: #8b8fa3; --accent: #4f8cff;
--green: #22c55e; --red: #ef4444; --orange: #f59e0b; --purple: #a855f7;
}
* { margin:0; padding:0; box-sizing:border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; }
.container { max-width: 1200px; margin: 0 auto; padding: 20px; }
.header { text-align:center; padding:40px 0 30px; border-bottom:1px solid var(--border); margin-bottom:30px; }
.header h1 { font-size:2rem; background:linear-gradient(135deg,var(--accent),var(--purple)); -webkit-background-clip:text; -webkit-text-fill-color:transparent; margin-bottom:8px; }
.header p { color:var(--text2); font-size:0.95rem; }
.nav-links { margin-top:12px; }
.nav-links a { margin:0 8px; padding:6px 16px; border:1px solid var(--border); border-radius:8px; font-size:0.85rem; color:var(--accent); text-decoration:none; transition:all .2s; }
.nav-links a:hover { border-color:var(--accent); background:rgba(79,140,255,.05); }
.nav-links a.active { border-color:var(--accent); background:rgba(79,140,255,.1); }
.stats-bar { display:flex; justify-content:center; gap:40px; margin-top:20px; }
.stat { text-align:center; }
.stat .num { font-size:1.8rem; font-weight:700; color:var(--accent); }
.stat .label { font-size:0.8rem; color:var(--text2); text-transform:uppercase; }
.loading { text-align:center; padding:60px 0; color:var(--text2); }
.loading .spinner { display:inline-block; width:40px; height:40px; border:3px solid var(--border); border-top-color:var(--accent); border-radius:50%; animation:spin 0.8s linear infinite; margin-bottom:16px; }
@keyframes spin { to { transform: rotate(360deg); } }
.factor-list { display:flex; flex-direction:column; gap:16px; margin-bottom:30px; }
.factor-card { background:var(--card); border:1px solid var(--border); border-radius:12px; padding:24px; cursor:pointer; transition:all 0.2s; }
.factor-card:hover { border-color:var(--accent); transform:translateY(-2px); box-shadow:0 8px 25px rgba(79,140,255,0.1); }
.factor-card.active { border-color:var(--accent); box-shadow:0 0 0 1px var(--accent); }
.card-top { display:flex; justify-content:space-between; align-items:flex-start; margin-bottom:12px; }
.card-title { font-size:1.2rem; font-weight:600; }
.card-title .en { font-size:0.85rem; color:var(--text2); font-weight:400; margin-left:8px; }
.badge { display:inline-block; padding:3px 10px; border-radius:20px; font-size:0.75rem; font-weight:600; }
.badge-weak { background:rgba(239,68,68,0.15); color:var(--red); }
.badge-moderate { background:rgba(245,158,11,0.15); color:var(--orange); }
.badge-strong { background:rgba(34,197,94,0.15); color:var(--green); }
.badge-warn { background:rgba(245,158,11,0.15); color:var(--orange); }
.card-meta { display:flex; flex-wrap:wrap; gap:16px; font-size:0.85rem; color:var(--text2); margin-bottom:12px; }
.card-desc { color:var(--text2); font-size:0.9rem; }
.metric-pills { display:flex; flex-wrap:wrap; gap:8px; margin-top:12px; }
.pill { background:rgba(79,140,255,0.1); border:1px solid rgba(79,140,255,0.2); padding:4px 12px; border-radius:8px; font-size:0.8rem; }
.pill .val { color:var(--accent); font-weight:600; margin-left:4px; }
.pill.neg .val { color:var(--red); }
.pill.pos .val { color:var(--green); }
.detail-panel { display:none; background:var(--card); border:1px solid var(--border); border-radius:12px; padding:30px; margin-bottom:30px; animation:fadeIn 0.3s; }
.detail-panel.show { display:block; }
@keyframes fadeIn { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:translateY(0)} }
.detail-section { margin-bottom:28px; padding-bottom:24px; border-bottom:1px solid var(--border); }
.detail-section:last-child { border-bottom:none; margin-bottom:0; padding-bottom:0; }
.detail-section h3 { font-size:1rem; color:var(--accent); margin-bottom:12px; }
.formula-box { background:#12141e; border:1px solid var(--border); border-radius:8px; padding:16px 20px; font-family:'SF Mono','Fira Code',monospace; font-size:0.9rem; white-space:pre-wrap; line-height:1.8; }
.metrics-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(160px,1fr)); gap:12px; }
.metric-box { background:#12141e; border-radius:8px; padding:14px 16px; text-align:center; }
.metric-box .label { font-size:0.75rem; color:var(--text2); margin-bottom:4px; }
.metric-box .value { font-size:1.3rem; font-weight:700; }
.metric-box .value.good { color:var(--green); }
.metric-box .value.bad { color:var(--red); }
.metric-box .value.neutral { color:var(--orange); }
.quintile-table { width:100%; border-collapse:collapse; font-size:0.85rem; }
.quintile-table th,.quintile-table td { padding:10px 14px; text-align:center; border-bottom:1px solid var(--border); }
.quintile-table th { color:var(--text2); font-weight:600; font-size:0.8rem; }
.chart-container { position:relative; height:350px; margin:16px 0; }
.chart-tabs { display:flex; gap:8px; margin-bottom:16px; }
.chart-tab { padding:6px 16px; border-radius:8px; border:1px solid var(--border); background:transparent; color:var(--text2); cursor:pointer; font-size:0.85rem; transition:all 0.2s; }
.chart-tab:hover { border-color:var(--accent); color:var(--text); }
.chart-tab.active { background:var(--accent); color:#fff; border-color:var(--accent); }
.conclusion-box { background:rgba(79,140,255,0.05); border-left:3px solid var(--accent); border-radius:0 8px 8px 0; padding:16px 20px; font-size:0.9rem; }
.lessons { margin-top:12px; padding-left:20px; }
.lessons li { color:var(--text2); font-size:0.85rem; margin-bottom:6px; }
.close-btn { float:right; background:none; border:1px solid var(--border); color:var(--text2); width:32px; height:32px; border-radius:8px; cursor:pointer; font-size:1.1rem; display:flex; align-items:center; justify-content:center; }
.close-btn:hover { border-color:var(--red); color:var(--red); }
.footer { text-align:center; padding:30px 0; color:var(--text2); font-size:0.8rem; border-top:1px solid var(--border); }
.topnav { display:flex; justify-content:center; gap:24px; padding:14px 20px; background:rgba(26,29,41,0.95); border-bottom:1px solid var(--border); position:sticky; top:0; z-index:100; backdrop-filter:blur(8px); }
.topnav a { color:var(--text2); text-decoration:none; font-size:0.85rem; font-weight:500; transition:color 0.2s; }
.topnav a:hover { color:var(--text); }
.topnav a.active { color:var(--accent); pointer-events:none; }
</style>
</head>
<body>
<div class="container">
<div class="topnav">
<a href="index.html">首页</a>
<a href="paper-trading.html">竞赛</a>
<a href="quant-lab.html">因子猎人</a>
<a href="research.html">投研报告</a>
</div>
<div class="header">
<h1>📊 Alpha Factor Lab</h1>
<p>量化因子研究库 — 赛博巴菲特出品</p>
<div class="stats-bar" id="statsBar"></div>
</div>
<div id="loadingIndicator" class="loading">
<div class="spinner"></div>
<p>正在加载因子数据...</p>
</div>
<div class="detail-panel" id="detailPanel"></div>
<div class="factor-list" id="factorList"></div>
<div class="footer">Alpha Factor Lab · Powered by 赛博巴菲特 · 数据仅供研究参考,不构成投资建议</div>
</div>
<script>
/* ====================== CONFIG ====================== */
let FACTORS = [];
const navDataCache = {}; // id -> normalized nav data
const icDataCache = {}; // id -> normalized ic data
const Q_COLORS = ['rgba(214,39,40,0.85)','rgba(255,127,14,0.85)','rgba(188,189,34,0.85)','rgba(44,160,44,0.85)','rgba(31,119,180,0.85)','rgba(148,103,189,0.85)'];
let navChart = null, icChart = null;
/* ====================== HELPERS ====================== */
function pct(v, d=2) { return v==null || isNaN(v) ? 'N/A' : (v*100).toFixed(d)+'%'; }
function num(v, d=4) { return v==null || isNaN(v) ? 'N/A' : v.toFixed(d); }
function rBadge(r) {
if (!r) return '';
const cls = r.includes('较弱') || r.includes('☆☆☆') || r.includes('无效') ? 'weak'
: r.includes('不足') || r.includes('异常') ? 'warn'
: r.includes('★★★') || r.includes('较强') ? 'strong' : 'moderate';
return `<span class="badge badge-${cls}">${r}</span>`;
}
/* ====================== DATA LOADING ====================== */
async function loadFactors() {
try {
const resp = await fetch('factors.json?v=' + Date.now());
FACTORS = await resp.json();
} catch (e) {
console.error('Failed to load factors.json:', e);
document.getElementById('loadingIndicator').innerHTML =
'<p style="color:var(--red)">❌ 无法加载 factors.json</p>';
return;
}
document.getElementById('loadingIndicator').style.display = 'none';
renderStats();
renderList();
}
/* Normalize NAV data from two possible formats:
Format A (old): { dates: [], series: { group_1..group_5, long_short } }
Format B (new): { dates: [], groups: { "0".."4": [] }, long_short: [] }
-> unified: { dates: [], series: { group_1..group_N, long_short } }
*/
function normalizeNavData(raw) {
if (raw.series) return raw; // Already format A
const result = { dates: raw.dates, series: {} };
if (raw.groups) {
const keys = Object.keys(raw.groups).sort((a,b) => parseInt(a) - parseInt(b));
keys.forEach((k, i) => { result.series[`group_${i+1}`] = raw.groups[k]; });
}
if (raw.long_short) result.series.long_short = raw.long_short;
return result;
}
/* Normalize IC data from two possible formats:
Format A (old): { dates: [], ic: [], rank_ic: [] }
Format B (new): [ { date: "...", ic: ... }, ... ]
-> unified: { dates: [], ic: [], rank_ic: [] }
*/
function normalizeIcData(raw) {
if (Array.isArray(raw)) {
return {
dates: raw.map(r => r.date),
ic: raw.map(r => r.ic),
rank_ic: raw.map(r => r.rank_ic || 0)
};
}
return raw; // Already format A
}
async function loadNavData(factor) {
const id = factor.id;
if (navDataCache[id]) return navDataCache[id];
const path = factor.nav_data;
if (!path) return null;
try {
const resp = await fetch(path);
if (!resp.ok) return null;
const raw = await resp.json();
navDataCache[id] = normalizeNavData(raw);
return navDataCache[id];
} catch (e) {
console.warn('Failed to load nav data for', id, e);
return null;
}
}
async function loadIcData(factor) {
const id = factor.id;
if (icDataCache[id]) return icDataCache[id];
const path = factor.ic_data;
if (!path) return null;
try {
const resp = await fetch(path);
if (!resp.ok) return null;
const raw = await resp.json();
icDataCache[id] = normalizeIcData(raw);
return icDataCache[id];
} catch (e) {
console.warn('Failed to load ic data for', id, e);
return null;
}
}
/* Determine if factor has chart data (check nav_data / ic_data paths) */
function hasChartData(f) {
return !!(f.nav_data || f.ic_data);
}
/* ====================== RENDERING ====================== */
function renderStats() {
const el = document.getElementById('statsBar');
const t = FACTORS.length;
const w = FACTORS.filter(f => f.metrics && f.metrics.ic_mean != null).length;
const strong = FACTORS.filter(f => f.rating && (f.rating.includes('★★★') || f.rating.includes('较强'))).length;
el.innerHTML = `
<div class="stat"><div class="num">${t}</div><div class="label">因子总数</div></div>
<div class="stat"><div class="num">${w}</div><div class="label">已回测</div></div>
<div class="stat"><div class="num">${strong}</div><div class="label">有效因子</div></div>`;
}
function renderList() {
const el = document.getElementById('factorList');
el.innerHTML = FACTORS.map((f, i) => {
const m = f.metrics || {};
let pills = '';
if (m.ic_mean != null) {
const c = Math.abs(m.ic_mean) > 0.03 ? (m.ic_mean > 0 ? 'pos' : 'neg') : '';
pills += `<span class="pill ${c}">IC<span class="val">${num(m.ic_mean)}</span></span>`;
}
if (m.monotonicity != null) {
const c = m.monotonicity >= 0.7 ? 'pos' : m.monotonicity >= 0.5 ? '' : 'neg';
pills += `<span class="pill ${c}">单调性<span class="val">${num(m.monotonicity, 2)}</span></span>`;
}
if (m.long_short_sharpe != null) {
const c = m.long_short_sharpe >= 1 ? 'pos' : m.long_short_sharpe >= 0.5 ? '' : 'neg';
pills += `<span class="pill ${c}">Sharpe<span class="val">${num(m.long_short_sharpe, 2)}</span></span>`;
}
if (m.long_short_annual_return != null) {
const c = m.long_short_annual_return > 0 ? 'pos' : 'neg';
pills += `<span class="pill ${c}">多空年化<span class="val">${pct(m.long_short_annual_return, 1)}</span></span>`;
}
return `<div class="factor-card" onclick="showDetail(${i})" id="card-${i}">
<div class="card-top">
<div class="card-title">${f.name}<span class="en">${f.name_en}</span></div>
${rBadge(f.rating)}
</div>
<div class="card-meta">
<span>📁 ${f.category}</span>
<span>📈 ${f.stock_pool}</span>
<span>📅 ${f.period}</span>
<span>🔄 ${f.rebalance_freq}天调仓</span>
</div>
<div class="card-desc">${f.description}</div>
${pills ? `<div class="metric-pills">${pills}</div>` : ''}
</div>`;
}).join('');
}
async function showDetail(idx) {
const f = FACTORS[idx], m = f.metrics || {};
const panel = document.getElementById('detailPanel');
document.querySelectorAll('.factor-card').forEach(c => c.classList.remove('active'));
document.getElementById(`card-${idx}`).classList.add('active');
let qTable = '';
if (m.group_returns_annualized) {
const rows = m.group_returns_annualized.map((r, i) => {
const s = m.group_sharpe ? num(m.group_sharpe[i], 2) : 'N/A';
const d = m.group_mdd ? pct(m.group_mdd[i], 1) : 'N/A';
const lb = i === 0 ? ' (低)' : i === m.group_returns_annualized.length - 1 ? ' (高)' : '';
return `<tr><td style="font-weight:600;color:${Q_COLORS[i]}">Q${i+1}${lb}</td><td>${pct(r,1)}</td><td>${s}</td><td>${d}</td></tr>`;
}).join('');
qTable = `<table class="quintile-table"><tr><th>分组</th><th>年化收益</th><th>Sharpe</th><th>最大回撤</th></tr>${rows}</table>`;
}
// Determine chart availability
const hasCharts = hasChartData(f);
let chartHTML = '';
if (hasCharts) {
const tabs = [];
if (f.nav_data) tabs.push(`<button class="chart-tab active" onclick="switchChart(${idx},'nav',this)">📈 净值曲线</button>`);
if (f.ic_data) tabs.push(`<button class="chart-tab${!f.nav_data ? ' active' : ''}" onclick="switchChart(${idx},'ic',this)">📊 IC 时序</button>`);
chartHTML = `<div class="detail-section"><h3>📉 回测图表</h3><div class="chart-tabs">${tabs.join('')}</div><div class="chart-container"><canvas id="detailChart"></canvas></div></div>`;
}
let lessonsHTML = '';
if (f.lessons_learned && f.lessons_learned.length) {
lessonsHTML = `<ul class="lessons">${f.lessons_learned.map(l => `<li>${l}</li>`).join('')}</ul>`;
}
panel.innerHTML = `
<button class="close-btn" onclick="closeDetail()">✕</button>
<h2 style="margin-bottom:24px;font-size:1.4rem">${f.name} <span style="color:var(--text2);font-weight:400;font-size:1rem">${f.name_en}</span></h2>
<div class="detail-section"><h3>📋 因子概述</h3>
<div style="display:grid;grid-template-columns:120px 1fr;gap:8px 16px;font-size:0.9rem">
<span style="color:var(--text2)">假设</span><span>${f.hypothesis || '-'}</span>
<span style="color:var(--text2)">预期方向</span><span>${f.expected_direction || '-'}</span>
<span style="color:var(--text2)">因子类型</span><span>${f.factor_type || '-'}</span>
<span style="color:var(--text2)">股票池</span><span>${f.stock_pool}</span>
<span style="color:var(--text2)">回测区间</span><span>${f.period}</span>
<span style="color:var(--text2)">调仓周期</span><span>${f.rebalance_freq}天</span>
<span style="color:var(--text2)">交易成本</span><span>${f.cost ? (f.cost*100).toFixed(1)+'% 单边' : '无'}</span>
</div>
</div>
<div class="detail-section"><h3>🧮 计算公式</h3><div class="formula-box">${f.formula_detail || f.formula}</div></div>
${m.ic_mean != null ? `
<div class="detail-section"><h3>📊 核心指标</h3>
<div class="metrics-grid">
<div class="metric-box"><div class="label">IC 均值</div><div class="value ${Math.abs(m.ic_mean) > 0.03 ? 'good' : 'bad'}">${num(m.ic_mean)}</div></div>
<div class="metric-box"><div class="label">Rank IC</div><div class="value">${num(m.rank_ic)}</div></div>
<div class="metric-box"><div class="label">IR</div><div class="value ${Math.abs(m.ir) > 0.3 ? 'good' : 'bad'}">${num(m.ir)}</div></div>
<div class="metric-box"><div class="label">IC 显著</div><div class="value ${(m.ic_significant || (m.ic_t && Math.abs(m.ic_t) >= 1.96)) ? 'good' : 'bad'}">${(m.ic_significant || (m.ic_t && Math.abs(m.ic_t) >= 1.96)) ? '✓ 显著 (t=' + num(m.ic_t, 2) + ')' : '✗ 不显著'}</div></div>
<div class="metric-box"><div class="label">单调性</div><div class="value ${m.monotonicity >= 0.7 ? 'good' : m.monotonicity >= 0.5 ? 'neutral' : 'bad'}">${num(m.monotonicity, 2)}</div></div>
<div class="metric-box"><div class="label">多空年化</div><div class="value ${m.long_short_annual_return > 0 ? 'good' : 'bad'}">${pct(m.long_short_annual_return, 1)}</div></div>
<div class="metric-box"><div class="label">多空 Sharpe</div><div class="value ${m.long_short_sharpe >= 1 ? 'good' : m.long_short_sharpe >= 0.5 ? 'neutral' : 'bad'}">${num(m.long_short_sharpe, 2)}</div></div>
<div class="metric-box"><div class="label">多空 MDD</div><div class="value bad">${pct(m.long_short_mdd, 1)}</div></div>
</div>
</div>
${qTable ? `<div class="detail-section"><h3>📶 分层回测</h3>${qTable}</div>` : ''}
` : '<div class="detail-section"><h3>📊 核心指标</h3><p style="color:var(--text2)">暂无回测数据</p></div>'}
${chartHTML}
<div class="detail-section"><h3>💡 结论</h3><div class="conclusion-box">${f.conclusion || '暂无结论'}${lessonsHTML}</div></div>
`;
panel.classList.add('show');
panel.scrollIntoView({ behavior: 'smooth', block: 'start' });
// Load and render charts
if (hasCharts) {
if (f.nav_data) {
setTimeout(() => renderNavChart(idx), 100);
} else if (f.ic_data) {
setTimeout(() => renderIcChart(idx), 100);
}
}
}
function closeDetail() {
document.getElementById('detailPanel').classList.remove('show');
document.querySelectorAll('.factor-card').forEach(c => c.classList.remove('active'));
if (navChart) { navChart.destroy(); navChart = null; }
if (icChart) { icChart.destroy(); icChart = null; }
}
function switchChart(idx, type, btn) {
document.querySelectorAll('.chart-tab').forEach(t => t.classList.remove('active'));
btn.classList.add('active');
if (type === 'nav') renderNavChart(idx); else renderIcChart(idx);
}
async function renderNavChart(idx) {
const f = FACTORS[idx];
const data = await loadNavData(f);
if (!data) return;
if (navChart) navChart.destroy();
if (icChart) { icChart.destroy(); icChart = null; }
const ctx = document.getElementById('detailChart').getContext('2d');
const datasets = [];
const keys = Object.keys(data.series).filter(k => k.startsWith('group_')).sort();
keys.forEach((key, i) => {
const gn = parseInt(key.split('_')[1]) - 1;
let lb = `Q${gn+1}`;
if (gn === 0) lb += ' (低)';
if (gn === keys.length - 1) lb += ' (高)';
datasets.push({
label: lb, data: data.series[key],
borderColor: Q_COLORS[gn], backgroundColor: 'transparent',
borderWidth: gn === 0 || gn === keys.length - 1 ? 2 : 1.2,
pointRadius: 0, tension: 0.1
});
});
if (data.series.long_short) {
datasets.push({
label: 'Long-Short', data: data.series.long_short,
borderColor: Q_COLORS[5], backgroundColor: 'transparent',
borderWidth: 2.5, borderDash: [6, 3], pointRadius: 0, tension: 0.1
});
}
navChart = new Chart(ctx, {
type: 'line',
data: { labels: data.dates, datasets },
options: {
responsive: true, maintainAspectRatio: false,
interaction: { mode: 'index', intersect: false },
plugins: {
legend: { position: 'top', labels: { color: '#8b8fa3', usePointStyle: true, pointStyle: 'line' } },
tooltip: { backgroundColor: '#1a1d29', borderColor: '#2a2d3a', borderWidth: 1, titleColor: '#e4e6eb', bodyColor: '#8b8fa3',
callbacks: { label: c => `${c.dataset.label}: ${c.parsed.y.toFixed(3)}` } }
},
scales: {
x: { type: 'time', time: { unit: 'month', tooltipFormat: 'yyyy-MM-dd' }, ticks: { color: '#8b8fa3', maxTicksLimit: 12 }, grid: { color: 'rgba(42,45,58,0.5)' } },
y: { ticks: { color: '#8b8fa3' }, grid: { color: 'rgba(42,45,58,0.5)' } }
}
}
});
}
async function renderIcChart(idx) {
const f = FACTORS[idx];
const data = await loadIcData(f);
if (!data) return;
if (icChart) icChart.destroy();
if (navChart) { navChart.destroy(); navChart = null; }
const ctx = document.getElementById('detailChart').getContext('2d');
const colors = data.ic.map(v => v >= 0 ? 'rgba(34,197,94,0.6)' : 'rgba(239,68,68,0.6)');
const cumIc = []; let s = 0;
data.ic.forEach(v => { s += v; cumIc.push(s); });
icChart = new Chart(ctx, {
type: 'bar',
data: {
labels: data.dates,
datasets: [
{ label: 'IC', data: data.ic, backgroundColor: colors, borderWidth: 0, yAxisID: 'y', order: 2 },
{ label: 'Cumulative IC', data: cumIc, type: 'line', borderColor: 'rgba(79,140,255,0.8)', backgroundColor: 'transparent', borderWidth: 2, pointRadius: 0, yAxisID: 'y1', order: 1 }
]
},
options: {
responsive: true, maintainAspectRatio: false,
interaction: { mode: 'index', intersect: false },
plugins: {
legend: { position: 'top', labels: { color: '#8b8fa3' } },
tooltip: { backgroundColor: '#1a1d29', borderColor: '#2a2d3a', borderWidth: 1, titleColor: '#e4e6eb', bodyColor: '#8b8fa3' }
},
scales: {
x: { type: 'time', time: { unit: 'month', tooltipFormat: 'yyyy-MM-dd' }, ticks: { color: '#8b8fa3' }, grid: { color: 'rgba(42,45,58,0.5)' } },
y: { position: 'left', ticks: { color: '#8b8fa3' }, grid: { color: 'rgba(42,45,58,0.5)' }, title: { display: true, text: 'IC', color: '#8b8fa3' } },
y1: { position: 'right', ticks: { color: '#4f8cff' }, grid: { display: false }, title: { display: true, text: 'Cumulative IC', color: '#4f8cff' } }
}
}
});
}
/* ====================== INIT ====================== */
loadFactors();
</script>
</body>
</html>