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.
fn –
Callable
used to compute the series of indicator values.kwargs –
dict
of kwargs to pass tofn
.
- class IndicatorSet[source]
Bases:
IndicatorsMixin
Computes data for multiple indicators.
- __call__(df: DataFrame, disable_parallel: bool = False) DataFrame [source]
Computes indicator data.
- Parameters:
df –
pandas.DataFrame
of input data.disable_parallel – If
True
, indicator data is computed serially. IfFalse
, indicator data is computed in parallel using multiple processes. Defaults toFalse
.
- Returns:
pandas.DataFrame
containing the computed indicator data.
- 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:
df –
pandas.DataFrame
used to compute the indicator values.indicator_syms –
Iterable
ofpybroker.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 allpybroker.common.IndicatorSymbol
pairs. IfFalse
, indicator data is computed in parallel using multiple processes.
- Returns:
dict
mapping eachpybroker.common.IndicatorSymbol
pair to a computedpandas.Series
of indicator values.
- highest(name: str, field: str, period: int) Indicator [source]
Creates a rolling high
Indicator
.- Parameters:
name – Indicator name.
field –
pybroker.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 withname
.- Parameters:
name – Name for referencing the indicator globally.
fn –
Callable[[BarData, ...], NDArray[float]]
used to compute the series of indicator values.**kwargs – Additional arguments to pass to
fn
.
- Returns:
Indicator
instance.