60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
|
|
"""
|
||
|
|
Technical Indicator Utilities
|
||
|
|
|
||
|
|
This module provides utility functions for managing technical indicator
|
||
|
|
configurations and validation.
|
||
|
|
"""
|
||
|
|
|
||
|
|
from typing import Dict, Any
|
||
|
|
|
||
|
|
|
||
|
|
def create_default_indicators_config() -> Dict[str, Dict[str, Any]]:
|
||
|
|
"""
|
||
|
|
Create default configuration for common technical indicators.
|
||
|
|
|
||
|
|
Returns:
|
||
|
|
Dictionary with default indicator configurations
|
||
|
|
"""
|
||
|
|
return {
|
||
|
|
'sma_20': {'type': 'sma', 'period': 20},
|
||
|
|
'sma_50': {'type': 'sma', 'period': 50},
|
||
|
|
'ema_12': {'type': 'ema', 'period': 12},
|
||
|
|
'ema_26': {'type': 'ema', 'period': 26},
|
||
|
|
'rsi_14': {'type': 'rsi', 'period': 14},
|
||
|
|
'macd_default': {'type': 'macd'},
|
||
|
|
'bollinger_bands_20': {'type': 'bollinger_bands', 'period': 20}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def validate_indicator_config(config: Dict[str, Any]) -> bool:
|
||
|
|
"""
|
||
|
|
Validate technical indicator configuration.
|
||
|
|
|
||
|
|
Args:
|
||
|
|
config: Indicator configuration dictionary
|
||
|
|
|
||
|
|
Returns:
|
||
|
|
True if configuration is valid, False otherwise
|
||
|
|
"""
|
||
|
|
required_fields = ['type']
|
||
|
|
|
||
|
|
# Check required fields
|
||
|
|
for field in required_fields:
|
||
|
|
if field not in config:
|
||
|
|
return False
|
||
|
|
|
||
|
|
# Validate indicator type
|
||
|
|
valid_types = ['sma', 'ema', 'rsi', 'macd', 'bollinger_bands']
|
||
|
|
if config['type'] not in valid_types:
|
||
|
|
return False
|
||
|
|
|
||
|
|
# Validate period fields
|
||
|
|
if 'period' in config and (not isinstance(config['period'], int) or config['period'] <= 0):
|
||
|
|
return False
|
||
|
|
|
||
|
|
# Validate standard deviation for Bollinger Bands
|
||
|
|
if config['type'] == 'bollinger_bands' and 'std_dev' in config:
|
||
|
|
if not isinstance(config['std_dev'], (int, float)) or config['std_dev'] <= 0:
|
||
|
|
return False
|
||
|
|
|
||
|
|
return True
|