solidrock-quant 0.2.0__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.
- solidrock_quant-0.2.0/.gitignore +33 -0
- solidrock_quant-0.2.0/LICENSE +201 -0
- solidrock_quant-0.2.0/PKG-INFO +195 -0
- solidrock_quant-0.2.0/README.md +154 -0
- solidrock_quant-0.2.0/docs/design.md +272 -0
- solidrock_quant-0.2.0/docs/mcp-setup.md +83 -0
- solidrock_quant-0.2.0/docs/release.md +45 -0
- solidrock_quant-0.2.0/docs/roadmap.md +86 -0
- solidrock_quant-0.2.0/pyproject.toml +104 -0
- solidrock_quant-0.2.0/src/solidrock/__init__.py +53 -0
- solidrock_quant-0.2.0/src/solidrock/agent/__init__.py +5 -0
- solidrock_quant-0.2.0/src/solidrock/agent/errors.py +95 -0
- solidrock_quant-0.2.0/src/solidrock/agent/mcp_server.py +224 -0
- solidrock_quant-0.2.0/src/solidrock/agent/skills/backtest-workflow.md +75 -0
- solidrock_quant-0.2.0/src/solidrock/agent/skills/data-update-workflow.md +46 -0
- solidrock_quant-0.2.0/src/solidrock/agent/skills/experiment-comparison-workflow.md +46 -0
- solidrock_quant-0.2.0/src/solidrock/agent/tools.py +638 -0
- solidrock_quant-0.2.0/src/solidrock/agent/validation.py +205 -0
- solidrock_quant-0.2.0/src/solidrock/backtest/__init__.py +21 -0
- solidrock_quant-0.2.0/src/solidrock/backtest/config.py +51 -0
- solidrock_quant-0.2.0/src/solidrock/backtest/context.py +158 -0
- solidrock_quant-0.2.0/src/solidrock/backtest/costs.py +137 -0
- solidrock_quant-0.2.0/src/solidrock/backtest/engine.py +562 -0
- solidrock_quant-0.2.0/src/solidrock/backtest/matching.py +285 -0
- solidrock_quant-0.2.0/src/solidrock/backtest/portfolio.py +209 -0
- solidrock_quant-0.2.0/src/solidrock/backtest/vectorized.py +109 -0
- solidrock_quant-0.2.0/src/solidrock/cli/__init__.py +5 -0
- solidrock_quant-0.2.0/src/solidrock/cli/main.py +560 -0
- solidrock_quant-0.2.0/src/solidrock/config.py +47 -0
- solidrock_quant-0.2.0/src/solidrock/data/__init__.py +36 -0
- solidrock_quant-0.2.0/src/solidrock/data/calendar.py +106 -0
- solidrock_quant-0.2.0/src/solidrock/data/futures.py +157 -0
- solidrock_quant-0.2.0/src/solidrock/data/quality.py +163 -0
- solidrock_quant-0.2.0/src/solidrock/data/schema.py +196 -0
- solidrock_quant-0.2.0/src/solidrock/data/sources/__init__.py +27 -0
- solidrock_quant-0.2.0/src/solidrock/data/sources/akshare_source.py +642 -0
- solidrock_quant-0.2.0/src/solidrock/data/sources/baostock_source.py +259 -0
- solidrock_quant-0.2.0/src/solidrock/data/sources/base.py +206 -0
- solidrock_quant-0.2.0/src/solidrock/data/sources/registry.py +53 -0
- solidrock_quant-0.2.0/src/solidrock/data/sources/tushare_source.py +290 -0
- solidrock_quant-0.2.0/src/solidrock/data/store.py +407 -0
- solidrock_quant-0.2.0/src/solidrock/data/symbols.py +170 -0
- solidrock_quant-0.2.0/src/solidrock/experiments/__init__.py +5 -0
- solidrock_quant-0.2.0/src/solidrock/experiments/tracker.py +149 -0
- solidrock_quant-0.2.0/src/solidrock/factors/__init__.py +24 -0
- solidrock_quant-0.2.0/src/solidrock/factors/analysis.py +284 -0
- solidrock_quant-0.2.0/src/solidrock/factors/base.py +120 -0
- solidrock_quant-0.2.0/src/solidrock/factors/processing.py +71 -0
- solidrock_quant-0.2.0/src/solidrock/factors/report.py +83 -0
- solidrock_quant-0.2.0/src/solidrock/report/__init__.py +15 -0
- solidrock_quant-0.2.0/src/solidrock/report/json_report.py +55 -0
- solidrock_quant-0.2.0/src/solidrock/report/markdown.py +99 -0
- solidrock_quant-0.2.0/src/solidrock/report/metrics.py +156 -0
- solidrock_quant-0.2.0/src/solidrock/risk/__init__.py +5 -0
- solidrock_quant-0.2.0/src/solidrock/risk/checks.py +56 -0
- solidrock_quant-0.2.0/src/solidrock/strategy/__init__.py +5 -0
- solidrock_quant-0.2.0/src/solidrock/strategy/base.py +59 -0
- solidrock_quant-0.2.0/src/solidrock/strategy/loader.py +50 -0
- solidrock_quant-0.2.0/src/solidrock/utils/__init__.py +5 -0
- solidrock_quant-0.2.0/src/solidrock/utils/loader.py +53 -0
- solidrock_quant-0.2.0/tests/__init__.py +1 -0
- solidrock_quant-0.2.0/tests/conftest.py +135 -0
- solidrock_quant-0.2.0/tests/test_akshare_mapping.py +358 -0
- solidrock_quant-0.2.0/tests/test_backtest_units.py +192 -0
- solidrock_quant-0.2.0/tests/test_calendar.py +85 -0
- solidrock_quant-0.2.0/tests/test_cli.py +82 -0
- solidrock_quant-0.2.0/tests/test_engine.py +275 -0
- solidrock_quant-0.2.0/tests/test_errors.py +42 -0
- solidrock_quant-0.2.0/tests/test_examples.py +53 -0
- solidrock_quant-0.2.0/tests/test_factors.py +238 -0
- solidrock_quant-0.2.0/tests/test_futures.py +319 -0
- solidrock_quant-0.2.0/tests/test_mcp_tools.py +183 -0
- solidrock_quant-0.2.0/tests/test_metrics_tracker.py +130 -0
- solidrock_quant-0.2.0/tests/test_minutes_baostock.py +243 -0
- solidrock_quant-0.2.0/tests/test_quality.py +71 -0
- solidrock_quant-0.2.0/tests/test_schema.py +83 -0
- solidrock_quant-0.2.0/tests/test_sources.py +108 -0
- solidrock_quant-0.2.0/tests/test_store.py +182 -0
- solidrock_quant-0.2.0/tests/test_symbols.py +74 -0
- solidrock_quant-0.2.0/tests/test_tushare_mapping.py +221 -0
- solidrock_quant-0.2.0/tests/test_validation.py +99 -0
- solidrock_quant-0.2.0/tests/test_vectorized.py +96 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.eggs/
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
.venv/
|
|
9
|
+
venv/
|
|
10
|
+
.mypy_cache/
|
|
11
|
+
.ruff_cache/
|
|
12
|
+
.pytest_cache/
|
|
13
|
+
.coverage
|
|
14
|
+
htmlcov/
|
|
15
|
+
|
|
16
|
+
# SolidRockQuant 本地数据(数据目录默认在项目根,不入库)
|
|
17
|
+
.solidrock/
|
|
18
|
+
|
|
19
|
+
# 环境与密钥
|
|
20
|
+
.env
|
|
21
|
+
*.token
|
|
22
|
+
|
|
23
|
+
# IDE
|
|
24
|
+
.idea/
|
|
25
|
+
.vscode/
|
|
26
|
+
*.swp
|
|
27
|
+
|
|
28
|
+
# OS
|
|
29
|
+
.DS_Store
|
|
30
|
+
Thumbs.db
|
|
31
|
+
|
|
32
|
+
# 工具本地状态
|
|
33
|
+
.mimosa/
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: solidrock-quant
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: SolidRockQuant · 磐石智擎 — Agent 原生的量化研究与回测框架
|
|
5
|
+
Author: SolidRockQuant Contributors
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: ai-agent,akshare,backtest,mcp,quant,trading,tushare
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Natural Language :: Chinese (Simplified)
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
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
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: duckdb>=1.0
|
|
21
|
+
Requires-Dist: numpy>=1.24
|
|
22
|
+
Requires-Dist: pandas>=2.0
|
|
23
|
+
Requires-Dist: pyarrow>=14.0
|
|
24
|
+
Requires-Dist: pydantic-settings>=2.1
|
|
25
|
+
Requires-Dist: pydantic>=2.5
|
|
26
|
+
Requires-Dist: rich>=13.0
|
|
27
|
+
Requires-Dist: typer>=0.12
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
33
|
+
Provides-Extra: mcp
|
|
34
|
+
Requires-Dist: mcp>=1.2; extra == 'mcp'
|
|
35
|
+
Provides-Extra: report
|
|
36
|
+
Requires-Dist: plotly>=5.18; extra == 'report'
|
|
37
|
+
Provides-Extra: sources
|
|
38
|
+
Requires-Dist: akshare>=1.14; extra == 'sources'
|
|
39
|
+
Requires-Dist: tushare>=1.4; extra == 'sources'
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
|
|
42
|
+
# SolidRockQuant · 磐石智擎
|
|
43
|
+
|
|
44
|
+
> **Agent 原生的量化研究与回测框架** —— 让 AI Agent 像研究员一样工作,让人类像审稿人一样把关。
|
|
45
|
+
>
|
|
46
|
+
> The agent-native quant research & backtest framework for China A-shares & futures.
|
|
47
|
+
|
|
48
|
+
[](https://github.com/samchuit/SolidRockQuant/actions/workflows/ci.yml)
|
|
49
|
+
[](LICENSE)
|
|
50
|
+
[](pyproject.toml)
|
|
51
|
+
[](https://github.com/astral-sh/ruff)
|
|
52
|
+
|
|
53
|
+
## 为什么做这个项目
|
|
54
|
+
|
|
55
|
+
vnpy、qlib、backtrader、rqalpha 等优秀框架都是"给人用"的,AI Agent 接入它们时处处碰壁:
|
|
56
|
+
|
|
57
|
+
- 报错信息人类能猜懂,Agent 只会反复重试;
|
|
58
|
+
- 回测结果埋在日志里,Agent 无法可靠地读取和对比;
|
|
59
|
+
- 数据没有版本概念,同一个策略两次回测结果不同,Agent 无法判断是策略问题还是数据漂移;
|
|
60
|
+
- 没有统一的工具协议,每个 Agent 平台都要单独写胶水代码。
|
|
61
|
+
|
|
62
|
+
SolidRockQuant 从第一天起就为 LLM Agent 设计:**MCP Server 是一等公民接口,实验自动留痕,数据可版本化,报错自带修复建议**。目标是让 Agent 在最少人工干预下完成"拉数据 → 写策略/因子 → 回测/分析 → 读结果 → 迭代"的完整研究闭环,而人负责设定目标和审阅结论。
|
|
63
|
+
|
|
64
|
+
## 核心特性
|
|
65
|
+
|
|
66
|
+
### 🤖 Agent 原生
|
|
67
|
+
- **MCP Server**(`srq mcp serve`):数据获取、回测、因子分析、实验查询共 13 个工具,Claude 等 LLM 客户端即插即用
|
|
68
|
+
- **结构化输出**:统一 JSON 信封 + Markdown 报告;错误码稳定且必带可执行的修复 hint
|
|
69
|
+
- **前视偏差检测**:`shift(-n)`、`bfill`、幻觉 API 等 LLM 常见错误的 AST 静态检查,回测前自动拦截
|
|
70
|
+
- **确定性可复现**:无随机性引擎 + 数据版本快照,同一实验永远得到同一结果
|
|
71
|
+
|
|
72
|
+
### 📊 数据层
|
|
73
|
+
- 可插拔数据源:AKShare(东财主通道 + 新浪自动回退)、Tushare Pro、Baostock,架构预留 Wind 等商业接口;日线 + 分钟线(1m/5m)
|
|
74
|
+
- 统一数据规范:原始价 + 后复权因子(前复权价会随除权漂移,破坏复现性,故不落库)、交易日历、股票/期货合约/主连/指数/ETF
|
|
75
|
+
- 本地缓存:Parquet 原子写入 + DuckDB 参数化读取,增量更新幂等
|
|
76
|
+
|
|
77
|
+
### ⚙️ 回测引擎(自研轻量)
|
|
78
|
+
- 事件驱动 bar 级引擎,默认 **next_open 防前视执行**(收盘信号次日开盘成交)
|
|
79
|
+
- A股规则内置:T+1、涨跌停按板块自动判别(主板 10% / 创业板科创 20% / 北交 30%,ST 可覆盖)、买入整手、停牌处理
|
|
80
|
+
- 费用模型:佣金(最低 5 元)/ 印花税(卖出)/ 过户费 / 滑点,全部可配置;拒单带原因码(`LIMIT_UP` / `T_PLUS_ONE` / `WEIGHT_CAP` / `SUSPENDED`…)
|
|
81
|
+
- 风控:单标的权重上限、回撤熔断自动清仓
|
|
82
|
+
|
|
83
|
+
### 🔬 因子研究
|
|
84
|
+
- `Factor` 基类 + 面板容器(宽表),MAD/分位数去极值、zscore、行业市值中性化(OLS 残差)
|
|
85
|
+
- **RankIC / ICIR / t 值**、分位数分层回测、多空价差、因子自相关(换手代理)
|
|
86
|
+
- 分析结果自动留痕,与回测共用同一套实验追踪
|
|
87
|
+
|
|
88
|
+
### 🧪 实验追踪(Agent 迭代的记忆)
|
|
89
|
+
- 每次回测/因子分析自动记录:参数、配置、数据快照、指标、产物路径(SQLite 零部署)
|
|
90
|
+
- Agent 可查询对比历史实验:"上次跑的动量策略和这次比哪个好?"
|
|
91
|
+
|
|
92
|
+
## 快速开始
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# 从源码安装(PyPI 发布后可直接 pip install solidrock-quant)
|
|
96
|
+
pip install "solidrock-quant[mcp,sources] @ git+https://github.com/samchuit/SolidRockQuant.git"
|
|
97
|
+
|
|
98
|
+
srq init # 初始化数据目录
|
|
99
|
+
srq data calendar --update # 拉取交易日历
|
|
100
|
+
srq data update --symbols 510300.SH --start 2024-01-01 # 更新行情
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Python API 回测
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from solidrock import BacktestConfig, BacktestEngine, Context, DataStore, Strategy
|
|
107
|
+
|
|
108
|
+
class DualMA(Strategy):
|
|
109
|
+
"""双均线策略"""
|
|
110
|
+
params = {"fast": 5, "slow": 20}
|
|
111
|
+
|
|
112
|
+
def setup(self, ctx: Context):
|
|
113
|
+
ctx.universe = ["510300.SH"]
|
|
114
|
+
|
|
115
|
+
def on_signal(self, ctx: Context):
|
|
116
|
+
close = ctx.history("510300.SH", self.params["slow"] + 1, fields="close")["510300.SH"]
|
|
117
|
+
window = close.iloc[-self.params["slow"]:]
|
|
118
|
+
if window.isna().any() or len(window) < self.params["slow"]:
|
|
119
|
+
return
|
|
120
|
+
target = 1.0 if window.iloc[-self.params["fast"]:].mean() > window.mean() else 0.0
|
|
121
|
+
ctx.order_target_percent("510300.SH", target)
|
|
122
|
+
|
|
123
|
+
store = DataStore(".solidrock")
|
|
124
|
+
result = BacktestEngine(DualMA, BacktestConfig(start="2025-01-01", end="2026-09-08"), store).run()
|
|
125
|
+
print(result.metrics["sharpe"], result.metrics["max_drawdown"])
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### CLI
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
srq backtest run examples/dual_ma.py --start 2025-01-01 --end 2026-09-08 --param fast=5
|
|
132
|
+
srq factor analyze examples/momentum_factor.py -u 000001.SZ,600519.SH,... --start 2025-01-01 --end 2026-09-08
|
|
133
|
+
srq experiment list # 每次回测/因子分析自动留痕
|
|
134
|
+
srq experiment compare <id1> <id2>
|
|
135
|
+
srq data snapshot create snap-20260908 # 数据版本快照(实验复现)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### MCP Server(Agent 接入)
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"mcpServers": {
|
|
143
|
+
"solidrock": { "command": "srq", "args": ["mcp", "serve"] }
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Claude 等 Agent 即可获得 13 个工具,研究闭环无需人工干预。详细配置见 [docs/mcp-setup.md](docs/mcp-setup.md),Agent 操作指南见 `src/solidrock/agent/skills/`。
|
|
149
|
+
|
|
150
|
+
## 项目结构
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
src/solidrock/
|
|
154
|
+
├── data/ # 数据层:数据源适配器(可插拔)、本地仓库、交易日历、符号规范
|
|
155
|
+
├── backtest/ # 回测引擎:事件驱动、撮合(A股规则)、组合核算、费用模型
|
|
156
|
+
├── strategy/ # Strategy 基类与加载器
|
|
157
|
+
├── factors/ # 因子研究:基类、截面处理、RankIC/分层分析
|
|
158
|
+
├── report/ # 绩效指标、Markdown/JSON 报告
|
|
159
|
+
├── experiments/ # SQLite 实验追踪
|
|
160
|
+
├── risk/ # 仓位上限、回撤熔断
|
|
161
|
+
├── agent/ # MCP Server、错误规范、策略校验、SKILL.md
|
|
162
|
+
├── cli/ # srq 命令行
|
|
163
|
+
└── utils/ # 通用工具
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## 文档
|
|
167
|
+
|
|
168
|
+
| 文档 | 内容 |
|
|
169
|
+
|------|------|
|
|
170
|
+
| [docs/design.md](docs/design.md) | 技术设计:架构、数据规范、引擎与 MCP 设计、关键取舍 |
|
|
171
|
+
| [docs/roadmap.md](docs/roadmap.md) | 路线图与任务拆解 |
|
|
172
|
+
| [docs/mcp-setup.md](docs/mcp-setup.md) | Claude Code / Claude Desktop 接入配置 |
|
|
173
|
+
| [docs/release.md](docs/release.md) | 版本发布流程 |
|
|
174
|
+
| [llms.txt](llms.txt) | 面向 LLM 的项目速览 |
|
|
175
|
+
|
|
176
|
+
## 路线图
|
|
177
|
+
|
|
178
|
+
| 版本 | 内容 | 状态 |
|
|
179
|
+
|------|------|------|
|
|
180
|
+
| v0.1 | 数据层(日线)+ 事件回测(股票)+ 绩效报告 + 实验追踪 + MCP Server | **完成** |
|
|
181
|
+
| v0.2 | 因子分析 ✅ · 期货回测(保证金/双向持仓/换月)· 分钟线 · 数据体检 | 进行中 |
|
|
182
|
+
| v0.3 | 模拟盘、期货 CTP 实盘、策略沙箱校验、多 Agent 工作流示例 | 规划中 |
|
|
183
|
+
| v0.4 | 插件注册机制、英语文档、更多数据源 | 规划中 |
|
|
184
|
+
|
|
185
|
+
## 参与贡献
|
|
186
|
+
|
|
187
|
+
项目处于早期快速迭代阶段,欢迎通过 Issue 讨论设计与提交 PR:
|
|
188
|
+
|
|
189
|
+
1. Fork → 创建特性分支 → 提交前运行 `ruff check` / `mypy src/solidrock` / `pytest -m "not network"`;
|
|
190
|
+
2. 新功能请附带测试(CI 会在 Python 3.10–3.12 上执行全量检查);
|
|
191
|
+
3. 面向 Agent 的改动请同步更新 `src/solidrock/agent/skills/` 与 docstring。
|
|
192
|
+
|
|
193
|
+
## 免责声明
|
|
194
|
+
|
|
195
|
+
本项目仅供量化研究与技术学习使用。回测结果基于历史数据与简化假设,**不构成任何投资建议**;期货实盘与自动交易涉及重大资金风险,请遵守所在 jurisdictions 的法律法规并自担风险。数据来源为第三方公开接口,准确性不作保证。
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# SolidRockQuant · 磐石智擎
|
|
2
|
+
|
|
3
|
+
> **Agent 原生的量化研究与回测框架** —— 让 AI Agent 像研究员一样工作,让人类像审稿人一样把关。
|
|
4
|
+
>
|
|
5
|
+
> The agent-native quant research & backtest framework for China A-shares & futures.
|
|
6
|
+
|
|
7
|
+
[](https://github.com/samchuit/SolidRockQuant/actions/workflows/ci.yml)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
[](pyproject.toml)
|
|
10
|
+
[](https://github.com/astral-sh/ruff)
|
|
11
|
+
|
|
12
|
+
## 为什么做这个项目
|
|
13
|
+
|
|
14
|
+
vnpy、qlib、backtrader、rqalpha 等优秀框架都是"给人用"的,AI Agent 接入它们时处处碰壁:
|
|
15
|
+
|
|
16
|
+
- 报错信息人类能猜懂,Agent 只会反复重试;
|
|
17
|
+
- 回测结果埋在日志里,Agent 无法可靠地读取和对比;
|
|
18
|
+
- 数据没有版本概念,同一个策略两次回测结果不同,Agent 无法判断是策略问题还是数据漂移;
|
|
19
|
+
- 没有统一的工具协议,每个 Agent 平台都要单独写胶水代码。
|
|
20
|
+
|
|
21
|
+
SolidRockQuant 从第一天起就为 LLM Agent 设计:**MCP Server 是一等公民接口,实验自动留痕,数据可版本化,报错自带修复建议**。目标是让 Agent 在最少人工干预下完成"拉数据 → 写策略/因子 → 回测/分析 → 读结果 → 迭代"的完整研究闭环,而人负责设定目标和审阅结论。
|
|
22
|
+
|
|
23
|
+
## 核心特性
|
|
24
|
+
|
|
25
|
+
### 🤖 Agent 原生
|
|
26
|
+
- **MCP Server**(`srq mcp serve`):数据获取、回测、因子分析、实验查询共 13 个工具,Claude 等 LLM 客户端即插即用
|
|
27
|
+
- **结构化输出**:统一 JSON 信封 + Markdown 报告;错误码稳定且必带可执行的修复 hint
|
|
28
|
+
- **前视偏差检测**:`shift(-n)`、`bfill`、幻觉 API 等 LLM 常见错误的 AST 静态检查,回测前自动拦截
|
|
29
|
+
- **确定性可复现**:无随机性引擎 + 数据版本快照,同一实验永远得到同一结果
|
|
30
|
+
|
|
31
|
+
### 📊 数据层
|
|
32
|
+
- 可插拔数据源:AKShare(东财主通道 + 新浪自动回退)、Tushare Pro、Baostock,架构预留 Wind 等商业接口;日线 + 分钟线(1m/5m)
|
|
33
|
+
- 统一数据规范:原始价 + 后复权因子(前复权价会随除权漂移,破坏复现性,故不落库)、交易日历、股票/期货合约/主连/指数/ETF
|
|
34
|
+
- 本地缓存:Parquet 原子写入 + DuckDB 参数化读取,增量更新幂等
|
|
35
|
+
|
|
36
|
+
### ⚙️ 回测引擎(自研轻量)
|
|
37
|
+
- 事件驱动 bar 级引擎,默认 **next_open 防前视执行**(收盘信号次日开盘成交)
|
|
38
|
+
- A股规则内置:T+1、涨跌停按板块自动判别(主板 10% / 创业板科创 20% / 北交 30%,ST 可覆盖)、买入整手、停牌处理
|
|
39
|
+
- 费用模型:佣金(最低 5 元)/ 印花税(卖出)/ 过户费 / 滑点,全部可配置;拒单带原因码(`LIMIT_UP` / `T_PLUS_ONE` / `WEIGHT_CAP` / `SUSPENDED`…)
|
|
40
|
+
- 风控:单标的权重上限、回撤熔断自动清仓
|
|
41
|
+
|
|
42
|
+
### 🔬 因子研究
|
|
43
|
+
- `Factor` 基类 + 面板容器(宽表),MAD/分位数去极值、zscore、行业市值中性化(OLS 残差)
|
|
44
|
+
- **RankIC / ICIR / t 值**、分位数分层回测、多空价差、因子自相关(换手代理)
|
|
45
|
+
- 分析结果自动留痕,与回测共用同一套实验追踪
|
|
46
|
+
|
|
47
|
+
### 🧪 实验追踪(Agent 迭代的记忆)
|
|
48
|
+
- 每次回测/因子分析自动记录:参数、配置、数据快照、指标、产物路径(SQLite 零部署)
|
|
49
|
+
- Agent 可查询对比历史实验:"上次跑的动量策略和这次比哪个好?"
|
|
50
|
+
|
|
51
|
+
## 快速开始
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# 从源码安装(PyPI 发布后可直接 pip install solidrock-quant)
|
|
55
|
+
pip install "solidrock-quant[mcp,sources] @ git+https://github.com/samchuit/SolidRockQuant.git"
|
|
56
|
+
|
|
57
|
+
srq init # 初始化数据目录
|
|
58
|
+
srq data calendar --update # 拉取交易日历
|
|
59
|
+
srq data update --symbols 510300.SH --start 2024-01-01 # 更新行情
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Python API 回测
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from solidrock import BacktestConfig, BacktestEngine, Context, DataStore, Strategy
|
|
66
|
+
|
|
67
|
+
class DualMA(Strategy):
|
|
68
|
+
"""双均线策略"""
|
|
69
|
+
params = {"fast": 5, "slow": 20}
|
|
70
|
+
|
|
71
|
+
def setup(self, ctx: Context):
|
|
72
|
+
ctx.universe = ["510300.SH"]
|
|
73
|
+
|
|
74
|
+
def on_signal(self, ctx: Context):
|
|
75
|
+
close = ctx.history("510300.SH", self.params["slow"] + 1, fields="close")["510300.SH"]
|
|
76
|
+
window = close.iloc[-self.params["slow"]:]
|
|
77
|
+
if window.isna().any() or len(window) < self.params["slow"]:
|
|
78
|
+
return
|
|
79
|
+
target = 1.0 if window.iloc[-self.params["fast"]:].mean() > window.mean() else 0.0
|
|
80
|
+
ctx.order_target_percent("510300.SH", target)
|
|
81
|
+
|
|
82
|
+
store = DataStore(".solidrock")
|
|
83
|
+
result = BacktestEngine(DualMA, BacktestConfig(start="2025-01-01", end="2026-09-08"), store).run()
|
|
84
|
+
print(result.metrics["sharpe"], result.metrics["max_drawdown"])
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### CLI
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
srq backtest run examples/dual_ma.py --start 2025-01-01 --end 2026-09-08 --param fast=5
|
|
91
|
+
srq factor analyze examples/momentum_factor.py -u 000001.SZ,600519.SH,... --start 2025-01-01 --end 2026-09-08
|
|
92
|
+
srq experiment list # 每次回测/因子分析自动留痕
|
|
93
|
+
srq experiment compare <id1> <id2>
|
|
94
|
+
srq data snapshot create snap-20260908 # 数据版本快照(实验复现)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### MCP Server(Agent 接入)
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"mcpServers": {
|
|
102
|
+
"solidrock": { "command": "srq", "args": ["mcp", "serve"] }
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Claude 等 Agent 即可获得 13 个工具,研究闭环无需人工干预。详细配置见 [docs/mcp-setup.md](docs/mcp-setup.md),Agent 操作指南见 `src/solidrock/agent/skills/`。
|
|
108
|
+
|
|
109
|
+
## 项目结构
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
src/solidrock/
|
|
113
|
+
├── data/ # 数据层:数据源适配器(可插拔)、本地仓库、交易日历、符号规范
|
|
114
|
+
├── backtest/ # 回测引擎:事件驱动、撮合(A股规则)、组合核算、费用模型
|
|
115
|
+
├── strategy/ # Strategy 基类与加载器
|
|
116
|
+
├── factors/ # 因子研究:基类、截面处理、RankIC/分层分析
|
|
117
|
+
├── report/ # 绩效指标、Markdown/JSON 报告
|
|
118
|
+
├── experiments/ # SQLite 实验追踪
|
|
119
|
+
├── risk/ # 仓位上限、回撤熔断
|
|
120
|
+
├── agent/ # MCP Server、错误规范、策略校验、SKILL.md
|
|
121
|
+
├── cli/ # srq 命令行
|
|
122
|
+
└── utils/ # 通用工具
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## 文档
|
|
126
|
+
|
|
127
|
+
| 文档 | 内容 |
|
|
128
|
+
|------|------|
|
|
129
|
+
| [docs/design.md](docs/design.md) | 技术设计:架构、数据规范、引擎与 MCP 设计、关键取舍 |
|
|
130
|
+
| [docs/roadmap.md](docs/roadmap.md) | 路线图与任务拆解 |
|
|
131
|
+
| [docs/mcp-setup.md](docs/mcp-setup.md) | Claude Code / Claude Desktop 接入配置 |
|
|
132
|
+
| [docs/release.md](docs/release.md) | 版本发布流程 |
|
|
133
|
+
| [llms.txt](llms.txt) | 面向 LLM 的项目速览 |
|
|
134
|
+
|
|
135
|
+
## 路线图
|
|
136
|
+
|
|
137
|
+
| 版本 | 内容 | 状态 |
|
|
138
|
+
|------|------|------|
|
|
139
|
+
| v0.1 | 数据层(日线)+ 事件回测(股票)+ 绩效报告 + 实验追踪 + MCP Server | **完成** |
|
|
140
|
+
| v0.2 | 因子分析 ✅ · 期货回测(保证金/双向持仓/换月)· 分钟线 · 数据体检 | 进行中 |
|
|
141
|
+
| v0.3 | 模拟盘、期货 CTP 实盘、策略沙箱校验、多 Agent 工作流示例 | 规划中 |
|
|
142
|
+
| v0.4 | 插件注册机制、英语文档、更多数据源 | 规划中 |
|
|
143
|
+
|
|
144
|
+
## 参与贡献
|
|
145
|
+
|
|
146
|
+
项目处于早期快速迭代阶段,欢迎通过 Issue 讨论设计与提交 PR:
|
|
147
|
+
|
|
148
|
+
1. Fork → 创建特性分支 → 提交前运行 `ruff check` / `mypy src/solidrock` / `pytest -m "not network"`;
|
|
149
|
+
2. 新功能请附带测试(CI 会在 Python 3.10–3.12 上执行全量检查);
|
|
150
|
+
3. 面向 Agent 的改动请同步更新 `src/solidrock/agent/skills/` 与 docstring。
|
|
151
|
+
|
|
152
|
+
## 免责声明
|
|
153
|
+
|
|
154
|
+
本项目仅供量化研究与技术学习使用。回测结果基于历史数据与简化假设,**不构成任何投资建议**;期货实盘与自动交易涉及重大资金风险,请遵守所在 jurisdictions 的法律法规并自担风险。数据来源为第三方公开接口,准确性不作保证。
|