Bayesian Optimization Framework
Euler Sousa last edited by
First I would like to congratulate the authors, contributors, and all the community for the awesome library/content provided.
Nowadays I'm a Sr. Data Scientist and a beginner in the field of trading investment strategies. After reading the documentation and going over some examples and discussions on the community, I wanted to contribute somehow. I noticed that there are a lot of similarities between Data Science experiments and backtesting trading strategies. One, in particular, is the parameters optimization of the strategy/machine learning model. The most simple approach is a grid search over a list of values for each parameter and their combination. In Data science this approach can be done by using GridsearchCV and I believe
cerebro.optstrategyhas a similar method.
Another approach in Data Science that outsmarts grid search is Bayesian Optimization. With that in mind, I created a framework that is available in this repo for optimizing the possible parameters of a given trading strategy using Bayesian optimization.
Besides backtrader, it was used mainly three libraries:
Hydra: The key feature used in this project is the ability to dynamically create a hierarchical configuration by composition and override it through config files and the command line.
Bayesian Optimization: This is a constrained global optimization package built upon bayesian inference and gaussian process, that attempts to find the maximum value of an unknown function in as few iterations as possible.
This framework produces a series of metadata during the optimization process, which is saved in the directories created automatically by Hydra. This metadata includes a
best_iteration.htmlfile showing the Bokeh plot of backtrader_plotting, a
main.logfile describing step by step of the optimization process, and a
STRATEGY_NAME.jsonfile containing the best set of parameters found by Bayesian optimization. After an experiment is concluded the main results are compiled and added to a
results.csvfile to easily keep tracking of all possibilities that were tried.
Take a look at the
README.mdand follow the steps to see these features running with a dummy example prepared.
I hope this can help some of you!
run-out last edited by
I think it's awesome you posted this and haven't forgotten, just haven't got to it yet.