Skip to main content

None

Project description

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
  • F is library that contains the operators defined by WorldQuant.
  • op.Fundamental implies the NeutralizePE belongs to fundamental alpha.
  • self.lag is 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

quantopian/alphalens

quantopian/zipline

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchqtm-0.5.0.tar.gz (637.9 kB view details)

Uploaded Source

Built Distribution

torchqtm-0.5.0-cp39-cp39-macosx_10_9_x86_64.whl (426.8 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

File details

Details for the file torchqtm-0.5.0.tar.gz.

File metadata

  • Download URL: torchqtm-0.5.0.tar.gz
  • Upload date:
  • Size: 637.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for torchqtm-0.5.0.tar.gz
Algorithm Hash digest
SHA256 a5b6f60334bb742df9c65eaf6b7ca571594a73a1de32bc84d0c9b4f09a04b7b1
MD5 7af8b429000c1509c10726c39786ca8f
BLAKE2b-256 aefd7e6f534154209c9e3113ec36df74752a89753fe91d463667ba8e70152bab

See more details on using hashes here.

File details

Details for the file torchqtm-0.5.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for torchqtm-0.5.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5ff122d76303c76738b1254fe9b6e5f16ecf3c82e4e529eb0f1e13173312b2d2
MD5 7998df84dea8c75730ba81d6f82ba26c
BLAKE2b-256 c50699193cd5db071bd9add2a645662cace24e2e11c7da331e1dc2130feb0186

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page