torchquantum
TorchQuantum is a backtesting framework that""" integrates the structure of PyTorch and WorldQuant's Operator for efficient quantitative financial analysis.
Contents
Installation
for Unix:
cd /path/to/your/directory
git clone git@github.com:nymath/torchqtm.git
cd ./torchqtm
Before running examples, you should compile the cython code.
python setup.py build_ext --inplace
Now you can run examples
python ./examples/main.py
If you are not downloading the dataset, then you should
cd ./examples
mkdir largedata
cd ./largedata
wget https://github.com/nymath/torchqtm/releases/download/V0.1/stocks_f64.pkl.zip
unzip stocks_f64.pkl.zip
rm stocks_f64.pkl.zip
cd ../
cd ../
git checkout dev
As for the backtesting dataset, we use the bundle provided by ricequant. We have wrapped the code into Makefile, you can just run the following command to download the bundle.
make rqalpha_download_bundle
for windows: We highly recommend you to use WSL2 to run torchquantum.
Examples
alpha mining
You can easily create an alpha through torchquantum!
import torchqtm.op as op
import torchqtm.op.functional as F
class NeutralizePE(op.Fundamental):
def __init__(self, env):
super().__init__(env)
self.lag = op.Parameter(5, requires_optim=False, feasible_region=None)
def forward(self):
self.data = F.divide(1, self.env.PE)
self.data = F.winsorize(self.data, 'std', 4)
self.data = F.normalize(self.data)
self.data = F.group_neutralize(self.data, self.env.Sector)
self.data = F.regression_neut(self.data, self.env.MktVal)
self.data = F.ts_mean(self.data, self.lag)
return self.data
Fis library that contains the operators defined by WorldQuant.op.Fundamentalimplies the NeutralizePE belongs to fundamental alpha.self.lagis the parameter of rolling mean, which can be optimized through grid search.
backtesting
Here we create a buy and hold strategy for illustration.
from torchqtm.edbt.algorithm import TradingAlgorithm
from torchqtm.assets import Equity
class BuyAndHold(TradingAlgorithm):
def initialize(self):
self.safe_set_attr("s0", Equity("000001.XSHE"))
self.safe_set_attr("count", 0)
def before_trading_start(self):
pass
def handle_data(self):
if self.count == 0:
self.order(self.s0, 10000)
self.count += 1
def analyze(self):
pass
Features
- High-speed backtesting framework (most of the operators are implemented through cython)
- A revised gplearn library that is compatible with Alpha mining.
- CNN and other state of the art models for mining alphas.
- Event Driven backtesting framework is available.
Contribution
For more information, we refer to Documentation.
Join us
If you are interested in quantitative finance and are committed to devoting your life to alpha mining, you can contact me through WeChat at Ny_math.
References
Metadata
Release files for torchqtm 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| torchqtm-0.6.0.tar.gz | 638.0 kB | Without provenance | Details for torchqtm-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| torchqtm-0.6.0-cp39-cp39-macosx_10_9_x86_64.whl | CPython 3.9 | CPython 3.9 | macOS 10.9+ x86-64 | Details for torchqtm-0.6.0-cp39-cp39-macosx_10_9_x86_64.whl |
Total release size: 1.1 MB
Release files / torchqtm-0.6.0.tar.gz
| Download URL | torchqtm-0.6.0.tar.gz |
|---|---|
| Size | 638.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d1889608d30a0f9f38c8d10fb1dfcf763d7c2c856f982e544bcf19363a5a0cc5
|
|
BLAKE2b-256 checksum How to use checksums |
7c08ba0ef3fe2a592ee4124d9c2fbfb911de4801b506b13bb076604b176535c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / torchqtm-0.6.0-cp39-cp39-macosx_10_9_x86_64.whl
| Download URL | torchqtm-0.6.0-cp39-cp39-macosx_10_9_x86_64.whl |
|---|---|
| Size | 426.8 kB |
| Tags | CPython 3.9 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
5a8a5bc378b0c76cd643796a2667e3769610ded6429840fcabaf7514dff9302d
|
|
BLAKE2b-256 checksum How to use checksums |
1ee5482665688f55093dfda08ad87ea5629e259496479349f022bf74cde625ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for torchqtm 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.