mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-07-28 16:07:46 +00:00
bd025e50dc
Implement automatic trading protection system to prevent excessive losses: PROTECTIONS (100% original code, NOT copied from Freqtrade): - Max Drawdown Protection: Blocks trading when DD > 15% (configurable) - Cooldown Period: 4h mandatory rest after 5% loss - Stoploss Guard: Detects stoploss clusters (>5 per day) - Low Performance Filter: Filters factors with Sharpe < 0.5, Win Rate < 40% ARCHITECTURE: - Base protection interface with common utilities - 4 specialized protection implementations - ProtectionManager orchestrates all active protections - Time-based blocking with automatic expiry TESTS (32 total, ALL PASS): - 25 unit tests in test/backtesting/test_protections.py - 7 integration tests in test/integration/test_all_features.py - Tests cover: normal operation, edge cases, error handling DOCUMENTATION: - Update QWEN.md with development guidelines for AI assistant * Mandatory rules: Update QWEN.md, README, requirements.txt, tests * Pre-commit checklist * Example workflow - Update README.md with protection system features - Update project structure with new modules All code is 100% original - NO license issues with Freqtrade GPLv3.
59 lines
1.5 KiB
Python
59 lines
1.5 KiB
Python
"""
|
|
Trading Protection System for Predix.
|
|
|
|
Prevents excessive losses by automatically pausing trading
|
|
when risk thresholds are exceeded.
|
|
|
|
Usage:
|
|
from rdagent.components.backtesting.protections import (
|
|
ProtectionManager,
|
|
MaxDrawdownProtection,
|
|
CooldownProtection,
|
|
StoplossGuardProtection,
|
|
LowPerformanceProtection,
|
|
)
|
|
|
|
manager = ProtectionManager()
|
|
manager.create_default_protections()
|
|
|
|
result = manager.check_all(
|
|
returns=[0.01, -0.02, 0.015],
|
|
timestamps=[...],
|
|
current_equity=98000,
|
|
peak_equity=100000
|
|
)
|
|
|
|
if result.should_block:
|
|
print(f"Trading blocked: {result.reason}")
|
|
"""
|
|
|
|
from .base import (
|
|
BaseProtection,
|
|
ProtectionConfig,
|
|
ProtectionResult,
|
|
ProtectionType,
|
|
ProtectionScope,
|
|
)
|
|
from .max_drawdown import MaxDrawdownProtection, MaxDrawdownConfig
|
|
from .cooldown import CooldownProtection, CooldownConfig
|
|
from .stoploss_guard import StoplossGuardProtection, StoplossGuardConfig
|
|
from .low_performance import LowPerformanceProtection, LowPerformanceConfig
|
|
from .protection_manager import ProtectionManager
|
|
|
|
__all__ = [
|
|
"BaseProtection",
|
|
"ProtectionConfig",
|
|
"ProtectionResult",
|
|
"ProtectionType",
|
|
"ProtectionScope",
|
|
"MaxDrawdownProtection",
|
|
"MaxDrawdownConfig",
|
|
"CooldownProtection",
|
|
"CooldownConfig",
|
|
"StoplossGuardProtection",
|
|
"StoplossGuardConfig",
|
|
"LowPerformanceProtection",
|
|
"LowPerformanceConfig",
|
|
"ProtectionManager",
|
|
]
|