prism-quant 1.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- prism_quant-1.0.3/LICENSE +21 -0
- prism_quant-1.0.3/PKG-INFO +217 -0
- prism_quant-1.0.3/README.md +177 -0
- prism_quant-1.0.3/README_EN.md +177 -0
- prism_quant-1.0.3/VERSION +1 -0
- prism_quant-1.0.3/prism_quant/__init__.py +38 -0
- prism_quant-1.0.3/prism_quant/adapters/__init__.py +3 -0
- prism_quant-1.0.3/prism_quant/adapters/data/__init__.py +4 -0
- prism_quant-1.0.3/prism_quant/adapters/data/miniqmt_gateway.py +360 -0
- prism_quant-1.0.3/prism_quant/adapters/data/yfinance_gateway.py +177 -0
- prism_quant-1.0.3/prism_quant/adapters/trade/__init__.py +5 -0
- prism_quant-1.0.3/prism_quant/adapters/trade/miniqmt_client.py +237 -0
- prism_quant-1.0.3/prism_quant/adapters/trade/miniqmt_gateway.py +121 -0
- prism_quant-1.0.3/prism_quant/adapters/trade/paper_gateway.py +31 -0
- prism_quant-1.0.3/prism_quant/backtest/__init__.py +32 -0
- prism_quant-1.0.3/prism_quant/backtest/engine.py +182 -0
- prism_quant-1.0.3/prism_quant/backtest/metrics.py +74 -0
- prism_quant-1.0.3/prism_quant/backtest/performance.py +394 -0
- prism_quant-1.0.3/prism_quant/charts/__init__.py +14 -0
- prism_quant-1.0.3/prism_quant/charts/performance.py +320 -0
- prism_quant-1.0.3/prism_quant/charts/price.py +64 -0
- prism_quant-1.0.3/prism_quant/charts/signals.py +181 -0
- prism_quant-1.0.3/prism_quant/core/__init__.py +14 -0
- prism_quant-1.0.3/prism_quant/core/base.py +20 -0
- prism_quant-1.0.3/prism_quant/core/config.py +80 -0
- prism_quant-1.0.3/prism_quant/core/logger.py +44 -0
- prism_quant-1.0.3/prism_quant/data/__init__.py +14 -0
- prism_quant-1.0.3/prism_quant/data/cleaner.py +39 -0
- prism_quant-1.0.3/prism_quant/data/fetcher.py +99 -0
- prism_quant-1.0.3/prism_quant/data/miniqmt_xtdata.py +101 -0
- prism_quant-1.0.3/prism_quant/data/source_map.py +25 -0
- prism_quant-1.0.3/prism_quant/data/storage.py +247 -0
- prism_quant-1.0.3/prism_quant/indicators/__init__.py +14 -0
- prism_quant-1.0.3/prism_quant/indicators/fundamental.py +45 -0
- prism_quant-1.0.3/prism_quant/indicators/talib_indicators.py +67 -0
- prism_quant-1.0.3/prism_quant/indicators/technical.py +251 -0
- prism_quant-1.0.3/prism_quant/live/__init__.py +28 -0
- prism_quant-1.0.3/prism_quant/live/engine.py +567 -0
- prism_quant-1.0.3/prism_quant/live/event_engine.py +19 -0
- prism_quant-1.0.3/prism_quant/live/gateway_registry.py +27 -0
- prism_quant-1.0.3/prism_quant/live/gateways.py +75 -0
- prism_quant-1.0.3/prism_quant/live/models.py +24 -0
- prism_quant-1.0.3/prism_quant/strategy/__init__.py +12 -0
- prism_quant-1.0.3/prism_quant/strategy/base.py +31 -0
- prism_quant-1.0.3/prism_quant/strategy/signals.py +190 -0
- prism_quant-1.0.3/prism_quant/trader/__init__.py +14 -0
- prism_quant-1.0.3/prism_quant/trader/engine.py +197 -0
- prism_quant-1.0.3/prism_quant/trader/order_manager.py +106 -0
- prism_quant-1.0.3/prism_quant/trader/position_manager.py +88 -0
- prism_quant-1.0.3/prism_quant.egg-info/PKG-INFO +217 -0
- prism_quant-1.0.3/prism_quant.egg-info/SOURCES.txt +55 -0
- prism_quant-1.0.3/prism_quant.egg-info/dependency_links.txt +1 -0
- prism_quant-1.0.3/prism_quant.egg-info/requires.txt +19 -0
- prism_quant-1.0.3/prism_quant.egg-info/top_level.txt +1 -0
- prism_quant-1.0.3/pyproject.toml +83 -0
- prism_quant-1.0.3/setup.cfg +4 -0
- prism_quant-1.0.3/setup.py +10 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 PrismQuant
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: prism_quant
|
|
3
|
+
Version: 1.0.3
|
|
4
|
+
Summary: A-share low-frequency quantitative trading framework covering research, backtesting, and execution (formerly prism_quant)
|
|
5
|
+
Author-email: PrismQuant <21429503@qq.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://gitee.com/beauty9235/prism_quant
|
|
8
|
+
Project-URL: Repository, https://gitee.com/beauty9235/prism_quant
|
|
9
|
+
Project-URL: Issues, https://gitee.com/beauty9235/prism_quant/issues
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: numpy>=1.21.0
|
|
24
|
+
Requires-Dist: pandas>=1.3.0
|
|
25
|
+
Requires-Dist: scipy>=1.7.0
|
|
26
|
+
Requires-Dist: matplotlib>=3.4.0
|
|
27
|
+
Requires-Dist: yfinance>=0.1.70
|
|
28
|
+
Requires-Dist: requests>=2.25.0
|
|
29
|
+
Requires-Dist: akshare>=1.13.0
|
|
30
|
+
Requires-Dist: plotly>=5.0.0
|
|
31
|
+
Provides-Extra: viz
|
|
32
|
+
Requires-Dist: plotly>=5.0.0; extra == "viz"
|
|
33
|
+
Provides-Extra: talib
|
|
34
|
+
Requires-Dist: TA-Lib>=0.4.24; extra == "talib"
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: black>=21.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: flake8>=3.9.0; extra == "dev"
|
|
38
|
+
Requires-Dist: sphinx>=4.0.0; extra == "dev"
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
# PrismQuant
|
|
42
|
+
|
|
43
|
+
<div align="center">
|
|
44
|
+
|
|
45
|
+
[中文](README.md) | [English](README_EN.md)
|
|
46
|
+
|
|
47
|
+

|
|
48
|
+

|
|
49
|
+

|
|
50
|
+

|
|
51
|
+

|
|
52
|
+
|
|
53
|
+
Python Open-source Quantitative Framework: Covering the full "Research, Backtest, Trade" lifecycle, building an industrial-grade closed-loop quantitative workflow from scratch to production.
|
|
54
|
+
|
|
55
|
+
<p align="center">
|
|
56
|
+
<img src="https://raw.githubusercontent.com/Delta-F/prism_quant/main/assets/signals.png" width="48%" alt="Strategy Signals" />
|
|
57
|
+
<img src="https://raw.githubusercontent.com/Delta-F/prism_quant/main/assets/overview.png" width="48%" alt="Backtest Overview" />
|
|
58
|
+
</p>
|
|
59
|
+
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
## 🎓 Official Tutorials
|
|
64
|
+
|
|
65
|
+
#### [iMOOC - AI Quantitative System Course](https://class.imooc.com/sale/aiqwm)
|
|
66
|
+
|
|
67
|
+
> Official Course: Deeply deconstructing the framework's architecture from 0 to 1, covering live trading logic and industrial-grade quantitative development. An essential course for mastering PrismQuant.
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
## 📦 Installation
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install prism_quant
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
For previous version source code, visit: https://pypi.org/project/prism_quant/#history
|
|
77
|
+
|
|
78
|
+
## ✨ Key Features
|
|
79
|
+
|
|
80
|
+
- 📥 Multi-source Data - Global multi-market historical/real-time data, ready to use
|
|
81
|
+
- 🧠 Rapid Development - Signal-driven architecture, fast implementation with strategy templates
|
|
82
|
+
- 📉 Professional Backtesting - High-performance matching engine, deep performance metrics and analysis
|
|
83
|
+
- ⚡ Event-driven - Second-level market data distribution, millisecond-level Tick signal processing
|
|
84
|
+
- 🤖 Live Gateway - Pluggable adapters, seamless switching between simulation and live trading
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
## ⚡ Quick Start
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
import prism_quant as prq
|
|
91
|
+
|
|
92
|
+
# 1. Define strategy logic
|
|
93
|
+
class MyStrategy( prq.strategy.BaseStrategy):
|
|
94
|
+
def generate_signals(self, data):
|
|
95
|
+
bands = prq.indicators.TechnicalIndicators().boll(data["Close"])
|
|
96
|
+
return prq.strategy.SignalGenerator().boll_signals(data["Close"], bands)
|
|
97
|
+
|
|
98
|
+
# 2. Minimal backtest & results
|
|
99
|
+
engine = prq.backtest.BacktestEngine()
|
|
100
|
+
engine.set_parameters("GOOGL", "2025-07-26", "2026-01-26")
|
|
101
|
+
engine.load_data()
|
|
102
|
+
engine.add_strategy(MyStrategy(name="BOLL"))
|
|
103
|
+
engine.run_backtest()
|
|
104
|
+
engine.show_report()
|
|
105
|
+
engine.show_chart(use_plotly=False)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
## 🚀 Application Example
|
|
110
|
+
PrismQuant is an open-source quantitative trading cloud platform based on prism_quant, integrating data services, strategy management, and trading access with paper and live support. Project: https://github.com/Delta-F/prism_quant/
|
|
111
|
+
|
|
112
|
+
<table align="center">
|
|
113
|
+
<tr>
|
|
114
|
+
<td><img src="https://raw.githubusercontent.com/Delta-F/prism_quant/main/assets/prism_quant_1.png" height="260" alt="PrismQuant Architecture" /></td>
|
|
115
|
+
<td><img src="https://raw.githubusercontent.com/Delta-F/prism_quant/main/assets/prism_quant_2.png" height="260" alt="PrismQuant Backtest Engine" /></td>
|
|
116
|
+
</tr>
|
|
117
|
+
</table>
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
## 🔌 Interface Integration
|
|
121
|
+
|
|
122
|
+
- [Data] yfinance ✅ - US, A-shares, HK, Crypto, Indices
|
|
123
|
+
- [Data] eastmoney ✅ - OTC Funds (Index, QDII, Stock, Bond, Mixed)
|
|
124
|
+
- [Data] miniQMT ✅ - A-share market data integration (see live trading section in the course)
|
|
125
|
+
- [Trade] PaperTrade ✅ - Local simulation, tick-driven order matching, position and order management
|
|
126
|
+
- [Trade] miniQMT Trade ✅ - A-share live trading (see live trading section in the course)
|
|
127
|
+
|
|
128
|
+
### Minimal miniQMT live trade setup
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from prism_quant.live import LiveEngine
|
|
132
|
+
|
|
133
|
+
engine = LiveEngine(symbol="000001.SZ", signal_interval="1m")
|
|
134
|
+
engine.set_data_gateway("miniqmt", interval=3.0, mode="poll")
|
|
135
|
+
engine.set_trade_gateway(
|
|
136
|
+
"miniqmt",
|
|
137
|
+
userdata_mini_path=r"D:\BrokerQMT\userdata_mini",
|
|
138
|
+
account_id="1234567890",
|
|
139
|
+
)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
See details:
|
|
143
|
+
- `documents/LiveEngine.md`
|
|
144
|
+
- `documents/MiniQmtTrade.md`
|
|
145
|
+
- `documents/MiniQmtLiveEngine.md`
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
## 🏗️ Project Architecture
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
prism_quant/
|
|
152
|
+
├── core/ # Base classes, config, logging
|
|
153
|
+
│ ├── base.py
|
|
154
|
+
│ ├── config.py
|
|
155
|
+
│ └── logger.py
|
|
156
|
+
├── data/ # Fetch, clean, store, source mapping
|
|
157
|
+
│ ├── fetcher.py
|
|
158
|
+
│ ├── cleaner.py
|
|
159
|
+
│ ├── storage.py
|
|
160
|
+
│ ├── source_map.py
|
|
161
|
+
│ └── miniqmt_xtdata.py # miniQMT / xtquant historical bars
|
|
162
|
+
├── indicators/ # Technical & fundamental factors
|
|
163
|
+
│ ├── technical.py
|
|
164
|
+
│ ├── fundamental.py
|
|
165
|
+
│ └── talib_indicators.py
|
|
166
|
+
├── strategy/ # Strategy base & signal generation
|
|
167
|
+
│ ├── base.py
|
|
168
|
+
│ └── signals.py
|
|
169
|
+
├── backtest/ # Backtest engine, metrics, reporting
|
|
170
|
+
│ ├── engine.py
|
|
171
|
+
│ ├── metrics.py
|
|
172
|
+
│ └── performance.py
|
|
173
|
+
├── live/ # Event engine, gateways, LiveEngine
|
|
174
|
+
│ ├── event_engine.py
|
|
175
|
+
│ ├── gateways.py # DataGateway / TradeGateway abstractions
|
|
176
|
+
│ ├── gateway_registry.py # Gateway factory & registry
|
|
177
|
+
│ ├── engine.py # LiveEngine orchestration
|
|
178
|
+
│ └── models.py # TickData, OrderRequest, …
|
|
179
|
+
├── adapters/ # Pluggable data / trade adapters
|
|
180
|
+
│ ├── data/ # Data gateways (yfinance, miniQMT, …)
|
|
181
|
+
│ │ ├── yfinance_gateway.py
|
|
182
|
+
│ │ └── miniqmt_gateway.py
|
|
183
|
+
│ └── trade/ # Trade gateways (Paper, miniQMT, …)
|
|
184
|
+
│ ├── paper_gateway.py
|
|
185
|
+
│ ├── miniqmt_client.py # xttrader client wrapper
|
|
186
|
+
│ └── miniqmt_gateway.py # Limit orders / cancel for LiveEngine
|
|
187
|
+
├── trader/ # Matching, orders, positions
|
|
188
|
+
│ ├── engine.py
|
|
189
|
+
│ ├── order_manager.py
|
|
190
|
+
│ └── position_manager.py
|
|
191
|
+
└── charts/ # Signal, price & performance charts
|
|
192
|
+
├── signals.py
|
|
193
|
+
├── price.py
|
|
194
|
+
└── performance.py
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
<table align="center">
|
|
198
|
+
<tr>
|
|
199
|
+
<td><img src="https://raw.githubusercontent.com/Delta-F/prism_quant/main/assets/prism_quant_arch.png" height="400" alt="Project Architecture" /></td>
|
|
200
|
+
<td><img src="https://raw.githubusercontent.com/Delta-F/prism_quant/main/assets/prism_quant_wf.png" height="400" alt="Workflow" /></td>
|
|
201
|
+
</tr>
|
|
202
|
+
</table>
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
## 🤝 Contributing
|
|
206
|
+
|
|
207
|
+
- Feedback: Bug reports and contributions are welcome via [Issue](https://github.com/Delta-F/prism_quant/issues) or Pull Requests.
|
|
208
|
+
- WeChat Official Account: Follow `PrismQuant开源量化` for updates, strategies, and quantitative resources.
|
|
209
|
+
|
|
210
|
+
<p align="center">
|
|
211
|
+
<img src="https://raw.githubusercontent.com/Delta-F/prism_quant/main/assets/wechat_qr.png" width="150" alt="WeChat Official Account" />
|
|
212
|
+
</p>
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
## 📄 License
|
|
216
|
+
|
|
217
|
+
MIT License. See [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# PrismQuant
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
[中文](README.md) | [English](README_EN.md)
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
Python 开源量化框架: 覆盖“研究、回测、交易”全生命周期,构建从零到实盘的工业级量化闭环工作流。
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<img src="assets/signals.png" width="48%" alt="策略信号图" />
|
|
17
|
+
<img src="assets/overview.png" width="48%" alt="回测结果面板" />
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## 🎓 官方教程
|
|
24
|
+
|
|
25
|
+
#### 棱镜量化 -AI 量化理财体系
|
|
26
|
+
|
|
27
|
+
> 项目官方配套课程:深度解析本框架从 0 到 1 的架构设计,涵盖实盘闭环逻辑与工业级量化开发实战,是掌握本项目精髓的进阶必修课。
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## 📦 安装
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install prism_quant
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
如需获取往期版本源码,请访问:https://pypi.org/project/prism_quant/#history
|
|
37
|
+
|
|
38
|
+
## ✨ 核心功能
|
|
39
|
+
|
|
40
|
+
- 📥 多源数据 - 全球多市场历史/实时数据,开箱即用
|
|
41
|
+
- 🧠 极速开发 - 信号驱动架构,策略模板化快捷实现
|
|
42
|
+
- 📉 专业回测 - 高性能撮合引擎,深度绩效度量与分析
|
|
43
|
+
- ⚡ 事件驱动 - 秒级行情分发,毫秒级 Tick 信号处理
|
|
44
|
+
- 🤖 实盘网关 - 插件化适配,模拟与实盘接口无缝切换
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## ⚡ 快速上手
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
import prism_quant as prq
|
|
51
|
+
|
|
52
|
+
# 1. 定义策略逻辑
|
|
53
|
+
class MyStrategy( prq.strategy.BaseStrategy):
|
|
54
|
+
def generate_signals(self, data):
|
|
55
|
+
bands = prq.indicators.TechnicalIndicators().boll(data["Close"])
|
|
56
|
+
return prq.strategy.SignalGenerator().boll_signals(data["Close"], bands)
|
|
57
|
+
|
|
58
|
+
# 2. 极简回测与展示
|
|
59
|
+
engine = prq.backtest.BacktestEngine()
|
|
60
|
+
engine.set_parameters("GOOGL", "2025-07-26", "2026-01-26")
|
|
61
|
+
engine.load_data()
|
|
62
|
+
engine.add_strategy(MyStrategy(name="BOLL"))
|
|
63
|
+
engine.run_backtest()
|
|
64
|
+
engine.show_report()
|
|
65
|
+
engine.show_chart(use_plotly=False)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## 🚀 应用示例
|
|
70
|
+
PrismQuant 基于 prism_quant 的开源量化交易云平台,集成数据服务、策略管理与交易接入,支持模拟与实盘。项目地址:https://github.com/Delta-F/prism_quant/
|
|
71
|
+
|
|
72
|
+
<table align="center">
|
|
73
|
+
<tr>
|
|
74
|
+
<td><img src="assets/prism_quant_1.png" height="260" alt="PrismQuant Architecture" /></td>
|
|
75
|
+
<td><img src="assets/prism_quant_2.png" height="260" alt="PrismQuant Backtest Engine" /></td>
|
|
76
|
+
</tr>
|
|
77
|
+
</table>
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
## 🔌 接口集成
|
|
81
|
+
|
|
82
|
+
- [Data] yfinance ✅ - 美股、A股、港股、加密、股指
|
|
83
|
+
- [Data] eastmoney ✅ - 场外基金(指数、QDII、股、债、混合)
|
|
84
|
+
- [Data] miniQMT ✅ - A 股行情接入(详情见课程实盘章节)
|
|
85
|
+
- [Trade] PaperTrade ✅ - 本地模拟交易、挂单按 Tick 撮合、持仓与订单管理
|
|
86
|
+
- [Trade] miniQMT Trade ✅ - A 股实盘交易(详情见课程实盘章节)
|
|
87
|
+
|
|
88
|
+
### miniQMT 实盘接口最小接入
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from prism_quant.live import LiveEngine
|
|
92
|
+
|
|
93
|
+
engine = LiveEngine(symbol="000001.SZ", signal_interval="1m")
|
|
94
|
+
engine.set_data_gateway("miniqmt", interval=3.0, mode="poll")
|
|
95
|
+
engine.set_trade_gateway(
|
|
96
|
+
"miniqmt",
|
|
97
|
+
userdata_mini_path=r"D:\券商QMT\userdata_mini",
|
|
98
|
+
account_id="1234567890",
|
|
99
|
+
)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
详细说明见:
|
|
103
|
+
- `documents/LiveEngine.md`
|
|
104
|
+
- `documents/MiniQmtTrade.md`
|
|
105
|
+
- `documents/MiniQmtLiveEngine.md`
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
## 🏗️ 项目架构
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
prism_quant/
|
|
112
|
+
├── core/ # 基类、配置、日志
|
|
113
|
+
│ ├── base.py
|
|
114
|
+
│ ├── config.py
|
|
115
|
+
│ └── logger.py
|
|
116
|
+
├── data/ # 拉数、清洗、存储与数据源映射
|
|
117
|
+
│ ├── fetcher.py
|
|
118
|
+
│ ├── cleaner.py
|
|
119
|
+
│ ├── storage.py
|
|
120
|
+
│ ├── source_map.py
|
|
121
|
+
│ └── miniqmt_xtdata.py # miniQMT / xtquant 历史 K 线
|
|
122
|
+
├── indicators/ # 技术指标与基本面因子
|
|
123
|
+
│ ├── technical.py
|
|
124
|
+
│ ├── fundamental.py
|
|
125
|
+
│ └── talib_indicators.py
|
|
126
|
+
├── strategy/ # 策略基类与信号生成
|
|
127
|
+
│ ├── base.py
|
|
128
|
+
│ └── signals.py
|
|
129
|
+
├── backtest/ # 回测引擎、指标与报告
|
|
130
|
+
│ ├── engine.py
|
|
131
|
+
│ ├── metrics.py
|
|
132
|
+
│ └── performance.py
|
|
133
|
+
├── live/ # 事件引擎、网关抽象、LiveEngine
|
|
134
|
+
│ ├── event_engine.py
|
|
135
|
+
│ ├── gateways.py # DataGateway / TradeGateway 抽象
|
|
136
|
+
│ ├── gateway_registry.py # 网关工厂与注册
|
|
137
|
+
│ ├── engine.py # LiveEngine 实盘编排
|
|
138
|
+
│ └── models.py # TickData、OrderRequest 等
|
|
139
|
+
├── adapters/ # 可插拔行情 / 交易适配
|
|
140
|
+
│ ├── data/ # 数据网关(yfinance、miniQMT 等)
|
|
141
|
+
│ │ ├── yfinance_gateway.py
|
|
142
|
+
│ │ └── miniqmt_gateway.py
|
|
143
|
+
│ └── trade/ # 交易网关(Paper、miniQMT 等)
|
|
144
|
+
│ ├── paper_gateway.py
|
|
145
|
+
│ ├── miniqmt_client.py # xttrader 交易封装
|
|
146
|
+
│ └── miniqmt_gateway.py # 柜台限价单 / 撤单适配 LiveEngine
|
|
147
|
+
├── trader/ # 撮合执行、订单与持仓
|
|
148
|
+
│ ├── engine.py
|
|
149
|
+
│ ├── order_manager.py
|
|
150
|
+
│ └── position_manager.py
|
|
151
|
+
└── charts/ # 信号、价格与绩效图
|
|
152
|
+
├── signals.py
|
|
153
|
+
├── price.py
|
|
154
|
+
└── performance.py
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
<table align="center">
|
|
158
|
+
<tr>
|
|
159
|
+
<td><img src="assets/prism_quant_arch.png" height="400" alt="项目架构" /></td>
|
|
160
|
+
<td><img src="assets/prism_quant_wf.png" height="400" alt="工作流" /></td>
|
|
161
|
+
</tr>
|
|
162
|
+
</table>
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
## 🤝 参与贡献
|
|
166
|
+
|
|
167
|
+
- 反馈与改进:欢迎通过 [Issue](https://github.com/Delta-F/prism_quant/issues) 或 PR 提交改进。
|
|
168
|
+
- 微信公众号:关注 `PrismQuant开源量化`,获取版本更新、重要策略与量化资料。
|
|
169
|
+
|
|
170
|
+
<p align="center">
|
|
171
|
+
<img src="assets/wechat_qr.png" width="150" alt="微信公众号" />
|
|
172
|
+
</p>
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
## 📄 许可证
|
|
176
|
+
|
|
177
|
+
MIT License,详见 [LICENSE](LICENSE)。
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# PrismQuant
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
[中文](README.md) | [English](README_EN.md)
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
Python Open-source Quantitative Framework: Covering the full "Research, Backtest, Trade" lifecycle, building an industrial-grade closed-loop quantitative workflow from scratch to production.
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<img src="https://raw.githubusercontent.com/Delta-F/prism_quant/main/assets/signals.png" width="48%" alt="Strategy Signals" />
|
|
17
|
+
<img src="https://raw.githubusercontent.com/Delta-F/prism_quant/main/assets/overview.png" width="48%" alt="Backtest Overview" />
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## 🎓 Official Tutorials
|
|
24
|
+
|
|
25
|
+
#### [iMOOC - AI Quantitative System Course](https://class.imooc.com/sale/aiqwm)
|
|
26
|
+
|
|
27
|
+
> Official Course: Deeply deconstructing the framework's architecture from 0 to 1, covering live trading logic and industrial-grade quantitative development. An essential course for mastering PrismQuant.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## 📦 Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install prism_quant
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
For previous version source code, visit: https://pypi.org/project/prism_quant/#history
|
|
37
|
+
|
|
38
|
+
## ✨ Key Features
|
|
39
|
+
|
|
40
|
+
- 📥 Multi-source Data - Global multi-market historical/real-time data, ready to use
|
|
41
|
+
- 🧠 Rapid Development - Signal-driven architecture, fast implementation with strategy templates
|
|
42
|
+
- 📉 Professional Backtesting - High-performance matching engine, deep performance metrics and analysis
|
|
43
|
+
- ⚡ Event-driven - Second-level market data distribution, millisecond-level Tick signal processing
|
|
44
|
+
- 🤖 Live Gateway - Pluggable adapters, seamless switching between simulation and live trading
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## ⚡ Quick Start
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
import prism_quant as prq
|
|
51
|
+
|
|
52
|
+
# 1. Define strategy logic
|
|
53
|
+
class MyStrategy( prq.strategy.BaseStrategy):
|
|
54
|
+
def generate_signals(self, data):
|
|
55
|
+
bands = prq.indicators.TechnicalIndicators().boll(data["Close"])
|
|
56
|
+
return prq.strategy.SignalGenerator().boll_signals(data["Close"], bands)
|
|
57
|
+
|
|
58
|
+
# 2. Minimal backtest & results
|
|
59
|
+
engine = prq.backtest.BacktestEngine()
|
|
60
|
+
engine.set_parameters("GOOGL", "2025-07-26", "2026-01-26")
|
|
61
|
+
engine.load_data()
|
|
62
|
+
engine.add_strategy(MyStrategy(name="BOLL"))
|
|
63
|
+
engine.run_backtest()
|
|
64
|
+
engine.show_report()
|
|
65
|
+
engine.show_chart(use_plotly=False)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## 🚀 Application Example
|
|
70
|
+
PrismQuant is an open-source quantitative trading cloud platform based on prism_quant, integrating data services, strategy management, and trading access with paper and live support. Project: https://github.com/Delta-F/prism_quant/
|
|
71
|
+
|
|
72
|
+
<table align="center">
|
|
73
|
+
<tr>
|
|
74
|
+
<td><img src="https://raw.githubusercontent.com/Delta-F/prism_quant/main/assets/prism_quant_1.png" height="260" alt="PrismQuant Architecture" /></td>
|
|
75
|
+
<td><img src="https://raw.githubusercontent.com/Delta-F/prism_quant/main/assets/prism_quant_2.png" height="260" alt="PrismQuant Backtest Engine" /></td>
|
|
76
|
+
</tr>
|
|
77
|
+
</table>
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
## 🔌 Interface Integration
|
|
81
|
+
|
|
82
|
+
- [Data] yfinance ✅ - US, A-shares, HK, Crypto, Indices
|
|
83
|
+
- [Data] eastmoney ✅ - OTC Funds (Index, QDII, Stock, Bond, Mixed)
|
|
84
|
+
- [Data] miniQMT ✅ - A-share market data integration (see live trading section in the course)
|
|
85
|
+
- [Trade] PaperTrade ✅ - Local simulation, tick-driven order matching, position and order management
|
|
86
|
+
- [Trade] miniQMT Trade ✅ - A-share live trading (see live trading section in the course)
|
|
87
|
+
|
|
88
|
+
### Minimal miniQMT live trade setup
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from prism_quant.live import LiveEngine
|
|
92
|
+
|
|
93
|
+
engine = LiveEngine(symbol="000001.SZ", signal_interval="1m")
|
|
94
|
+
engine.set_data_gateway("miniqmt", interval=3.0, mode="poll")
|
|
95
|
+
engine.set_trade_gateway(
|
|
96
|
+
"miniqmt",
|
|
97
|
+
userdata_mini_path=r"D:\BrokerQMT\userdata_mini",
|
|
98
|
+
account_id="1234567890",
|
|
99
|
+
)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
See details:
|
|
103
|
+
- `documents/LiveEngine.md`
|
|
104
|
+
- `documents/MiniQmtTrade.md`
|
|
105
|
+
- `documents/MiniQmtLiveEngine.md`
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
## 🏗️ Project Architecture
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
prism_quant/
|
|
112
|
+
├── core/ # Base classes, config, logging
|
|
113
|
+
│ ├── base.py
|
|
114
|
+
│ ├── config.py
|
|
115
|
+
│ └── logger.py
|
|
116
|
+
├── data/ # Fetch, clean, store, source mapping
|
|
117
|
+
│ ├── fetcher.py
|
|
118
|
+
│ ├── cleaner.py
|
|
119
|
+
│ ├── storage.py
|
|
120
|
+
│ ├── source_map.py
|
|
121
|
+
│ └── miniqmt_xtdata.py # miniQMT / xtquant historical bars
|
|
122
|
+
├── indicators/ # Technical & fundamental factors
|
|
123
|
+
│ ├── technical.py
|
|
124
|
+
│ ├── fundamental.py
|
|
125
|
+
│ └── talib_indicators.py
|
|
126
|
+
├── strategy/ # Strategy base & signal generation
|
|
127
|
+
│ ├── base.py
|
|
128
|
+
│ └── signals.py
|
|
129
|
+
├── backtest/ # Backtest engine, metrics, reporting
|
|
130
|
+
│ ├── engine.py
|
|
131
|
+
│ ├── metrics.py
|
|
132
|
+
│ └── performance.py
|
|
133
|
+
├── live/ # Event engine, gateways, LiveEngine
|
|
134
|
+
│ ├── event_engine.py
|
|
135
|
+
│ ├── gateways.py # DataGateway / TradeGateway abstractions
|
|
136
|
+
│ ├── gateway_registry.py # Gateway factory & registry
|
|
137
|
+
│ ├── engine.py # LiveEngine orchestration
|
|
138
|
+
│ └── models.py # TickData, OrderRequest, …
|
|
139
|
+
├── adapters/ # Pluggable data / trade adapters
|
|
140
|
+
│ ├── data/ # Data gateways (yfinance, miniQMT, …)
|
|
141
|
+
│ │ ├── yfinance_gateway.py
|
|
142
|
+
│ │ └── miniqmt_gateway.py
|
|
143
|
+
│ └── trade/ # Trade gateways (Paper, miniQMT, …)
|
|
144
|
+
│ ├── paper_gateway.py
|
|
145
|
+
│ ├── miniqmt_client.py # xttrader client wrapper
|
|
146
|
+
│ └── miniqmt_gateway.py # Limit orders / cancel for LiveEngine
|
|
147
|
+
├── trader/ # Matching, orders, positions
|
|
148
|
+
│ ├── engine.py
|
|
149
|
+
│ ├── order_manager.py
|
|
150
|
+
│ └── position_manager.py
|
|
151
|
+
└── charts/ # Signal, price & performance charts
|
|
152
|
+
├── signals.py
|
|
153
|
+
├── price.py
|
|
154
|
+
└── performance.py
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
<table align="center">
|
|
158
|
+
<tr>
|
|
159
|
+
<td><img src="https://raw.githubusercontent.com/Delta-F/prism_quant/main/assets/prism_quant_arch.png" height="400" alt="Project Architecture" /></td>
|
|
160
|
+
<td><img src="https://raw.githubusercontent.com/Delta-F/prism_quant/main/assets/prism_quant_wf.png" height="400" alt="Workflow" /></td>
|
|
161
|
+
</tr>
|
|
162
|
+
</table>
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
## 🤝 Contributing
|
|
166
|
+
|
|
167
|
+
- Feedback: Bug reports and contributions are welcome via [Issue](https://github.com/Delta-F/prism_quant/issues) or Pull Requests.
|
|
168
|
+
- WeChat Official Account: Follow `PrismQuant开源量化` for updates, strategies, and quantitative resources.
|
|
169
|
+
|
|
170
|
+
<p align="center">
|
|
171
|
+
<img src="https://raw.githubusercontent.com/Delta-F/prism_quant/main/assets/wechat_qr.png" width="150" alt="WeChat Official Account" />
|
|
172
|
+
</p>
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
## 📄 License
|
|
176
|
+
|
|
177
|
+
MIT License. See [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.0.3
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PrismQuant - A comprehensive Python quantitative finance library.
|
|
3
|
+
|
|
4
|
+
This library provides tools for strategy development, backtesting,
|
|
5
|
+
paper trading, and live trading.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
# Read version from VERSION file
|
|
12
|
+
_version_file = Path(__file__).parent.parent / "VERSION"
|
|
13
|
+
if _version_file.exists():
|
|
14
|
+
__version__ = _version_file.read_text().strip()
|
|
15
|
+
else:
|
|
16
|
+
__version__ = "0.9.1"
|
|
17
|
+
|
|
18
|
+
__author__ = "PrismQuant"
|
|
19
|
+
|
|
20
|
+
# Import core modules
|
|
21
|
+
from . import core
|
|
22
|
+
from . import data
|
|
23
|
+
from . import strategy
|
|
24
|
+
from . import backtest
|
|
25
|
+
from . import indicators
|
|
26
|
+
from . import trader
|
|
27
|
+
from . import live
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"core",
|
|
31
|
+
"data",
|
|
32
|
+
"strategy",
|
|
33
|
+
"backtest",
|
|
34
|
+
"indicators",
|
|
35
|
+
"trader",
|
|
36
|
+
"live"
|
|
37
|
+
]
|
|
38
|
+
|