Skip to main content

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.

4 min read Reviewed Revision 1

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

Worked numbers

Each result is recomputed from the formula shown.

WhatFormulaResult
open of bar 1100.0100.0
high of the 5-minute barmax(100.4, 100.6, 100.7, 100.3, 100.2)100.7
low of the 5-minute barmin(99.9, 100.1, 100.2, 99.8, 99.7)99.7
close of the 5-minute bar100.1100.1
volume of the 5-minute bar1200 + 900 + 1500 + 2100 + 8006,500
range of the 5-minute barh_all - l_all1.0
close over open, 5-minute barc_all / o1 - 10.1%
overnight return101 / 100 - 11.0%
intraday return100.5 / 101 - 1-0.50%
combined(1 + overnight) * (1 + intraday) - 10.5%
minutes in the session6.5 * 60390
5-minute bars in the sessionsession_min / 578
volume bars of 10,000 shares from 3,900,0003900000 / 10000390 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

OHLC barTimeframeCandlestick

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.

    As of 2026. Source: Holidays and Trading Hours.

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

Informational content. Not investment advice.