mlfinlab.online_data_structures.time_bars

Advances in Financial Machine Learning, Marcos Lopez de Prado Chapter 2: Financial Data Structures: Time Bars

Module for implementation of online time bars data structures. This module allows for sequential input of ticks to form time bars.

Module Contents

Classes

TimeBarGenerator

Class which implements time bars compression.

class TimeBarGenerator(threshold: int = 86400, tick_fields_mapping: dict = None, aggressor_side_mapping: dict = None, exchange: str = None, contract: str = None)

Bases: mlfinlab.online_data_structures.base_bars.BarGenerator

Class which implements time bars compression.

__metaclass__
process_tick(tick: dict) bool

Process one tick. :param tick: (dict) tick to process. {‘timestamp’: pd.Timestamp, ‘price’: float, ‘volume’: float, ‘aggressor_side’(optional): int} :return: (bool) Flag indicating that a new bar was formed.

set_threshold(threshold: float)

Set new threshold for bar calculations. :param threshold: (float) threshold to set.

apply_tick_rule(price: float) Tuple[int, float]

Applies the tick rule as defined on page 29 of Advances in Financial Machine Learning. :param price: (float) Price at time t. :return: (Tuple[int, float]) The signed tick and tick difference.