import sys
from pathlib import Path
import pytest

# Añadir raíz del proyecto al path
sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent))


from src.risk.sizing.volatility import VolatilitySizer


def test_volatility_sizer_basic():
    sizer = VolatilitySizer(volatility_multiplier=2.0)

    capital = 10_000
    entry_price = 100
    volatility = 0.02  # 2%

    units = sizer.calculate_size(
        capital=capital,
        entry_price=entry_price,
        volatility=volatility
    )

    # riesgo por unidad = 0.02 * 100 * 2 = 4
    # unidades = 10_000 / 4 = 2500
    assert units == 2500


def test_volatility_requires_volatility():
    sizer = VolatilitySizer()

    with pytest.raises(ValueError):
        sizer.calculate_size(
            capital=10_000,
            entry_price=100
        )


def test_volatility_invalid_multiplier():
    with pytest.raises(ValueError):
        VolatilitySizer(volatility_multiplier=0)
