mlquantx 0.2.5__py3-none-any.whl

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 (54) hide show
  1. mlquant/__init__.py +18 -0
  2. mlquant/backtest/__init__.py +14 -0
  3. mlquant/backtest/engine.py +118 -0
  4. mlquant/backtest/metrics.py +95 -0
  5. mlquant/cli/__init__.py +1 -0
  6. mlquant/cli/main.py +292 -0
  7. mlquant/configs/__init__.py +1 -0
  8. mlquant/configs/small.yaml +41 -0
  9. mlquant/data/__init__.py +88 -0
  10. mlquant/data/akshare_loader.py +168 -0
  11. mlquant/data/baostock_loader.py +137 -0
  12. mlquant/data/loaders.py +125 -0
  13. mlquant/data/panel.py +206 -0
  14. mlquant/data/synthetic.py +138 -0
  15. mlquant/data/yfinance_loader.py +101 -0
  16. mlquant/features/__init__.py +42 -0
  17. mlquant/features/_factors_add.py +288 -0
  18. mlquant/features/_factors_alpha101.py +98 -0
  19. mlquant/features/_factors_best.py +177 -0
  20. mlquant/features/_factors_better.py +385 -0
  21. mlquant/features/_factors_change.py +53 -0
  22. mlquant/features/_factors_extra.py +147 -0
  23. mlquant/features/_factors_market.py +61 -0
  24. mlquant/features/_factors_old.py +563 -0
  25. mlquant/features/_factors_original.py +215 -0
  26. mlquant/features/_factors_stock.py +270 -0
  27. mlquant/features/alpha101.py +84 -0
  28. mlquant/features/bias.py +81 -0
  29. mlquant/features/legacy_factors.py +126 -0
  30. mlquant/features/market_breadth.py +190 -0
  31. mlquant/features/neutralize.py +75 -0
  32. mlquant/features/target.py +62 -0
  33. mlquant/features/tensor_factors.py +301 -0
  34. mlquant/features.py +613 -0
  35. mlquant/models/__init__.py +8 -0
  36. mlquant/models/losses.py +88 -0
  37. mlquant/models/nets.py +62 -0
  38. mlquant/portfolio/__init__.py +5 -0
  39. mlquant/portfolio/frontier.py +49 -0
  40. mlquant/portfolio/markowitz.py +144 -0
  41. mlquant/training/__init__.py +6 -0
  42. mlquant/training/augment.py +89 -0
  43. mlquant/training/dataset.py +50 -0
  44. mlquant/training/trainer.py +108 -0
  45. mlquant/utils/__init__.py +5 -0
  46. mlquant/utils/config.py +60 -0
  47. mlquant/utils/seed.py +35 -0
  48. mlquantx-0.2.5.dist-info/METADATA +108 -0
  49. mlquantx-0.2.5.dist-info/RECORD +54 -0
  50. mlquantx-0.2.5.dist-info/WHEEL +5 -0
  51. mlquantx-0.2.5.dist-info/entry_points.txt +2 -0
  52. mlquantx-0.2.5.dist-info/licenses/LICENSE +21 -0
  53. mlquantx-0.2.5.dist-info/licenses/NOTICE.md +5 -0
  54. mlquantx-0.2.5.dist-info/top_level.txt +1 -0
mlquant/utils/seed.py ADDED
@@ -0,0 +1,35 @@
1
+ """Deterministic seeding across numpy, python, and (optionally) torch."""
2
+ from __future__ import annotations
3
+
4
+ import os
5
+ import random
6
+
7
+
8
+ def seed_everything(seed: int = 42, *, deterministic_torch: bool = True) -> None:
9
+ """Seed all RNGs the project touches.
10
+
11
+ Parameters
12
+ ----------
13
+ seed : int
14
+ Master seed. Each library is seeded with the same value.
15
+ deterministic_torch : bool
16
+ If True and torch is importable, set deterministic cuDNN flags so
17
+ that runs are bit-reproducible on the same hardware. Marginally
18
+ slower; turn off for production training.
19
+ """
20
+ random.seed(seed)
21
+ os.environ["PYTHONHASHSEED"] = str(seed)
22
+ try:
23
+ import numpy as np
24
+ np.random.seed(seed)
25
+ except ImportError:
26
+ pass
27
+ try:
28
+ import torch
29
+ torch.manual_seed(seed)
30
+ torch.cuda.manual_seed_all(seed)
31
+ if deterministic_torch:
32
+ torch.backends.cudnn.deterministic = True
33
+ torch.backends.cudnn.benchmark = False
34
+ except ImportError:
35
+ pass
@@ -0,0 +1,108 @@
1
+ Metadata-Version: 2.4
2
+ Name: mlquantx
3
+ Version: 0.2.5
4
+ Summary: Reference implementation of ‘ML-Enhanced Multi-Factor Quantitative Trading’ (arXiv:2507.07107).
5
+ Author: Yimin Du
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/initial-d/ml-quant-trading
8
+ Project-URL: Documentation, https://initial-d.github.io/ml-quant-trading/
9
+ Project-URL: Paper, https://arxiv.org/abs/2507.07107
10
+ Project-URL: Issues, https://github.com/initial-d/ml-quant-trading/issues
11
+ Project-URL: Changelog, https://github.com/initial-d/ml-quant-trading/blob/main/CHANGELOG.md
12
+ Keywords: quant,alpha,factor,portfolio,pytorch,markowitz
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Financial and Insurance Industry
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Topic :: Office/Business :: Financial :: Investment
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ License-File: NOTICE.md
26
+ Requires-Dist: numpy>=1.24
27
+ Requires-Dist: pandas>=2.0
28
+ Requires-Dist: scipy>=1.10
29
+ Requires-Dist: scikit-learn>=1.3
30
+ Requires-Dist: torch>=2.0
31
+ Requires-Dist: cvxpy>=1.4
32
+ Requires-Dist: scs>=3.2
33
+ Requires-Dist: pyyaml>=6.0
34
+ Requires-Dist: click>=8.1
35
+ Requires-Dist: rich>=13.0
36
+ Requires-Dist: tqdm>=4.65
37
+ Requires-Dist: yfinance>=0.2.0
38
+ Requires-Dist: baostock>=0.8.8
39
+ Requires-Dist: akshare>=1.18.0
40
+ Provides-Extra: mosek
41
+ Requires-Dist: Mosek>=10.0; extra == "mosek"
42
+ Provides-Extra: ecos
43
+ Requires-Dist: ecos>=2.0; extra == "ecos"
44
+ Provides-Extra: gpu
45
+ Requires-Dist: cupy-cuda12x>=12.0; extra == "gpu"
46
+ Provides-Extra: dev
47
+ Requires-Dist: pytest>=7.4; extra == "dev"
48
+ Requires-Dist: pytest-cov>=4.1; extra == "dev"
49
+ Requires-Dist: ruff>=0.4; extra == "dev"
50
+ Requires-Dist: mypy>=1.7; extra == "dev"
51
+ Requires-Dist: hypothesis>=6.90; extra == "dev"
52
+ Dynamic: license-file
53
+
54
+ # mlquant
55
+
56
+ **A reproducible PyTorch research stack for machine-learning multi-factor
57
+ trading: 213 factors, bias correction, portfolio optimization, and vectorized
58
+ backtesting.**
59
+
60
+ [![CI](https://github.com/initial-d/ml-quant-trading/actions/workflows/ci.yml/badge.svg)](https://github.com/initial-d/ml-quant-trading/actions/workflows/ci.yml)
61
+ [![arXiv](https://img.shields.io/badge/arXiv-2507.07107-b31b1b.svg)](https://arxiv.org/abs/2507.07107)
62
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9%2B-blue.svg)](https://www.python.org/downloads/)
63
+
64
+ ## Install and run
65
+
66
+ ```bash
67
+ python -m pip install mlquantx
68
+ mlquant demo
69
+ ```
70
+
71
+ The demo needs no market-data account or API key. It runs the deterministic
72
+ synthetic pipeline from data generation through 213 factor dimensions, model
73
+ training, portfolio construction, cost-aware backtesting, and Markdown/JSON
74
+ report generation. The default config ships inside the wheel, so the command
75
+ works outside a repository checkout.
76
+
77
+ ## What is included
78
+
79
+ - 204 hand-crafted factors plus 9 curated Alpha101-style factors
80
+ - mask-aware PyTorch tensor primitives for cross-sectional panels
81
+ - limit-up, limit-down, halt, and missing-data bias handling
82
+ - MLP and Transformer research baselines
83
+ - constrained Markowitz portfolio construction
84
+ - vectorized backtesting with turnover and transaction costs
85
+ - AkShare, Baostock, yfinance, and deterministic synthetic data paths
86
+ - auditable public-data validation reports, including negative results
87
+
88
+ ## Start here
89
+
90
+ - [Source and full documentation](https://github.com/initial-d/ml-quant-trading)
91
+ - [Google Colab quick start](https://colab.research.google.com/github/initial-d/ml-quant-trading/blob/main/notebooks/quickstart_colab.ipynb)
92
+ - [Public validation dashboard](https://github.com/initial-d/ml-quant-trading/blob/main/docs/validation_dashboard.md)
93
+ - [Research card and limitations](https://github.com/initial-d/ml-quant-trading/blob/main/docs/research_card.md)
94
+ - [100,000-row synthetic dataset](https://huggingface.co/datasets/dddyym/ml-quant-trading-synthetic)
95
+ - [213-input MLP checkpoint](https://huggingface.co/dddyym/ml-quant-trading-synthetic-mlp)
96
+ - [Paper: arXiv:2507.07107](https://arxiv.org/abs/2507.07107)
97
+
98
+ ## Research boundary
99
+
100
+ `mlquant` is research and educational software. It is not investment advice or
101
+ a production trading system. Synthetic smoke tests verify engineering behavior,
102
+ not profitability. Public-data backtests depend on data quality, survivorship,
103
+ transaction costs, slippage, and modeling assumptions and do not represent live
104
+ or guaranteed out-of-sample performance.
105
+
106
+ ## License
107
+
108
+ MIT. See the [repository license](https://github.com/initial-d/ml-quant-trading/blob/main/LICENSE).
@@ -0,0 +1,54 @@
1
+ mlquant/__init__.py,sha256=uVaPEuJhOkokTGzFL25IE3qfr_Yfh3i_Bw4zjuXgqBA,754
2
+ mlquant/features.py,sha256=ZIVzEAaYF9_CQs-05vzDGKnLCLABCp_H87ylQj2pKc0,24406
3
+ mlquant/backtest/__init__.py,sha256=s97dmR-zuxk9BmRhyGkh9KG_RVsdUkMs5hMJjBlUmFY,481
4
+ mlquant/backtest/engine.py,sha256=uDWtW--3LeopJPhK_eBVLLwmCC0JJG2V0F-9-9xPjLo,4133
5
+ mlquant/backtest/metrics.py,sha256=z6oRMQ3uI8EleKtqXKsIzq4Y3arjuNseOAQjgUDeBy4,3092
6
+ mlquant/cli/__init__.py,sha256=H4glUfFV2xFtdABrNKMXCPDuKq4fxAJi7RoBNvFQ5h4,87
7
+ mlquant/cli/main.py,sha256=DMnow9uMpET6UqLYqXXiRnxTnS4_zFAJ_ruOW6-gHIo,10580
8
+ mlquant/configs/__init__.py,sha256=3EU0PeW_1PtralYIn9UM7ZIcVLZbx7Etz7-U6RntKbc,68
9
+ mlquant/configs/small.yaml,sha256=6OU_EkAcvtdl-meV1UH1qAbUE5VuGvJPS70UTB2vVzU,837
10
+ mlquant/data/__init__.py,sha256=hyUgEKDv70M-N08ZwBIqzEFpva5ozFZ_vsNw2Mr6dpA,3484
11
+ mlquant/data/akshare_loader.py,sha256=ngZ6bber8xz7ztP-S9T6z8Yrk-ig6uRbu14VNFYdAgY,5292
12
+ mlquant/data/baostock_loader.py,sha256=kVzVD9v-7mMPPbuecUABELzA5VmeqKM7-FOuRx5eau4,4692
13
+ mlquant/data/loaders.py,sha256=tjwYn0sZPAVo-39oEV2ifbI8HJvEYUZVQAihl8op3Z8,4454
14
+ mlquant/data/panel.py,sha256=hrVmz9nUigV4zeK1lA8neAqOhz8XI0ix-smdXhe294U,8259
15
+ mlquant/data/synthetic.py,sha256=ZpBxXolSi7B0xY2kNXRt7u2nb0IhVejBHO9fn6zkxco,5826
16
+ mlquant/data/yfinance_loader.py,sha256=GezSUEabJqntR0FJsBlWtpzwjnTD6dpbinOn8m-_TIo,3322
17
+ mlquant/features/__init__.py,sha256=aYmj_n8Jph9d3pDsksYo1LulIIKa-oni0bvzkd7C5tk,1266
18
+ mlquant/features/_factors_add.py,sha256=WNat44Ai8_Uxz9pLpdm5tf6wzyxOgvMDLHdh8D1GHvg,9885
19
+ mlquant/features/_factors_alpha101.py,sha256=s7m5MECtkmSzDZDg1hA48bWIFnw9Bgg7dpYienXPVvE,3423
20
+ mlquant/features/_factors_best.py,sha256=RRbHmLDf5-L289BxYzLcC8NzhmY_tyrWSTDHrU8WCTU,5912
21
+ mlquant/features/_factors_better.py,sha256=Hq8MiXdm-_rraWTuSkFtaRTMqY2oGVylPOlujo_kVAs,14217
22
+ mlquant/features/_factors_change.py,sha256=ljfa2rbay961me8EQPPaxWXlau77ab-B5FutXLB97V0,1773
23
+ mlquant/features/_factors_extra.py,sha256=gK3Lo3SrfGQPKtAKns68ua0KNrhYGvv18R521RQjk18,4958
24
+ mlquant/features/_factors_market.py,sha256=jwr4D3w_PzKRD5VYFyV5afJt_tx4St0nL6m-wOsomKs,1999
25
+ mlquant/features/_factors_old.py,sha256=I-5LlK1ZEpUhdie_k3wkESmSAAw1K9wIeIEZq8xVsig,19750
26
+ mlquant/features/_factors_original.py,sha256=DflSuk4Rmfh4WOo7NuT5VkQB6wq6IrjPJf3fm7r-Whk,7247
27
+ mlquant/features/_factors_stock.py,sha256=hFZNLmWMSVCM-uI4u-kT5H6eKQF33onGpnqdBw7qj4o,10076
28
+ mlquant/features/alpha101.py,sha256=_ZI3zmO1y0awE-leNeGNGfvjMgBZVf_iZ581Sa-lShs,2605
29
+ mlquant/features/bias.py,sha256=YLq0FxdHrAG5dBCLYgGhhKFo0QmV8FMzN4sac17sIIs,3160
30
+ mlquant/features/legacy_factors.py,sha256=CT7SwCinwHs0_X9GOkbsWrqf0FiRXZNJ9FWSemqoi94,4449
31
+ mlquant/features/market_breadth.py,sha256=JQdPKG8q8YDwJ0pP58QaaxTvLEel00kKu2QguEFd6z8,7021
32
+ mlquant/features/neutralize.py,sha256=FbiY85KirckMjl1Atoch089mct6V3u2gpTft1SbzgXk,2479
33
+ mlquant/features/target.py,sha256=L-2d1BnTf8hV4Ye4eBanuhQfMSaZCrg2QHyy3L3haEk,1857
34
+ mlquant/features/tensor_factors.py,sha256=SGHVJFUKz59rgkl9TDZ2qQCMFD3eFZXIb8Nq3qTp1LY,12759
35
+ mlquant/models/__init__.py,sha256=lJnTTRu9pv3_y6ynsDZFAjwUL8m6grUYkV7ozagcKSw,259
36
+ mlquant/models/losses.py,sha256=iWEjXidVY-n8v1duXkQJBMgY10YxRTxsn_QprV0W5P0,3235
37
+ mlquant/models/nets.py,sha256=wb4NfGbDXSYhjsj9-Vzm8spIvbqbEOmzpBv6Fua42XA,2360
38
+ mlquant/portfolio/__init__.py,sha256=DGg4bzdr2WKGGwVTf5KKQ1xzgecoRdB4P6iwT-QR_2k,242
39
+ mlquant/portfolio/frontier.py,sha256=NC9gAO-as9-FAqAEKOlR1K8k-wMjqSA7Q0lcDhp9WNo,1629
40
+ mlquant/portfolio/markowitz.py,sha256=tPYKKOMtW7TygT4nuo8LFzdfT3rE6xCcDIYlEgD6NLU,5104
41
+ mlquant/training/__init__.py,sha256=ZNR6ZLCJD2P3lBMNyD7UG6z6UU_tjUI5SEnW1NMCKng,237
42
+ mlquant/training/augment.py,sha256=KlrXPlYLDKeQNNpqHfBWZtNmcqOR9ISp14J6MOBuYzU,3546
43
+ mlquant/training/dataset.py,sha256=y45uMK8eke3ogKAplXIYTlprR9AgrG41n8Gf2hy4aC8,1882
44
+ mlquant/training/trainer.py,sha256=FIxE2me54axG3If6NDETWO0wtSBc0kDpR2iDOosQ3FQ,3898
45
+ mlquant/utils/__init__.py,sha256=9OrXGFAnfUD70SBV2gNH5qpGVzGfVTCq15rGtjdJ5UM,195
46
+ mlquant/utils/config.py,sha256=VgS7Dy4MPrGoODLhd7NwyebZhiV3LXC0jBQ49AYipyQ,1804
47
+ mlquant/utils/seed.py,sha256=DGEHljgpF7U_FGtCW_PaoSu8CZeLayhzmAKhM5IE2sI,1052
48
+ mlquantx-0.2.5.dist-info/licenses/LICENSE,sha256=92uRftTq4Ikic-EIrJb1F2Z2TvFO5fv0qLaGnDuRBDU,1065
49
+ mlquantx-0.2.5.dist-info/licenses/NOTICE.md,sha256=gybGh0pbDjXoCRKvcD6CdTatz-IICFgA_yKpWc_DX2M,333
50
+ mlquantx-0.2.5.dist-info/METADATA,sha256=pmABT3SwOpp9OQMjmo7Y9Q-7DqxVXG8JZBRhhJdRzrE,4776
51
+ mlquantx-0.2.5.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
52
+ mlquantx-0.2.5.dist-info/entry_points.txt,sha256=mqFmTmkhepJU6wI6yZsfIVtyEBuHXiefTixBr42P24s,50
53
+ mlquantx-0.2.5.dist-info/top_level.txt,sha256=DWYIR6afD0xGLmSkRZne8HtmT8gpEX9U2LYf4TxqnNs,8
54
+ mlquantx-0.2.5.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ mlquant = mlquant.cli.main:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Yimin Du
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,5 @@
1
+ # Notices
2
+
3
+ This repository is distributed under the MIT License. Some optional third-party dependencies have their own licenses and terms.
4
+
5
+ In particular, MOSEK is an optional solver backend and may require a commercial or academic license from MOSEK ApS. The default install path uses open-source solvers available through `cvxpy`.
@@ -0,0 +1 @@
1
+ mlquant