pysatl_tsp.implementations.processor.midpoint_handler

Module Contents

Classes

MidpointHandler

Midpoint price handler.

API

class pysatl_tsp.implementations.processor.midpoint_handler.MidpointHandler(length: int = 10, source: pysatl_tsp.core.Handler[Any, pysatl_tsp.core.handler.T] | None = None)[source]

Bases: pysatl_tsp.core.processor.inductive.moving_window_handler.MovingWindowHandler[float | None, float | None]

Midpoint price handler.

Calculates the average of highest and lowest values over the period. This handler is useful for identifying the central price level within a range, providing a simple measure of the balance between high and low extremes.

Inherits parameters from MovingWindowHandler: :param length: The period for the calculation, defaults to 10 :param source: Input data source, defaults to None

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

# Create a midpoint handler with length of 4
midpoint_handler = MidpointHandler(length=4)
midpoint_handler.set_source(data_source)

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

# Output:
# None
# None
# None
# 3.0  (midpoint of [1.0, 2.0, 3.0, 5.0] = (1.0 + 5.0) / 2 = 3.0)
# 3.5  (midpoint of [2.0, 3.0, 5.0, 4.0] = (2.0 + 5.0) / 2 = 3.5)
# 4.0  (midpoint of [3.0, 5.0, 4.0, 3.0] = (3.0 + 5.0) / 2 = 4.0)
# 3.5  (midpoint of [5.0, 4.0, 3.0, 2.0] = (2.0 + 5.0) / 2 = 3.5)
# 3.0  (midpoint of [4.0, 3.0, 2.0, 1.0] = (1.0 + 4.0) / 2 = 2.5)

Initialization

Initialize moving window handler with specified parameters.

Parameters:
  • length – The period for the calculation, defaults to 10

  • source – Input data source, defaults to None

_compute_result(state: dict[str, Any]) float | None[source]

Calculate midpoint as (highest + lowest) / 2.

Computes the average of the highest and lowest values in the current window. Returns None if there aren’t enough values to fill the window or if any value in the window is None.

Parameters:

state – Current state dictionary containing window values

Returns:

Midpoint value or None if conditions aren’t met