"""Tests for portfolio analytics."""

import pytest
import pandas as pd
import numpy as np
from src.portfolio.analytics import get_portfolio_analytics, PortfolioAnalytics


class TestPortfolioAnalytics:
    """Tests for PortfolioAnalytics."""
    
    @pytest.fixture
    def analytics(self):
        """Create portfolio analytics instance."""
        return get_portfolio_analytics()
    
    def test_calculate_sharpe_ratio(self, analytics):
        """Test Sharpe ratio calculation."""
        returns = pd.Series([0.01, -0.005, 0.02, -0.01, 0.015])
        sharpe = analytics.calculate_sharpe_ratio(returns, risk_free_rate=0.0)
        assert isinstance(sharpe, float)
    
    def test_calculate_sortino_ratio(self, analytics):
        """Test Sortino ratio calculation."""
        returns = pd.Series([0.01, -0.005, 0.02, -0.01, 0.015])
        sortino = analytics.calculate_sortino_ratio(returns, risk_free_rate=0.0)
        assert isinstance(sortino, float)
    
    def test_calculate_max_drawdown(self, analytics):
        """Test max drawdown calculation."""
        equity_curve = pd.Series([10000, 10500, 10200, 11000, 10800])
        drawdown = analytics.calculate_max_drawdown(equity_curve)
        assert isinstance(drawdown, float)
        assert 0 <= drawdown <= 1

