一个面向小资金个人投资者的轻量级量化交易框架,专注于入场/出场时机的精准判断,由AI辅助编码,量化思维驱动。
A lightweight quantitative trading framework for retail investors with small capital, focusing on precise entry/exit timing, AI-assisted coding, and quantitative-driven mindset.
| 中文 | English |
|---|---|
| 本系统不追求“选股圣杯”,而是致力于解决交易中最核心的问题:什么时候买,什么时候卖。通过多指标融合评分、市场状态过滤和严格风控,将主观判断转化为可回测、可执行的量化规则。 | This system does not chase the "holy grail" of stock picking. Instead, it tackles the core issue in trading: when to buy and when to sell. By combining multi-indicator scoring, market regime filtering, and strict risk controls, it converts subjective judgment into backtestable and executable quantitative rules. |
| 中文 | English |
|---|---|
| 择时为核心:趋势跟踪 + 均值回归双策略融合,适应不同市场环境 | Timing-first : Combines trend-following and mean-reversion strategies to adapt to varying market conditions |
| 多指标融合评分:综合趋势、动量、波动、资金流四个维度,输出 -10 ~ +10 综合分值 | Multi-indicator scoring : Integrates trend, momentum, volatility, and flow dimensions into a composite score from -10 to +10 |
| 震荡市过滤器:ADX指标自动识别趋势/震荡状态,避免在无行情时频繁交易 | Sideways market filter : Uses ADX to automatically identify trend/range-bound regimes, avoiding whipsaws |
| 动态风控体系:ATR动态止损 + 移动止盈 + 时间止损 + 单日回撤熔断 | Dynamic risk management : ATR-based stop-loss, trailing take-profit, time-based stop, and daily drawdown circuit breaker |
| 类别 / Category | 工具 / Tools |
|---|---|
| 语言 / Language | Python 3.8+ |
| 开发环境 / IDE | Jupyter Notebook / Cursor / VS Code |
| 数据处理 / Data | Pandas, NumPy |
| 可视化 / Visualization | Matplotlib, Seaborn |
| 回测引擎 / Backtesting | Backtrader |
| 数据源 / Data Source | Tushare / AkShare (免费 / Free) |
| AI辅助 / AI Assistant | Claude Code |
quant_timing_system/
├── data/ # 数据目录 / Data directory
│ └── stock_history.csv # 历史行情数据 / Historical price data
├── indicators/ # 指标计算模块 / Indicator modules
│ ├── trend.py # 趋势指标 (均线、ADX) / Trend indicators
│ ├── momentum.py # 动量指标 (RSI、MACD) / Momentum indicators
│ └── volatility.py # 波动指标 (ATR、布林带) / Volatility indicators
├── strategy/ # 策略核心 / Strategy core
│ ├── scorer.py # 综合评分系统 / Composite scoring system
│ ├── signals.py # 信号生成器 / Signal generator
│ └── filters.py # 市场状态过滤器 / Market regime filter
├── backtest/ # 回测引擎 / Backtesting engine
│ ├── runner.py # 回测运行器 / Backtest runner
│ └── analyzer.py # 绩效分析 / Performance analyzer
├── risk/ # 风控模块 / Risk management
│ └── stop_loss.py # 动态止损/止盈 / Dynamic stop-loss/take-profit
├── config/ # 配置文件 / Configuration
│ └── params.yaml # 策略参数 / Strategy parameters
├── notebooks/ # 交互式分析 / Interactive notebooks
│ └── exploration.ipynb # 数据探索与可视化 / Data exploration
├── results/ # 回测结果 / Backtest results
│ ├── equity_curve.png # 资金曲线 / Equity curve
│ └── report.html # 回测报告 / Backtest report
├── README.md # 项目说明 (中英双语) / README (Bilingual)
└── requirements.txt # 依赖清单 / Dependencies
# 克隆仓库 / Clone repository
git clone https://github.com/BELLABARCA/quant-timing-system.git
cd quant-timing-system
# 安装依赖 / Install dependencies
pip install -r requirements.txtrequirements.txt 内容 / Contents:
pandas>=1.3.0
numpy>=1.21.0
matplotlib>=3.4.0
backtrader>=1.9.78
akshare>=1.8.0
pyyaml>=5.4.0
jupyter>=1.0.0
# 使用 AkShare 获取股票数据 / Fetch stock data with AkShare
import akshare as ak
# 获取贵州茅台日线数据 / Get daily data for Moutai
df = ak.stock_zh_a_hist(symbol="600519", period="daily",
start_date="2020-01-01", end_date="2024-12-31")
df.to_csv("data/stock_history.csv", index=False)Note:
akshareis unstable sometimes, the user can run basic test files at first.
# 在 Jupyter Notebook 中执行 / Run in Jupyter Notebook
from strategy.scorer import CompositeScorer
from backtest.runner import BacktestRunner
from risk.stop_loss import DynamicStopLoss
# 初始化评分系统 / Initialize scorer
scorer = CompositeScorer(weights={
'trend': 0.3,
'momentum': 0.3,
'volatility': 0.2,
'flow': 0.2
})
# 运行回测 / Run backtest
runner = BacktestRunner(
data_path="data/stock_history.csv",
scorer=scorer,
stop_loss=DynamicStopLoss(atr_multiplier=2.0),
adx_threshold=25 # ADX > 25 才交易 / Trade only when ADX > 25
)
results = runner.run()
runner.plot_equity_curve()总分 = 0.3 × 趋势分 + 0.3 × 动量分 + 0.2 × 波动分 + 0.2 × 资金流分
总分范围 / Score range: -10 ~ +10
交易规则 / Trading Rules:
- 总分 > +5 → 开仓 / Open long
- 总分 < -5 → 平仓 / Close position
- -5 ≤ 总分 ≤ +5 → 观望 / Wait
| 维度 / Dimension | 指标 / Indicators | 权重 / Weight |
|---|---|---|
| 趋势 / Trend | 均线排列、ADX | 30% |
| 动量 / Momentum | RSI、MACD柱线 | 30% |
| 波动 / Volatility | ATR、布林带位置 | 20% |
| 资金流 / Flow | 成交量相对变化 | 20% |
重要提示 / IMPORTANT
本系统仅供学习和研究使用,不构成任何投资建议。量化策略的过去表现不代表未来收益,实盘交易可能导致本金损失。请务必:
- 在模拟盘上充分测试后再考虑实盘
- 使用小资金(建议1-2万元)起步验证
- 设置严格的单笔止损和单日熔断机制
- 理解策略逻辑,而非盲目信任回测数据
This system is for educational and research purposes only and does not constitute investment advice. Past performance does not guarantee future returns, and live trading may result in loss of capital. Please ensure you:
- Thoroughly test on paper trading before going live
- Start with small capital (recommended 10,000-20,000 RMB)
- Implement strict stop-loss and daily circuit breaker rules
- Understand the strategy logic rather than blindly trust backtest results
运行回测后将输出以下关键指标 / Key metrics after running backtest:
| 指标 / Metric | 说明 / Description |
|---|---|
| 总收益率 / Total Return | 策略期间累计收益 / Cumulative return |
| 年化收益率 / Annualized Return | 折算年化收益 / Annualized return |
| 最大回撤 / Max Drawdown | 最大峰谷跌幅 / Maximum peak-to-trough decline |
| 夏普比率 / Sharpe Ratio | 风险调整后收益 / Risk-adjusted return |
| 胜率 / Win Rate | 盈利交易占比 / Percentage of winning trades |
| 盈亏比 / Profit Factor | 总盈利/总亏损 / Gross profit / Gross loss |
| 交易次数 / Total Trades | 开平仓总次数 / Total number of trades |
通过 config/params.yaml 调整策略参数 / Tune strategy parameters via config/params.yaml:
strategy:
entry_threshold: 5.0 # 开仓阈值 / Entry threshold
exit_threshold: -5.0 # 平仓阈值 / Exit threshold
adx_filter: 25 # ADX过滤值 / ADX filter
atr_multiplier: 2.0 # ATR止损倍数 / ATR stop-loss multiplier
risk:
max_position_pct: 0.3 # 单次最大仓位 / Max position per trade
max_daily_drawdown: 0.05 # 单日最大回撤 / Max daily drawdown
trailing_stop_pct: 0.05 # 移动止盈阈值 / Trailing stop threshold
time_stop_days: 3 # 时间止损天数 / Time stop days| 阶段 / Phase | 内容 / Content |
|---|---|
| V1.0 | 单股票择时回测框架 / Single-stock timing backtest framework ✅ |
| V1.5 | 多股票批量回测 + 参数网格搜索 / Multi-stock batch backtest + grid search |
| V2.0 | 市场状态自适应切换 (趋势/震荡) / Market regime adaptive switching |
| V2.5 | 接入券商API,模拟盘自动交易 / Broker API integration, automated paper trading |
| V3.0 | 实盘小资金运行 + 实时监控看板 / Live trading with small capital + real-time dashboard |
欢迎提交Issue和Pull Request。本项目定位为个人学习工具,保持轻量和透明。
Issues and PRs are welcome. This project is positioned as a personal learning tool, staying lightweight and transparent.
MIT License
- Backtrader - 强大的回测框架 / Powerful backtesting framework
- AkShare - 免费金融数据接口 / Free financial data API
- 开源社区与AI工具的支持 / Support from open-source community and AI tools
最后更新 / Last Updated: 2026-06-30