wqbkit 0.2.2__tar.gz → 0.3.1__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.
Files changed (48) hide show
  1. wqbkit-0.3.1/.github/workflows/publish.yml +35 -0
  2. wqbkit-0.3.1/LICENSE +21 -0
  3. wqbkit-0.3.1/PKG-INFO +304 -0
  4. wqbkit-0.3.1/README.md +249 -0
  5. wqbkit-0.3.1/__init__.py +62 -0
  6. wqbkit-0.3.1/app/__init__.py +0 -0
  7. wqbkit-0.3.1/app/config.py +55 -0
  8. wqbkit-0.3.1/app/core/__init__.py +5 -0
  9. wqbkit-0.3.1/app/core/alpha_base_core.py +266 -0
  10. wqbkit-0.3.1/app/core/alpha_db_core.py +228 -0
  11. wqbkit-0.3.1/app/core/decorators.py +60 -0
  12. wqbkit-0.3.1/app/core/logger.py +65 -0
  13. wqbkit-0.3.1/app/core/wqb_urls.py +48 -0
  14. wqbkit-0.3.1/app/database/__init__.py +2 -0
  15. wqbkit-0.3.1/app/database/alpha_db_manager.py +926 -0
  16. wqbkit-0.3.1/app/database/db_models.py +203 -0
  17. wqbkit-0.3.1/app/database/schemas.py +99 -0
  18. wqbkit-0.3.1/app/utils/alpha_utils.py +34 -0
  19. wqbkit-0.3.1/modules/__init__.py +0 -0
  20. wqbkit-0.3.1/modules/competitions/Osmosis/osmosis_allocator_v3.py +608 -0
  21. wqbkit-0.3.1/modules/competitions/Osmosis/osmosis_clear_v3.py +202 -0
  22. wqbkit-0.3.1/modules/competitions/Osmosis/osmosis_runner_v3.py +292 -0
  23. wqbkit-0.3.1/modules/competitions/Osmosis/osmosis_selector_v3.py +1579 -0
  24. wqbkit-0.3.1/modules/competitions/__init__.py +0 -0
  25. wqbkit-0.3.1/modules/correlation/__init__.py +1 -0
  26. wqbkit-0.3.1/modules/correlation/alpha_calc_corr.py +361 -0
  27. wqbkit-0.3.1/modules/message/__init__.py +1 -0
  28. wqbkit-0.3.1/modules/message/alpha_message_sender.py +61 -0
  29. wqbkit-0.3.1/modules/regular_alpha/__init__.py +2 -0
  30. wqbkit-0.3.1/modules/regular_alpha/alpha_machine/__init__.py +2 -0
  31. wqbkit-0.3.1/modules/regular_alpha/alpha_machine/alpha_generator.py +148 -0
  32. wqbkit-0.3.1/modules/regular_alpha/alpha_machine/alpha_machine.py +358 -0
  33. wqbkit-0.3.1/modules/regular_alpha/alpha_machine/config/constants.py +11 -0
  34. wqbkit-0.3.1/modules/regular_alpha/alpha_machine/config/events.py +92 -0
  35. wqbkit-0.3.1/modules/regular_alpha/alpha_machine/config/groups.py +207 -0
  36. wqbkit-0.3.1/modules/regular_alpha/alpha_machine/config/operators.py +83 -0
  37. wqbkit-0.3.1/modules/regular_alpha/alpha_simulator/__init__.py +1 -0
  38. wqbkit-0.3.1/modules/regular_alpha/alpha_simulator/alpha_simulator.py +723 -0
  39. wqbkit-0.3.1/modules/regular_alpha/alpha_simulator/neutralization.json +25 -0
  40. wqbkit-0.3.1/modules/regular_alpha/alpha_simulator/setting.json +5 -0
  41. wqbkit-0.3.1/modules/super_alpha/__init__.py +3 -0
  42. wqbkit-0.3.1/modules/super_alpha/alpha_dyeing.py +131 -0
  43. wqbkit-0.3.1/modules/super_alpha/super_alpha_creator.py +155 -0
  44. wqbkit-0.3.1/modules/super_alpha/super_alpha_simulator.py +218 -0
  45. {wqbkit-0.2.2 → wqbkit-0.3.1}/pyproject.toml +3 -9
  46. wqbkit-0.2.2/PKG-INFO +0 -89
  47. wqbkit-0.2.2/README.md +0 -54
  48. {wqbkit-0.2.2 → wqbkit-0.3.1}/.gitignore +0 -0
@@ -0,0 +1,35 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ jobs:
9
+ build-and-publish:
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: read
13
+ id-token: write # for trusted publishing (optional, if configured)
14
+ steps:
15
+ - name: Checkout
16
+ uses: actions/checkout@v4
17
+
18
+ - name: Set up Python
19
+ uses: actions/setup-python@v5
20
+ with:
21
+ python-version: '3.12'
22
+
23
+ - name: Install build tools
24
+ run: |
25
+ python -m pip install --upgrade pip
26
+ pip install build twine
27
+
28
+ - name: Build package
29
+ run: python -m build
30
+
31
+ - name: Publish to PyPI
32
+ env:
33
+ TWINE_USERNAME: __token__
34
+ TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
35
+ run: twine upload dist/*
wqbkit-0.3.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Crotes
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.
wqbkit-0.3.1/PKG-INFO ADDED
@@ -0,0 +1,304 @@
1
+ Metadata-Version: 2.4
2
+ Name: wqbkit
3
+ Version: 0.3.1
4
+ Summary: WorldQuant Brain Alpha Research Automation Toolkit
5
+ Project-URL: Homepage, https://github.com/Crotes/wqbkit
6
+ Project-URL: Issues, https://github.com/Crotes/wqbkit/issues
7
+ Author-email: Crotes <Crotes@yeah.net>
8
+ License: MIT License
9
+
10
+ Copyright (c) 2025 Crotes
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+ License-File: LICENSE
30
+ Keywords: alpha,finance,quantitative,research,trading,worldquant
31
+ Classifier: Development Status :: 3 - Alpha
32
+ Classifier: Intended Audience :: Financial and Insurance Industry
33
+ Classifier: License :: OSI Approved :: MIT License
34
+ Classifier: Programming Language :: Python :: 3
35
+ Classifier: Programming Language :: Python :: 3.10
36
+ Classifier: Programming Language :: Python :: 3.11
37
+ Classifier: Programming Language :: Python :: 3.12
38
+ Classifier: Topic :: Office/Business :: Financial
39
+ Requires-Python: >=3.10
40
+ Requires-Dist: numpy
41
+ Requires-Dist: pandas
42
+ Requires-Dist: psycopg2-binary
43
+ Requires-Dist: python-dotenv
44
+ Requires-Dist: pytz
45
+ Requires-Dist: requests
46
+ Requires-Dist: scipy
47
+ Requires-Dist: sqlalchemy>=2.0
48
+ Requires-Dist: tqdm
49
+ Requires-Dist: wqb
50
+ Provides-Extra: dev
51
+ Requires-Dist: jupyter; extra == 'dev'
52
+ Requires-Dist: matplotlib; extra == 'dev'
53
+ Requires-Dist: pytest; extra == 'dev'
54
+ Description-Content-Type: text/markdown
55
+
56
+ # wqbkit
57
+
58
+ WorldQuant Brain (WQB) Alpha Research Automation Toolkit
59
+
60
+ **[English](#overview) | [中文](#概述)**
61
+
62
+ ---
63
+
64
+ ## Overview
65
+
66
+ `wqbkit` is a Python toolkit that automates alpha research workflows on the [WorldQuant Brain](https://www.worldquantbrain.com) (WQB) platform. It covers the entire alpha lifecycle — from simulation and scoring to correlation analysis, genetic expression evolution, and Osmosis competition allocation.
67
+
68
+ ### Key Features
69
+
70
+ | Module | Description |
71
+ |--------|-------------|
72
+ | `AlphaBaseCore` | WQB authentication, HTTP request wrapper with 429 retry |
73
+ | `AlphaDbCore` | `AlphaBaseCore` + PostgreSQL ORM + PnL cache + token extraction |
74
+ | `AlphaCalcCorr` | Multi-metric correlation engine (self / ppac / prod / self_web) |
75
+ | `AlphaGenerator` | Expression factory (0/1/2/3-order) with operator/field validation |
76
+ | `AlphaMachine` | Genetic iteration pipeline — pruning, deduplication, next-generation |
77
+ | `AlphaSimulator` | Multi-threaded batch simulation scheduler with queue-based results |
78
+ | `SuperAlphaSimulator` | Dedicated simulator for SUPER-type alphas |
79
+ | `AlphaDyeing` | SUPER alpha construction and combo template management |
80
+ | `Osmosis V3` | `OsmosisAlphaSelectorV3` + `OsmosisAllocatorV3` + `OsmosisClearV3` + `OsmosisRunnerV3` |
81
+ | `sc_send` | Bark (iOS) push notification for long-running jobs |
82
+
83
+ ---
84
+
85
+ ## Installation
86
+
87
+ ```bash
88
+ pip install wqbkit
89
+ ```
90
+
91
+ ### Prerequisites
92
+
93
+ - Python >= 3.10
94
+ - PostgreSQL (optional, for local alpha metadata caching)
95
+ - `wqb` SDK — WorldQuant Brain official Python client
96
+
97
+ ```bash
98
+ pip install wqb
99
+ ```
100
+
101
+ ---
102
+
103
+ ## Quick Start
104
+
105
+ ```python
106
+ from wqbkit import AlphaDbCore, AlphaCalcCorr, AlphaGenerator, OsmosisRunnerV3
107
+
108
+ # Initialize core (auto-loads .env if present)
109
+ core = AlphaDbCore()
110
+
111
+ # Correlation analysis
112
+ calcor = AlphaCalcCorr()
113
+ self_corr = calcor.calc_corr(alpha_id, calc_type='self')
114
+
115
+ # Generate expressions
116
+ generator = AlphaGenerator()
117
+ new_exprs = generator.second_order_factory(
118
+ expression="ts_mean(close, 20)",
119
+ region="USA",
120
+ atom=True
121
+ )
122
+
123
+ # Osmosis V3 pipeline
124
+ runner = OsmosisRunnerV3()
125
+ runner.run(update=True, dry_run=False)
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Configuration
131
+
132
+ Create a `.env` file in your **project root directory** (the directory above `wqbkit/` in editable-install mode):
133
+
134
+ ```env
135
+ # Database (optional)
136
+ DB_HOST=localhost
137
+ DB_PORT=5432
138
+ DB_NAME=WorldQuant
139
+ DB_USER=your_db_user
140
+ DB_PASSWORD=your_db_password
141
+
142
+ # WQB Credentials
143
+ WQB_USERNAME=your_wqb_username
144
+ WQB_PASSWORD=your_wqb_password
145
+
146
+ # Retry
147
+ MAX_RETRIES=5
148
+ RETRY_DELAY_BASE=2
149
+
150
+ # Bark Push (optional)
151
+ BARK_KEY=your_bark_device_key
152
+ ```
153
+
154
+ `wqbkit` automatically loads `.env` on import via `python-dotenv`.
155
+
156
+ ### Runtime Paths
157
+
158
+ Logs and temporary data are written to your **project root directory**, never inside the package:
159
+
160
+ | Type | Default Path | Configurable via |
161
+ |------|-------------|------------------|
162
+ | Logs | `{project_root}/logs/` | `config.LOGS_DIR` |
163
+ | Correlation cache | `{project_root}/data/correlation/` | `config.DATA_DIR / "correlation"` |
164
+ | Osmosis data | `{project_root}/data/Osmosis/` | `config.DATA_DIR / "Osmosis"` |
165
+
166
+ ---
167
+
168
+ ## API Reference
169
+
170
+ ### Core Classes
171
+
172
+ ```python
173
+ from wqbkit import (
174
+ AlphaBaseCore, # WQB session + HTTP + retry
175
+ AlphaDbCore, # AlphaBaseCore + DB + PnL cache
176
+ AlphaCalcCorr, # Correlation analysis engine
177
+ AlphaGenerator, # Expression factory
178
+ AlphaSimulator, # Multi-threaded simulation scheduler
179
+ AlphaMachine, # Genetic iteration pipeline
180
+ AlphaDyeing, # SUPER alpha builder
181
+ SuperAlphaSimulator, # SUPER alpha simulator
182
+ OsmosisAlphaSelectorV3, # Osmosis V3 selector
183
+ OsmosisAllocatorV3, # Osmosis V3 allocator
184
+ OsmosisClearV3, # Osmosis V3 score clearer
185
+ OsmosisRunnerV3, # Osmosis V3 end-to-end runner
186
+ sc_send, # Push notification helper
187
+ schemas, # Data models: FactorData, TaskData, SimulationData
188
+ )
189
+ ```
190
+
191
+ ### Osmosis V3
192
+
193
+ ```python
194
+ from wqbkit import OsmosisAlphaSelectorV3, OsmosisAllocatorV3, OsmosisRunnerV3
195
+
196
+ # 1. Select alphas
197
+ selector = OsmosisAlphaSelectorV3()
198
+ df = selector.select(region="USA")
199
+
200
+ # 2. Allocate scores
201
+ allocator = OsmosisAllocatorV3()
202
+ df = allocator.allocate(df, method="mixed")
203
+ allocator.update_osmosis_points(df, dry_run=False)
204
+
205
+ # 3. Or run the full pipeline
206
+ runner = OsmosisRunnerV3()
207
+ runner.run(update=True, dry_run=False)
208
+ ```
209
+
210
+ ### Correlation Analysis
211
+
212
+ ```python
213
+ from wqbkit import AlphaCalcCorr
214
+
215
+ calcor = AlphaCalcCorr()
216
+
217
+ # Compute correlations
218
+ corr = calcor.calc_corr(alpha_id, calc_type='self') # self-correlation
219
+ corr = calcor.calc_corr(alpha_id, calc_type='ppac') # ppac correlation
220
+ corr = calcor.calc_corr(alpha_id, calc_type='prod') # prod correlation
221
+ ```
222
+
223
+ ### Alpha Simulation
224
+
225
+ ```python
226
+ from wqbkit import AlphaSimulator
227
+
228
+ sim = AlphaSimulator()
229
+
230
+ # Single alpha simulation
231
+ result = sim.simulate(expression="rank(close)", region="USA", universe="TOP3000")
232
+
233
+ # Batch simulation from database queue
234
+ sim.run_batch_simulation(task_id=123)
235
+ ```
236
+
237
+ ---
238
+
239
+ ## Project Structure
240
+
241
+ ```
242
+ wqbkit/
243
+ ├── app/
244
+ │ ├── core/ # AlphaBaseCore, AlphaDbCore, decorators, logger, URLs
245
+ │ ├── database/ # SQLAlchemy models, AlphaDBManager, schemas
246
+ │ └── utils/ # Token extraction helpers
247
+ └── modules/
248
+ ├── regular_alpha/ # AlphaSimulator, AlphaMachine, AlphaGenerator
249
+ ├── super_alpha/ # SuperAlphaSimulator, AlphaDyeing, SuperAlphaCreator
250
+ ├── correlation/ # AlphaCalcCorr
251
+ ├── message/ # Bark push notifications
252
+ └── competitions/
253
+ └── Osmosis/ # Osmosis V3 toolkit
254
+ ```
255
+
256
+ ---
257
+
258
+ ## License
259
+
260
+ MIT
261
+
262
+ ---
263
+
264
+ ## 概述
265
+
266
+ `wqbkit` 是一个用于自动化 [WorldQuant Brain](https://www.worldquantbrain.com) 平台 Alpha 研究的 Python 工具包,覆盖 Alpha 全生命周期:模拟、评分、去相关、遗传迭代进化、Osmosis 竞赛分配。
267
+
268
+ ### 核心功能
269
+
270
+ | 模块 | 说明 |
271
+ |------|------|
272
+ | `AlphaBaseCore` | WQB 认证、HTTP 封装、429 重试 |
273
+ | `AlphaDbCore` | `AlphaBaseCore` + PostgreSQL ORM + PnL 缓存 + token 提取 |
274
+ | `AlphaCalcCorr` | 多指标相关性引擎(self / ppac / prod / self_web) |
275
+ | `AlphaGenerator` | 表达式工厂(0/1/2/3 阶),带算子/字段校验 |
276
+ | `AlphaMachine` | 遗传迭代管线:剪枝、去重、下一代 |
277
+ | `AlphaSimulator` | 多线程批量模拟调度器,队列式结果处理 |
278
+ | `SuperAlphaSimulator` | SUPER 类型 Alpha 专用模拟器 |
279
+ | `AlphaDyeing` | SUPER Alpha 构造与 combo 模板管理 |
280
+ | `Osmosis V3` | `OsmosisAlphaSelectorV3` + `OsmosisAllocatorV3` + `OsmosisClearV3` + `OsmosisRunnerV3` |
281
+ | `sc_send` | Bark (iOS) 推送通知,用于长时任务提醒 |
282
+
283
+ ### 快速开始
284
+
285
+ ```python
286
+ from wqbkit import AlphaDbCore, AlphaCalcCorr, AlphaGenerator, OsmosisRunnerV3
287
+
288
+ core = AlphaDbCore()
289
+ calcor = AlphaCalcCorr()
290
+ generator = AlphaGenerator()
291
+ runner = OsmosisRunnerV3()
292
+ runner.run(update=True, dry_run=False)
293
+ ```
294
+
295
+ ### 配置说明
296
+
297
+ 在项目根目录创建 `.env`:
298
+
299
+ ```env
300
+ WQB_USERNAME=your_username
301
+ WQB_PASSWORD=your_password
302
+ ```
303
+
304
+ 日志和运行时数据统一写入项目根目录的 `logs/` 和 `data/` 下,不会写入包内部。
wqbkit-0.3.1/README.md ADDED
@@ -0,0 +1,249 @@
1
+ # wqbkit
2
+
3
+ WorldQuant Brain (WQB) Alpha Research Automation Toolkit
4
+
5
+ **[English](#overview) | [中文](#概述)**
6
+
7
+ ---
8
+
9
+ ## Overview
10
+
11
+ `wqbkit` is a Python toolkit that automates alpha research workflows on the [WorldQuant Brain](https://www.worldquantbrain.com) (WQB) platform. It covers the entire alpha lifecycle — from simulation and scoring to correlation analysis, genetic expression evolution, and Osmosis competition allocation.
12
+
13
+ ### Key Features
14
+
15
+ | Module | Description |
16
+ |--------|-------------|
17
+ | `AlphaBaseCore` | WQB authentication, HTTP request wrapper with 429 retry |
18
+ | `AlphaDbCore` | `AlphaBaseCore` + PostgreSQL ORM + PnL cache + token extraction |
19
+ | `AlphaCalcCorr` | Multi-metric correlation engine (self / ppac / prod / self_web) |
20
+ | `AlphaGenerator` | Expression factory (0/1/2/3-order) with operator/field validation |
21
+ | `AlphaMachine` | Genetic iteration pipeline — pruning, deduplication, next-generation |
22
+ | `AlphaSimulator` | Multi-threaded batch simulation scheduler with queue-based results |
23
+ | `SuperAlphaSimulator` | Dedicated simulator for SUPER-type alphas |
24
+ | `AlphaDyeing` | SUPER alpha construction and combo template management |
25
+ | `Osmosis V3` | `OsmosisAlphaSelectorV3` + `OsmosisAllocatorV3` + `OsmosisClearV3` + `OsmosisRunnerV3` |
26
+ | `sc_send` | Bark (iOS) push notification for long-running jobs |
27
+
28
+ ---
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ pip install wqbkit
34
+ ```
35
+
36
+ ### Prerequisites
37
+
38
+ - Python >= 3.10
39
+ - PostgreSQL (optional, for local alpha metadata caching)
40
+ - `wqb` SDK — WorldQuant Brain official Python client
41
+
42
+ ```bash
43
+ pip install wqb
44
+ ```
45
+
46
+ ---
47
+
48
+ ## Quick Start
49
+
50
+ ```python
51
+ from wqbkit import AlphaDbCore, AlphaCalcCorr, AlphaGenerator, OsmosisRunnerV3
52
+
53
+ # Initialize core (auto-loads .env if present)
54
+ core = AlphaDbCore()
55
+
56
+ # Correlation analysis
57
+ calcor = AlphaCalcCorr()
58
+ self_corr = calcor.calc_corr(alpha_id, calc_type='self')
59
+
60
+ # Generate expressions
61
+ generator = AlphaGenerator()
62
+ new_exprs = generator.second_order_factory(
63
+ expression="ts_mean(close, 20)",
64
+ region="USA",
65
+ atom=True
66
+ )
67
+
68
+ # Osmosis V3 pipeline
69
+ runner = OsmosisRunnerV3()
70
+ runner.run(update=True, dry_run=False)
71
+ ```
72
+
73
+ ---
74
+
75
+ ## Configuration
76
+
77
+ Create a `.env` file in your **project root directory** (the directory above `wqbkit/` in editable-install mode):
78
+
79
+ ```env
80
+ # Database (optional)
81
+ DB_HOST=localhost
82
+ DB_PORT=5432
83
+ DB_NAME=WorldQuant
84
+ DB_USER=your_db_user
85
+ DB_PASSWORD=your_db_password
86
+
87
+ # WQB Credentials
88
+ WQB_USERNAME=your_wqb_username
89
+ WQB_PASSWORD=your_wqb_password
90
+
91
+ # Retry
92
+ MAX_RETRIES=5
93
+ RETRY_DELAY_BASE=2
94
+
95
+ # Bark Push (optional)
96
+ BARK_KEY=your_bark_device_key
97
+ ```
98
+
99
+ `wqbkit` automatically loads `.env` on import via `python-dotenv`.
100
+
101
+ ### Runtime Paths
102
+
103
+ Logs and temporary data are written to your **project root directory**, never inside the package:
104
+
105
+ | Type | Default Path | Configurable via |
106
+ |------|-------------|------------------|
107
+ | Logs | `{project_root}/logs/` | `config.LOGS_DIR` |
108
+ | Correlation cache | `{project_root}/data/correlation/` | `config.DATA_DIR / "correlation"` |
109
+ | Osmosis data | `{project_root}/data/Osmosis/` | `config.DATA_DIR / "Osmosis"` |
110
+
111
+ ---
112
+
113
+ ## API Reference
114
+
115
+ ### Core Classes
116
+
117
+ ```python
118
+ from wqbkit import (
119
+ AlphaBaseCore, # WQB session + HTTP + retry
120
+ AlphaDbCore, # AlphaBaseCore + DB + PnL cache
121
+ AlphaCalcCorr, # Correlation analysis engine
122
+ AlphaGenerator, # Expression factory
123
+ AlphaSimulator, # Multi-threaded simulation scheduler
124
+ AlphaMachine, # Genetic iteration pipeline
125
+ AlphaDyeing, # SUPER alpha builder
126
+ SuperAlphaSimulator, # SUPER alpha simulator
127
+ OsmosisAlphaSelectorV3, # Osmosis V3 selector
128
+ OsmosisAllocatorV3, # Osmosis V3 allocator
129
+ OsmosisClearV3, # Osmosis V3 score clearer
130
+ OsmosisRunnerV3, # Osmosis V3 end-to-end runner
131
+ sc_send, # Push notification helper
132
+ schemas, # Data models: FactorData, TaskData, SimulationData
133
+ )
134
+ ```
135
+
136
+ ### Osmosis V3
137
+
138
+ ```python
139
+ from wqbkit import OsmosisAlphaSelectorV3, OsmosisAllocatorV3, OsmosisRunnerV3
140
+
141
+ # 1. Select alphas
142
+ selector = OsmosisAlphaSelectorV3()
143
+ df = selector.select(region="USA")
144
+
145
+ # 2. Allocate scores
146
+ allocator = OsmosisAllocatorV3()
147
+ df = allocator.allocate(df, method="mixed")
148
+ allocator.update_osmosis_points(df, dry_run=False)
149
+
150
+ # 3. Or run the full pipeline
151
+ runner = OsmosisRunnerV3()
152
+ runner.run(update=True, dry_run=False)
153
+ ```
154
+
155
+ ### Correlation Analysis
156
+
157
+ ```python
158
+ from wqbkit import AlphaCalcCorr
159
+
160
+ calcor = AlphaCalcCorr()
161
+
162
+ # Compute correlations
163
+ corr = calcor.calc_corr(alpha_id, calc_type='self') # self-correlation
164
+ corr = calcor.calc_corr(alpha_id, calc_type='ppac') # ppac correlation
165
+ corr = calcor.calc_corr(alpha_id, calc_type='prod') # prod correlation
166
+ ```
167
+
168
+ ### Alpha Simulation
169
+
170
+ ```python
171
+ from wqbkit import AlphaSimulator
172
+
173
+ sim = AlphaSimulator()
174
+
175
+ # Single alpha simulation
176
+ result = sim.simulate(expression="rank(close)", region="USA", universe="TOP3000")
177
+
178
+ # Batch simulation from database queue
179
+ sim.run_batch_simulation(task_id=123)
180
+ ```
181
+
182
+ ---
183
+
184
+ ## Project Structure
185
+
186
+ ```
187
+ wqbkit/
188
+ ├── app/
189
+ │ ├── core/ # AlphaBaseCore, AlphaDbCore, decorators, logger, URLs
190
+ │ ├── database/ # SQLAlchemy models, AlphaDBManager, schemas
191
+ │ └── utils/ # Token extraction helpers
192
+ └── modules/
193
+ ├── regular_alpha/ # AlphaSimulator, AlphaMachine, AlphaGenerator
194
+ ├── super_alpha/ # SuperAlphaSimulator, AlphaDyeing, SuperAlphaCreator
195
+ ├── correlation/ # AlphaCalcCorr
196
+ ├── message/ # Bark push notifications
197
+ └── competitions/
198
+ └── Osmosis/ # Osmosis V3 toolkit
199
+ ```
200
+
201
+ ---
202
+
203
+ ## License
204
+
205
+ MIT
206
+
207
+ ---
208
+
209
+ ## 概述
210
+
211
+ `wqbkit` 是一个用于自动化 [WorldQuant Brain](https://www.worldquantbrain.com) 平台 Alpha 研究的 Python 工具包,覆盖 Alpha 全生命周期:模拟、评分、去相关、遗传迭代进化、Osmosis 竞赛分配。
212
+
213
+ ### 核心功能
214
+
215
+ | 模块 | 说明 |
216
+ |------|------|
217
+ | `AlphaBaseCore` | WQB 认证、HTTP 封装、429 重试 |
218
+ | `AlphaDbCore` | `AlphaBaseCore` + PostgreSQL ORM + PnL 缓存 + token 提取 |
219
+ | `AlphaCalcCorr` | 多指标相关性引擎(self / ppac / prod / self_web) |
220
+ | `AlphaGenerator` | 表达式工厂(0/1/2/3 阶),带算子/字段校验 |
221
+ | `AlphaMachine` | 遗传迭代管线:剪枝、去重、下一代 |
222
+ | `AlphaSimulator` | 多线程批量模拟调度器,队列式结果处理 |
223
+ | `SuperAlphaSimulator` | SUPER 类型 Alpha 专用模拟器 |
224
+ | `AlphaDyeing` | SUPER Alpha 构造与 combo 模板管理 |
225
+ | `Osmosis V3` | `OsmosisAlphaSelectorV3` + `OsmosisAllocatorV3` + `OsmosisClearV3` + `OsmosisRunnerV3` |
226
+ | `sc_send` | Bark (iOS) 推送通知,用于长时任务提醒 |
227
+
228
+ ### 快速开始
229
+
230
+ ```python
231
+ from wqbkit import AlphaDbCore, AlphaCalcCorr, AlphaGenerator, OsmosisRunnerV3
232
+
233
+ core = AlphaDbCore()
234
+ calcor = AlphaCalcCorr()
235
+ generator = AlphaGenerator()
236
+ runner = OsmosisRunnerV3()
237
+ runner.run(update=True, dry_run=False)
238
+ ```
239
+
240
+ ### 配置说明
241
+
242
+ 在项目根目录创建 `.env`:
243
+
244
+ ```env
245
+ WQB_USERNAME=your_username
246
+ WQB_PASSWORD=your_password
247
+ ```
248
+
249
+ 日志和运行时数据统一写入项目根目录的 `logs/` 和 `data/` 下,不会写入包内部。
@@ -0,0 +1,62 @@
1
+ """WorldQuant Brain Alpha Research Toolkit"""
2
+
3
+ from wqbkit.app.config import PROJECT_ROOT
4
+ from dotenv import load_dotenv
5
+
6
+ # 显式加载项目根目录的 .env(适用于 editable install 模式)
7
+ # load_dotenv 默认 override=False,不会覆盖已存在的环境变量
8
+ _env_path = PROJECT_ROOT / ".env"
9
+ if _env_path.exists():
10
+ load_dotenv(_env_path)
11
+ else:
12
+ load_dotenv()
13
+
14
+ from importlib.metadata import version, PackageNotFoundError
15
+
16
+ try:
17
+ __version__ = version("wqbkit")
18
+ except PackageNotFoundError:
19
+ __version__ = "0.0.0"
20
+
21
+ # ---------- Public API ----------
22
+ # 核心基础设施
23
+ from wqbkit.app.core.alpha_base_core import AlphaBaseCore
24
+ from wqbkit.app.core.alpha_db_core import AlphaDbCore
25
+
26
+ # 数据模型
27
+ from wqbkit.app.database import schemas
28
+
29
+ # 业务模块
30
+ from wqbkit.modules.correlation.alpha_calc_corr import AlphaCalcCorr
31
+ from wqbkit.modules.regular_alpha.alpha_machine.alpha_generator import AlphaGenerator
32
+ from wqbkit.modules.regular_alpha.alpha_machine.alpha_machine import AlphaMachine
33
+ from wqbkit.modules.regular_alpha.alpha_simulator.alpha_simulator import AlphaSimulator
34
+ from wqbkit.modules.super_alpha.alpha_dyeing import AlphaDyeing
35
+ from wqbkit.modules.super_alpha.super_alpha_simulator import SuperAlphaSimulator
36
+ from wqbkit.modules.message.alpha_message_sender import sc_send
37
+ from wqbkit.modules.competitions.Osmosis.osmosis_selector_v3 import OsmosisAlphaSelectorV3
38
+ from wqbkit.modules.competitions.Osmosis.osmosis_allocator_v3 import OsmosisAllocatorV3
39
+ from wqbkit.modules.competitions.Osmosis.osmosis_clear_v3 import OsmosisClearV3
40
+ from wqbkit.modules.competitions.Osmosis.osmosis_runner_v3 import OsmosisRunnerV3
41
+
42
+ __all__ = [
43
+ "__version__",
44
+ # 核心
45
+ "AlphaBaseCore",
46
+ "AlphaDbCore",
47
+ # 数据模型
48
+ "schemas",
49
+ # 业务模块
50
+ "AlphaCalcCorr",
51
+ "AlphaGenerator",
52
+ "AlphaMachine",
53
+ "AlphaSimulator",
54
+ "AlphaDyeing",
55
+ "SuperAlphaSimulator",
56
+ "sc_send",
57
+ # Osmosis V3
58
+ "OsmosisAlphaSelectorV3",
59
+ "OsmosisAllocatorV3",
60
+ "OsmosisClearV3",
61
+ "OsmosisRunnerV3",
62
+ ]
File without changes