modular_trader.indicator.handler#

Submodules#

Classes#

AlpacaIndicatorHandler

Alpaca indicator handler.

BaseIndicatorHandler

Abstract base class for indicator handlers.

Package Contents#

class modular_trader.indicator.handler.AlpacaIndicatorHandler#

Bases: modular_trader.indicator.handler.base.BaseIndicatorHandler

Inheritance diagram of modular_trader.indicator.handler.AlpacaIndicatorHandler

Alpaca indicator handler.

This class is used to handle indicators for Alpaca.

Attributes:
indicators (list[BaseIndicator]):

The list of indicators to be used.

frequency (Frequency):

The frequency of the indicator handler.

warmup_length (int | None):

The length of the warmup period. If None, it is set to the maximum cache size of the indicators.

_attached_indicators (benedict):

The dictionary of attached indicators. The keys are the symbol names and the values are the indicator objects.

__iter__() Generator[modular_trader.indicator.technical.base.BaseIndicator, None, None]#

Iterate over the indicators.

Yields:

BaseIndicator: The next indicator.

Return type:

Generator[modular_trader.indicator.technical.base.BaseIndicator, None, None]

__post_init__() None#

Find the minimum cache size of the indicators and use it to set the warmup length. If warmup_length is already set, it is not changed.

Return type:

None

get(symbol: str, name: str | None = None) modular_trader.indicator.technical.base.BaseIndicator | Mapping[str, modular_trader.indicator.technical.base.BaseIndicator] | None#

Get the indicator(s) by symbol and name.

Args:

symbol (str): The symbol name. name (str | None): The indicator name. If None, it returns all

indicators for the symbol.

Returns:
BaseIndicator | Mapping[str, BaseIndicator] | None: The indicator or

all indicators for the symbol if name is None. If the symbol or indicator is not found, it returns None.

Parameters:
  • symbol (str)

  • name (str | None)

Return type:

modular_trader.indicator.technical.base.BaseIndicator | Mapping[str, modular_trader.indicator.technical.base.BaseIndicator] | None

init_indicator(universe: modular_trader.universe.AssetUniverse) None#

Initialize the indicators for added symbols and remove them for removed symbols.

Args:

universe (AssetUniverse): The asset universe.

Returns:

None

Parameters:

universe (modular_trader.universe.AssetUniverse)

Return type:

None

update(bar: alpaca.data.models.bars.Bar) None#

Update the indicators for the given symbol.

Args:

bar (Bar): The bar to update the indicators with.

Returns:

None

Parameters:

bar (alpaca.data.models.bars.Bar)

Return type:

None

warmup(data: pandas.DataFrame) None#

Warm up the indicators from historical data.

Args:
data (pd.DataFrame): The historical data to warm up the indicators.

The DataFrame should have a MultiIndex [symbol, …].

Returns:

None

Parameters:

data (pandas.DataFrame)

Return type:

None

_attached_indicators: benedict.benedict = None#
attached_indicators#
frequency: Frequency = None#
indicators: list[modular_trader.indicator.technical.base.BaseIndicator] = None#
property is_warmup: bool#

Check if the warmup period is finished.

Returns:

bool: True if the warmup period is finished, False otherwise.

Return type:

bool

symbols#
warmup_length: int | None = None#
class modular_trader.indicator.handler.BaseIndicatorHandler#

Bases: abc.ABC

Inheritance diagram of modular_trader.indicator.handler.BaseIndicatorHandler

Abstract base class for indicator handlers.

abstract update()#

Update the indicators.

This method is called for each new bar.

abstract warmup()#

Warmup the indicators.

This method is called once when the indicator handler is created.