pysatl_tsp.implementations.processor.hma_handler

Module Contents

Classes

HMAHandler

Hull Moving Average (HMA) handler.

API

class pysatl_tsp.implementations.processor.hma_handler.HMAHandler(length: int)[source]

Bases: pysatl_tsp.core.Handler[float | None, float | None]

Hull Moving Average (HMA) handler.

The Hull Moving Average is designed to reduce lag while maintaining smoothness. It uses weighted moving averages (WMA) in a multi-step process to create a more responsive indicator that better follows price action.

The HMA is calculated using the following formula: HMA = WMA(2*WMA(n/2) - WMA(n), sqrt(n))

Parameters:

length – The period for HMA calculation

Example:
# Create a data source with numeric values
data_source = SimpleDataProvider([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0])

# Create a Hull Moving Average handler with length of 4
hma_handler = HMAHandler(length=4)
hma_handler.set_source(data_source)

# Process the data
for value in hma_handler:
    print(value)

# The first few values may be None as the HMA needs historical data
# Then the HMA values will follow, being more responsive than traditional
# moving averages while maintaining smoothness.

Initialization

Initialize a Hull Moving Average handler.

Parameters:

length – The period for HMA calculation

__iter__() collections.abc.Iterator[float | None][source]

Create an iterator that yields HMA values.

This method constructs a pipeline that: 1. Takes values from the source 2. Calculates two WMAs with different periods (length//2 and length) 3. Combines them using the formula: 2*WMA(length//2) - WMA(length) 4. Applies another WMA with period=sqrt(length) to the result

Returns:

Iterator yielding HMA values

Raises:

ValueError – If no source has been set