Creating Bars#

We create 1-minute bars (bucket_interval=60 seconds) below.

import onetick.py as otp

trd = otp.DataSource('NYSE_TAQ', tick_type='TRD')

trd, _ = trd[trd['COND'].str.match('^[^O6TUHILNRWZ47QMBCGPV]*$')]

bars = trd.agg({'VOLUME': otp.agg.sum('SIZE'),
                'HIGH': otp.agg.max('PRICE'),
                'LOW': otp.agg.min('PRICE'),
                'OPEN': otp.agg.first('PRICE'),
                'COUNT': otp.agg.count(),
                'CLOSE': otp.agg.last('PRICE')},
                bucket_interval=otp.Minute(1))

otp.run(
    bars,
    symbols=['SPY'],
    start=otp.dt(2023, 5, 15, 9, 30),
    end=otp.dt(2023, 5, 15, 10),
    timezone='EST5EDT'
)
Time VOLUME HIGH LOW OPEN COUNT CLOSE
0 2023-05-15 09:31:00 264719 412.2900 412.0350 412.2200 1446 412.0400
1 2023-05-15 09:32:00 218724 412.2600 412.0000 412.0500 1537 412.1600
2 2023-05-15 09:33:00 271364 412.2000 411.9400 412.1650 1649 412.0200
3 2023-05-15 09:34:00 312764 412.0200 411.6312 412.0100 1827 411.8200
4 2023-05-15 09:35:00 252569 411.8300 411.3600 411.8100 1241 411.3983
5 2023-05-15 09:36:00 202980 411.6250 411.3200 411.3900 1286 411.6250
6 2023-05-15 09:37:00 114774 411.6800 411.4400 411.6200 841 411.5900
7 2023-05-15 09:38:00 152180 411.6000 411.4100 411.5800 927 411.4300
8 2023-05-15 09:39:00 96940 411.5100 411.3600 411.4300 592 411.3600
9 2023-05-15 09:40:00 129613 411.4650 411.2300 411.3550 884 411.4471
10 2023-05-15 09:41:00 111231 411.6668 411.3600 411.4550 723 411.6300
11 2023-05-15 09:42:00 214502 411.7100 411.4300 411.6400 1395 411.4750
12 2023-05-15 09:43:00 262713 411.6600 411.4200 411.4700 1379 411.4700
13 2023-05-15 09:44:00 106379 411.5200 411.3520 411.4700 654 411.4400
14 2023-05-15 09:45:00 103743 411.5250 411.4000 411.4200 551 411.5016
15 2023-05-15 09:46:00 137092 411.6600 411.5200 411.5200 871 411.6300
16 2023-05-15 09:47:00 189016 411.6900 411.3600 411.6300 1201 411.3900
17 2023-05-15 09:48:00 121331 411.4780 411.3100 411.3900 612 411.3150
18 2023-05-15 09:49:00 108976 411.3900 411.1600 411.3200 664 411.2900
19 2023-05-15 09:50:00 112394 411.3000 411.1200 411.3000 637 411.1900
20 2023-05-15 09:51:00 94153 411.2700 411.0300 411.1900 469 411.0300
21 2023-05-15 09:52:00 112302 411.1900 410.9800 411.0300 687 410.9900
22 2023-05-15 09:53:00 114025 411.1179 410.9700 410.9850 599 410.9900
23 2023-05-15 09:54:00 80763 411.1299 410.9500 410.9850 458 411.0150
24 2023-05-15 09:55:00 66556 411.1099 411.0100 411.0190 435 411.0350
25 2023-05-15 09:56:00 131143 411.1100 410.9100 411.0350 790 410.9205
26 2023-05-15 09:57:00 128274 410.9300 410.8200 410.9205 679 410.8400
27 2023-05-15 09:58:00 162243 410.9500 410.8000 410.8200 953 410.8900
28 2023-05-15 09:59:00 105649 410.9300 410.8300 410.8800 572 410.8700
29 2023-05-15 10:00:00 145019 410.9100 410.7800 410.8600 911 410.8400
Note: OneTick Cloud has minute bars precomputed and available in *_BARS databases under the tick type TRD_1M.

Daily OHLCV data with the official closing prices is also available: see OHLCV.

Note the use of apply_times_daily to limit each day’s interval to 9:30-4:00pm (plus one minute is added as the minute bar for 9:30-9:31 has the timestamp of 9:31).

bars = otp.DataSource('NYSE_TAQ_BARS', tick_type='TRD_1M')
bars = bars[['FIRST', 'HIGH', 'LOW', 'LAST', 'VOLUME']]
otp.run(
    bars,
    symbols=['SPY'],
    start=otp.dt(2023, 5, 15, 9, 31),
    end=otp.dt(2023, 5, 19, 16, 1),
    timezone='EST5EDT',
    apply_times_daily=True)
Time FIRST HIGH LOW LAST VOLUME
0 2023-05-15 09:31:00 412.220 412.290 412.0350 412.0400 264719
1 2023-05-15 09:32:00 412.050 412.260 412.0000 412.1600 218724
2 2023-05-15 09:33:00 412.165 412.200 411.9400 412.0200 271364
3 2023-05-15 09:34:00 412.010 412.020 411.6312 411.8200 312764
4 2023-05-15 09:35:00 411.810 411.830 411.3600 411.3983 252569
... ... ... ... ... ... ...
1945 2023-05-19 15:56:00 418.890 418.950 418.8501 418.9200 465446
1946 2023-05-19 15:57:00 418.910 418.915 418.7200 418.8700 618549
1947 2023-05-19 15:58:00 418.870 418.980 418.8400 418.9500 601161
1948 2023-05-19 15:59:00 418.950 418.990 418.9000 418.9600 711607
1949 2023-05-19 16:00:00 418.960 418.970 418.5700 418.6100 1565989

1950 rows × 6 columns