Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ CLAUDE.local.md
.claude/docs/

# Local work-in-progress notes
TODO.md
TODO.md

# Results
results
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# hqbacktest - A股量化策略回测与交易模拟引擎

<p align="center">
<img src="https://img.shields.io/badge/status-v0.1.4-blue"/>
<img src="https://img.shields.io/pypi/v/hqbacktest.svg"/>
<img src="https://img.shields.io/pypi/pyversions/hqbacktest.svg"/>
<img src="https://img.shields.io/badge/hqdata-%3E%3D0.1.22-blue"/>
<img src="https://img.shields.io/badge/python-%3E%3D3.10-blue"/>
</p>
Expand Down Expand Up @@ -113,6 +114,17 @@ result.save("results/moving-average")

命令行(推荐用于 CI 与可复现实验):

`hqbacktest` 不下载数据,命令行示例需要你本地已有一份 `hqdata` CSV 快照。先用 `hqdata` CLI 抓一段真实日线(换成你自己的 tushare/ricequant token 和日期区间):

```bash
hqdata --source tushare calendar --start 20260123 --end 20260212
hqdata --source tushare stock-list --start 20260123 --end 20260212
hqdata --source tushare stock-daily --start 20260123 --end 20260212
hqdata --source tushare stock-factor --start 20260123 --end 20260212
```

再跑仓库自带的 [`configs/moving_average.toml`](configs/moving_average.toml)(日期区间需要和你抓取的快照区间对上):

```bash
hqbacktest run --config configs/moving_average.toml --output results/moving-average
```
Expand Down
26 changes: 26 additions & 0 deletions configs/moving_average.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Example config for `hqbacktest run` using the `examples.moving_average`
# strategy against a real hqdata CSV snapshot.
#
# The date range below assumes you already have a `tushare` snapshot under
# `~/.hqdata/tushare` covering 20260123-20260212 (fetch it first with the
# `hqdata` CLI, see README "配置数据源"). If your snapshot covers a
# different range, change `start_date` / `end_date` accordingly -- they
# must fall within calendar.csv's trading days AND have stock_daily /
# stock_list / stock_factor CSVs on disk for every day in range.

[start]
start_date = "20260123" # first trading day with data in your snapshot
end_date = "20260212" # last trading day with data in your snapshot

[capital]
initial_cash = "100000"

[data]
source = "tushare" # or "ricequant"; must match a snapshot under data_root
data_root = "~/.hqdata"

[strategy]
module = "examples.moving_average"

[output]
directory = "results/moving-average"
2 changes: 2 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ hqbacktest run --config configs/moving_average.toml --output results/moving-aver
python -m hqbacktest run --config configs/moving_average.toml --output results/moving-average
```

`configs/moving_average.toml` 是仓库自带的示例配置,但 `hqbacktest` 不下载数据——运行前需要本地已有一份覆盖该日期区间的 `hqdata` CSV 快照(`hqdata` CLI 抓取步骤见 README「配置数据源」一节),否则会以退出码 2 报 `SnapshotFileMissingError`。

### 1.1 策略模块解析

`hqbacktest run` 把 config 文件所在目录和当前工作目录加入 `sys.path`,让 `[strategy].module = "my_strategy"` 这类**不带点号的写法**可以直接 `import` 成功,行为与 `python -m hqbacktest run` 一致。
Expand Down
4 changes: 3 additions & 1 deletion src/hqbacktest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""hqbacktest - A-share quantitative strategy backtest and trading simulation engine."""

from importlib.metadata import version

from hqbacktest.data import (
CacheKey,
DataCache,
Expand Down Expand Up @@ -51,7 +53,7 @@
TradingRuleSet,
)

__version__ = "0.1.4"
__version__ = version("hqbacktest")

__all__ = [
"__version__",
Expand Down
Loading