03 / 回测03 / BACKTESTING

盘口报价变成策略,必须先定义成交。A quote becomes a strategy only after you define execution.

用盘口数据模拟可能的成交,并明确说明每一个把展示流动性转换为模拟交易的假设。Use the order book to model a possible fill, then state every assumption that turns displayed liquidity into a simulated trade.

推荐的市场窗口Recommended market window

如果你只研究市场窗口内部,建议从这个基线开始:For a market-internal backtest, the clean baseline is:

window_start_ts ≤ ts < window_end_ts

归档中也可能有开盘前数据(offset_s < 0)和超过市场时长的开盘后数据。如果研究问题需要,可以保留,但要明确写出这个选择。The archive can contain pre-market rows where offset_s < 0 and post-market rows where the offset is beyond the market duration. Keep them if your research question needs them, and label the choice.

成交模拟规则Fill simulation rules

动作Action建议Use避免Avoid
买入Buy从 ASK 侧由 level 1 向上消耗。Consume the ASK side from level 1 upward.用中间价或 BID 作为买入成交价。Using midpoint or BID as the buy fill.
卖出Sell从 BID 侧由 level 1 向下消耗。Consume the BID side from level 1 downward.用中间价或 ASK 作为卖出成交价。Using midpoint or ASK as the sell fill.
数量Size考虑部分成交、最大深度和队列 / 数量折扣。Apply partial fills, max depth, and a queue/size discount.把展示数量当作保证能成交的数量。Treating displayed size as guaranteed execution.
时间Timing加入明确的决策到下单延迟。Add an explicit decision-to-order delay.假定策略在观测时间点立即成交。Assuming the strategy trades at the observation timestamp.
成本Costs建模费用、滑点以及无效 / 过期订单。Model fees, slippage, and invalid/expired orders.把毛收益当作可执行的净收益。Reporting gross returns as executable net returns.

值得同时报告的三种情景Three scenarios worth reporting

乐观情景Optimistic

较短延迟、高成交比例、较小滑点。适合作为上限,不应作为主要结论。Small delay, high fill ratio, shallow slippage. Useful as an upper bound, not as the main claim.

基准情景Base case

明确延迟、部分成交、深度限制、费用和适度的队列折扣。Explicit delay, partial fills, depth limit, fees, and a modest queue discount.

保守情景Conservative

更长延迟、更低成交比例、更强滑点,并更严格处理缺口和过期报价。Longer delay, lower fill ratio, stronger slippage, and stricter treatment of gaps and stale quotes.

分别比较两边Compare both sides

分别报告 UP 和 DOWN。即使处在同一个窗口,它们的流动性和价差也可能不同。Report UP and DOWN separately. Their liquidity and spread can be different even inside the same market window.

最低质量报告Minimum quality report

一份有用的结果应该展示样本覆盖、有效结算市场、缺失区间、理论成交与部分成交、深度档位、延迟、成交比例、费用、滑点,以及按日期和持有期切分的结果。A useful result should show sample coverage, valid outcome markets, missing intervals, theoretical versus partial fills, depth levels, delay, fill ratio, fees, slippage, and date/horizon slices.

当前数据集不包含底层 BTC 价格源、完整的原始 WebSocket event ID、市场规则快照或逐笔成交明细。如果模型依赖这些输入,需要另行补充。The dataset has no underlying BTC price feed, complete raw WebSocket event IDs, market-rule snapshot, or individual trade tape. Add those inputs separately if your model depends on them.