The original monolithic Momentum Long + Short Strategy.py file has been completely reorganized into a clean, modular structure following SOLID principles and best practices.
strategy_params.py-StrategyParamsdataclasstrade_result.py-TradeResultdataclass
base.py- Abstract base classes and protocolsmoving_averages.py-ExponentialMovingAverage,SimpleMovingAverage,MovingAverageFactorymomentum.py-RelativeStrengthIndexvolatility.py-AverageTrueRangetrend.py-AverageDirectionalIndexcalculator.py-TechnicalIndicatorCalculatorservice
signal_generator.py-SignalGeneratorclass
trade_simulator.py-TradeSimulatorclass
momentum_strategy.py- MainMomentumStrategyorchestrator class
- Each class now has one clear, focused responsibility
- Easy to test and maintain individual components
- Components can be used independently
- Easy to extend or replace individual parts
- Each module can be unit tested in isolation
- Clear interfaces make mocking easier
- Indicators can be used in other strategies
- Signal generators can be swapped or combined
- Changes to one component don't affect others
- Clear package structure makes navigation easy
- Better IDE support with proper imports
- Clear typing throughout the codebase
# Everything in one large file
from strategy import MomentumStrategy# Use complete strategy
from strategy import create_default_strategy
# Or use individual components
from models import StrategyParams
from indicators import TechnicalIndicatorCalculator
from signals import SignalGenerator
from trading import TradeSimulator
# Or mix and match as needed
from indicators import RelativeStrengthIndex, ExponentialMovingAverage
from models import TradeResultThe new structure maintains clean dependency flow:
models/- No dependencies (pure data)indicators/- Depends onmodels/signals/- Depends onmodels/trading/- Depends onmodels/strategy/- Depends on all other packages
This creates a clean dependency graph with no circular dependencies.
/models/__init__.py/models/strategy_params.py/models/trade_result.py/indicators/__init__.py/indicators/base.py/indicators/moving_averages.py/indicators/momentum.py/indicators/volatility.py/indicators/trend.py/indicators/calculator.py/signals/__init__.py/signals/signal_generator.py/trading/__init__.py/trading/trade_simulator.py/__init__.py(root package)/demo.py(usage examples)
/strategy/__init__.py- Updated imports/strategy/Momentum Long + Short Strategy.py→/strategy/momentum_strategy.py(renamed and cleaned)/README.md- Updated documentation
The modular structure is now ready for:
- Adding unit tests for each component
- Implementing additional indicators in their respective modules
- Creating new signal generation strategies
- Building optimization and backtesting engines
- Adding web dashboard or GUI components
Each new feature can be added to the appropriate package without affecting existing code.