历史回放
原能力
按固定输入闭包回放历史,区分原样复现与假设条件下的重新计算。(合同附件 R7 19.4)
首选项目
Qlib(MIT)。 Qlib
匹配范围
模拟回测、锁定数据和版本重建。
源码
Qlib · def backtest(
qlib/backtest/__init__.py · 217–230 行。 在 GitHub 查看源码 · 许可证与声明
源码片段
def backtest(
start_time: Union[pd.Timestamp, str],
end_time: Union[pd.Timestamp, str],
strategy: Union[str, dict, object, Path],
executor: Union[str, dict, object, Path],
benchmark: str = "SH000300",
account: Union[float, int, dict] = 1e9,
exchange_kwargs: dict = {},
pos_type: str = "Position",
) -> Tuple[PORT_METRIC, INDICATOR_METRIC]:
"""initialize the strategy and executor, then backtest function for the interaction of the outermost strategy and
executor in the nested decision execution
Parameters
- # Copyright (c) Microsoft Corporation.
DVC · def to_lockfile(
dvc/stage/serialize.py · 195–208 行。 在 GitHub 查看源码 · 许可证与声明
源码片段
def to_lockfile(stage: "PipelineStage", **kwargs) -> dict:
assert stage.name
return {stage.name: to_single_stage_lockfile(stage, **kwargs)}
def to_single_stage_file(stage: "Stage", **kwargs):
state = stage.dumpd(**kwargs)
# When we load a stage we parse yaml with a fast parser, which strips
# off all the comments and formatting. To retain those on update we do
# a trick here:
# - reparse the same yaml text with a slow but smart ruamel yaml parser
# - apply changes to a returned structure
# - serialize it
实现与验收要点
历史可得性、真实操作、许可和原决策状态回放。