pysatl_tsp.implementations.processor.dema_handler
Module Contents
Classes
A handler that calculates the Double Exponential Moving Average (DEMA). |
API
- class pysatl_tsp.implementations.processor.dema_handler.DEMAHandler(length: int = 10, source: pysatl_tsp.core.Handler[Any, float | None] | None = None)[source]
Bases:
pysatl_tsp.core.Handler[float | None,float | None]A handler that calculates the Double Exponential Moving Average (DEMA).
The Double Exponential Moving Average (DEMA) is designed to reduce the lag associated with traditional moving averages. It puts more weight on recent data by using the formula: DEMA = 2 * EMA - EMA of EMA.
This implementation automatically configures a pipeline of EMA handlers to calculate both the primary EMA and the EMA of that EMA to produce DEMA values.
- Parameters:
length – The period for EMA calculations, defaults to 10
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 DEMA handler with length of 3 dema_handler = DEMAHandler(length=3) dema_handler.set_source(data_source) # Process the data for value in dema_handler: print(value) # The first few values will be None as the EMA needs to be established # Then the DEMA values will be calculated using 2 * EMA - EMA of EMA
Initialization
Initialize a DEMA handler.
- Parameters:
length – The period for EMA calculations, defaults to 10
source – Input data source, defaults to None
- __iter__() collections.abc.Iterator[float | None][source]
Create an iterator that yields DEMA values.
This method constructs a pipeline that: 1. Takes values from the source 2. Calculates the primary EMA 3. Calculates the EMA of the EMA 4. Combines them using the DEMA formula
- Returns:
Iterator yielding DEMA values
- Raises:
ValueError – If no source has been set
- static _combine(ema: float | None, ema_of_ema: float | None) float | None[source]
Combine EMA and EMA-of-EMA to produce DEMA.
Applies the formula: DEMA = 2 * EMA - EMA of EMA. If either input is None, returns None.
- Parameters:
ema – The primary EMA value
ema_of_ema – The EMA of the EMA value
- Returns:
The calculated DEMA value or None if inputs are None