otp.Source.time_interval_change#

Source.time_interval_change(start_change=0, end_change=0, inplace=False)#

Changing time interval by making it bigger or smaller.

All timestamps of ticks that are crossing the border of original time range will be set to original start time or end time depending on their original time.

Parameters
  • start_change (int or datetime offset) – Offset to shift start time. Can be positive or negative. Positive value moves start time into the future, negative – to the past. int values are interpreted as milliseconds.

  • end_change (int or datetime offset) – Offset to shift end time. Can be positive or negative. Positive value moves end time into the future, negative – to the past. int values are interpreted as milliseconds.

  • inplace (bool) – The flag controls whether operation should be applied inplace or not. If inplace=True, then it returns nothing. Otherwise method returns a new modified object.

  • self (Source) –

Return type

Source or None

Examples

>>> start = otp.dt(2022, 3, 2)
>>> end = otp.dt(2022, 3, 2) + otp.Milli(3)
>>> data = otp.DataSource('NYSE_TAQ', symbols='AAPL', tick_type='TRD')

By default, time_interval_change() does nothing:

>>> t = data.time_interval_change()
>>> otp.run(t, start=start, end=end)
                     Time  PRICE  SIZE
0 2022-03-02 00:00:00.000    1.0   100
1 2022-03-02 00:00:00.001    1.1   101
2 2022-03-02 00:00:00.002    1.2   102

Decreasing time range will not change ticks’ timestamps:

>>> t = data.time_interval_change(start_change=otp.Milli(1), end_change=-otp.Milli(1))
>>> otp.run(t, start=start, end=end)
                     Time  PRICE  SIZE
0 2022-03-02 00:00:00.001    1.1   101

Increasing time range will change timestamps of the ticks that crossed the border. In this case first tick’s timestamp will be set to original start time, and third tick’s to original end time.

>>> t = data.time_interval_change(start_change=-otp.Milli(1), end_change=otp.Milli(1))
>>> otp.run(t, start=start + otp.Milli(1), end=start + otp.Milli(2))
                     Time  PRICE  SIZE
0 2022-03-02 00:00:00.001    1.0   100
1 2022-03-02 00:00:00.001    1.1   101
2 2022-03-02 00:00:00.002    1.2   102

Here we are querying empty time interval, but changing start time one second back to get ticks.

>>> t = data.time_interval_change(start_change=-otp.Second(1))
>>> otp.run(t, start=start + otp.Second(1), end=end + otp.Second(1))
                 Time  PRICE  SIZE
0 2022-03-02 00:00:01    1.0   100
1 2022-03-02 00:00:01    1.1   101
2 2022-03-02 00:00:01    1.2   102