Files
openclaw-trading/README.md
OpenClaw Trading 4ae8061172 初始提交:纯信号量化交易系统 v1.0
策略:纯信号模式(不定期换仓,止损止盈卖出后因子选股补仓)
股票池:沪深300+中证500(800+只)
止损-8% / 止盈+25% / 单只20% / 最多5只
5年回测:+371.7%,夏普0.82,年化21.3%

组件:
- engine.py: 核心交易引擎 + 因子评分 + 数据管理
- scheduler.py: APScheduler定时调度 + HTTP状态接口
- trade_tool.py: 命令行工具
- config.json: 策略参数配置
- Dockerfile + docker-compose.yml: 容器化部署

日志系统:
- 文件日志(按日轮转,保留90天)
- SQLite: trades/daily_log/signal_log/system_log
2026-04-05 16:59:50 +08:00

173 lines
4.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# A股纯信号量化交易系统
## 策略说明
纯信号交易策略(固定参数):
- **不做定期换仓**,只根据止损/止盈信号卖出
- 卖出后立即因子选股补仓每10天扫描补充新标的
- 止损 -8% / 止盈 +25%
- 单只仓位 ≤20%最多持有5只
- 股票池沪深300+中证500约800-900只
## 系统架构
```
trading-system/
├── config/
│ └── config.json # 策略配置
├── scripts/
│ ├── engine.py # 核心交易引擎 + 因子评分
│ ├── scheduler.py # APScheduler定时调度
│ ├── trade_tool.py # 命令行工具
│ ├── start.sh # Host模式启动
│ └── docker-start.sh # Docker模式启动
├── data/ # 运行数据gitignore
│ ├── state.json # 策略状态(持仓/现金/净值)
│ ├── trading.db # SQLite交易日志
│ └── pool_codes.json # 股票池缓存
├── logs/ # 运行日志
│ ├── engine.log # 引擎日志按日轮转保留90天
│ ├── scheduler.log # 调度日志
│ └── daily_YYYYMMDD.txt # 日终报告
├── Dockerfile # Docker构建
├── docker-compose.yml
└── requirements.txt
```
## 快速开始
### Host模式推荐NAS使用
```bash
# 启动调度器(后台运行)
nohup bash scripts/start.sh > logs/startup.log 2>&1 &
# 或手动运行一天
python3 scripts/trade_tool.py run --date 20260403
```
### Docker模式
```bash
# 构建 & 启动
bash scripts/docker-start.sh
# 查看日志
docker logs -f trading-signal
```
### 命令行工具
```bash
# 查看状态
python3 scripts/trade_tool.py status
# 初始化(重置资金)
python3 scripts/trade_tool.py init --cash 100000
# 手动买入
python3 scripts/trade_tool.py buy 600519.SH --price 1700 --qty 100
# 手动卖出
python3 scripts/trade_tool.py sell 600519.SH --price 1750
# 交易历史
python3 scripts/trade_tool.py history --limit 20
# 净值曲线
python3 scripts/trade_tool.py nav
```
## 定时任务
| 时间 | 任务 | 说明 |
|------|------|------|
| 09:00 | 盘前准备 | 刷新股票池 |
| 9:30-14:30 | 每30分钟 | 止损止盈检查 + 补仓 |
| 15:10 | 日终报告 | 更新收盘价 + 生成报告 |
| 周六 10:00 | 周报 | 本周交易统计 |
## HTTP接口
- `http://localhost:8888/status` — JSON状态
- `http://localhost:8888/report` — 文本报告
## 日志系统
### 文件日志
- `logs/engine.log` — 每日轮转保留90天
- `logs/daily_YYYYMMDD.txt` — 每日报告
### SQLite日志表
| 表名 | 内容 |
|------|------|
| trades | 交易记录(买卖方向/价格/盈亏/原因) |
| daily_log | 每日净值快照 |
| signal_log | 信号记录(买入评分/卖出原因) |
| system_log | 系统事件日志 |
### 查询示例
```python
import sqlite3
db = sqlite3.connect('data/trading.db')
# 最近交易
db.execute('SELECT date,name,direction,qty,price,pnl,pnl_pct,reason FROM trades ORDER BY id DESC LIMIT 10').fetchall()
# 净值曲线
db.execute('SELECT date,total_nav,return_pct FROM daily_log ORDER BY date').fetchall()
# 交易胜率
db.execute('SELECT COUNT(*), SUM(CASE WHEN pnl>0 THEN 1 END) FROM trades WHERE direction="sell"').fetchall()
```
## 配置说明
`config/config.json`:
```json
{
"initial_cash": 100000, // 初始资金
"position": {
"max_position_pct": 0.20, // 单只上限20%
"max_holdings": 5, // 最多5只
"top_n_buy": 3 // 每次最多买3只
},
"exit": {
"stop_loss_pct": -0.08, // 止损-8%
"take_profit_pct": 0.25 // 止盈+25%
},
"scan": {
"interval_days": 10, // 10天扫描间隔
"factor_pool_size": 50 // 因子Top N
}
}
```
## 因子评分
10维纯量价因子
| 因子 | 权重 | 方向 |
|------|------|------|
| 历史波动率(20日) | 20% | 低波动好 |
| ATR比率 | 18% | 低ATR好 |
| 量比(5/20日) | 10% | 缩量好 |
| 放量突破 | 8% | — |
| MACD柱趋势 | 6% | — |
| 60日动量 | 4% | 低动量好 |
| MA20斜率 | 4% | — |
| RSI(14) | 10% | 低RSI好 |
| MA距离 | 10% | 均线下方好 |
| 换手率 | 10% | 适中好 |
## 回测表现5年
| 指标 | 数值 |
|------|------|
| 总收益 | +371.7% |
| 年化收益 | 21.3% |
| 最大回撤 | -35.0% |
| 夏普比率 | 0.82 |