Working with Price Bars, Momentum, Volume, and Time Aggregation
Summary
This reference explains a price-bars data object that stores a time-indexed DataFrame with open, high, low, close, volume, dividend, and stock-split fields. It identifies metadata such as the data source and symbol, and describes helpers for retrieving the latest close or dividend, calculating price momentum over an optional date range, summing volume, and filtering observations. It also describes converting bars to a different frequency, such as aggregating minute data into a longer interval.
The page is an API reference rather than a trading strategy or empirical study; it provides no evidence about the predictive value of momentum or any other signal. It notes that timestamps use the America/New_York timezone and that Interactive Brokers may throttle historical data requests when pacing limits are exceeded. In live Interactive Brokers use, some helper operations use tick data, and dividend retrieval is unavailable. These details matter when interpreting data behavior and building applications around the object.
Key ideas
- A bar record groups open, high, low, close, volume, dividend, and split data over time.
- The object provides helpers for recent prices, dividends, momentum, volume totals, and date filtering.
- Bars can be aggregated into a different time frequency.
- Its DataFrame index uses the America/New_York timezone.
- Interactive Brokers historical pacing limits and live-data behavior can affect access to these helpers.
Tags
Full text
# entities.bars Bars ---------------------------- .. meta:: :description: This object contains all pricing data over time, including open, close, high, low, etc prices. You can get the raw pandas DataFrame by using bars.df. This object contains all pricing data over time, including open, close, high, low, etc prices. You can get the raw pandas DataFrame by using ``bars.df``. The dataframe has the following columns: * open * high * low * close * volume * dividend * stock_splits The dataframe index is of type pd. Timestamp localized at the timezone ``America/New_York``. Bars objects have the following fields: * source: the source of the data e.g. (yahoo, alpaca, ...) * symbol: the symbol of the bars * df: the pandas dataframe containing all the datas Bars objects has the following helper methods: * get_last_price(): Returns the closing price of the last dataframe row * get_last_dividend(): Returns the dividend per share value of the last dataframe row * get_momentum(start=None, end=None): Calculates the global price momentum of the dataframe. * aggregate_bars(frequency): Will convert a set of bars to a different timeframe (eg. 1 min to 15 min) frequency (string): The new timeframe that the bars should be in, eg. "15Min", "1H", or "1D". Returns a new Bars object. When specified, ``start`` and ``end`` will be used to filter the daterange for the momentum calculation. If none of start or end are specified the momentum will be calculated from the first row untill the last row of the dataframe. * ``get_total_volume(start = None, end = None)``: returns the sum of the volume column. When ``start`` and/or end is/are specified use them to filter for that given daterange before returning the total volume * ``filter(start = None, end = None)``: Filter the bars dataframe. When ``start`` and/or ``end`` is/are specified use them to filter for that given daterange before returning the total volume When getting historical data from Interactive Brokers, it is important to note that they do not consider themselves a data supplier. If you exceed these data access pacing rates, your data will be throttled. Additionally, with respect to above three mentioned helpers, when using Interactive Brokers live, tick data is called instead of bar data. This allows for more frequent and accurate pricing updates. ``get_last_dividend`` are not available in Interactive Brokers. (see [Interactive Brokers' pacing rules](https://interactivebrokers.github. io/tws-api/historical_limitations.html)) Documentation """"""""""""""""""" .. automodule:: lumibot.entities.bars :noindex: :members: :undoc-members: :show-inheritance:
Shown in full with attribution under the source's licence. Licence: GPL-3.0
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.