Skip to content

Commit 87540b0

Browse files
kay-ouclaude
andcommitted
chore(release): 准备 v2.3.0 发布
- 版本号升级至 2.3.0 - CHANGELOG 新增完整变更记录 - ta-lib 改为可选依赖 (pip install simtradelab[indicators]) - Development Status 升级为 Production/Stable - 新增 Python 3.13 classifier - 移除 importlib_metadata 兼容代码 - README 更新安装说明和版本信息 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1d95873 commit 87540b0

4 files changed

Lines changed: 65 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,54 @@
55
格式基于 [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66
项目遵循 [语义化版本](https://semver.org/spec/v2.0.0.html) 规范。
77

8+
## [2.3.0] - 2026-02-12
9+
10+
### ✨ 新增功能
11+
12+
- **沙箱模式** - 新增 `BacktestConfig(sandbox=True/False)` 配置。`sandbox=True`(默认)限制策略代码的 `import`(禁止 os/sys/io/subprocess 等)和 `builtins`(禁止 exec/eval/compile),与 PTrade 平台行为一致;`sandbox=False` 解除所有限制,适合本地开发调试
13+
- **run_daily 实际执行** - `run_daily()` 不再是空操作,日频模式在每日收盘前执行,分钟模式在注册时间对应的分钟 bar 执行
14+
15+
### 🐛 Bug 修复
16+
17+
- **日期类型验证修正** - `BacktestConfig``start_date`/`end_date` 验证器简化为 `pd.Timestamp(v)`,不再限制只接受 `str``pd.Timestamp`,修复传入 `datetime.date` 等类型时的报错
18+
- **估值数据查询日期修正** - `get_fundamentals` 对 valuation 表改用 `side='right'` 查找,返回查询日当天数据而非前一交易日
19+
- **order_target_value 生命周期校验** - 补加 `@validate_lifecycle` 装饰器(此前缺失)
20+
- **佣金零费率路径修正** - 移除 `calculate_commission``commission_ratio == 0` 的提前返回,统一走标准计算流程(确保 min_commission 仍生效)
21+
22+
### 🔧 改进
23+
24+
- **统计收集器重构** - `StatsCollector` 的内部存储从 `dict[str, list]` 重构为 `BacktestStats` 数据类,属性访问替代字典键查找
25+
- **生命周期装饰器零开销优化** - `validate_lifecycle` 对全阶段 API(get_history/get_price 等)直接返回原函数,无任何包装开销;受限 API 仅做 `frozenset` 成员检查,移除 `RLock``Pydantic` 验证对象
26+
- **日期索引 int64 化** - `get_stock_date_index``int64` 纳秒戳作为 dict key 和 numpy 数组做二分查找,避免 `pd.Timestamp` 构造开销
27+
- **LRU 缓存替代手动淘汰** - `stock_status_cache``fundamentals_cache` 改用 `cachetools.LRUCache`,移除手动 `.clear()` 逻辑
28+
- **前复权精度修正** - 新增 `_round2()` 函数,使用 Python `round()` 语义替代 `np.round()`,修正银行家舍入导致的与 PTrade 精度不一致
29+
- **复权计算简化** - 移除从原始除权事件手动计算的 fallback 路径,统一使用平台预计算因子,代码量减少 ~60 行
30+
- **交易 API 去重** - 提取 `_get_price_and_check_limit``_adjust_buy_amount``_submit_order` 三个内部方法,`order`/`order_target`/`order_value` 共用,消除大量重复代码
31+
- **生命周期控制器精简** - 移除 `APICallRecord``LifecycleValidationResult`、调用历史记录、全局控制器等未使用功能,代码从 ~350 行缩减至 ~50 行
32+
- **图表渲染优化** - 每日盈亏和交易金额改用 `fill_between` 替代 `bar`(无需 bar_width 参数);`tight_layout()` 替代 `bbox_inches='tight'` 避免双重渲染
33+
- **分钟 bar 生成优化** - 使用类级别预计算的时间偏移模板,避免每日重复调用 `pd.date_range`
34+
- **Portfolio 收盘价日缓存** - 同一交易日内多次计算 `portfolio_value` 时复用收盘价查找结果
35+
- **get_price/get_history 空结果日志** - 返回空时输出 warning 级别日志,便于排查数据问题
36+
- **ta-lib 改为可选依赖** - `pip install simtradelab` 不再强制安装 ta-lib;需要技术指标时使用 `pip install simtradelab[indicators]`
37+
- **清理死代码** - 移除 `importlib_metadata` fallback、`API_MODE_RESTRICTIONS``ptrade/__init__.py` 中未使用的导出等
38+
- **Python 3.13 支持** - classifiers 新增 Python 3.13
39+
40+
### 🏗️ 基础设施
41+
42+
- **CI 工作流** - 添加同步 dev 分支的 GitHub Actions 工作流配置
43+
44+
### 📦 升级指南
45+
46+
从 v2.2.1 升级:
47+
48+
```bash
49+
pip install --upgrade simtradelab==2.3.0
50+
```
51+
52+
**兼容性:** ✅ 向后兼容,无 breaking change。
53+
54+
---
55+
856
## [2.2.1] - 2026-02-09
957

1058
### 🐛 Bug 修复

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Python](https://img.shields.io/badge/Python-3.9+-blue.svg)](https://www.python.org/)
66
[![License](https://img.shields.io/badge/License-AGPL--3.0-blue.svg)](LICENSE)
77
[![License: Commercial](https://img.shields.io/badge/License-Commercial--Available-red)](licenses/LICENSE-COMMERCIAL.md)
8-
[![Version](https://img.shields.io/badge/Version-2.2.1-orange.svg)](#)
8+
[![Version](https://img.shields.io/badge/Version-2.3.0-orange.svg)](#)
99
[![PyPI](https://img.shields.io/pypi/v/simtradelab.svg)](https://pypi.org/project/simtradelab/)
1010
[![PyPI - Downloads](https://img.shields.io/pypi/dm/simtradelab.svg)](https://pypi.org/project/simtradelab/)
1111

@@ -27,7 +27,7 @@ SimTradeLab(深测Lab) 是一个由社区独立开发的开源策略回测
2727
- 📊 **完整统计报告** - 收益、风险、交易明细、持仓批次、FIFO分红税
2828
- 🔌 **模块化设计** - 清晰的代码结构,易于扩展和定制
2929

30-
**当前版本:** v2.2.1 | **开发状态:** Beta - 核心功能完善,正在策略实战中持续优化
30+
**当前版本:** v2.3.0 | **开发状态:** 核心功能完善,正在策略实战中持续优化
3131

3232
---
3333

@@ -44,13 +44,20 @@ venv\Scripts\activate # Windows
4444
# 安装最新版本
4545
pip install simtradelab
4646

47+
# 包含技术指标(需要系统级ta-lib,可选)
48+
pip install simtradelab[indicators]
49+
4750
# 包含优化器(可选)
4851
pip install simtradelab[optimizer]
52+
53+
# 安装全部可选依赖
54+
pip install simtradelab[all]
4955
```
5056

51-
**系统依赖:**
57+
**系统依赖(仅使用技术指标API时需要)**
5258
- macOS: `brew install ta-lib`
5359
- Linux: [ta-lib源码编译](docs/INSTALLATION.md)
60+
- Windows: 从 [ta-lib releases](https://github.com/ta-lib/ta-lib-python) 下载预编译包
5461

5562
> 详细安装指南:[docs/INSTALLATION.md](docs/INSTALLATION.md)
5663

pyproject.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Poetry configuration
22
[tool.poetry]
33
name = "simtradelab"
4-
version = "2.2.1"
4+
version = "2.3.0"
55
description = "开源策略回测框架,灵感来自PTrade的事件驱动模型,提供轻量、清晰、可插拔的策略验证环境"
66
authors = ["kay <kayou@duck.com>"]
77
license = "AGPL-3.0-or-later"
@@ -12,7 +12,7 @@ repository = "https://github.com/kay-ou/SimTradeLab"
1212
documentation = "https://github.com/kay-ou/SimTradeLab/tree/main/docs"
1313
keywords = ["quantitative", "backtest", "trading", "strategy", "ptrade", "finance"]
1414
classifiers = [
15-
"Development Status :: 4 - Beta",
15+
"Development Status :: 5 - Production/Stable",
1616
"Intended Audience :: Financial and Insurance Industry",
1717
"Intended Audience :: Science/Research",
1818
"Intended Audience :: Developers",
@@ -25,6 +25,7 @@ classifiers = [
2525
"Programming Language :: Python :: 3.10",
2626
"Programming Language :: Python :: 3.11",
2727
"Programming Language :: Python :: 3.12",
28+
"Programming Language :: Python :: 3.13",
2829
"Operating System :: OS Independent",
2930
]
3031

@@ -37,11 +38,13 @@ joblib = "^1.3.0"
3738
matplotlib = "^3.7.0"
3839
tqdm = "^4.67.1"
3940
pydantic = "^2.12.5"
40-
ta-lib = "*"
41+
ta-lib = {version = "*", optional = true}
4142
optuna = {version = "^3.0.0", optional = true}
4243

4344
[tool.poetry.extras]
45+
indicators = ["ta-lib"]
4446
optimizer = ["optuna"]
47+
all = ["ta-lib", "optuna"]
4548

4649
[tool.poetry.group.dev.dependencies]
4750
baostock = "^0.8.9"

src/simtradelab/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,11 @@
99
"""
1010

1111
# 从 pyproject.toml 动态读取版本号(单一数据源)
12-
try:
13-
from importlib.metadata import version, PackageNotFoundError
14-
except ImportError:
15-
# Python < 3.8 的兼容性
16-
from importlib_metadata import version, PackageNotFoundError # type: ignore
12+
from importlib.metadata import version, PackageNotFoundError
1713

1814
try:
1915
__version__ = version("simtradelab")
2016
except PackageNotFoundError:
21-
# 包未安装时的后备版本(开发环境)
2217
__version__ = "0.0.0.dev"
2318

2419
__all__ = ["__version__"]

0 commit comments

Comments
 (0)