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
43 changes: 43 additions & 0 deletions .github/workflows/auto-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Auto Tag on Version Change

on:
push:
branches: [main]
paths:
- 'pyproject.toml'

permissions:
contents: write

jobs:
auto-tag:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Extract version from pyproject.toml
id: version
run: |
VERSION=$(grep -m1 '^version' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=v$VERSION" >> $GITHUB_OUTPUT

- name: Check if tag exists
id: check
run: |
if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi

- name: Create and push tag
if: steps.check.outputs.exists == 'false'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}"
git push origin "v${{ steps.version.outputs.version }}"
53 changes: 48 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,49 @@
格式基于 [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
项目遵循 [语义化版本](https://semver.org/spec/v2.0.0.html) 规范。

## [2.2.0] - 2026-02-07

### ✨ 新增功能

- **分钟线回测** - 支持 `frequency='1m'` 分钟级回测,需配合 `data/stocks_1m/` 分钟数据
- **API 增强** - 增强股票筛选和策略参数配置能力
- **Ptrade API 类型声明脚本** - `scripts/setup_typeshed.sh`,让 Pylance 识别策略中的 Ptrade API 全局函数

### 🔧 改进

- **回测图表中文化** - 图表标签从英文改为中文(策略净值、每日盈亏、买卖金额、持仓市值)
- **图表柱宽自适应** - 根据回测周期自动调整柱状图宽度
- **统计数据收集优化** - 改进 StatsCollector 数据采集流程
- **复权计算向量化** - `_apply_adj_factors` 替代逐行计算,提升性能
- **类型注解现代化** - 全面使用 `list[str]`、`dict[str, Any]`、`X | None` 等现代语法
- **发布工作流精简** - 移除冗余步骤,简化 CI 配置

### 📦 升级指南

从 v2.1.0 升级:

```bash
pip install --upgrade simtradelab==2.2.0
```

**兼容性:** ✅ 向后兼容,无 breaking change。分钟回测为新增功能,需额外准备分钟数据。

---

## [2.1.0] - 2026-01-30

### 🔧 改进

- **持仓更新逻辑优化** - 优化持仓更新和卖出验证流程
- **API 异常处理** - 优化异常处理和复权计算性能
- **订单字段规范化** - 订单处理中统一使用 `symbol` 替换 `stock` 字段

### ⚠️ 破坏性变更

- **数据保存格式变更** - 从 HDF5(.h5)改为 Parquet 格式,旧缓存需重建

---

## [2.0.0] - 2026-01-08

### ⚠️ 重大变更(Breaking Changes)
Expand Down Expand Up @@ -314,11 +357,11 @@ poetry run python -m simtradelab.backtest.run_backtest
- **测试覆盖不全** - 由于时间限制,主要通过实际策略发现和修复问题
- **内存占用较大** - 全量加载5000+股票需要8-12GB内存
- **SimTradeData性能** - 数据获取项目存在性能问题,需要优化
- **部分API未实现** - 还有99个PTrade API待实现
- 融资融券:19个API
- 期货交易:7个API
- 期权交易:15个API
- 实时交易:高级交易、盘后交易、IPO申购等
- **部分API不在范围内** - 以下为实盘交易API,不适用于回测框架
- 融资融券:19个API(实盘交易)
- 期货交易:7个API(实盘交易)
- 期权交易:15个API(实盘交易)
- 实时交易:高级交易、盘后交易、IPO申购等(实盘交易)

### 💡 贡献指南

Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Python](https://img.shields.io/badge/Python-3.9+-blue.svg)](https://www.python.org/)
[![License](https://img.shields.io/badge/License-AGPL--3.0-blue.svg)](LICENSE)
[![License: Commercial](https://img.shields.io/badge/License-Commercial--Available-red)](licenses/LICENSE-COMMERCIAL.md)
[![Version](https://img.shields.io/badge/Version-2.1.0-orange.svg)](#)
[![Version](https://img.shields.io/badge/Version-2.2.0-orange.svg)](#)
[![PyPI](https://img.shields.io/pypi/v/simtradelab.svg)](https://pypi.org/project/simtradelab/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/simtradelab.svg)](https://pypi.org/project/simtradelab/)

Expand All @@ -19,15 +19,15 @@ SimTradeLab(深测Lab) 是一个由社区独立开发的开源策略回测

**核心特性:**
- ✅ **46个回测/研究API** - 股票日/分钟线回测场景100%覆盖
- ⚡ **20-30倍性能提升** - 本地回测比PTrade平台快20-30倍
- ⚡ **100-160倍性能提升** - 本地回测比PTrade平台快100-160倍
- 🚀 **数据常驻内存** - 单例模式,首次加载后常驻,二次运行秒级启动
- 💾 **多级智能缓存** - LRU缓存(MA/VWAP/复权/历史数据),命中率>95%
- 🧠 **智能数据加载** - AST静态分析策略代码,按需加载数据,节省内存
- 🔧 **生命周期控制** - 7个生命周期阶段,严格模拟PTrade的API调用限制
- 📊 **完整统计报告** - 收益、风险、交易明细、持仓批次、FIFO分红税
- 🔌 **模块化设计** - 清晰的代码结构,易于扩展和定制

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

---

Expand Down Expand Up @@ -183,8 +183,8 @@ stocks = api.get_index_stocks('000300.SS', date='2024-01-01')
| 技术指标 | ✅ | get_MACD, get_KDJ, get_RSI, get_CCI |
| 策略配置 | ✅ | set_benchmark, set_commission, set_slippage, set_universe, set_parameters, set_yesterday_position |
| 生命周期 | ✅ | initialize, before_trading_start, handle_data, after_trading_end |
| 融资融券 | | 19个API未实现 |
| 期货/期权 | | 22个API未实现 |
| 融资融券 | | 不在回测范围内(实盘交易API) |
| 期货/期权 | | 不在回测范围内(实盘交易API) |

**完整API列表和实现状态:** [docs/PTrade_API_Implementation_Status.md](docs/PTrade_API_Implementation_Status.md)

Expand Down Expand Up @@ -258,7 +258,6 @@ SimTradeLab/
### 主要限制
- ❌ 不支持实盘交易(仅回测)
- ⚠️ 测试覆盖不全面(策略驱动测试中)
- ⏳ 实盘PTrade API未实现(融资融券、期货、期权等)

### 计划改进
- 🔧 命令行工具(目前需要修改Python文件)
Expand Down
21 changes: 21 additions & 0 deletions docs/TOOLS.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,26 @@ fixer.fix_and_save()

---

## Ptrade API 类型声明

### setup_typeshed.sh

在 pyright/Pylance 的 typeshed 中注入 Ptrade API 类型声明,使 VS Code 能识别策略代码中的全局函数(如 `order`、`get_history`、`context` 等)。

#### 用法

```bash
bash scripts/setup_typeshed.sh
```

#### 说明

- 脚本幂等,重复运行会自动跳过
- pyright 更新后需重新运行
- 仅修改 `.venv` 内的 typeshed,不影响项目代码

---

## 工具脚本列表

| 脚本 | 功能 | 路径 |
Expand All @@ -371,6 +391,7 @@ fixer.fix_and_save()
| 策略分析 | 静态分析策略代码 | `ptrade/strategy_data_analyzer.py` |
| 兼容性检查 | Python 3.5兼容性检查 | `utils/py35_compat_checker.py` |
| f-string修复 | 自动修复f-string语法 | `utils/fstring_fixer.py` |
| 类型声明注入 | 让Pylance识别Ptrade API全局函数 | `scripts/setup_typeshed.sh` |

---

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Poetry configuration
[tool.poetry]
name = "simtradelab"
version = "2.1.0"
version = "2.2.0"
description = "开源策略回测框架,灵感来自PTrade的事件驱动模型,提供轻量、清晰、可插拔的策略验证环境"
authors = ["kay <kayou@duck.com>"]
license = "AGPL-3.0-or-later"
Expand Down