Quant Analytics: from scratch to pro · Quant foundations: returns, risk and clean data · Advanced
Bars and resampling: building candles from finer data
Candles at every timeframe are built from finer data with fixed aggregation rules. This lesson covers the OHLCV rules, left and right bar labels, sessions, missing minutes, the split of a return into overnight and intraday parts, and bars built by activity instead of by the clock.
In this lesson
- Aggregate fine bars into a coarser bar with the correct open, high, low, close and volume rules
- Choose and apply a bar label so that no bar is used before it is complete
- Handle missing intervals and session boundaries explicitly
- Split a close-to-close return into overnight and intraday parts
- Explain how tick, volume and dollar bars differ from time bars
Read first: Returns: simple, log and compounded, Clean data: timestamps, time zones, DST and survivorship
Every candle on a chart is a summary of finer data. A daily bar summarises the day's trades; an hourly bar summarises sixty one-minute bars. The summary rules are fixed, and the details around them, such as labels, sessions and missing intervals, are where mistakes enter. A study built on mislabelled bars can use information from the future without anyone noticing.
The OHLCV rules
A bar records open, high, low, close and volume (OHLCV) for an interval. To build a coarser bar from finer ones, in time order:
| Field | Rule |
|---|---|
| Open | The open of the first fine bar |
| High | The maximum of all the highs |
| Low | The minimum of all the lows |
| Close | The close of the last fine bar |
| Volume | The sum of all the volumes |
Resample in one direction only. You can go from one-minute bars to five-minute bars, never the reverse; the detail is gone.
Worked example: five minutes from five bars
| Bar | Open | High | Low | Close | Volume |
|---|---|---|---|---|---|
| 1 | 100.0 | 100.4 | 99.9 | 100.2 | 1,200 |
| 2 | 100.2 | 100.6 | 100.1 | 100.5 | 900 |
| 3 | 100.5 | 100.7 | 100.2 | 100.3 | 1,500 |
| 4 | 100.3 | 100.3 | 99.8 | 99.9 | 2,100 |
| 5 | 99.9 | 100.2 | 99.7 | 100.1 | 800 |
The five-minute bar opens at 100.0, the first open. Its high is 100.7 and its low is 99.7, so the range is 1.0. It closes at 100.1, the last close. The volume is 6,500. The close over the open is 100.1 / 100.0 - 1, which is 0.1%.
Note that the high of the aggregate came from bar 3 and the low from bar 5. Neither is the last bar.
Labels: when is a bar known
A bar covering 09:30 to 09:35 can be stamped 09:30 (left label, the start) or 09:35 (right label, the end). Both exist in practice and vendors differ. The consequence is large. A bar is complete only at its end. A left-labelled bar stamped 09:30 must not be used by a rule at 09:30. Doing so is look-ahead: the rule sees a close that had not happened yet.
Check this once per data source: find a known event, such as an announcement time, and see which bar its price move lands in. Then state the convention in the code.
Sessions and boundaries
A daily bar needs a definition of the day. Equity exchanges have an open and close: the NYSE core session is 9:30 a.m. to 4:00 p.m. Eastern, 390 minutes, so a 5-minute bar divides it into 78. Some markets trade nearly around the clock on weekdays, so the daily cut-off is a choice, and its time zone matters because the offset to UTC moves with daylight saving (see clean data). Do not build a bar across a weekend or a halt without marking it.
Gaps and missing minutes
If no trade occurs in an interval, many sources produce no bar. Two options: leave the gap, or fill it with a flat bar (open, high, low and close equal to the previous close, volume zero). Fill when a model needs a regular grid, but remember that zero-volume bars have no real prices, and that a long run of them often points to a data fault rather than a quiet market.
Between sessions the price can jump. A close-to-close return splits into an overnight part and an intraday part, which multiply. With a previous close of 100, an open of 101 and a close of 100.5:
- Overnight: 101 / 100 - 1 = 1.0%.
- Intraday: 100.5 / 101 - 1 = -0.50%.
- Combined: 1.01 x 0.995 - 1 = 0.5%, the same as 100.5 / 100 - 1.
The two parts can have different signs and different risk. See gaps and weekend risk.
Tick, volume and dollar bars
Time bars sample on the clock, so busy and quiet periods get the same weight. Tick bars close after a fixed number of trades, volume bars after a fixed quantity traded, and dollar bars after a fixed value traded. López de Prado (2018) discusses them as alternatives whose returns can have better statistical properties. With 3,900,000 shares traded in a session and 10,000 per bar, a day makes 390 volume bars. More bars arrive when activity is high.
Common mistakes
- Taking the high from the last bar instead of the maximum.
- Averaging closes instead of taking the last close.
- Using left-labelled bars at their stamped time.
- Filling gaps with the previous close and treating them as real prices.
- Mixing sessions: daily bars cut at different times in different series.
- Resampling coarse data to a finer interval and treating the result as new information.
In practice
Write the aggregation rule, label, session and time zone next to every dataset. When comparing two vendors, check one day by hand, and check the bar count against the expected count. Data on FinUties provides price series to practise these checks on; the data APIs are free after registration.
Worked numbers
Each result is recomputed from the formula shown.
| What | Formula | Result |
|---|---|---|
| open of bar 1 | 100.0 | 100.0 |
| high of the 5-minute bar | max(100.4, 100.6, 100.7, 100.3, 100.2) | 100.7 |
| low of the 5-minute bar | min(99.9, 100.1, 100.2, 99.8, 99.7) | 99.7 |
| close of the 5-minute bar | 100.1 | 100.1 |
| volume of the 5-minute bar | 1200 + 900 + 1500 + 2100 + 800 | 6,500 |
| range of the 5-minute bar | h_all - l_all | 1.0 |
| close over open, 5-minute bar | c_all / o1 - 1 | 0.1% |
| overnight return | 101 / 100 - 1 | 1.0% |
| intraday return | 100.5 / 101 - 1 | -0.50% |
| combined | (1 + overnight) * (1 + intraday) - 1 | 0.5% |
| minutes in the session | 6.5 * 60 | 390 |
| 5-minute bars in the session | session_min / 5 | 78 |
| volume bars of 10,000 shares from 3,900,000 | 3900000 / 10000 | 390 volume bars |
Check yourself
Four 1-minute bars have highs 5.0, 5.4, 5.2, 5.1 and lows 4.8, 4.9, 4.7, 4.9. What are the high and low of the 4-minute bar?
High = max of the highs = 5.4. Low = min of the lows = 4.7. The aggregate high is the highest high, not the high of the last bar.
A bar covering 09:30 to 09:35 is stamped 09:30. A rule decides at 09:30 using that bar. What is wrong?
The bar's close is not known until 09:35. Using it at 09:30 is look-ahead. Either stamp the bar with its end time (right label) or only use it from 09:35.
Previous close 100, open 101, close 100.5. Split the daily return.
Overnight: 101 / 100 - 1 = 1.0%. Intraday: 100.5 / 101 - 1 = -0.50%. Combined: 1.01 x 0.995 - 1 = 0.5%, which equals 100.5 / 100 - 1.
How many 5-minute bars are in a 390-minute session, and how many volume bars if 3,900,000 shares trade and each bar holds 10,000?
390 / 5 = 78 time bars. 3,900,000 / 10,000 = 390 volume bars. Time bars are constant in number; volume bars are more numerous when trading is busy.
Key terms
Checked facts
Every figure below carries how it was checked: Primary checked (read in the cited primary, official, academic or data source), Two sources agree, or Approximate (an order of magnitude only).
- Primary checked
The NYSE core trading session runs from 9:30 a.m. to 4:00 p.m. Eastern Time, which is 390 minutes.
Sources
- Advances in Financial Machine Learning. Wiley (Marcos López de Prado), 2018. Accessed 9 Nov 2026
- Trading and Exchanges: Market Microstructure for Practitioners. Oxford University Press (Larry Harris), 2003. Accessed 9 Nov 2026
- Holidays and Trading Hours. New York Stock Exchange (Intercontinental Exchange), 2026. Accessed 9 Nov 2026