initial: import DOLPHIN baseline 2026-04-21 from dolphinng5_predict working tree
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.
This commit is contained in:
126
nautilus_dolphin/examples/acb_example.py
Executable file
126
nautilus_dolphin/examples/acb_example.py
Executable file
@@ -0,0 +1,126 @@
|
||||
"""
|
||||
ACB v5 Usage Example
|
||||
====================
|
||||
|
||||
Demonstrates how to use the Adaptive Circuit Breaker v5
|
||||
on the Nautilus-Dolphin stack.
|
||||
"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add parent to path
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
from nautilus_dolphin.nautilus_dolphin.nautilus.adaptive_circuit_breaker import (
|
||||
AdaptiveCircuitBreaker,
|
||||
ACBConfig,
|
||||
ACBPositionSizer,
|
||||
get_acb_cut_for_date
|
||||
)
|
||||
|
||||
|
||||
def example_1_basic_usage():
|
||||
"""Example 1: Basic ACB usage."""
|
||||
print("=" * 70)
|
||||
print("Example 1: Basic ACB Usage")
|
||||
print("=" * 70)
|
||||
|
||||
# Create ACB instance
|
||||
acb = AdaptiveCircuitBreaker()
|
||||
|
||||
# Get cut for a specific date
|
||||
date_str = '2026-02-06' # Feb 6 crash day
|
||||
cut_info = acb.get_cut_for_date(date_str)
|
||||
|
||||
print(f"\nDate: {date_str}")
|
||||
print(f"Cut Rate: {cut_info['cut']*100:.0f}%")
|
||||
print(f"Signals Detected: {cut_info['signals']:.1f}")
|
||||
print(f"Severity: {cut_info['severity']}")
|
||||
print(f"Config Used: {cut_info['config_used']}")
|
||||
|
||||
|
||||
def example_2_position_sizer():
|
||||
"""Example 2: Using ACBPositionSizer."""
|
||||
print("\n" + "=" * 70)
|
||||
print("Example 2: ACB Position Sizer")
|
||||
print("=" * 70)
|
||||
|
||||
# Create position sizer
|
||||
sizer = ACBPositionSizer()
|
||||
|
||||
# Simulate position sizing for multiple days
|
||||
base_sizes = [1000.0, 1500.0, 2000.0, 1200.0, 800.0]
|
||||
dates = ['2026-02-01', '2026-02-02', '2026-02-03', '2026-02-04', '2026-02-05']
|
||||
|
||||
print(f"\n{'Date':<12} {'Base Size':<12} {'Cut':<8} {'Final Size':<12} {'Saved':<10}")
|
||||
print("-" * 70)
|
||||
|
||||
total_base = 0
|
||||
total_final = 0
|
||||
|
||||
for date, base in zip(dates, base_sizes):
|
||||
final_size, acb_info = sizer.calculate_size(base, date)
|
||||
|
||||
cut_pct = acb_info['cut'] * 100
|
||||
saved = base - final_size
|
||||
|
||||
print(f"{date:<12} ${base:>10,.2f} {cut_pct:>6.0f}% ${final_size:>10,.2f} ${saved:>8,.2f}")
|
||||
|
||||
total_base += base
|
||||
total_final += final_size
|
||||
|
||||
print("-" * 70)
|
||||
print(f"{'TOTAL':<12} ${total_base:>10,.2f} {'':<8} ${total_final:>10,.2f} ${total_base - total_final:>8,.2f}")
|
||||
|
||||
|
||||
def example_3_convenience_function():
|
||||
"""Example 3: Using convenience function."""
|
||||
print("\n" + "=" * 70)
|
||||
print("Example 3: Convenience Function")
|
||||
print("=" * 70)
|
||||
|
||||
# Quick lookup without creating instance
|
||||
dates = ['2026-01-15', '2026-02-06', '2026-02-08']
|
||||
|
||||
print(f"\n{'Date':<12} {'Cut':<8} {'Signals':<10} {'Protection Level':<20}")
|
||||
print("-" * 70)
|
||||
|
||||
for date in dates:
|
||||
cut_info = get_acb_cut_for_date(date)
|
||||
|
||||
cut = cut_info['cut']
|
||||
signals = cut_info['signals']
|
||||
|
||||
# Determine protection level
|
||||
if cut == 0:
|
||||
level = "None (Normal)"
|
||||
elif cut <= 0.15:
|
||||
level = "Light"
|
||||
elif cut <= 0.45:
|
||||
level = "Moderate"
|
||||
elif cut <= 0.55:
|
||||
level = "High (Crash)"
|
||||
else:
|
||||
level = "Extreme"
|
||||
|
||||
print(f"{date:<12} {cut*100:>6.0f}% {signals:>8.1f} {level:<20}")
|
||||
|
||||
|
||||
def main():
|
||||
"""Run all examples."""
|
||||
print("\n" + "=" * 70)
|
||||
print("ACB v5 - Usage Examples")
|
||||
print("=" * 70)
|
||||
|
||||
example_1_basic_usage()
|
||||
example_2_position_sizer()
|
||||
example_3_convenience_function()
|
||||
|
||||
print("\n" + "=" * 70)
|
||||
print("Examples Complete")
|
||||
print("=" * 70)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user