Is it possible within the framework to run multiple backtests in order to train a neural network? I.e., I'm looking to train a neural network using the result of each backtest to update the neural network's weights. Training will consist of thousands of backtests.
On my local machines, I could create a “backtest runner” to run, evaluate, and update the weights. and repeate after each backtest however that solution would be redundant if the same functionality can be handled within the framework.
Adam W
It should technically be possible using a combination of ObjectStore and lean-cli to run backtests, but is it really necessary? It would be much simpler to simply pull some historical data and train the DNN in one run (perhaps iteratively in some loop).
Alpha23
Adam, the lean-cli is what I was thinking about using in the backtest runner I was referring to. It would be simpler if I could train on historical data alone but the problem requires that the weights are updated, e.g., via backpropagation, based on the results of the trading algorithm and not on historical data. Historical data is only used as inputs to the algorithm.
If there are thoughts on how to accomplish the above without having to code outside of the framework, please let me know.
Adam W
If the algorithm itself is simple enough, then one way that may work is to just simulate a quick and simple vectorized backtest inside each training loop. In psuedo-code, this will look something like
Now if the algorithm has a bunch of moving parts like daily changing universes, complicated order logic, etc, then this will be pretty messy and you may have to automate some scripts using lean-cli.
I may have other ideas if you have more details (or a simplified example) of what it is you are trying to do
Alpha23
Adam, Thank you for your input above. I solved the issue by putting the neural network logic in the Initialze and OnEdnOfAlgorithm methods, saving the network and other needed variables in those methods, and using a bash script to run ‘lean backtest <PROJECTNAME> -d’ in a for loop.
Alpha23
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!