pybroker.indicator module

Contains indicator related functionality.

class Indicator(name: str, fn: Callable[[...], ndarray[Any, dtype[float64]]], kwargs: dict[str, Any])[source]

Bases: object

Class representing an indicator.

Parameters:
  • name – Name of indicator.

  • fnCallable used to compute the series of indicator values.

  • kwargsdict of kwargs to pass to fn.

__call__(data: BarData | DataFrame) Series[source]

Computes indicator values.

iqr(data: BarData | DataFrame) float[source]

Generates indicator data with data and computes its interquartile range (IQR).

relative_entropy(data: BarData | DataFrame) float[source]

Generates indicator data with data and computes its relative entropy.

class IndicatorSet[source]

Bases: IndicatorsMixin

Computes data for multiple indicators.

__call__(df: DataFrame, disable_parallel: bool = False) DataFrame[source]

Computes indicator data.

Parameters:
  • dfpandas.DataFrame of input data.

  • disable_parallel – If True, indicator data is computed serially. If False, indicator data is computed in parallel using multiple processes. Defaults to False.

Returns:

pandas.DataFrame containing the computed indicator data.

add(indicators: Indicator | Iterable[Indicator], *args)[source]

Adds indicators.

clear()[source]

Removes all indicators.

remove(indicators: Indicator | Iterable[Indicator], *args)[source]

Removes indicators.

class IndicatorsMixin[source]

Bases: object

Mixin implementing indicator related functionality.

compute_indicators(df: DataFrame, indicator_syms: Iterable[IndicatorSymbol], cache_date_fields: CacheDateFields | None, disable_parallel: bool) dict[IndicatorSymbol, Series][source]

Computes indicator data for the provided pybroker.common.IndicatorSymbol pairs.

Parameters:
  • dfpandas.DataFrame used to compute the indicator values.

  • indicator_symsIterable of pybroker.common.IndicatorSymbol pairs of indicators to compute.

  • cache_date_fields – Date fields used to key cache data. Pass None to disable caching.

  • disable_parallel – If True, indicator data is computed serially for all pybroker.common.IndicatorSymbol pairs. If False, indicator data is computed in parallel using multiple processes.

Returns:

dict mapping each pybroker.common.IndicatorSymbol pair to a computed pandas.Series of indicator values.

highest(name: str, field: str, period: int) Indicator[source]

Creates a rolling high Indicator.

Parameters:
  • name – Indicator name.

  • fieldpybroker.common.BarData field for computing the rolling high.

  • period – Lookback period.

Returns:

Rolling high Indicator.

indicator(name: str, fn: Callable[[...], ndarray[Any, dtype[float64]]], **kwargs) Indicator[source]

Creates an Indicator instance and registers it globally with name.

Parameters:
  • name – Name for referencing the indicator globally.

  • fnCallable[[BarData, ...], NDArray[float]] used to compute the series of indicator values.

  • **kwargs – Additional arguments to pass to fn.

Returns:

Indicator instance.

lowest(name: str, field: str, period: int) Indicator[source]

Creates a rolling low Indicator.

Parameters:
  • name – Indicator name.

  • fieldpybroker.common.BarData field for computing the rolling low.

  • period – Lookback period.

Returns:

Rolling low Indicator.

returns(name: str, field: str, period: int = 1) Indicator[source]

Creates a rolling returns Indicator.

Parameters:
  • name – Indicator name.

  • fieldpybroker.common.BarData field for computing the rolling returns.

  • period – Returns period. Defaults to 1.

Returns:

Rolling returns Indicator.