"""
Backtesting module for TradingAgent and ML model validation.

This module provides comprehensive backtesting capabilities for:
- Individual strategy testing
- Ensemble model testing
- Walk-forward validation
- ML model validation

Core Components:
- BacktestEngine: Main engine for running backtests
- PositionManager: Manages positions with Kelly criterion sizing
- Trade: Trade data structure with full lifecycle tracking

Transaction Cost Models:
- Forex: 0.5 pips commission default
- Crypto: 0.1% commission default
- Configurable slippage

Position Sizing:
- Kelly criterion (default, max 2%)
- Fixed percentage
- Fixed risk per trade
- Volatility adjusted

Example:
    ```python
    from backtesting import BacktestEngine, BacktestConfig

    config = BacktestConfig.for_forex(
        initial_capital=10000,
        position_sizing='kelly',
        max_position_pct=0.02
    )

    engine = BacktestEngine(config)
    result = engine.run_backtest(strategy, data)
    result.print_summary()
    ```
"""

from .trade import (
    Trade,
    TradeDirection,
    TradeStatus
)

from .position_manager import (
    PositionManager,
    PositionSizingConfig,
    MarginRequirements,
    PositionSummary
)

from .ml_backtest_engine import (
    BacktestEngine,
    BacktestConfig,
    BacktestResult,
    BacktestMetrics,
    WalkForwardPeriod,
    Strategy,
    create_simple_strategy
)

from .engine import (
    MaxMinBacktester,
    BacktestResult as MaxMinBacktestResult,
    Trade as MaxMinTrade
)

from .metrics import (
    TradingMetrics,
    TradeRecord,
    MetricsCalculator,
    PerformanceMetrics
)

from .rr_backtester import (
    RRBacktester,
    BacktestConfig as RRBacktestConfig,
    BacktestResult as RRBacktestResult
)

from .effectiveness_validator import (
    EffectivenessValidator,
    ValidationResult,
    validate_backtest_effectiveness
)

from .confidence_analysis import (
    ConfidenceAnalyzer,
    CalibrationData,
    ReliabilityDiagramData,
    ConfidenceBandAnalysis,
    analyze_trade_confidence
)

from .report_generator import (
    ReportGenerator,
    StrategyReport,
    EnsembleReport,
    ComparisonReport,
    PerformanceThresholds,
    ReportSection
)

from .visualization import (
    VisualizationData,
    ChartSeries,
    ChartDataPoint,
    prepare_equity_curve_data,
    prepare_drawdown_chart_data,
    prepare_monthly_returns_heatmap_data,
    prepare_trade_distribution_data,
    prepare_strategy_weights_data,
    prepare_calibration_plot_data,
    prepare_rolling_metrics_data
)

from .comparison import (
    StrategyComparison,
    ComparisonResult,
    StrategyMetrics,
    RankingEntry
)

from .strategy_adapter import (
    StrategyAdapter,
    BaseStrategy,
    Signal,
    SignalDirection,
    Prediction,
    PVAAdapter,
    MRDAdapter,
    VBPAdapter,
    MSAAdapter,
    MTSAdapter
)

from .walk_forward import (
    WalkForwardValidator,
    WalkForwardConfig,
    WalkForwardSplit,
    AggregatedResult
)

from .runner import (
    BacktestRunner,
    ValidationReport,
    PerformanceMetrics as RunnerPerformanceMetrics,
    ValidationResult as RunnerValidationResult
)

__all__ = [
    # Core trade structures
    'Trade',
    'TradeDirection',
    'TradeStatus',

    # Position management
    'PositionManager',
    'PositionSizingConfig',
    'MarginRequirements',
    'PositionSummary',

    # ML Backtest Engine (primary)
    'BacktestEngine',
    'BacktestConfig',
    'BacktestResult',
    'BacktestMetrics',
    'WalkForwardPeriod',
    'Strategy',
    'create_simple_strategy',

    # Legacy MaxMin backtester
    'MaxMinBacktester',
    'MaxMinBacktestResult',
    'MaxMinTrade',

    # Metrics
    'TradingMetrics',
    'TradeRecord',
    'MetricsCalculator',
    'PerformanceMetrics',

    # R:R Backtester
    'RRBacktester',
    'RRBacktestConfig',
    'RRBacktestResult',

    # Effectiveness Validation
    'EffectivenessValidator',
    'ValidationResult',
    'validate_backtest_effectiveness',

    # Confidence Analysis
    'ConfidenceAnalyzer',
    'CalibrationData',
    'ReliabilityDiagramData',
    'ConfidenceBandAnalysis',
    'analyze_trade_confidence',

    # Report Generation
    'ReportGenerator',
    'StrategyReport',
    'EnsembleReport',
    'ComparisonReport',
    'PerformanceThresholds',
    'ReportSection',

    # Visualization
    'VisualizationData',
    'ChartSeries',
    'ChartDataPoint',
    'prepare_equity_curve_data',
    'prepare_drawdown_chart_data',
    'prepare_monthly_returns_heatmap_data',
    'prepare_trade_distribution_data',
    'prepare_strategy_weights_data',
    'prepare_calibration_plot_data',
    'prepare_rolling_metrics_data',

    # Strategy Comparison
    'StrategyComparison',
    'ComparisonResult',
    'StrategyMetrics',
    'RankingEntry',

    # Strategy Adapters
    'StrategyAdapter',
    'BaseStrategy',
    'Signal',
    'SignalDirection',
    'Prediction',
    'PVAAdapter',
    'MRDAdapter',
    'VBPAdapter',
    'MSAAdapter',
    'MTSAdapter',

    # Walk-Forward Validation
    'WalkForwardValidator',
    'WalkForwardConfig',
    'WalkForwardSplit',
    'AggregatedResult',

    # Backtest Runner
    'BacktestRunner',
    'ValidationReport',
    'RunnerPerformanceMetrics',
    'RunnerValidationResult'
]


__version__ = '2.2.0'
