Historical market data for backtesting must match the decision clock用于回测的历史市场数据必须匹配决策时钟
Choose data by the strategy’s information set, not by the largest advertised history. A daily fundamental strategy needs point-in-time statements, filing availability, corporate actions and historical universe membership. An intraday strategy needs exchange calendars, timestamps, quote or trade granularity, missing-bar policy, latency assumptions and realistic spread. A dataset can be accurate today yet invalid for a past decision if it contains later revisions.
应按策略的信息集选数据,而不是按宣传的最长历史选数据。日频基本面策略需要时点正确的报表、申报可用时间、公司行动与历史成分;日内策略需要交易日历、时间戳、报价或成交粒度、缺失K线策略、延迟假设与现实价差。即使数据今天准确,只要包含后续修订,也可能不适合模拟过去决策。
Active, delisted, renamed, acquired and multi-class securities; historical index or screen membership.
活跃、退市、更名、被收购和多股类证券,以及历史指数或筛选成分。
Availability timestamp, revision, fiscal period, source, units, currency and version.
可用时间、修订、财期、来源、单位、币种与版本。
Signal delay, next eligible price, bid-ask spread, fees, slippage, volume and market impact.
信号延迟、下一可成交价格、买卖价差、费用、滑点、成交量与市场冲击。
Use this guide when data quality can change the backtest conclusion当数据质量可能改变回测结论时,请使用本指南
This guide is for quantitative researchers, AI investment-agent engineers, backtesting-platform teams, data engineers, and model-risk reviewers who need a historical dataset that can be explained and reproduced. It covers research and controlled simulation, not autonomous order placement or a promise that a strategy will work live.
本指南适合量化研究人员、AI 投资智能体工程师、回测平台团队、数据工程师与模型风险审核人员,目标是构建可解释、可复现的历史数据集。内容聚焦研究与受控模拟,不涉及自主下单,也不承诺策略在实盘中有效。
Reconstruct historical constituents, features, prices and costs at every decision date.
在每个决策日重建历史成分、特征、价格与成本。
Normalize providers without losing raw payloads, timestamps, schemas or lineage.
规范化供应商数据,同时保留原始载荷、时间戳、结构与血缘。
Prove which data, tool, parameters and code produced each research result.
证明每项研究结果由哪些数据、工具、参数与代码产生。
Write the research contract before downloading data下载数据前先写清研究契约
Specify the decision time, eligible universe, asset class, venue, currency, timezone, regular or extended session, required granularity, adjustment policy, execution delay, costs, and train–validation–test windows. If any field is undecided, two engineers can build different datasets for the same strategy and both appear correct.
应先明确决策时间、可投资范围、资产类别、交易场所、币种、时区、常规或盘前盘后时段、数据粒度、复权规则、执行延迟、成本以及训练—验证—测试窗口。只要其中一项未定义,两名工程师就可能为同一策略构建不同数据集,而且都看似正确。
Separate raw history, point-in-time joins, simulation, and audit分离原始历史、时点连接、模拟与审计
Keep provider ingestion independent from the research-ready dataset. Raw payloads and schemas feed a versioned security master, exchange calendar and corporate-action store. Point-in-time joins create immutable research snapshots; the backtest engine consumes those snapshots with an explicit execution model, while an audit layer records data, code, parameters and results.
供应商采集层应与研究就绪数据集分离。原始载荷与结构进入版本化证券主数据、交易日历和公司行动存储;时点连接生成不可变研究快照;回测引擎通过明确执行模型消费这些快照;审计层记录数据、代码、参数与结果。
Requests, payloads, schemas, retrieval times and provider identifiers.
请求、载荷、结构、获取时间与供应商标识。
Security identity, symbol history, venues, sessions and corporate actions.
证券身份、代码历史、场所、交易时段与公司行动。
As-of joins, missing-data rules, adjustment policy and validation reports.
As-of 连接、缺失数据规则、复权策略与验证报告。
Signals, eligible fills, costs, portfolio accounting and risk constraints.
信号、可成交价格、成本、组合记账与风险约束。
Locked time windows, tuning boundaries and final evaluation policy.
锁定时间窗口、调参边界与最终评估策略。
Dataset version, code hash, parameters, seed, logs and generated reports.
数据集版本、代码哈希、参数、随机种子、日志与生成报告。
Build a point-in-time backtesting dataset in eight controlled steps通过八个受控步骤构建时点正确的回测数据集
Store effective membership dates and include securities that later disappeared.
保存成分生效日期,并包含后来消失的证券。
Preserve vendor fields, timezone, venue, interval, request and retrieval timestamp.
保留供应商字段、时区、场所、周期、请求与获取时间。
Keep splits, dividends, mergers, spin-offs and symbol changes separately from raw bars.
把拆股、分红、并购、分拆与代码变更和原始K线分开保存。
Use when a record became observable, not only the fiscal or event date it describes.
使用记录实际可观察时间,而不只是其描述的财期或事件日期。
Delay fills appropriately and model spread, fees, slippage, borrow and capacity.
适当延后成交,并建模价差、费用、滑点、借券与容量。
Separate training, tuning and evaluation; preserve parameters, code and data hashes.
分离训练、调参与评估,并保存参数、代码和数据哈希。
Test known splits, delistings, holidays, missing intervals and revision dates.
测试已知拆股、退市、节假日、缺失周期与修订日期。
Publish an immutable manifest tying dataset, code, configuration and result together.
发布不可变清单,把数据集、代码、配置与结果绑定在一起。
Split time forward instead of randomly shuffling history按时间向前切分,而不是随机打乱历史
Random cross-validation lets later market regimes influence earlier training folds and breaks the chronology the strategy will face in production. Use expanding or rolling training windows, tune only inside the historical portion, and evaluate on the next untouched interval. Add a gap or embargo when labels, features or positions overlap the split boundary.
随机交叉验证会让后来的市场环境影响更早的训练折,并破坏策略在生产中面对的时间顺序。应使用扩展或滚动训练窗口,只在历史部分调参,再在下一个未触碰区间评估。当标签、特征或持仓跨越切分边界时,应增加 gap 或 embargo。
Freeze feature definitions and transformations within each training window. Do not normalize using statistics calculated from the full sample.
在每个训练窗口内冻结特征定义与转换,不能使用完整样本统计量进行标准化。
Choose parameters on a validation interval that precedes the test interval. Repeated test inspection turns the test set into training data.
在测试区间之前的验证区间选择参数。反复查看测试结果会让测试集变成训练数据。
Run the final holdout only after data, features, parameters and cost assumptions are frozen; report each window, not only the aggregate.
只有在数据、特征、参数与成本假设冻结后才运行最终留出集,并报告每个窗口,而不只报告汇总值。
The official scikit-learn TimeSeriesSplit documentation describes time-ordered folds and its optional gap parameter.
官方 scikit-learn TimeSeriesSplit 文档说明了按时间排序的折叠方式和可选 gap 参数。
Stop the shortcuts that make a backtest look better than reality阻止让回测表现优于现实的捷径
A universe built from today’s members silently removes bankruptcies, delistings and removals. Reconstruct membership on each decision date.
用今天的成分构造历史范围,会静默删除破产、退市和被剔除标的。必须按每个决策日重建成分。
A year-end statement was not known at year-end. Join by filing or release availability and preserve later revisions separately.
年末报表并不会在年末立即可知。应按申报或发布日期连接,并单独保存后续修订。
Keep raw values and event tables. Apply one documented policy consistently to signals, fills, shares and portfolio accounting.
保留原始值与事件表,对信号、成交、股数和组合记账一致应用一套书面策略。
A close-based signal cannot automatically fill at the same close. Add decision delay, spread, liquidity, fees and market-impact assumptions.
基于收盘价生成的信号不能自动按同一收盘价成交。应加入决策延迟、价差、流动性、费用与市场冲击。
Choose daily, intraday, trade or quote data from the execution model根据执行模型选择日频、日内、成交或报价数据
Daily OHLCV can be sufficient when signals are formed after the close and orders execute no earlier than the next eligible session. Intraday bars are useful for time-of-day rules, but they compress the sequence of trades and quotes inside each interval. Trade data observes executions without showing the full opportunity set; quote data adds bid, ask and spread information but creates much larger storage and processing requirements. More granularity is not automatically more truth—the strategy must define which event could trigger a decision and which later event could fill it.
当信号在收盘后形成、订单最早在下一可交易时段执行时,日频OHLCV可能足够。日内K线适合分时规则,但会压缩周期内成交与报价的先后顺序。成交数据能看到实际成交,却不展示完整机会集合;报价数据增加买价、卖价和价差信息,同时显著提高存储与处理要求。粒度更细不等于更真实,策略必须定义哪个事件能够触发决策、哪个后续事件能够成交。
Verify session date, official close definition, split and dividend treatment, non-trading days, stale prices and next-session execution.
核验交易日、官方收盘定义、拆股与分红处理、非交易日、过期价格和下一时段执行。
Verify bar boundaries, timezone, daylight saving, auction periods, extended hours, interval gaps and whether bars are empty or absent.
核验K线边界、时区、夏令时、集合竞价、盘前盘后、周期缺口,以及无成交时K线为空还是缺失。
Verify venue, condition codes, corrections, cancellations, sequence, quote side, NBBO assumptions and timestamp precision before simulating orders.
模拟订单前核验交易场所、条件代码、更正、取消、序列、报价方向、NBBO假设与时间戳精度。
Schema drift also matters. Vendor fields, enum values, endpoint defaults and adjustment behavior can change after the data is first downloaded. Store a schema version and raw payload alongside normalized columns. Treat a backfill as a new dataset version, compare row counts and value changes, and never overwrite the snapshot that produced a reported result.
结构漂移同样重要。供应商字段、枚举值、端点默认值和复权行为可能在首次下载后变化。应在规范列旁保存结构版本与原始载荷,把回填视为新数据版本,比较行数和数值变化,并且绝不覆盖曾生成报告结果的快照。
Version the dataset contract and enforce backward as-of joins版本化数据集契约,并执行向后 as-of 连接
The manifest should make the data decision reproducible without reading notebook comments. Store it beside the immutable dataset and validate it before every run.
数据清单应让团队无需阅读 Notebook 注释也能复现数据决策。把它与不可变数据集放在一起,并在每次运行前验证。
{
"dataset_version": "us-equity-pit-2026-07",
"universe_as_of": "2024-01-01",
"include_delisted": true,
"session": "regular",
"timezone": "America/New_York",
"bar_interval": "1d",
"price_adjustment": "split_and_dividend",
"feature_time_field": "available_at",
"fill_rule": "next_session_open",
"cost_model": {"commission_bps": 1, "slippage_bps": 5}
}
For features that arrive irregularly, sort both tables and join each decision row only to the latest record already available. A forward join leaks future information.
对于不规则到达的特征,应先排序两张表,并让每个决策行只连接当时已经可用的最新记录。向前连接会泄露未来信息。
features = features.sort_values("available_at")
decisions = decisions.sort_values("decision_at")
dataset = pd.merge_asof(
decisions,
features,
left_on="decision_at",
right_on="available_at",
by="instrument_id",
direction="backward",
allow_exact_matches=True
)
assert (dataset["available_at"] <= dataset["decision_at"]).all()
A provider such as FMP can supply one layer of a prototype, but verify history, adjustment behavior, inactive-symbol coverage, limits and rights against the current account. Keep the provider response and retrieval timestamp beside normalized columns.
FMP 等供应商可以提供原型中的一个数据层,但仍应对照当前账户验证历史范围、复权行为、非活跃证券覆盖、限制与权利,并在规范列旁保存供应商响应与获取时间。
Implementation references: pandas merge_asof and FMP API quickstart.
实施资料:pandas merge_asof 与 FMP API 快速入门。
Reject a historical dataset that cannot reproduce the same run无法复现同一运行的历史数据集应被拒绝
- Coverage:覆盖: expected sessions, symbols, venues and delistings with explicit gap reports. 预期交易日、标的、场所与退市覆盖,并有明确缺口报告。
- Time:时间: UTC normalization, exchange calendar, daylight-saving rules and observable-time joins. UTC规范、交易所日历、夏令时规则与可观察时间连接。
- Economics:经济性: splits, dividends, fees, spread, slippage, borrow and capacity. 拆股、分红、费用、价差、滑点、借券与容量。
- Reproducibility:可复现: immutable snapshot, schema version, code hash, parameters, seed and run log. 不可变快照、结构版本、代码哈希、参数、随机种子与运行日志。
- Rights:权利: permitted storage, derived use, team access, publication and redistribution. 允许的存储、衍生使用、团队访问、发布与再分发。
- Identity:身份: stable instrument IDs, symbol changes, listings and multi-class securities resolve correctly. 稳定证券 ID、代码变更、上市地与多股类证券解析正确。
- Bars:K 线: high is not below open or close, low is not above them, and interval boundaries match the calendar. 最高价不低于开盘或收盘价,最低价不高于它们,周期边界与交易日历一致。
- Actions:公司行动: known splits, dividends, mergers and delistings produce the documented treatment. 已知拆股、分红、并购与退市得到书面规则规定的处理。
- Leakage:泄漏: every feature satisfies available_at ≤ decision_at and revised values remain separate vintages. 每个特征满足 available_at ≤ decision_at,修订值保留为独立版本。
- Errors:错误: no record, closed market, entitlement denial, timeout, rate limit and provider failure remain distinct. 无记录、休市、授权拒绝、超时、限流与供应商失败可明确区分。
Bound every historical-data build before it starts在历史数据构建开始前设置边界
Use scoped secrets, redact logs, bind provider entitlements to the workload, and restrict storage or redistribution by contract.
使用范围受限的密钥,对日志脱敏,把供应商授权绑定到工作负载,并按合同限制存储或再分发。
Cap symbols, venues, lookback, schema, page count, retries and response size. Cache immutable raw partitions and avoid re-downloading unchanged history.
限制证券、场所、回看期、结构、页数、重试与响应大小。缓存不可变原始分区,避免重复下载未变化历史。
Track provider time, network transfer, normalization, PIT joins, validation and snapshot publication—not only API response latency.
跟踪供应商、网络传输、规范化、PIT 连接、验证与快照发布,而不只是 API 响应延迟。
Trace suspicious performance back to the data contract把可疑表现追溯到数据契约
Use discover, inspect, probe, call, validate, and audit as separate gates把 discover、inspect、probe、call、validate 与 audit 作为独立门禁
Find historical price, security-master, corporate-action or filing capabilities for the required scope.
按所需范围发现历史价格、证券主数据、公司行动或监管文件能力。
Review parameters, coverage, provider identity, examples, output shape and quality signals.
检查参数、覆盖、供应商身份、示例、输出结构与质量信号。
Validate candidate parameters and obtain a quote before a large historical execution.
在大规模历史数据执行前验证候选参数并取得报价。
Execute bounded requests and preserve search, tool, execution and provider request IDs.
执行有界请求,并保留搜索、工具、执行与供应商请求 ID。
Apply identity, calendar, timestamp, adjustment, gap, rights and reproducibility checks.
应用身份、日历、时间戳、复权、缺口、权利与可复现性检查。
Use usage history and the credits ledger to reconcile outcomes and final settlement.
使用调用历史与积分账本核对结果和最终结算。
QVeris can help AI workflows call authorized market, statement and filing tools with bounded dates, quotas, provider identity and source metadata. Preserve raw evidence before any model summary.
QVeris可让AI工作流在日期、额度、供应商身份与来源元数据约束下调用已授权行情、报表与文件工具。模型总结前应先保存原始证据。
QVeris does not remove look-ahead or survivorship bias, guarantee fills, validate a strategy, grant data rights or promise live performance. Those require research design, testing, contracts and human review.
QVeris不会自动消除前视或幸存者偏差,不保证成交,不验证策略,不授予数据权利,也不承诺实盘表现。这些需要研究设计、测试、合同与人工复核。
Related guides: market data MCP server, financial data MCP server, and financial statement analysis.
相关指南:市场数据 MCP 服务器、金融数据 MCP 服务器以及财务报表分析。
Historical market data for backtesting questions用于回测的历史市场数据常见问题
What historical market data is needed for backtesting?回测需要哪些历史市场数据?
Match universe, granularity, timestamps, corporate actions, delistings, features and execution assumptions to the strategy’s decision clock.
让投资范围、粒度、时间戳、公司行动、退市、特征与执行假设匹配策略决策时钟。
Should backtests use adjusted or unadjusted prices?回测应使用复权还是未复权价格?
Preserve both raw prices and events, then apply a documented policy consistently across signals, fills, shares and accounting.
保留原始价格与事件,再对信号、成交、股数和记账一致应用书面策略。
How do I avoid survivorship bias?如何避免幸存者偏差?
Use historical membership and include delisted, acquired and renamed securities that were investable at each simulated date.
使用历史成分,并包含每个模拟日期可投资的退市、被收购和更名证券。
How do I avoid look-ahead bias?如何避免前视偏差?
Join every feature by availability time and delay the simulated action until after the information could be observed.
按可用时间连接每个特征,并把模拟行动延后到信息可观察之后。
Is free historical data enough for backtesting?免费历史数据足够回测吗?
It can support prototypes, but quality depends on delistings, adjustments, gaps, timestamps, history, rights and reproducibility—not price alone.
可用于原型,但质量取决于退市、复权、缺口、时间戳、历史、权利与可复现性,而不只是价格。
Can QVeris help with backtesting data?QVeris能帮助处理回测数据吗?
QVeris can govern authorized tools and provenance, while the research system still owns time alignment, bias control, execution and licensing.
QVeris可治理已授权工具与来源,研究系统仍负责时间对齐、偏差控制、执行与许可。
Are OHLCV bars enough for intraday backtesting?OHLCV K 线足够用于日内回测吗?
Only when the strategy and fill model do not require the sequence, spread, depth or venue information hidden inside each bar. Execution-sensitive research may need trades, quotes or order-book data.
只有当策略与成交模型不需要 K 线内部被压缩的事件顺序、价差、深度或场所信息时才可能足够。执行敏感研究可能需要成交、报价或订单簿数据。
Verify timestamps, joins, evaluation, providers, and MCP behavior核对时间戳、连接、评估、供应商与 MCP 行为
Databento timestamp, venue, instrument and schema conventionsDatabento 时间戳、场所、证券与结构约定
pandas merge_asof documentationpandas merge_asof 文档
scikit-learn TimeSeriesSplit documentationscikit-learn TimeSeriesSplit 文档
Financial Modeling Prep API quickstartFinancial Modeling Prep API 快速入门

