otp.Source.time_interval_shift#
- Source.time_interval_shift(shift, inplace=False)[source]#
Shifting time interval for a source.
The whole data flow is shifted all the way up to the source of the graph.
The ticks’ timestamps are changed accordingly so they fit into original time range.
- Parameters
shift (int or datetime offset) – Offset to shift the whole time interval. Can be positive or negative. Positive value moves time interval 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.
- Return type
Source
orNone
Examples
–> Also see use-case using
time_interval_shift()
for calculating Markouts>>> 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')
Default data:
>>> otp.run(data, 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
Get window for a third tick:
>>> otp.run(data, start=start + otp.Milli(2), end=start + otp.Milli(3)) Time PRICE SIZE 0 2022-03-02 00:00:00.002 1.2 102
Shifting time window will result in different set of ticks, but the ticks will have their timestamps changed to fit into original time range. Let’s shift time 2 milliseconds back and thus get the first tick:
>>> t = data.time_interval_shift(shift=-otp.Milli(2)) >>> otp.run(t, start=start + otp.Milli(2), end=start + otp.Milli(3)) Time PRICE SIZE 0 2022-03-02 00:00:00.002 1.0 100
Here we are querying empty time interval, but shifting one second back to get ticks.
>>> t = data.time_interval_shift(shift=-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.000 1.0 100 1 2022-03-02 00:00:01.001 1.1 101 2 2022-03-02 00:00:01.002 1.2 102