Improve freqtrade strategy with parameter optimization

This revision is from 2024/04/16 03:01. You can Restore it.

Before optimizing our strategy, we need to see if it would have been profitable as a baseline.

Work in config.json, give it enough pairs and a timeframe. Perhaps a one hour timeframe and about fifty pairs. The more pairs in the list, the more data and the supposedly the better the optmization.

To perform a baseline backtest, download the data for the pairs with the following command :

freqtrade download-data -t 1h --timerange=20210101-

-t : define the timeframe for the data. (5m,1h,4h,1d).

--timerange= : Download data from 2021/01/01 until today.

Run the backtest

freqtrade backtesting -s MyStrategy --timerange=20210601-20210630

Review where the strategy is losing money. The first sell reason is because of the stop loss, maybe too close, maybe too far, Our ROI table can also be optimized to take more profits.

Optimize the stop loss and ROI table using hyperopt included in freqtrade.

What is Hyperopt?

Hyperopt is freqtrade’s tool to search and automate optimal parameters for our strategy. Applicable on technical indicators variables but also on sell, buy and stop loss variables. Hyperopt will use the data we have downloaded before to find the best parameters, this is why it’s important to have a lot of data.

Be aware that hyperopt takes time and it’s resource hungry.

Freqtrade’s Hyperopt example

Let’s optimize the stop loss and our ROI with the following command :

freqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --spaces roi stoploss --strategy MyStrategy -e 100

freqtrade hyperopt --hyperopt-loss SortinoHyperOptLoss -s broken_result --spaces buy, roi, stoploss, trailing -e 1000 -i 1h --timerange 20210422-20220908

Hyperopt has different calculation methods depending on your strategy, modes dedicated to scalping, Sharpe ratio, Sortino ration. Be sure to chose the right one according to your strategy.

-e defines how many evaluations hyperopt will do, the more you have, the more the results will be precise. Beyond 500-1000 there will usually no longer be any changes in the results.

Hyperopt work is finished, we can see that it transformed our losing strategy into a winning one simply by modifying our ROI table and our Stop Loss. Now we just have to modify our strategy with the values provided by hyperopt and do a new backtest to see if our strategy has been improved.

Source: https://blog.botcrypto.io/en/2021/07/08/tutorial-improve-your-freqtrade-strategy-with-hyperopt/

  

📝 📜 ⏱️ ⬆️