Skip to content

contango.stream.indicators.helpers.wilder_helper

contango.stream.indicators.helpers.wilder_helper

WilderHelper

WilderHelper(period: days)

Wilder's Moving Average (RMA).

Initializes WilderAverage.

Parameters:

Name Type Description Default
period days

Lookback period to derive the smoothing factor. Larger values -> slower to react to price changes.

required
Source code in src\contango\stream\indicators\helpers\wilder_helper.py
14
15
16
17
18
19
20
21
22
23
24
def __init__(self, period: days) -> None:
    """
    Initializes `WilderAverage`.

    Args:
        period: Lookback period to derive the smoothing factor. Larger values -> slower to react to price changes.
    """
    self._period = period
    self._window: deque[float] = deque(maxlen=period)

    self._value: float | None = None

value property

value: float | None

Returns the latest value for the wilder average.

update

update(price: USD) -> float | None

Takes in a new value and return smoothed result.

Parameters:

Name Type Description Default
price USD

The price for the current bar.

required

Returns:

Type Description
float | None

The current WilderAverage. Returns None if period amount of days have not been reached.

Source code in src\contango\stream\indicators\helpers\wilder_helper.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def update(self, price: USD) -> float | None:
    """
    Takes in a new value and return smoothed result.

    Args:
        price: The price for the current bar.

    Returns:
        The current WilderAverage. Returns None if period amount of days have not been reached.
    """
    self._window.append(price)

    if len(self._window) < self._period:
        return None

    # First full initialization: simple average
    if self._value is None:
        self._value = sum(self._window) / self._period
        return self._value

    self._value = (
        (self._value * (self._period - 1)) + price
    ) / self._period

    return self._value