finmlkit.bar.kit module

class finmlkit.bar.kit.CUSUMBarKit(trades: TradesData, sigma: ndarray[tuple[int, ...], dtype[float64]], sigma_floor: float = 0.0005, sigma_mult: float = 2.0)[source]

Bases: BarBuilderBase

__init__(trades: TradesData, sigma: ndarray[tuple[int, ...], dtype[float64]], sigma_floor: float = 0.0005, sigma_mult: float = 2.0)[source]

Initialize the CUSUM bar builder with raw trades data and threshold.

Parameters:
  • trades – DataFrame of raw trades with ‘timestamp’, ‘price’, and ‘amount’.

  • sigma – Standard deviation vector of the price series or a constant value for all ticks.

  • sigma_floor – Minimum value for sigma to avoid small events.

  • sigma_mult – the sigma multiplier for adaptive threshold (lambda_th = lambda_mult * sigma).

_abc_impl = <_abc._abc_data object>
_comp_bar_close() Tuple[ndarray[tuple[int, ...], dtype[int64]], ndarray[tuple[int, ...], dtype[int64]]][source]

Generate CUSUM bar indices using the CUSUM bar indexer. :returns: Open timestamps and corresponding open indices in the raw trades data.

get_sigma() ndarray[tuple[int, ...], dtype[float64]][source]

The sigma threshold used for the CUSUM at close indices. :return: sigma vector

class finmlkit.bar.kit.DollarBarKit(trades: TradesData, dollar_thrs: float)[source]

Bases: BarBuilderBase

Dollar bar builder class.

__init__(trades: TradesData, dollar_thrs: float)[source]

Initialize the dollar bar builder with raw trades data and dollar amount.

Parameters:
  • trades – DataFrame of raw trades with ‘timestamp’, ‘price’, and ‘amount’.

  • dollar_thrs – Dollar amount threshold for the dollar bar.

_abc_impl = <_abc._abc_data object>
_comp_bar_close() Tuple[ndarray[tuple[int, ...], dtype[int64]], ndarray[tuple[int, ...], dtype[int64]]][source]

Generate dollar bar indices using the dollar bar indexer. :returns: Close timestamps and corresponding close indices in the raw trades data.

class finmlkit.bar.kit.TickBarKit(trades: TradesData, tick_count_thrs: int)[source]

Bases: BarBuilderBase

Tick bar builder class.

__init__(trades: TradesData, tick_count_thrs: int)[source]

Initialize the tick bar builder with raw trades data and tick count.

Parameters:
  • trades – DataFrame of raw trades with ‘timestamp’, ‘price’, and ‘amount’.

  • tick_count_thrs – Tick count threshold for the tick bar.

_abc_impl = <_abc._abc_data object>
_comp_bar_close() Tuple[ndarray[tuple[int, ...], dtype[int64]], ndarray[tuple[int, ...], dtype[int64]]][source]

Generate tick bar indices using the tick bar indexer. :returns: Close timestamps and corresponding close indices in the raw trades data.

class finmlkit.bar.kit.TimeBarKit(trades: TradesData, period: Timedelta)[source]

Bases: BarBuilderBase

Time bar builder class.

__init__(trades: TradesData, period: Timedelta)[source]

Initialize the time bar builder with raw trades data and time interval.

Parameters:
  • trades – DataFrame of raw trades with ‘timestamp’, ‘price’, and ‘amount’.

  • period – The time interval of a bar.

_abc_impl = <_abc._abc_data object>
_comp_bar_close() Tuple[ndarray[tuple[int, ...], dtype[int64]], ndarray[tuple[int, ...], dtype[int64]]][source]

Generate time bar indices using the time bar indexer. :returns: Close timestamps and corresponding Close indices in the raw trades data.

class finmlkit.bar.kit.VolumeBarKit(trades: TradesData, volume_ths: float)[source]

Bases: BarBuilderBase

Volume bar builder class.

__init__(trades: TradesData, volume_ths: float)[source]

Initialize the volume bar builder with raw trades data and volume.

Parameters:
  • trades – DataFrame of raw trades with ‘timestamp’, ‘price’, and ‘amount’.

  • volume_ths – Volume Bucket threshold for the volume bar.

_abc_impl = <_abc._abc_data object>
_comp_bar_close() Tuple[ndarray[tuple[int, ...], dtype[int64]], ndarray[tuple[int, ...], dtype[int64]]][source]

Generate volume bar indices using the volume bar indexer. :returns: Close timestamps and corresponding close indices in the raw trades data.