tradingSystem/research/score_recurrence_20261029/dashboard.html.tpl

56 lines
21 KiB
Smarty
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>反复活跃股票的持有期矩阵</title><style>
:root{font-family:-apple-system,BlinkMacSystemFont,"PingFang SC","Microsoft YaHei",sans-serif;color:#233244;background:#f4f6f8;font-size:14px}*{box-sizing:border-box}body{margin:0}main{max-width:1540px;margin:auto;padding:24px}header{margin-bottom:18px}h1{font-size:28px;margin:0 0 8px;font-weight:650}h2{font-size:18px;margin:0}p{line-height:1.65;margin:6px 0}.muted{color:#607084}.tag{font-size:12px;color:#235a80;background:#e4eff8;border-radius:4px;padding:4px 8px;display:inline-block;margin:8px 6px 0 0}.panel{background:white;border:1px solid #e0e6ed;border-radius:12px;padding:18px;margin-bottom:16px}.filters{display:grid;grid-template-columns:repeat(6,minmax(145px,1fr));gap:12px}label{display:block;color:#607084;font-size:12px}select{margin-top:5px;width:100%;height:36px;border:1px solid #cbd4df;border-radius:6px;background:white;color:#233244;padding:0 7px;font-size:13px}select:disabled{background:#f1f3f5;color:#8d99a6}.actions{display:flex;gap:8px;flex-wrap:wrap;margin:14px 0 4px}button{border:1px solid #bdcddd;border-radius:6px;background:#fff;color:#2c5271;padding:8px 12px;cursor:pointer;font-size:13px}button:hover{background:#eaf2f9}button.primary{background:#265f87;color:white;border-color:#265f87}.charts{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}.charts.wide{grid-template-columns:1fr}.chart-panel{background:white;border:1px solid #e0e6ed;border-radius:12px;padding:16px;min-width:0}.chart-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:6px}.chart-sub{font-size:12px;min-height:34px;color:#607084;line-height:1.5}.canvas-box{position:relative;height:800px}.legend{display:flex;align-items:center;gap:10px;font-size:12px;margin:8px auto;justify-content:center}.gradient{height:12px;width:180px;background:linear-gradient(90deg,#2166ac,#f7f7f7,#b2182b);border:1px solid #e0e6ed}.grey{display:inline-block;background:#e1e5ea;width:12px;height:12px;margin-right:4px}.notice{padding:11px 14px;border-left:3px solid #7199b9;background:#eef4f8;font-size:13px;line-height:1.6;margin:14px 0}.kpis{display:grid;grid-template-columns:repeat(4,1fr);gap:10px}.kpi{padding:14px;background:#fff;border:1px solid #e0e6ed;border-radius:10px}.kpi strong{display:block;font-size:22px;margin-top:5px}.kpi span{font-size:12px;color:#607084}table{border-collapse:collapse;width:100%;font-size:12px;white-space:nowrap}th,td{padding:8px 10px;border-bottom:1px solid #e6ebf0;text-align:right}th{background:#f3f6f9;font-weight:600;position:sticky;top:0}th:first-child,td:first-child{text-align:left}.scroll{overflow:auto;max-height:530px}#loading{padding:40px;text-align:center;color:#5a7187}footer{font-size:12px;color:#607084;margin:20px 0}a{color:#265f87}.hidden{display:none!important}@media(max-width:1050px){.filters{grid-template-columns:repeat(3,minmax(135px,1fr))}.charts{grid-template-columns:1fr}.kpis{grid-template-columns:repeat(2,1fr)}}@media(max-width:580px){main{padding:12px}h1{font-size:23px}.filters{grid-template-columns:repeat(2,minmax(120px,1fr))}.chart-panel{padding:10px}.canvas-box{min-width:480px}.chart-panel{overflow:auto}}@media print{.filters,.actions,button{display:none}.charts{display:block}.chart-panel{break-inside:avoid;margin:12px 0}body{background:#fff}}
</style></head><body><main>
<header><h1>反复活跃股票的持有期矩阵</h1><p class="muted">固定一个条件,比较持有1至10个交易日。2025年与2026年并排查看,分清绝对收益、频次增量和指数差额。</p><span class="tag">前20个交易日,不含信号当天</span><span class="tag">全市场同一合格池</span><span class="tag">5160组参数 · 389个可用信号日</span></header>
<section class="panel"><div class="filters">
<label>矩阵坐标<select id="view"><option value="count_hold">次数 × 持有日</option><option value="threshold_hold">分数门槛 × 持有日</option><option value="threshold_count">分数门槛 × 次数</option></select></label>
<label>单独考察的分数<select id="score"><option value="smart">smart_score 聪明资金分</option><option value="total">total_score 综合分</option></select></label>
<label>筛选规则<select id="mode"><option value="frequency">仅看前20日次数</option><option value="both">次数足够且当天达标</option><option value="current">只看当天分数</option></select></label>
<label>固定分数门槛<select id="threshold"></select></label><label>固定次数下限 K<select id="k"></select></label><label>固定持有日 H<select id="hold"></select></label>
<label>年份<select id="period"><option value="compare">2025与2026并排</option><option value="2026">仅2026</option><option value="2025">仅2025</option><option value="full">全部历史</option></select></label>
<label>市场阶段<select id="stage"><option value="99">全部阶段</option><option value="1">上涨</option><option value="0">震荡</option><option value="-1">下跌</option></select></label>
<label>阶段划分依据<select id="phase_index"></select></label>
<label>着色指标<select id="metric"><option value="return">平均每批收益</option><option value="delta_k0">增加频次要求的改善</option><option value="delta_current">相对只看当天分数</option><option value="delta_universe">相对共同全市场池</option><option value="index_excess">相对同期指数</option><option value="win30">个股胜率(30基点)</option><option value="active_days">有效信号日数</option><option value="mean_selected">日均入选股票数</option></select></label>
<label>每边费用<select id="fee"><option value="30">30基点净收益</option><option value="60">60基点压力</option><option value="0">0基点毛收益</option></select></label>
<label>同期收益对照指数<select id="benchmark"></select></label>
<label>收益色标范围<select id="scale"><option value="auto">当前两图统一范围</option><option value="1">固定 ±1%</option><option value="2">固定 ±2%</option><option value="5">固定 ±5%</option><option value="10">固定 ±10%</option></select></label>
</div><div class="actions"><button class="primary" id="preset-current">先看单日分数</button><button id="preset-frequency">再看20日频次</button><button id="preset-both">叠加当天达标</button><button id="download-csv">下载当前矩阵CSV</button></div>
<p id="rule" class="muted"></p></section>
<div class="notice">评分日后下一交易日开盘买入,买后H个交易日开盘卖出;卖出受阻顺延。每格是已结束交易的平均批次收益,不是账户累计收益。缺失历史评分不会记为0次;未达20个有效信号日或100笔完成交易的格子标灰。</div>
<div id="loading">正在读取本地矩阵数据…</div><section class="charts" id="charts"></section>
<section class="panel" style="margin-top:16px"><h2 id="detail-title">点击一个格子,查看该行持有1至10日的明细</h2><p class="muted" id="detail-note"></p><div class="scroll"><table><thead><tr><th>年份</th><th>门槛</th><th>次数</th><th>持有日</th><th id="value-heading">当前指标</th><th>毛收益</th><th>30bp净收益</th><th>60bp净收益</th><th>有效日</th><th>完成笔数</th><th>日均入选</th><th>未退出笔数</th></tr></thead><tbody id="details"></tbody></table></div></section>
<footer><p>共同信号窗口:2025-01-22至2026-09-30;行情与退出估值截至2026-10-23。2026-03-19缺评分及其后20个交易日无法形成完整观察窗。历史评分可被覆盖,未能核实首次可用时点,结果属于现存历史分数回放。</p><p>阶段只使用信号日及以前的指数趋势,不改变股票池。收益对照指数可独立选择;同期指数按每笔股票的实际买卖日开盘计算,属于价格收益对照,不是风险中性收益或ETF成交回报。所有年份均为已见历史,少数高收益格不代表稳定最优参数。</p><p><a href="反复活跃与持有期矩阵研究.md">研究报告</a> · <a href="grid.csv.gz">完整压缩CSV</a> · <a href="protocol.json">冻结协议</a> · <a href="window_examples.csv">20日计数实例</a> · <a href="accounts.csv">预设现金账户结果</a></p></footer>
</main><script>/*__CHARTJS__*/</script><script>
const PAYLOAD=/*__PAYLOAD__*/;
const Q=[.5,.6,.7,.8,.9,.95],INDEX={csi300:'沪深300',csi500:'中证500',csi1000:'中证1000',csi2000:'中证2000'},STAGE={'99':'全部阶段','1':'上涨','0':'震荡','-1':'下跌'};
const COL={gross:0,net30:1,net60:2,win30:3,active_days:4,completed:5,mean_selected:6,filled:7,unresolved:8,delayed:9,delta_k0:10,delta_current:11,delta_universe:12,csi300:13,csi500:14,csi1000:15,csi2000:16};
const $=id=>document.getElementById(id),cache=new Map();let charts=[],visible=[],generation=0,selection={q:.8,k:5,h:5},ready=false;
const percent=v=>v==null?'—':(v>=0?'+':'')+(v*100).toFixed(2)+'%';const number=v=>v==null?'—':v.toLocaleString('zh-CN',{maximumFractionDigits:1});
for(const id of ['threshold']){Q.forEach(q=>$(id).add(new Option(q,q)));$(id).value='.8';$(id).value='0.8'}
for(let k=0;k<=20;k++)$('k').add(new Option(k,k));$('k').value='5';for(let h=1;h<=10;h++)$('hold').add(new Option(h,h));$('hold').value='5';
for(const id of ['phase_index','benchmark'])Object.entries(INDEX).forEach(([k,v])=>$(id).add(new Option(v,k)));$('benchmark').value='csi2000';
function state(){return Object.fromEntries([...document.querySelectorAll('select')].map(e=>[e.id,e.value]))}
async function chunk(s,period){const ix=s.stage==='99'?'all':s.phase_index,key=[s.score,period,ix,s.stage].join('|');if(cache.has(key))return cache.get(key);const bytes=Uint8Array.from(atob(PAYLOAD[key]),c=>c.charCodeAt(0));const stream=new Blob([bytes]).stream().pipeThrough(new DecompressionStream('gzip'));const data=JSON.parse(await new Response(stream).text());cache.set(key,data);if(cache.size>8)cache.delete(cache.keys().next().value);return data}
function lookup(data,s,q,k,h){const off=Q.indexOf(Number(q))*43;const config=off+(s.mode==='current'?0:s.mode==='frequency'?1+Number(k):22+Number(k));return data[config*10+Number(h)-1]}
function value(v,s){if(!v)return null;const fee=Number(s.fee)/10000,f=(1-fee)/(1+fee);if(s.metric==='return')return v[s.fee==='0'?0:s.fee==='30'?1:2];if(s.metric.startsWith('delta_'))return v[COL[s.metric]]==null?null:v[COL[s.metric]]*f/(.997/1.003);if(s.metric==='index_excess'){if(v[0]==null||v[COL[s.benchmark]]==null)return null;return v[COL[s.benchmark]]+(v[0]+1)*f-1-v[0]}return v[COL[s.metric]]}
function isCount(s){return ['active_days','mean_selected'].includes(s.metric)}function unit(s){return isCount(s)?(s.metric==='active_days'?'日':'只'):s.metric==='return'||s.metric==='win30'?'%':'百分点'}
function formatted(v,s){if(v==null)return '—';if(isCount(s))return number(v);if(s.metric==='win30')return (v*100).toFixed(1)+'%';return (v>=0?'+':'')+(v*100).toFixed(2)+(unit(s)==='%'?'%':'')}
function supported(v){return v&&v[4]>=20&&v[5]>=100}
function color(v,limit,s){if(v==null)return '#e1e5ea';let z=Math.max(-1,Math.min(1,v/limit));if(isCount(s)||s.metric==='win30')z=Math.max(0,z);const white=[247,247,247],end=z<0?[33,102,172]:[178,24,43];return 'rgb('+white.map((a,i)=>Math.round(a+(end[i]-a)*Math.abs(z))).join(',')+')'}
function rowsFor(s){return s.view==='count_hold'?Array.from({length:21},(_,i)=>i):Q}
function columnsFor(s){return s.view==='threshold_count'?Array.from({length:21},(_,i)=>i):Array.from({length:10},(_,i)=>i+1)}
function pointsFor(data,s){const rows=rowsFor(s),cols=columnsFor(s),out=[];rows.forEach((r,y)=>cols.forEach((c,x)=>{const q=s.view==='count_hold'?Number(s.threshold):r,k=s.view==='count_hold'?r:s.view==='threshold_count'?c:Number(s.k),h=s.view==='threshold_count'?Number(s.hold):c,v=lookup(data,s,q,k,h);out.push({x,y,q,k:s.mode==='current'?0:k,h,v,z:value(v,s),ok:supported(v)})}));return out}
const cells={id:'matrixCells',beforeDraw(chart){const c=chart.ctx;c.save();c.fillStyle='#fff';c.fillRect(0,0,chart.width,chart.height);c.restore()},beforeDatasetsDraw(chart){const {ctx,scales:{x,y}}=chart,opts=chart.options.plugins.matrixCells,s=opts.state;const width=Math.abs(x.getPixelForValue(1)-x.getPixelForValue(0)),height=Math.abs(y.getPixelForValue(1)-y.getPixelForValue(0));ctx.save();for(const p of chart.data.datasets[0].data){const px=x.getPixelForValue(p.x),py=y.getPixelForValue(p.y);ctx.fillStyle=p.ok?color(p.z,opts.limit,s):'#e1e5ea';ctx.fillRect(px-width/2+.7,py-height/2+.7,width-1.4,height-1.4);ctx.textAlign='center';ctx.textBaseline='middle';ctx.font=(width<40?'10':'12')+'px -apple-system, "PingFang SC", sans-serif';ctx.fillStyle=p.ok&&p.z!=null&&Math.abs(p.z)>opts.limit*.58?'#fff':'#273849';let text=p.z==null?'—':isCount(s)?Math.round(p.z).toString():(p.z*100).toFixed(2);if(!p.ok&&p.z!=null)text+='*';ctx.fillText(text,px,py,width-4)}ctx.restore()},afterDraw(chart){const c=chart.ctx;c.save();c.fillStyle='#607084';c.font='10px -apple-system, "PingFang SC", sans-serif';c.textAlign='center';c.fillText('信号截至2026-09-30;行情与退出估值截至2026-10-23;现存历史评分回放',chart.width/2,chart.height-5);c.restore()}};
Chart.register(cells);
function matrix(canvas,data,s,period,limit){const rows=rowsFor(s),cols=columnsFor(s),pts=pointsFor(data,s);return new Chart(canvas,{type:'scatter',data:{datasets:[{data:pts,pointRadius:0,pointHitRadius:23}]},options:{layout:{padding:{bottom:20}},animation:false,responsive:true,maintainAspectRatio:false,devicePixelRatio:2,interaction:{mode:'nearest',intersect:false},plugins:{title:{display:true,text:[`${period==='full'?'全历史':period+'年'} · ${s.score}_score · ${s.mode==='current'?'仅当天':s.mode==='frequency'?'历史频次':'历史频次且当天达标'}`,`${s.view==='count_hold'?'门槛≥'+s.threshold:s.view==='threshold_count'?'持有'+s.hold+'日':s.mode==='current'?'单日筛选':'次数≥'+s.k} · ${s.stage==='99'?'全部阶段':INDEX[s.phase_index]+' '+STAGE[s.stage]} · ${$('metric').selectedOptions[0].text}(${unit(s)})`,`${s.metric==='index_excess'?INDEX[s.benchmark]+'对照 · ':''}${isCount(s)||s.metric==='win30'?'':$('fee').selectedOptions[0].text+' · '}色标上限${formatted(limit,s)};灰格样本不足`],font:{size:11},color:'#233244',padding:{bottom:12}},legend:{display:false},matrixCells:{state:s,limit},tooltip:{enabled:true,callbacks:{title:items=>{const p=items[0].raw;return `门槛 ≥ ${p.q} · ${s.mode==='current'?'仅当天':`前20日 ≥ ${p.k}次`} · 持有${p.h}日`},label:context=>{const p=context.raw;return [`${$('metric').selectedOptions[0].text}:${formatted(p.z,s)} ${unit(s)==='百分点'?'个百分点':''}`,`有效信号日:${p.v[4]};完成交易:${p.v[5]}`,`日均入选:${number(p.v[6])}只;未退出:${p.v[8]}笔`,p.ok?'达到最低展示样本要求':'样本不足,实际数值仅供观察']}}}},scales:{x:{type:'linear',min:-.5,max:cols.length-.5,afterBuildTicks:axis=>axis.ticks=cols.map((_,i)=>({value:i})),ticks:{callback:v=>cols[v],font:{size:12},maxRotation:0},grid:{display:false},title:{display:true,text:s.view==='threshold_count'?'此前20个交易日达标次数下限 K':'持有交易日 H',font:{size:13}}},y:{type:'linear',min:-.5,max:rows.length-.5,reverse:true,afterBuildTicks:axis=>axis.ticks=rows.map((_,i)=>({value:i})),ticks:{callback:v=>rows[v],font:{size:12}},grid:{display:false},title:{display:true,text:s.view==='count_hold'?'此前20日达标次数下限 K':'分数下限(含边界)',font:{size:13}}}},onClick:(event,items)=>{if(items.length){const p=pts[items[0].index];selection={q:p.q,k:p.k,h:p.h};renderDetails(s)}}}})}
function renderDetails(s){$('value-heading').textContent=$('metric').selectedOptions[0].text+'('+unit(s)+')';$('detail-title').textContent=`该条件持有1至10日:${s.score}_score ≥ ${selection.q},${s.mode==='current'?'只看当天':`前20日 ≥ ${selection.k}次`}`;$('detail-note').textContent='点击任一矩阵格可切换此表;灰格的实际值仍保留。日均入选包含对应阶段内无法形成信号的日期。';const lines=[];for(const v of visible){for(let h=1;h<=10;h++){const a=lookup(v.data,s,selection.q,selection.k,h),z=value(a,s);lines.push(`<tr><td>${v.period==='full'?'全历史':v.period}</td><td>${selection.q}</td><td>${s.mode==='current'?'—':selection.k}</td><td>${h}</td><td>${formatted(z,s)}${supported(a)?'':' *'}</td><td>${percent(a[0])}</td><td>${percent(a[1])}</td><td>${percent(a[2])}</td><td>${a[4]}</td><td>${number(a[5])}</td><td>${number(a[6])}</td><td>${a[8]}</td></tr>`)}}$('details').innerHTML=lines.join('')}
async function render(){const turn=++generation;ready=false;let s=state();if(s.mode==='current'&&s.view!=='threshold_hold'){$('view').value='threshold_hold';s=state()}$('threshold').disabled=s.view!=='count_hold';$('k').disabled=s.view!=='threshold_hold'||s.mode==='current';$('hold').disabled=s.view!=='threshold_count';$('phase_index').disabled=s.stage==='99';$('benchmark').disabled=s.metric!=='index_excess';$('fee').disabled=isCount(s)||s.metric==='win30';$('scale').disabled=isCount(s)||s.metric==='win30';const periods=s.period==='compare'?['2025','2026']:[s.period];$('loading').classList.remove('hidden');try{const chunks=await Promise.all(periods.map(p=>chunk(s,p)));if(turn!==generation)return;visible=periods.map((period,i)=>({period,data:chunks[i]}));const all=visible.flatMap(v=>pointsFor(v.data,s)).filter(p=>p.ok&&p.z!=null).map(p=>Math.abs(p.z));let limit=s.scale==='auto'?Math.max(isCount(s)?1:.001,...all):Number(s.scale)/100;if(isCount(s)||s.metric==='win30')limit=Math.max(s.metric==='win30'?1:1,...all);else if(s.scale==='auto')limit=Math.ceil(limit*1000)/1000;charts.forEach(c=>c.destroy());charts=[];$('charts').innerHTML='';$('charts').classList.toggle('wide',s.view==='threshold_count'||periods.length===1);
for(const [i,v] of visible.entries()){const panel=document.createElement('article');panel.className='chart-panel';const phase=s.stage==='99'?'全部阶段':INDEX[s.phase_index]+'划分 · '+STAGE[s.stage],metric=$('metric').selectedOptions[0].text+(s.metric==='index_excess'?' '+INDEX[s.benchmark]:'');panel.innerHTML=`<div class="chart-head"><h2>${v.period==='full'?'全历史':v.period+'年'}</h2><button data-download="${i}">下载PNG</button></div><div class="chart-sub">${phase} · ${metric} · ${isCount(s)||s.metric==='win30'?'':$('fee').selectedOptions[0].text}</div><div class="canvas-box" style="height:${s.view==='count_hold'?820:370}px"><canvas aria-label="${v.period}年参数热力图,明细在下方表格" role="img"></canvas></div><div class="legend"><span>${formatted(isCount(s)||s.metric==='win30'?0:-limit,s)}</span><div class="gradient" style="background:${isCount(s)||s.metric==='win30'?'linear-gradient(90deg,#f7f7f7,#b2182b)':'linear-gradient(90deg,#2166ac,#f7f7f7,#b2182b)'}"></div><span>${formatted(limit,s)} ${unit(s)==='百分点'?'个百分点':''}</span></div><p class="muted" style="font-size:12px"><span class="grey"></span>灰色为样本不足或无样本;*保留实际值。两图使用相同色标${s.scale==='auto'?',切换条件后重算':',超出范围按端点色显示'}。</p>`;$('charts').appendChild(panel);charts.push(matrix(panel.querySelector('canvas'),v.data,s,v.period,limit));panel.querySelector('button').onclick=()=>download(charts[i].toBase64Image(),'矩阵_'+s.score+'_'+v.period+'.png')}
$('rule').textContent=(s.mode==='current'?'只检验当天一个分数门槛。':s.mode==='frequency'?'只检验此前20日达标频次,当天不额外要求达标。':'此前20日达标次数满足要求,同时要求当天分数达标。')+' K=0为同一可观察样本的对照;不含当天,不要求连续。';if(!Q.includes(selection.q))selection.q=.8;if(s.view==='count_hold')selection.q=Number(s.threshold);if(s.view==='threshold_hold'&&s.mode!=='current')selection.k=Number(s.k);renderDetails(s);$('loading').classList.add('hidden');ready=true;window.__dashboardReady=true;window.__dashboardState=s}catch(error){$('loading').textContent='数据读取失败:'+error.message;console.error(error)}}
function download(url,name){const a=document.createElement('a');a.href=url;a.download=name;a.click()}
for(const e of document.querySelectorAll('select'))e.addEventListener('change',render);
$('preset-current').onclick=()=>{$('mode').value='current';$('view').value='threshold_hold';render()};$('preset-frequency').onclick=()=>{$('mode').value='frequency';$('view').value='count_hold';render()};$('preset-both').onclick=()=>{$('mode').value='both';$('view').value='count_hold';render()};
$('download-csv').onclick=()=>{const s=state(),rows=[['年份','分数','门槛','规则','前20日次数下限','持有日','阶段指数','阶段','收益对照指数','费用每边基点','指标','指标值原比例','有效日','完成笔数','日均入选','样本足够']];for(const v of visible)for(const p of pointsFor(v.data,s))rows.push([v.period,s.score,p.q,s.mode,p.k,p.h,s.stage==='99'?'all':s.phase_index,s.stage,s.benchmark,s.fee,s.metric,p.z??'',p.v[4],p.v[5],p.v[6],p.ok]);const blob=new Blob(['\ufeff'+rows.map(r=>r.join(',')).join('\n')],{type:'text/csv;charset=utf-8'}),u=URL.createObjectURL(blob);download(u,'当前矩阵.csv');setTimeout(()=>URL.revokeObjectURL(u),1000)};
window.getDisplayedCell=(period,q,k,h)=>{const s=state(),v=visible.find(v=>v.period===period);return v?lookup(v.data,s,q,k,h):null};render();
</script></body></html>