freqtrade-strategies
freqtrade-strategies copied to clipboard
FOttStrategy Futures Strategy is very slow
Hi Gents
I have been trying to backtest and been dry running the strategy for two days now on a local Pi. The strategy is very slow and most of the bot logic (Updating prices, canceling orders etc.) do not happen as specified in the config file. For example, performance could be stuck for hours before it actually updates. I am running on the latest version (July 22) and Python 3.9. Also, backtesting takes ages before it actually finishes. I believe the bot get stuck at some point since I never see the heartbeat log line at all. Could anyone help optimize the code to run faster?
Thanks
https://github.com/freqtrade/freqtrade-strategies/blob/main/user_data/strategies/futures/FOttStrategy.py
The big problem is the loop in the indicator (https://github.com/freqtrade/freqtrade-strategies/blob/f6ff6572948602f8c453d5e1e6351398ff0d8041/user_data/strategies/futures/FOttStrategy.py#L96-L99).
The calculation of the value for each row relies on the value of the prior row - making vectorization of the calculation impossible (it needs to be calculated from top to bottom - row by row) - which is slow (especially with larger backtesting ranges).
there is little "easy" things to be done here without modifying the indicator to not use this logic (which would make it a different logic/indicator). The best thing will be to throw more CPU power onto it - or use shorter timeranges for backtesting (or simply be patient). The indicator could be reimplemented in cython - which would probably mean a significant speedup - but that'd imply that you'll need a dedicated cython library (pre-compiled wheels for most important platforms)- where the setup and learning time will be a lot higher.
Neither of the two are within the scope of a sample-strategy-repository - but if you find this indicator implemented in a cythonized library, feel free to suggest using that library.
Thank you Matt, I am no coder and still hoping someone would look into this. I took the easy road and put more CPU and RAM to work utilizing Mac M1 CPU which seems to run a lot faster now. Thanks a lot helpful as always.
These strategies are meant to be used as guides for development and not for immediate use. It's unlikely anyone will look at this actively unless they decide to feed back any improvements.