Files
NexQuant/rdagent/components/coder/rl/__init__.py
T
TPTBusiness 5ce86c824e feat: Full system integration - RL + Protections + Backtesting + CLI
Connect all Predix components into unified trading system:

INTEGRATION (ALL 295 TESTS PASS):
- RL Trading connected with Protection Manager
- RL Trading connected with Backtesting Engine
- CLI command 'rdagent rl_trading' added (train/backtest/live modes)
- Graceful fallback for users without stable-baselines3

OPEN SOURCE COMPATIBILITY:
- System works WITHOUT stable-baselines3 (momentum fallback)
- System works WITHOUT local models/prompts (uses standard)
- Clear warning messages when optional deps missing
- GitHub users get FULLY WORKING system

CLOSED SOURCE PROTECTION:
- models/local/, prompts/local/, .env stay local only
- .gitignore properly configured
- Our alpha (best models/prompts) remains private

DOCUMENTATION:
- QWEN.md: Open/closed source strategy
- QWEN.md: Development guidelines for AI assistant
- QWEN.md: Open source compatibility principle
- README.md: RL Trading CLI commands and examples
- requirements/rl.txt: Optional RL dependencies

Modified files:
- rdagent/app/cli.py: Added rl_trading command
- rdagent/components/backtesting/backtest_engine.py: RL backtest support
- rdagent/components/coder/rl/costeer.py: Protection Manager integration
- rdagent/components/coder/rl/__init__.py: Conditional imports + fallback
- rdagent/components/coder/rl/fallback.py: NEW - Simple momentum fallback
- requirements.txt: Optional RL deps commented
- requirements/rl.txt: NEW - Full RL dependencies
- test/integration/test_all_features.py: 7 new integration tests
- QWEN.md: Open source strategy + development guidelines
- README.md: RL Trading documentation

295 tests pass: 67 integration + 89 RL + 139 backtesting
2026-04-03 13:53:32 +02:00

79 lines
2.3 KiB
Python

"""RL Trading Agent components for Predix.
This package provides reinforcement learning trading capabilities.
Works with or without stable-baselines3 (graceful fallback).
OPEN SOURCE: Full RL system works for all GitHub users.
- With stable-baselines3: Full PPO/A2C/SAC training
- Without stable-baselines3: Simple momentum fallback
CLOSED SOURCE: Your trained models in models/local/
"""
# Try to import stable-baselines3
try:
import stable_baselines3 # noqa: F401
HAS_STABLE_BASELINES3 = True
except ImportError:
HAS_STABLE_BASELINES3 = False
import warnings
warnings.warn(
"stable-baselines3 not installed. RL trading will use simple momentum fallback. "
"Install with: pip install stable-baselines3[extra]",
UserWarning,
)
# Always import core components (work regardless of stable-baselines3)
from rdagent.components.coder.rl.env import TradingEnv
from rdagent.components.coder.rl.indicators import (
calculate_atr,
calculate_bollinger_bands,
calculate_cci,
calculate_macd,
calculate_rsi,
prepare_features,
)
# Import RL-specific components only if available
if HAS_STABLE_BASELINES3:
from rdagent.components.coder.rl.agent import RLTradingAgent
from rdagent.components.coder.rl.costeer import RLCoSTEER, RLCosteer
else:
# Use fallback implementations
from rdagent.components.coder.rl.fallback import SimpleRLFallback as RLTradingAgent
from rdagent.components.coder.rl.costeer import RLCosteer
# Create RLCoSTEER stub for when stable-baselines3 is not available
class RLCoSTEER: # type: ignore[no-redef]
"""
Stub RLCoSTEER when stable-baselines3 is not available.
This class exists only for import compatibility.
Use RLCosteer with SimpleRLFallback instead.
"""
def __init__(self, *args, **kwargs):
raise NotImplementedError(
"RLCoSTEER requires stable-baselines3. "
"Install with: pip install stable-baselines3[extra]"
)
__all__ = [
"HAS_STABLE_BASELINES3",
"RLCoSTEER",
"RLCosteer",
"RLTradingAgent",
"TradingEnv",
"calculate_atr",
"calculate_bollinger_bands",
"calculate_cci",
"calculate_macd",
"calculate_rsi",
"prepare_features",
]
__version__ = "1.0.0"