Hello Quants,
I recently trained a model using a Liquide Neuron Network (LNN) based on PyTorch and want to use the same model in the QuantConnect (QC) environment to generate signals.
Issues I'm Facing:
- Liquide Neuron Network (LNN) support: LNN is not directly supported in QuantConnect or ONNX.
- torch.jit: I've tried using torch.jit to save and load the model, but my custom LNN model does not support JIT at the moment. I’m working on resolving this issue, but it's not fixed yet.
My Findings:
- Successful Module Loading: I was able to successfully load the LNN model when I used the GitHub repository code directly in the QC environment as a library.
- ONNX Support: I noticed that ONNX was supported in the past, but it doesn't seem to be mentioned in the current documentation.
- torch.jit: I am not sure why my custom LNN model does not support the torch.jit method for saving and loading.
- Saving/Loading using state_dict: I saved the model parameters using state_dict and loaded them in the QC environment, where I recreated the architecture. This works, but it may not be the most efficient method.
Open to Suggestions:
I’m open to any suggestions or best practices for loading and using a custom PyTorch-based Liquide Neuron Network model in the QuantConnect environment.
Thank you for your help!
Mia Alissi
To integrate your Liquide Neuron Network (LNN) model into the QuantConnect environment, you can follow these steps:
Model Architecture Recreation: Recreate the architecture of your LNN model within the QuantConnect environment using PyTorch. This involves defining a subclass of
nn.Module
that matches your original model's layers and parameters.State Dict Usage: Since your model does not support
torch.jit
, using thestate_dict
method is a viable alternative. Save your model's parameters usingstate_dict
and load them into the recreated model in QuantConnect. This method is efficient and commonly used when direct serialization methods are not supported.Custom Library Integration: If your model relies on custom components, consider integrating your model as a custom library within the QuantConnect environment. This approach has been successful for you in the past and allows you to leverage your existing codebase.
Data Subscription: Use the
add_equity
method to subscribe to the necessary data for your model to generate signals. This ensures you have access to the required historical and live data. Here's an example of how to add an equity:Signal Generation: Implement the logic for signal generation within the
on_data
method. Use the loaded model to make predictions based on incoming data. Here's a basic structure for theon_data
method:Risk Management: Incorporate risk management strategies to handle drawdowns and ensure your algorithm adheres to your risk tolerance levels. You can explore QuantConnect's risk management models to implement this.
Testing and Optimization: Thoroughly test your algorithm in the QuantConnect backtesting environment. Optimize parameters and ensure the model's predictions align with your trading strategy.
By following these steps, you can effectively integrate your LNN model into the QuantConnect environment and leverage its capabilities for signal generation and trading.
Sources: PyTorch - QuantConnect.com, PyTorch - QuantConnect.com, Long Short-Term Memory - QuantConnect.com, Pytorch Neural Network Algorithm, Detecting Impactful News In ETF Constituents
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Sukhvinder Pal Singh
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!