pysatl_tsp.implementations.processor.zlma_handler

Module Contents

Classes

ZLMAHandler

Zero Lag Moving Average (ZLMA) handler with lazy evaluation.

API

class pysatl_tsp.implementations.processor.zlma_handler.ZLMAHandler(length: int = 10, ma_handler: pysatl_tsp.core.Handler[Any, float | None] | None = None, source: pysatl_tsp.core.Handler[Any, float | None] | None = None)[source]

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

Zero Lag Moving Average (ZLMA) handler with lazy evaluation.

Implements the formula ZLMA = MA(2 * close - close.shift(lag)), where lag = int(0.5 * (length - 1)). All calculations are performed lazily in a streaming fashion, computing values only when requested by the iterator.

The ZLMA reduces lag by applying a forward-shifted moving average that compensates for the lag inherent in traditional moving averages.

Parameters:
  • length – Period for the moving average calculation

  • ma_handler – Moving average handler to apply. Default is EMA with the specified length.

  • source – Input data source, defaults to None

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 ZLMA handler with length of 5
zlma_handler = ZLMAHandler(length=5)
zlma_handler.set_source(data_source)

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

# Initial values will be None due to lag calculation requirements
# Then ZLMA values will be calculated using the formula

Initialization

Initialize a Zero Lag Moving Average handler.

Parameters:
  • length – Period for the moving average calculation, defaults to 10

  • ma_handler – Moving average handler to apply, defaults to EMAHandler with the specified length

  • source – Input data source, defaults to None

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

Create an iterator that yields ZLMA values.

This method implements the ZLMA calculation pipeline according to the formula: ZLMA = MA(2 * close - close.shift(lag)), where lag = int(0.5 * (length - 1)).

Returns:

Iterator yielding ZLMA values

Raises:

ValueError – If no source has been set