4.0 - 2.0 Implement strategy configuration utilities and templates

- Introduced `config_utils.py` for loading and managing strategy configurations, including functions for loading templates, generating dropdown options, and retrieving parameter schemas and default values.
- Added JSON templates for EMA Crossover, MACD, and RSI strategies, defining their parameters and validation rules to enhance modularity and maintainability.
- Implemented `StrategyManager` in `manager.py` for managing user-defined strategies with file-based storage, supporting easy sharing and portability.
- Updated `__init__.py` to include new components and ensure proper module exports.
- Enhanced error handling and logging practices across the new modules for improved reliability.

These changes establish a robust foundation for strategy management and configuration, aligning with project goals for modularity, performance, and maintainability.
This commit is contained in:
Vasily.onl
2025-06-12 15:17:35 +08:00
parent fd5a59fc39
commit d34da789ec
17 changed files with 2220 additions and 243 deletions

View File

@@ -0,0 +1,55 @@
{
"type": "ema_crossover",
"name": "EMA Crossover",
"description": "Exponential Moving Average crossover strategy that generates buy signals when fast EMA crosses above slow EMA and sell signals when fast EMA crosses below slow EMA.",
"category": "trend_following",
"parameter_schema": {
"fast_period": {
"type": "int",
"description": "Period for fast EMA calculation",
"min": 5,
"max": 50,
"default": 12,
"required": true
},
"slow_period": {
"type": "int",
"description": "Period for slow EMA calculation",
"min": 10,
"max": 200,
"default": 26,
"required": true
},
"min_price_change": {
"type": "float",
"description": "Minimum price change percentage to validate signal",
"min": 0.0,
"max": 10.0,
"default": 0.5,
"required": false
}
},
"default_parameters": {
"fast_period": 12,
"slow_period": 26,
"min_price_change": 0.5
},
"metadata": {
"required_indicators": ["ema"],
"timeframes": ["1h", "4h", "1d"],
"market_conditions": ["trending"],
"risk_level": "medium",
"difficulty": "beginner",
"signals": {
"buy": "Fast EMA crosses above slow EMA",
"sell": "Fast EMA crosses below slow EMA"
},
"performance_notes": "Works best in trending markets, may generate false signals in sideways markets"
},
"validation_rules": {
"fast_period_less_than_slow": {
"rule": "fast_period < slow_period",
"message": "Fast period must be less than slow period"
}
}
}

View File

@@ -0,0 +1,77 @@
{
"type": "macd",
"name": "MACD Strategy",
"description": "Moving Average Convergence Divergence strategy that generates signals based on MACD line crossovers with the signal line and zero line.",
"category": "trend_following",
"parameter_schema": {
"fast_period": {
"type": "int",
"description": "Fast EMA period for MACD calculation",
"min": 5,
"max": 30,
"default": 12,
"required": true
},
"slow_period": {
"type": "int",
"description": "Slow EMA period for MACD calculation",
"min": 15,
"max": 50,
"default": 26,
"required": true
},
"signal_period": {
"type": "int",
"description": "Signal line EMA period",
"min": 5,
"max": 20,
"default": 9,
"required": true
},
"signal_type": {
"type": "str",
"description": "Type of MACD signal to use",
"options": ["line_cross", "zero_cross", "histogram"],
"default": "line_cross",
"required": true
},
"histogram_threshold": {
"type": "float",
"description": "Minimum histogram value for signal confirmation",
"min": 0.0,
"max": 1.0,
"default": 0.0,
"required": false
}
},
"default_parameters": {
"fast_period": 12,
"slow_period": 26,
"signal_period": 9,
"signal_type": "line_cross",
"histogram_threshold": 0.0
},
"metadata": {
"required_indicators": ["macd"],
"timeframes": ["1h", "4h", "1d"],
"market_conditions": ["trending", "volatile"],
"risk_level": "medium",
"difficulty": "intermediate",
"signals": {
"buy": "MACD line crosses above signal line (or zero line)",
"sell": "MACD line crosses below signal line (or zero line)",
"confirmation": "Histogram supports signal direction"
},
"performance_notes": "Effective in trending markets but may lag during rapid price changes"
},
"validation_rules": {
"fast_period_less_than_slow": {
"rule": "fast_period < slow_period",
"message": "Fast period must be less than slow period"
},
"valid_signal_type": {
"rule": "signal_type in ['line_cross', 'zero_cross', 'histogram']",
"message": "Signal type must be one of: line_cross, zero_cross, histogram"
}
}
}

View File

@@ -0,0 +1,67 @@
{
"type": "rsi",
"name": "RSI Strategy",
"description": "Relative Strength Index momentum strategy that generates buy signals when RSI is oversold and sell signals when RSI is overbought.",
"category": "momentum",
"parameter_schema": {
"period": {
"type": "int",
"description": "Period for RSI calculation",
"min": 2,
"max": 50,
"default": 14,
"required": true
},
"overbought": {
"type": "float",
"description": "RSI overbought threshold (sell signal)",
"min": 50.0,
"max": 95.0,
"default": 70.0,
"required": true
},
"oversold": {
"type": "float",
"description": "RSI oversold threshold (buy signal)",
"min": 5.0,
"max": 50.0,
"default": 30.0,
"required": true
},
"neutrality_zone": {
"type": "bool",
"description": "Enable neutrality zone between 40-60 RSI",
"default": false,
"required": false
}
},
"default_parameters": {
"period": 14,
"overbought": 70.0,
"oversold": 30.0,
"neutrality_zone": false
},
"metadata": {
"required_indicators": ["rsi"],
"timeframes": ["15m", "1h", "4h", "1d"],
"market_conditions": ["volatile", "ranging"],
"risk_level": "medium",
"difficulty": "beginner",
"signals": {
"buy": "RSI below oversold threshold",
"sell": "RSI above overbought threshold",
"hold": "RSI in neutral zone (if enabled)"
},
"performance_notes": "Works well in ranging markets, may lag in strong trending markets"
},
"validation_rules": {
"oversold_less_than_overbought": {
"rule": "oversold < overbought",
"message": "Oversold threshold must be less than overbought threshold"
},
"valid_threshold_range": {
"rule": "oversold >= 5 and overbought <= 95",
"message": "Thresholds must be within valid RSI range (5-95)"
}
}
}