How does Alpaca calculate minute bars for market data?

Minute bar data includes open, high, low, close price, volume, vwap, and number of trades. These data are calculated from trade data (ie trade price and volume). The calculations are done in three steps. Trades are 1) aggregated by the time the trade was executed, 2) filtered by ‘trade condition’, then 3) have the appropriate function applied (sum, minimum, maximum, etc).

1) Aggregate by the time the trade was executed. Trade data is placed into minute ‘buckets’ based upon the trade execution, or ‘participant’, timestamp. The interval is closed left and open right. It includes the lower limit but excludes the upper ( Tstart <= trade < Tend). The bars are labeled with the start time so, for example, the bar with trades between 9:31-9:32 is labeled 9:31.

2) Filter by ‘trade condition’. Only certain trade types are used in the bar calculations. Each field, such as Open, Close, or Volume, filters by different conditions. The Close price for example, considers only a limited number of ‘typical’ trades while Volume includes almost all trades. Alpaca follows the guidance given by the Securities Information Providers (SIPs) in determining which trades to exclude from calculations. That guidance is on page 64 of the Consolidated Tape System (CTS) Specification and page 43 of the UTP Specification. Below is a summary of trade conditions which exclude a trade from a close price.

Feed

Tape

Condition

Description

CTS

AB

B

Average Price Trade

UTDF

C

W

Average Price Trade

CTS/UTD

ABC

4

Derivatively Priced

CTS/UTD

ABC

7

Qualified Contingent Trade (“QCT”)

CTS/UTD

ABC

9

Corrected Consolidated Close (per listing market)

CTS/UTD

ABC

C

Cash Sale

CTS/UTD

ABC

G

Bunched Sold Trade

CTS/UTD

ABC

H

Price Variation Trade

CTS/UTD

ABC

I

Odd Lot Trade

CTS/UTD

ABC

M

Market Center Official Close

CTS/UTD

ABC

N

Next Day

CTS/UTD

ABC

P

Prior Reference Price

CTS/UTD

ABC

Q

Market Center Official Open

CTS/UTD

ABC

R

Seller

CTS/UTD

ABC

T

Form T

CTS/UTD

ABC

U

Extended Trading Hours (Sold Out of Sequence)

CTS/UTD

ABC

V

Contingent Trade

CTS/UTD

ABC

Z

Sold (out of Sequence)

3) Apply appropriate function. Once the trades are filtered, the specific fields are determined using the following functions :

Field

Function


Description

Open

First


Price of first trade (by participant timestamp)

High

Max


Highest price of trades in bar

Low

Min


Lowest price of trades in bar

Close

Last


Price of last trade (by participant timestamp)

Volume

Sum


Sum of shares traded

Number

Count


Count of number of trades

VWAP

Weighted Average


(Price x Volume) / Volume total

Bars are calculated, and available, 1 second after the close of each minute (eg the 9:31 bar is calculated at 9:32:01). Because trade data can be delivered up to 10 seconds after the actual execution, the bar is then recalculated after 30 seconds (eg the 9:31 bar is re-calculated at 9:32:30) and will include any trades received after the initial calculation.


Please note that this article is for general informational purposes only. All examples are for illustrative purposes only. Alpaca does not recommend any specific securities, cryptocurrencies or investment strategies.

All investments involve risk and the past performance of a security, or financial product does not guarantee future results or returns.There is no guarantee that any investment strategy will be successful in achieving its investment objectives. Diversification does not ensure a profit or protection against a loss. There is always the potential of losing money when you invest in securities, or other financial products. Investors should consider their investment objectives and risks carefully before investing.

Brokerage services are provided by Alpaca Securities LLC ("Alpaca Securities"), member FINRA/SIPC, a wholly-owned subsidiary of AlpacaDB, Inc. Technology and services are offered by AlpacaDB, Inc.