Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FOttStrategy Futures Strategy is very slow #261

Open
FahadAziz opened this issue Aug 3, 2022 · 3 comments
Open

FOttStrategy Futures Strategy is very slow #261

FahadAziz opened this issue Aug 3, 2022 · 3 comments
Labels

Comments

@FahadAziz
Copy link

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

@FahadAziz FahadAziz added the bug Something isn't working label Aug 3, 2022
@xmatthias xmatthias added question and removed bug Something isn't working labels Aug 3, 2022
@xmatthias
Copy link
Member

xmatthias commented Aug 3, 2022

The big problem is the loop in the indicator (

for i in range(pds, len(df)):
df["Var"].iat[i] = (alpha * df["CMO"].iat[i] * df["close"].iat[i]) + (
1 - alpha * df["CMO"].iat[i]
) * df["Var"].iat[i - 1]
).

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.

@FahadAziz
Copy link
Author

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.

@froggleston
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants