How netanelshoshan/freqai-lstm works
Main Components
• Trading Strategy Component – Represented by files like ExampleLSTMStrategy.py. This module is responsible for calculating technical indicators, normalizing them, applying dynamic weights, and generating the final target score for determining entry/exit signals.
• Model Implementations – Two primary implementations, one under the “tensorflow” directory (e.g., LSTMRegressor.py) and one under the “torch” directory. Since the PyTorch version is the updated focus, include these files: BasePyTorchModel.py, PyTorchLSTMModel.py, PyTorchLSTMRegressor.py, and PyTorchModelTrainer.py.
• Configuration and Integration – The config-example.json and instructions in the README show how to integrate the model with the freqtrade framework. Also, note that files need to be copied into specific freqtrade directories.
Detail the Relationships and Interactions
• Data Flow: Start by illustrating how historical market data is downloaded (using freqtrade commands) and passed into the strategy component for processing.
• Strategy Processing: Show that the ExampleLSTMStrategy processes input data by computing indicators (SMA, MACD, RSI, etc.), normalizing them, and applying dynamic weighting to generate an aggregate “target score.”
• Model Training and Prediction: Next, detail how that target score becomes part of the input for the LSTM network. The PyTorchLSTMModel takes these inputs through multiple layers (LSTM layers with Batch Normalization, Dropout, fully connected layers, etc.), and the PyTorchModelTrainer coordinates model training (with configurable hyperparameters like learning rate, batch size, n_epochs).
• Integration with Freqtrade: The trained model then feeds back into the freqtrade bot for live or backtesting trading decisions.
• Containerization: Use Docker (as per torch/Dockerfile) to indicate that the PyTorch model can run in a containerized environment, ensuring that dependencies and runtime environments are isolated.
Architectural Patterns and Design Principles
• Separation of Concerns: The project separates the logic into distinct modules (strategy definition, model definition, training, and deployment). Emphasize the decoupling between the strategy logic (which computes indicators and scores) and the AI model’s logic (which is responsible for learning and prediction).
• Configuration-Driven Design: The model’s hyperparameters are easily configurable (via JSON configuration files) which ensures flexibility and adaptability across different market conditions.
• Containerization and Deployment: The presence of a Dockerfile highlights a modern approach to deployment, ensuring consistency across development and production environments.
Incorporate Relevant Technologies
• PyTorch and (briefly) TensorFlow for the model implementation.
• Docker for containerized deployment.
• Technical analysis libraries (implied by the use of TA functions) which feed into the strategy.
• Freqtrade (from GitHub/freqtrade and FreqAI module) as the overarching trading bot framework.
• Standard configuration files (JSON) and version control (.gitignore, LICENSE).