cnhkmcp 1.0.2__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.
@@ -0,0 +1,40 @@
1
+ # Dependencies
2
+ node_modules/
3
+ npm-debug.log*
4
+ yarn-debug.log*
5
+ yarn-error.log*
6
+
7
+ # Build outputs
8
+ dist/
9
+ build/
10
+ *.tsbuildinfo
11
+
12
+ # Environment variables and secrets
13
+ .env
14
+ .env.local
15
+ .env.development.local
16
+ .env.test.local
17
+ .env.production.local
18
+
19
+ # Configuration files with credentials
20
+ config/brain-config.json
21
+
22
+ # Browser automation
23
+ screenshots/
24
+ downloads/
25
+
26
+ # Logs
27
+ logs/
28
+ *.log
29
+
30
+ # IDE
31
+ .vscode/settings.json
32
+ .idea/
33
+
34
+ # OS
35
+ .DS_Store
36
+ Thumbs.db
37
+
38
+ # Test outputs
39
+ test-results/
40
+ coverage/
cnhkmcp-1.0.2/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 WorldQuant BRAIN MCP
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.
cnhkmcp-1.0.2/PKG-INFO ADDED
@@ -0,0 +1,463 @@
1
+ Metadata-Version: 2.4
2
+ Name: cnhkmcp
3
+ Version: 1.0.2
4
+ Summary: A Model Context Protocol server for quantitative research and data analysis
5
+ Project-URL: Homepage, https://github.com/cnhk/cnhkmcp
6
+ Project-URL: Documentation, https://github.com/cnhk/cnhkmcp/blob/main/README.md
7
+ Project-URL: Repository, https://github.com/cnhk/cnhkmcp
8
+ Project-URL: Bug Tracker, https://github.com/cnhk/cnhkmcp/issues
9
+ Author-email: CNHK MCP <support@example.com>
10
+ Maintainer-email: CNHK MCP <support@example.com>
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: api,data-analysis,mcp,model-context-protocol,quantitative,research
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.8
21
+ Classifier: Programming Language :: Python :: 3.9
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
26
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
27
+ Requires-Python: >=3.8
28
+ Requires-Dist: anyio>=3.0.0
29
+ Requires-Dist: beautifulsoup4>=4.12.0
30
+ Requires-Dist: httpx>=0.25.0
31
+ Requires-Dist: lxml>=4.9.0
32
+ Requires-Dist: mcp>=1.0.0
33
+ Requires-Dist: pydantic>=2.0.0
34
+ Requires-Dist: selenium>=4.0.0
35
+ Provides-Extra: dev
36
+ Requires-Dist: black>=23.0.0; extra == 'dev'
37
+ Requires-Dist: isort>=5.0.0; extra == 'dev'
38
+ Requires-Dist: mypy>=1.0.0; extra == 'dev'
39
+ Requires-Dist: pre-commit>=3.0.0; extra == 'dev'
40
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
41
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
42
+ Description-Content-Type: text/markdown
43
+
44
+ # CNHK MCP Server
45
+
46
+ [![PyPI version](https://badge.fury.io/py/cnhkmcp.svg)](https://badge.fury.io/py/cnhkmcp)
47
+ [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
48
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
49
+
50
+ A Model Context Protocol (MCP) server for quantitative research and data analysis. This package provides comprehensive tools for research, simulation, and data analysis workflows.
51
+
52
+ ## Features
53
+
54
+ ### ๐Ÿ” Authentication & Session Management
55
+ - Secure authentication with platform API
56
+ - Automatic token refresh and session persistence
57
+ - Credential storage and management
58
+
59
+ ### ๐Ÿš€ Research & Simulation
60
+ - **Single & Batch Simulations**: Submit individual models or batch process up to 10 models simultaneously
61
+ - **Smart Waiting**: Intelligent monitoring with automatic retry logic
62
+ - **Multi-Model Support**: Regular and advanced simulation strategies
63
+ - **Real-time Monitoring**: Track simulation progress and completion status
64
+
65
+ ### ๐Ÿ“Š Data Analysis & Export
66
+ - **Performance Analytics**: Performance analysis, statistical metrics, analytical tools
67
+ - **Portfolio Analysis**: Aggregate data from multiple models
68
+ - **Data Export**: CSV export for performance data and statistics
69
+ - **Result Archival**: JSON export for complete simulation results
70
+
71
+ ### ๐Ÿ” Research Tools
72
+ - **Data Discovery**: Explore available datasets, data fields, and operators
73
+ - **Validation Tools**: Correlation checks and analysis tools
74
+ - **Forum Integration**: Access community forum posts and discussions
75
+ - **Quality Assurance**: Comprehensive validation before submission
76
+
77
+ ### ๐Ÿ“ˆ Advanced Features
78
+ - **Batch Processing**: Parallel processing of multiple models with configurable batch sizes
79
+ - **Data Transformation**: Flatten complex nested data structures for analysis
80
+ - **Link Generation**: Create clickable links to platform resources
81
+ - **Error Handling**: Comprehensive error tracking and reporting
82
+
83
+ ## Installation
84
+
85
+ ### From PyPI (Recommended)
86
+
87
+ ```bash
88
+ pip install cnhkmcp
89
+ ```
90
+
91
+ ### From Source
92
+
93
+ ```bash
94
+ git clone https://github.com/cnhk/cnhkmcp.git
95
+ cd cnhkmcp
96
+ pip install -e .
97
+ ```
98
+
99
+ ## Quick Start
100
+
101
+ ### 1. Basic Setup
102
+
103
+ First, start the MCP server:
104
+
105
+ ```bash
106
+ cnhkmcp-server
107
+ ```
108
+
109
+ ### 2. Authentication
110
+
111
+ ```python
112
+ # The server will automatically handle authentication
113
+ # You can also configure credentials in config files
114
+ ```
115
+
116
+ ### 3. Basic Simulation
117
+
118
+ ```python
119
+ # Example simulation request
120
+ {
121
+ "tool": "create_simulation",
122
+ "arguments": {
123
+ "type": "REGULAR",
124
+ "settings": {
125
+ "instrumentType": "EQUITY",
126
+ "region": "USA",
127
+ "universe": "TOP3000",
128
+ "delay": 1,
129
+ "decay": 0,
130
+ "neutralization": "SUBUNIV",
131
+ "truncation": 0.08,
132
+ "testPeriod": "P1Y6M",
133
+ "unitHandling": "VERIFY",
134
+ "nanHandling": "ELIMINATE",
135
+ "language": "FASTEXPR",
136
+ "visualization": true
137
+ },
138
+ "regular": "close"
139
+ }
140
+ }
141
+ ```
142
+
143
+ ## Configuration
144
+
145
+ ### Credentials Configuration
146
+
147
+ Create a `config/cnhk-config.json` file:
148
+
149
+ ```json
150
+ {
151
+ "credentials": {
152
+ "email": "your-email@example.com",
153
+ "password": "your-password"
154
+ },
155
+ "defaults": {
156
+ "instrumentType": "EQUITY",
157
+ "region": "USA",
158
+ "universe": "TOP3000",
159
+ "delay": 1,
160
+ "decay": 0,
161
+ "neutralization": "SUBUNIV",
162
+ "truncation": 0.08,
163
+ "testPeriod": "P1Y6M",
164
+ "unitHandling": "VERIFY",
165
+ "nanHandling": "ELIMINATE",
166
+ "language": "FASTEXPR",
167
+ "visualization": true
168
+ }
169
+ }
170
+ ```
171
+
172
+ ## Available Tools
173
+
174
+ ### Core Research Tools
175
+
176
+ | Tool | Description | Use Case |
177
+ |------|-------------|----------|
178
+ | `authenticate` | ๐Ÿ” Authenticate with platform | Required first step |
179
+ | `create_simulation` | ๐Ÿš€ Submit expressions for simulation | Single model research |
180
+ | `create_multi_simulation` | ๐Ÿš€ Batch submit multiple models | Batch research |
181
+ | `wait_for_simulation` | โณ Smart simulation waiting | Monitor completion |
182
+ | `get_simulation_status` | โฑ๏ธ Check simulation progress | Status monitoring |
183
+
184
+ ### Alpha Management
185
+
186
+ | Tool | Description | Use Case |
187
+ |------|-------------|----------|
188
+ | `get_alpha_details` | ๐Ÿ“Š Get alpha metadata and results | Result extraction |
189
+ | `get_user_alphas` | ๐Ÿ“‹ Retrieve user's alpha list | Portfolio management |
190
+ | `submit_alpha` | โœ… Submit alpha for evaluation | Production submission |
191
+ | `set_alpha_properties` | โš™๏ธ Update alpha properties | Alpha organization |
192
+
193
+ ### Data Analysis
194
+
195
+ | Tool | Description | Use Case |
196
+ |------|-------------|----------|
197
+ | `get_alpha_pnl` | ๐Ÿ“ˆ Get PnL data | Performance analysis |
198
+ | `get_alpha_yearly_stats` | ๐Ÿ“Š Get yearly statistics | Annual performance |
199
+ | `combine_pnl_data` | ๐Ÿ“ˆ Aggregate PnL from multiple alphas | Portfolio analysis |
200
+ | `save_simulation_data` | ๐Ÿ’พ Export simulation results | Data archival |
201
+ | `save_pnl_data` | ๐Ÿ“ค Export PnL to CSV | External analysis |
202
+
203
+ ### Validation & Quality
204
+
205
+ | Tool | Description | Use Case |
206
+ |------|-------------|----------|
207
+ | `check_production_correlation` | ๐Ÿ” Check production correlation | Pre-submission validation |
208
+ | `check_self_correlation` | ๐Ÿ” Check self-correlation | Uniqueness validation |
209
+ | `get_submission_check` | โœ… Comprehensive submission check | Quality assurance |
210
+ | `get_alpha_checks` | ๐Ÿงช Detailed validation results | Debug validation issues |
211
+
212
+ ### Data Discovery
213
+
214
+ | Tool | Description | Use Case |
215
+ |------|-------------|----------|
216
+ | `get_datasets` | ๐Ÿ” List available datasets | Data exploration |
217
+ | `get_datafields` | ๐Ÿ“Š Get data fields | Field discovery |
218
+ | `get_operators` | โš™๏ธ Get available operators | Expression building |
219
+ | `get_instrument_options` | ๐Ÿ”ง Get configuration options | Setup assistance |
220
+
221
+ ### Forum & Community
222
+
223
+ | Tool | Description | Use Case |
224
+ |------|-------------|----------|
225
+ | `get_forum_post` | ๐Ÿ“„ Extract forum post content | Community research |
226
+ | `search_forum_posts` | ๐Ÿ” Search forum discussions | Topic discovery |
227
+
228
+ ## Usage Examples
229
+
230
+ ### Example 1: Basic Alpha Research Workflow
231
+
232
+ ```python
233
+ # 1. Authenticate
234
+ await authenticate({
235
+ "email": "user@example.com",
236
+ "password": "password"
237
+ })
238
+
239
+ # 2. Create simulation
240
+ simulation = await create_simulation({
241
+ "type": "REGULAR",
242
+ "settings": {
243
+ "instrumentType": "EQUITY",
244
+ "region": "USA",
245
+ "universe": "TOP3000",
246
+ "delay": 1,
247
+ "decay": 0,
248
+ "neutralization": "SUBUNIV",
249
+ "truncation": 0.08,
250
+ "testPeriod": "P1Y6M",
251
+ "unitHandling": "VERIFY",
252
+ "nanHandling": "ELIMINATE",
253
+ "language": "FASTEXPR",
254
+ "visualization": True
255
+ },
256
+ "regular": "close"
257
+ })
258
+
259
+ # 3. Wait for completion
260
+ result = await wait_for_simulation({
261
+ "simulationId": simulation["id"],
262
+ "maxWaitTime": 1800
263
+ })
264
+
265
+ # 4. Get detailed results
266
+ details = await get_alpha_details({
267
+ "alphaId": result["alpha_id"]
268
+ })
269
+ ```
270
+
271
+ ### Example 2: Batch Alpha Processing
272
+
273
+ ```python
274
+ # Get user's alphas
275
+ alphas = await get_user_alphas({
276
+ "stage": "IS",
277
+ "limit": 50
278
+ })
279
+
280
+ # Extract alpha IDs
281
+ alpha_ids = [alpha["id"] for alpha in alphas["results"]]
282
+
283
+ # Batch process for correlations
284
+ correlations = await batch_process_alphas({
285
+ "alphaIds": alpha_ids,
286
+ "operation": "get_correlations",
287
+ "batchSize": 5
288
+ })
289
+ ```
290
+
291
+ ### Example 3: Multi-Simulation
292
+
293
+ ```python
294
+ # Create multiple simulations
295
+ multi_sim = await create_multi_simulation({
296
+ "simulations": [
297
+ {
298
+ "type": "REGULAR",
299
+ "settings": {...},
300
+ "regular": "close"
301
+ },
302
+ {
303
+ "type": "REGULAR",
304
+ "settings": {...},
305
+ "regular": "open"
306
+ }
307
+ # ... up to 10 total
308
+ ]
309
+ })
310
+ ```
311
+
312
+ ### Example 4: Forum Research
313
+
314
+ ```python
315
+ # Get forum post content
316
+ post = await get_forum_post({
317
+ "postUrlOrId": "32995186681879-ๅธธ็”จๆจกๆฟๅˆ†ๆž",
318
+ "includeComments": True
319
+ })
320
+
321
+ # Search forum posts
322
+ search_results = await search_forum_posts({
323
+ "searchQuery": "ๆจกๆฟ",
324
+ "maxResults": 20
325
+ })
326
+ ```
327
+
328
+ ## Advanced Features
329
+
330
+ ### Batch Processing
331
+
332
+ Process multiple alphas efficiently:
333
+
334
+ ```python
335
+ results = await batch_process_alphas({
336
+ "alphaIds": ["alpha1", "alpha2", "alpha3"],
337
+ "operation": "get_details", # or "get_pnl", "get_stats", "get_correlations"
338
+ "batchSize": 3
339
+ })
340
+ ```
341
+
342
+ ### Data Export
343
+
344
+ Export results for external analysis:
345
+
346
+ ```python
347
+ # Save simulation data
348
+ save_result = await save_simulation_data({
349
+ "simulationResult": simulation_data,
350
+ "folderPath": "my_results"
351
+ })
352
+
353
+ # Export PnL data to CSV
354
+ csv_result = await save_pnl_data({
355
+ "alphaId": "alpha123",
356
+ "region": "USA",
357
+ "pnlData": pnl_data,
358
+ "folderPath": "pnl_exports"
359
+ })
360
+ ```
361
+
362
+ ### Data Analysis
363
+
364
+ Combine and analyze multiple alphas:
365
+
366
+ ```python
367
+ # Combine PnL data from multiple alphas
368
+ combined = await combine_pnl_data({
369
+ "results": [result1, result2, result3]
370
+ })
371
+
372
+ # Expand nested data structures
373
+ expanded = await expand_nested_data({
374
+ "data": complex_data,
375
+ "preserveOriginal": True
376
+ })
377
+ ```
378
+
379
+ ## Error Handling
380
+
381
+ The server provides comprehensive error handling:
382
+
383
+ - **Authentication Errors**: Automatic token refresh
384
+ - **Rate Limiting**: Built-in retry logic with exponential backoff
385
+ - **Network Errors**: Automatic reconnection and retry
386
+ - **Validation Errors**: Detailed error messages with suggestions
387
+
388
+ ## Logging
389
+
390
+ Configure logging level in your environment:
391
+
392
+ ```bash
393
+ export CNHK_MCP_LOG_LEVEL=INFO # DEBUG, INFO, WARNING, ERROR
394
+ ```
395
+
396
+ ## Development
397
+
398
+ ### Setting up Development Environment
399
+
400
+ ```bash
401
+ git clone https://github.com/cnhk/cnhkmcp.git
402
+ cd cnhkmcp
403
+ pip install -e ".[dev]"
404
+ ```
405
+
406
+ ### Running Tests
407
+
408
+ ```bash
409
+ pytest
410
+ ```
411
+
412
+ ### Code Formatting
413
+
414
+ ```bash
415
+ black src/
416
+ isort src/
417
+ ```
418
+
419
+ ## Requirements
420
+
421
+ - Python 3.8+
422
+ - Platform account access
423
+ - Chrome/Chromium browser (for forum functionality)
424
+
425
+ ## Dependencies
426
+
427
+ - `mcp>=1.0.0`: Model Context Protocol SDK
428
+ - `httpx>=0.25.0`: HTTP client
429
+ - `pydantic>=2.0.0`: Data validation
430
+ - `selenium>=4.0.0`: Web automation
431
+ - `beautifulsoup4>=4.12.0`: HTML parsing
432
+
433
+ ## Contributing
434
+
435
+ 1. Fork the repository
436
+ 2. Create a feature branch
437
+ 3. Make your changes
438
+ 4. Add tests
439
+ 5. Submit a pull request
440
+
441
+ ## License
442
+
443
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
444
+
445
+ ## Support
446
+
447
+ - ๐Ÿ“– [Documentation](https://github.com/cnhk/cnhkmcp/blob/main/README.md)
448
+ - ๐Ÿ› [Issue Tracker](https://github.com/cnhk/cnhkmcp/issues)
449
+ - ๐Ÿ’ฌ [Discussions](https://github.com/cnhk/cnhkmcp/discussions)
450
+
451
+ ## Changelog
452
+
453
+ ### v1.0.0
454
+ - Initial release
455
+ - Core MCP server functionality
456
+ - Alpha simulation and management
457
+ - Forum integration
458
+ - Data analysis tools
459
+ - Batch processing capabilities
460
+
461
+ ---
462
+
463
+ **CNHK MCP Server** - Bringing quantitative research capabilities to AI assistants through the Model Context Protocol.