"""Tests for position sizing."""

import pytest
from src.risk.position_sizing import get_position_sizer, PositionSizing


class TestPositionSizing:
    """Tests for PositionSizing."""
    
    @pytest.fixture
    def position_sizer(self):
        """Create position sizer instance."""
        return get_position_sizer()
    
    def test_fixed_percentage(self, position_sizer):
        """Test fixed percentage sizing."""
        size = position_sizer.fixed_percentage(10000.0, 0.02)  # 2%
        assert size == 200.0
    
    def test_fixed_amount(self, position_sizer):
        """Test fixed amount sizing."""
        size = position_sizer.fixed_amount(500.0)
        assert size == 500.0
    
    def test_volatility_based(self, position_sizer):
        """Test volatility-based sizing."""
        size = position_sizer.volatility_based(
            capital=10000.0,
            atr=100.0,
            risk_per_trade_percentage=0.01  # 1%
        )
        assert size > 0
    
    def test_kelly_criterion(self, position_sizer):
        """Test Kelly Criterion."""
        fraction = position_sizer.kelly_criterion(
            win_probability=0.6,
            payout_ratio=1.5
        )
        assert 0 <= fraction <= 1

