4.0 - 1.0 Implement strategy engine foundation with modular components

- Introduced a new `strategies` package containing the core structure for trading strategies, including `BaseStrategy`, `StrategyFactory`, and various strategy implementations (EMA, RSI, MACD).
- Added utility functions for signal detection and validation in `strategies/utils.py`, enhancing modularity and maintainability.
- Updated `pyproject.toml` to include the new `strategies` package in the build configuration.
- Implemented comprehensive unit tests for the strategy foundation components, ensuring reliability and adherence to project standards.

These changes establish a solid foundation for the strategy engine, aligning with project goals for modularity, performance, and maintainability.
This commit is contained in:
Vasily.onl
2025-06-12 14:41:16 +08:00
parent 571d583a5b
commit fd5a59fc39
14 changed files with 1624 additions and 13 deletions

View File

@@ -38,19 +38,31 @@
- **Layered Chart Integration**: Strategy signals and performance visualizations will be integrated into the dashboard as a new chart layer, utilizing the existing modular chart system.
- **Comprehensive Testing**: Ensure that all new classes, functions, and modules within the strategy engine have corresponding unit tests placed in the `tests/strategies/` directory, following established testing conventions.
## Decisions
### 1. Vectorized vs. Iterative Calculation
- **Decision**: Refactored strategy signal detection to use vectorized Pandas operations (e.g., `shift()`, boolean indexing) instead of iterative Python loops.
- **Reasoning**: Significantly improves performance for signal generation, especially with large datasets, while maintaining identical results as verified by dedicated tests.
- **Impact**: All core strategy implementations (EMA Crossover, RSI, MACD) now leverage vectorized functions for their primary signal detection logic.
### 2. Indicator Key Generation Consistency
- **Decision**: Centralized the `_create_indicator_key` logic into a shared utility function `create_indicator_key()` in `strategies/utils.py`.
- **Reasoning**: Eliminates code duplication in `StrategyFactory` and individual strategy implementations, ensuring consistent key generation and easier maintenance if indicator naming conventions change.
- **Impact**: `StrategyFactory` and all strategy implementations now use this shared utility for generating unique indicator keys.
## Tasks
- [ ] 1.0 Core Strategy Foundation Setup
- [ ] 1.1 Create `strategies/` directory structure following indicators pattern
- [ ] 1.2 Implement `BaseStrategy` abstract class in `strategies/base.py` with `calculate()` and `get_required_indicators()` methods
- [ ] 1.3 Create `strategies/data_types.py` with `StrategySignal`, `SignalType`, and `StrategyResult` classes
- [ ] 1.4 Implement `StrategyFactory` class in `strategies/factory.py` for dynamic strategy loading and registration
- [ ] 1.5 Create strategy implementations directory `strategies/implementations/`
- [ ] 1.6 Implement `EMAStrategy` in `strategies/implementations/ema_crossover.py` as reference implementation
- [ ] 1.7 Implement `RSIStrategy` in `strategies/implementations/rsi.py` for momentum-based signals
- [ ] 1.8 Implement `MACDStrategy` in `strategies/implementations/macd.py` for trend-following signals
- [ ] 1.9 Create `strategies/utils.py` with helper functions for signal validation and processing
- [ ] 1.10 Create comprehensive unit tests for all strategy foundation components
- [x] 1.0 Core Strategy Foundation Setup
- [x] 1.1 Create `strategies/` directory structure following indicators pattern
- [x] 1.2 Implement `BaseStrategy` abstract class in `strategies/base.py` with `calculate()` and `get_required_indicators()` methods
- [x] 1.3 Create `strategies/data_types.py` with `StrategySignal`, `SignalType`, and `StrategyResult` classes
- [x] 1.4 Implement `StrategyFactory` class in `strategies/factory.py` for dynamic strategy loading and registration
- [x] 1.5 Create strategy implementations directory `strategies/implementations/`
- [x] 1.6 Implement `EMAStrategy` in `strategies/implementations/ema_crossover.py` as reference implementation
- [x] 1.7 Implement `RSIStrategy` in `strategies/implementations/rsi.py` for momentum-based signals
- [x] 1.8 Implement `MACDStrategy` in `strategies/implementations/macd.py` for trend-following signals
- [x] 1.9 Create `strategies/utils.py` with helper functions for signal validation and processing
- [x] 1.10 Create comprehensive unit tests for all strategy foundation components
- [ ] 2.0 Strategy Configuration System
- [ ] 2.1 Create `config/strategies/` directory structure mirroring indicators configuration
@@ -77,7 +89,7 @@
- [ ] 4.0 Strategy Data Integration
- [ ] 4.1 Create `StrategyDataIntegrator` class in new `strategies/data_integration.py` module
- [ ] 4.2 Implement data loading interface that leverages existing `TechnicalIndicators` class for indicator dependencies
- [ ] 4.3 Add multi-timeframe data handling for strategies that require indicators from different timeframes
- [x] 4.3 Add multi-timeframe data handling for strategies that require indicators from different timeframes
- [ ] 4.4 Implement strategy calculation orchestration with proper indicator dependency resolution
- [ ] 4.5 Create caching layer for computed indicator results to avoid recalculation across strategies
- [ ] 4.6 Add strategy signal generation and validation pipeline