Skip to content

input #

The module contains functionality related to the processing of indicators' input.

Sampler #

Sampler(period_type: SamplingPeriodType)

Implementation of timeframe auto-sampling.

Timeframe auto-sampling allows to evaluate whether two timestamps belong into the same period or not. This is later used by indicators to "merge" several input values received within selected timeframe and keep only the last value in the given timeframe.

Each timeframe is counted from different starting point. Seconds are counted since whole minutes, minutes are counted since whole hours, hours are counted since whole days and days are counted since the beginning of the year.

Examples:

Sampling: 1 sec
Timestamp 1: 00:00:01.000000
Timestamp 2: 00:00:01.700000
Result: same timeframe

Sampling: 5 sec
Timestamp 1: 00:00:01.000000
Timestamp 2: 00:00:04.000000
Result: same timeframe

Sampling: 5 sec
Timestamp 1: 00:00:04.000000
Timestamp 2: 00:00:06.000000
Result: different timeframe

Parameters:

Name Type Description Default
period_type SamplingPeriodType

The sampling period.

required
Source code in talipp/input.py
def __init__(self, period_type: SamplingPeriodType):
    self._period_type: SamplingPeriodType = period_type

is_same_period #

is_same_period(first: OHLCV, second: OHLCV) -> bool

Evaluate whether two OHLCV objects belong to the same period.

OHLCV objects have to contain time component to be comparable.

Parameters:

Name Type Description Default
first OHLCV

The first OHLCV object.

required
second OHLCV

The second OHLCV object.

required

Returns:

Type Description
bool

True if two objects belong to the same period, otherwise False.

Source code in talipp/input.py
def is_same_period(self, first: OHLCV, second: OHLCV) -> bool:
    """Evaluate whether two [OHLCV][talipp.ohlcv.OHLCV] objects belong to the same period.

    `OHLCV` objects have to contain time component to be comparable.

    Args:
        first: The first `OHLCV` object.
        second: The second `OHLCV` object.

    Returns:
        `True` if two objects belong to the same period, otherwise `False`.
    """

    first_normalized = self._normalize(first.time)
    second_normalized = self._normalize(second.time)

    return first_normalized == second_normalized

SamplingPeriodType #

Bases: Enum

Available sampling periods.

Each sampling period consists of a unit and its span. E.g. SEC_1 means sampling every second, SEC_3 means sampling every three seconds and so on.

Note

Only those spans are allowed which divide full unit's period without remainder.

3 seconds => OK (60 % 3 = 0)
5 seconds => OK (60 % 5 = 0)
8 seconds => NOT OK (60 % 8 != 0)
4 hours   => OK (24 % 4 = 0)
5 hours   => NOT OK (24 % 5 != 0)

DAY_1 class-attribute instance-attribute #

DAY_1 = (DAY, 1)

1 day

HOUR_1 class-attribute instance-attribute #

HOUR_1 = (HOUR, 1)

1 hour

HOUR_2 class-attribute instance-attribute #

HOUR_2 = (HOUR, 2)

2 hours

HOUR_3 class-attribute instance-attribute #

HOUR_3 = (HOUR, 3)

3 hours

HOUR_4 class-attribute instance-attribute #

HOUR_4 = (HOUR, 4)

4 hours

MIN_1 class-attribute instance-attribute #

MIN_1 = (MIN, 1)

1 minute

MIN_10 class-attribute instance-attribute #

MIN_10 = (MIN, 10)

10 minutes

MIN_15 class-attribute instance-attribute #

MIN_15 = (MIN, 15)

15 minutes

MIN_3 class-attribute instance-attribute #

MIN_3 = (MIN, 3)

3 minutes

MIN_30 class-attribute instance-attribute #

MIN_30 = (MIN, 30)

30 minutes

MIN_5 class-attribute instance-attribute #

MIN_5 = (MIN, 5)

5 minutes

SEC_1 class-attribute instance-attribute #

SEC_1 = (SEC, 1)

1 second

SEC_10 class-attribute instance-attribute #

SEC_10 = (SEC, 10)

10 seconds

SEC_15 class-attribute instance-attribute #

SEC_15 = (SEC, 15)

15 seconds

SEC_3 class-attribute instance-attribute #

SEC_3 = (SEC, 3)

3 seconds

SEC_30 class-attribute instance-attribute #

SEC_30 = (SEC, 30)

30 seconds

SEC_5 class-attribute instance-attribute #

SEC_5 = (SEC, 5)

5 seconds