Includes core prod + GREEN/BLUE subsystems: - prod/ (BLUE harness, configs, scripts, docs) - nautilus_dolphin/ (GREEN Nautilus-native impl + dvae/ preserved) - adaptive_exit/ (AEM engine + models/bucket_assignments.pkl) - Observability/ (EsoF advisor, TUI, dashboards) - external_factors/ (EsoF producer) - mc_forewarning_qlabs_fork/ (MC regime/envelope) Excludes runtime caches, logs, backups, and reproducible artifacts per .gitignore.
62 lines
2.1 KiB
Python
Executable File
62 lines
2.1 KiB
Python
Executable File
"""Tests for VolatilityRegimeDetector."""
|
|
|
|
import pytest
|
|
import numpy as np
|
|
from unittest.mock import Mock
|
|
from nautilus_dolphin.nautilus.volatility_detector import VolatilityRegimeDetector
|
|
|
|
|
|
class TestVolatilityRegimeDetector:
|
|
|
|
def test_insufficient_data_returns_true(self):
|
|
"""Permissive default when insufficient data."""
|
|
detector = VolatilityRegimeDetector(min_history=100)
|
|
assert detector.is_high_regime() == True
|
|
|
|
def test_update_calculates_volatility(self):
|
|
"""Test volatility calculation from bars."""
|
|
detector = VolatilityRegimeDetector(lookback_bars=50, min_history=10)
|
|
|
|
# Generate synthetic bars with increasing volatility
|
|
for i in range(60):
|
|
bar = Mock()
|
|
bar.close = 100 + np.random.randn() * (1 + i * 0.1)
|
|
detector.update(bar)
|
|
|
|
assert detector._current_vol is not None
|
|
assert len(detector._volatility_history) > 0
|
|
|
|
def test_high_regime_detection(self):
|
|
"""Test dual-threshold regime detection."""
|
|
detector = VolatilityRegimeDetector(lookback_bars=50, min_history=10)
|
|
|
|
# Low volatility period
|
|
for i in range(30):
|
|
bar = Mock()
|
|
bar.close = 100 + np.random.randn() * 0.1
|
|
detector.update(bar)
|
|
|
|
# High volatility period
|
|
for i in range(30):
|
|
bar = Mock()
|
|
bar.close = 100 + np.random.randn() * 5.0
|
|
detector.update(bar)
|
|
|
|
# Should detect high regime
|
|
assert detector.is_high_regime() == True
|
|
|
|
def test_regime_info(self):
|
|
"""Test regime info dict."""
|
|
detector = VolatilityRegimeDetector(lookback_bars=50, min_history=10)
|
|
|
|
for i in range(60):
|
|
bar = Mock()
|
|
bar.close = 100 + np.random.randn()
|
|
detector.update(bar)
|
|
|
|
info = detector.get_regime_info()
|
|
assert 'status' in info
|
|
assert 'current_vol' in info
|
|
assert 'p50' in info
|
|
assert 'p75' in info
|