TorchQuantum is a backtesting framework that integrates the structure of PyTorch and WorldQuant's Operator for efficient quantitative financial analysis.
for Unix:
cd /path/to/your/directory
git clone [email protected]:nymath/torchquantum.git
cd ./torchquantumBefore running examples, you should compile the cython code.
python setup.py build_ext --inplaceNow you can run examples
python ./examples/main.pyIf you are not downloading the dataset, then you should
cd ./examples
mkdir largedata
cd ./largedata
wget https://github.com/nymath/torchquantum/releases/download/V0.1/stocks_f64.pkl.zip
unzip stocks_f64.pkl.zip
rm stocks_f64.pkl.zip
cd ../
cd ../
git checkout devYou 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, required_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.dataFis 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.
- 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.
For more information, we refer to Documentation.
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.
