Time Modeling

Periods

Introduction

Data comes in two different "shapes" according to the time period it covers: point values or period values. In QuantConnect, ticks are point values, and bars are a period values. These data formats have different properties, which control when LEAN emits them into your algorithm.

Start and End Time

Bars have a start and end time that represent the time period of which the bar aggregates data. LEAN passes the bar to your algorithm at the end time so that you don't receive the bar before it was actually available. Other data providers commonly timestamp their bars to the start time of the bar. This can cause one-off errors when you import the data into QC or compare indicator values across different platforms.

Period Values

Bars aggregate data across a period of time into a single object. We make this easy for you by pre-aggregating billions of raw trade-ticks into TradeBar objects and quote-ticks into QuoteBar objects.

We don't know the close of a bar until the start of the next bar, which can sometimes be confusing. For example, a price bar for Friday will include all the ticks from Friday 00:00:00 to Friday 23:59:59.99999, but LEAN will emit it to your algorithm on Saturday at midnight. As a result, if you analyze the Friday data and then place an order, LEAN sends the order to your brokerage on Saturday.

When there are no ticks during a period, LEAN emits the previous bar. This is the default behavior for bar data and it's referred to as "filling the data forward". You can enable and disable this setting when you create the security subscription.

We provide bar data in second, minute, hour, and daily bar formats. To create other periods of bars, see Consolidating Data.

Daily Periods

LEAN emits daily bars at midnight. To be notified when a security has finished trading for the day, add an OnEndOfDay method to your algorithm. LEAN calls this method for each security every day.

def OnEndOfDay(self, symbol: Symbol) -> None:
    pass
public override void OnEndOfDay(Symbol symbol)
{
    
}

Point Values

Point values have no period because they occur at a singular point in time. Examples of point data includes ticks, open interest, and news releases. Tick data represents a single trade or quote in the market. It's a discrete event with no period, so the Time and EndTime properties are the same. LEAN emits ticks as soon as they arrive and doesn't fill them forward.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: