Skip to content

RangeConsolidator

QuantConnect.Data.Consolidators.RangeConsolidator

RangeConsolidator(
    range: int, selector: Any, volume_selector: Any = None
)
RangeConsolidator(
    range: int,
    selector: Callable[[IBaseData], float] = None,
    volume_selector: Callable[[IBaseData], float] = None,
)

Bases: BaseTimelessConsolidator[RangeBar]

This consolidator can transform a stream of IBaseData instances into a stream of RangeBar

Initializes a new instance of the RangeConsolidator class.

Parameters:

Name Type Description Default
range int

The Range interval sets the range in which the price moves, which in turn initiates the formation of a new bar.

required
selector Any | Callable[[IBaseData], float]

Extracts the value from a data instance to be formed into a RangeBar. The default

None
volume_selector Any | Callable[[IBaseData], float]

Extracts the volume from a data instance. The default value is null which does

None

current_bar

current_bar: RangeBar

Bar being created

This Property is protected.

range_size

range_size: float

Range for each RangeBar, this is, the difference between the High and Low for each RangeBar

range

range: int

Number of MinimumPriceVariation units

output_type

output_type: Type

Gets RangeBar which is the type emitted in the IDataConsolidator.data_consolidated event.

working_data

working_data: IBaseData

Gets a clone of the data being currently consolidated

consolidated

consolidated: IBaseData

Gets the most recently consolidated piece of data. This will be null if this consolidator has not produced any data yet.

input_type

input_type: Type

Gets the type consumed by this consolidator

data_consolidated

data_consolidated: _EventContainer[
    Callable[
        [
            Object,
            QuantConnect_Data_Consolidators_BaseTimelessConsolidator_T,
        ],
        Any,
    ],
    Any,
]

Typed event handler that fires when a new piece of data is produced

DEFAULT_WINDOW_SIZE

DEFAULT_WINDOW_SIZE: int

The default number of values to keep in the rolling window history

window

window: RollingWindow[QuantConnect_Indicators_WindowBase_T]

A rolling window keeping a history of values. The most recent value is at index 0. Uses lazy initialization to support Python subclasses that do not call base constructors.

current

current: QuantConnect_Indicators_WindowBase_T

Gets the most recent value. The protected setter adds the value to the rolling window.

previous

previous: QuantConnect_Indicators_WindowBase_T

Gets the previous value, or default if fewer than two values have been produced.

selector

selector: Callable[[IBaseData], float]

Extracts the value from a data instance to be formed into a T.

This Property is protected.

volume_selector

volume_selector: Callable[[IBaseData], float]

Extracts the volume from a data instance. The default value is null which does not aggregate volume per bar.

This Property is protected.

create_new_bar

create_new_bar(
    data: IBaseData, current_value: float, volume: float
) -> None

Creates a new bar with the given data

This Class is protected.

Parameters:

Name Type Description Default
data IBaseData

The new data for the bar

required
current_value float

The new value for the bar

required
volume float

The new volume for the bar

required

reset

reset() -> None

Resets the consolidator

update_bar

update_bar(
    time: Union[datetime, date],
    current_value: float,
    volume: float,
) -> None

Updates the current RangeBar being created with the given data. Additionally, if it's the case, it consolidates the current RangeBar

This Class is protected.

Parameters:

Name Type Description Default
time Union[datetime, date]

Time of the given data

required
current_value float

Value of the given data

required
volume float

Volume of the given data

required

scan

scan(current_local_time: Union[datetime, date]) -> None

Scans this consolidator to see if it should emit a bar due to time passing

Parameters:

Name Type Description Default
current_local_time Union[datetime, date]

The current time in the local time zone (same as BaseData.time)

required

update

update(data: IBaseData) -> None

Updates this consolidator with the specified data

Parameters:

Name Type Description Default
data IBaseData

The new data for the consolidator

required

__getitem__

__getitem__(i: int) -> QuantConnect_Indicators_WindowBase_T

Indexes the history window, where index 0 is the most recent value.

Parameters:

Name Type Description Default
i int

The index

required

Returns:

Type Description
QuantConnect_Indicators_WindowBase_T

The ith most recent value.

__iter__

__iter__() -> (
    Iterator[QuantConnect_Indicators_WindowBase_T]
)

get_enumerator

get_enumerator() -> (
    IEnumerator[QuantConnect_Indicators_WindowBase_T]
)

Returns an enumerator that iterates through the history window.

reset_window

reset_window() -> None

Resets the rolling window, clearing all stored values.

This Class is protected.

dispose

dispose() -> None

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

fire_data_consolidated

fire_data_consolidated(consolidated: IBaseData) -> None

Raises the strongly typed DataConsolidated event

This Class is protected.

Parameters:

Name Type Description Default
consolidated IBaseData

The newly consolidated data

required

on_data_consolidated

on_data_consolidated(consolidated: IBaseData) -> None

Event invocator for the DataConsolidated event. Populates the rolling window, raises the strongly typed and interface events, and finally updates the consolidated property.

This Class is protected.