# app/src/trading/market_analysis/indicators/volume.py

from __future__ import annotations


def average_volume(values: list[float], period: int) -> float | None:
    if period <= 0 or len(values) < period:
        return None

    recent = values[-period:]
    return sum(recent) / period


def volume_ratio(
    *,
    current_volume: float | None,
    average_volume_value: float | None,
) -> float | None:
    if current_volume is None or average_volume_value is None:
        return None

    if average_volume_value <= 0:
        return None

    return current_volume / average_volume_value