-
Notifications
You must be signed in to change notification settings - Fork 0
/
advanced_regime_engine.py
55 lines (49 loc) · 1.74 KB
/
advanced_regime_engine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from dataclasses import dataclass
from typing import Dict, Optional, List, Tuple
import numpy as np
@dataclass
class AdvancedRegimeEngine:
REGIME_PARAMETERS = {
'calm': {
'probability': 0.55,
'volatility_threshold': 0.10, # 10% annualized vol
'correlation_threshold': 0.3,
'risk_scaling': 1.0,
'description': 'Normal Market Conditions'
},
'stress': {
'probability': 0.30,
'volatility_threshold': 0.20, # 20% annualized vol
'correlation_threshold': 0.6,
'risk_scaling': 0.7,
'description': 'Elevated Market Stress'
},
'crisis': {
'probability': 0.15,
'volatility_threshold': 0.35, # 35% annualized vol
'correlation_threshold': 0.8,
'risk_scaling': 0.4,
'description': 'Crisis Conditions'
}
}
DETECTION_CONFIG = {
'estimation_windows': [21, 63, 252], # Multiple time horizons
'minimum_history': 252,
'decay_factor': 0.94,
'confidence_threshold': 0.75,
'regime_persistence': 5, # Minimum days in regime
'transition_smoothing': True
}
def __post_init__(self):
"""Initialize regime detection system"""
self._validate_parameters()
self._initialize_detection_matrices()
def detect_regime(
self,
returns: np.ndarray,
volumes: Optional[np.ndarray] = None,
market_data: Optional[Dict] = None
) -> Dict[str, float]:
"""Detect current market regime and transition probabilities"""
pass # Implementation details available in full version
# For commercial licensing: [email protected]