---
title: "US Equity"
description: "Learn how to request and handle US Equities in the research environment in QuantConnect"
canonical: https://www.quantconnect.com/docs/v2/research-environment/datasets/us-equity
markdown: https://www.quantconnect.com/docs/v2/research-environment/datasets/us-equity.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/04%20Research%20Environment/03%20Datasets/04%20US%20Equity
modified: 2026-11-01
index: https://www.quantconnect.com/llms.txt
---

# US Equity

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Research Environment](https://www.quantconnect.com/docs/v2/research-environment.md) > Datasets > US Equity

> Code examples are shown in Python. Append `?lang=csharp` to this URL for the C# version of this page.

## Introduction

This page explains how to request, manipulate, and visualize historical US Equity data.

## Create Subscriptions

Follow these steps to subscribe to a US Equity security:

1. Create a `QuantBook`.
   ```python
   qb = QuantBook()
   ```
2. Call the `add_equity` method with a ticker and then save a reference to the US Equity `Symbol`.
   ```python
   spy = qb.add_equity("SPY").symbol
   tlt = qb.add_equity("TLT").symbol
   ```

To view the supported assets in the US Equities dataset, see the [Data Explorer](https://www.quantconnect.com/datasets/algoseek-us-equities/explorer).

## Get Historical Data

You need a [subscription](https://www.quantconnect.com/docs/v2/research-environment/datasets/us-equity.md#03-Create-Subscriptions) before you can request historical data for a security. On the time dimension, you can request an amount of historical data based on a trailing number of bars, a trailing period of time, or a defined period of time. On the security dimension, you can request historical data for a single US Equity, a subset of the US Equities you created subscriptions for in your notebook, or all of the US Equities in your notebook.

### Trailing Number of Bars

To get historical data for a number of trailing bars, call the `history` method with the `Symbol` object(s) and an integer.

```python
# DataFrame of trade and quote data
single_history_df = qb.history(spy, 10)
subset_history_df = qb.history([spy, tlt], 10)
all_history_df = qb.history(qb.securities.keys(), 10)

# DataFrame of trade data
single_history_trade_bar_df = qb.history(TradeBar, spy, 10)
subset_history_trade_bar_df = qb.history(TradeBar, [spy, tlt], 10)
all_history_trade_bar_df = qb.history(TradeBar, qb.securities.keys(), 10)

# DataFrame of quote data
single_history_quote_bar_df = qb.history(QuoteBar, spy, 10)
subset_history_quote_bar_df = qb.history(QuoteBar, [spy, tlt], 10)
all_history_quote_bar_df = qb.history(QuoteBar, qb.securities.keys(), 10)

# Slice objects
all_history_slice = qb.history(10)

# TradeBar objects
single_history_trade_bars = qb.history[TradeBar](spy, 10)
subset_history_trade_bars = qb.history[TradeBar]([spy, tlt], 10)
all_history_trade_bars = qb.history[TradeBar](qb.securities.keys(), 10)

# QuoteBar objects
single_history_quote_bars = qb.history[QuoteBar](spy, 10)
subset_history_quote_bars = qb.history[QuoteBar]([spy, tlt], 10)
all_history_quote_bars = qb.history[QuoteBar](qb.securities.keys(), 10)
```

The preceding calls return the most recent bars, excluding periods of time when the exchange was closed.

### Trailing Period of Time

To get historical data for a trailing period of time, call the `history` method with the `Symbol` object(s) and a `timedelta`.

```python
# DataFrame of trade and quote data
single_history_df = qb.history(spy, timedelta(days=3))
subset_history_df = qb.history([spy, tlt], timedelta(days=3))
all_history_df = qb.history(qb.securities.keys(), timedelta(days=3))

# DataFrame of trade data
single_history_trade_bar_df = qb.history(TradeBar, spy, timedelta(days=3))
subset_history_trade_bar_df = qb.history(TradeBar, [spy, tlt], timedelta(days=3))
all_history_trade_bar_df = qb.history(TradeBar, qb.securities.keys(), timedelta(days=3))

# DataFrame of quote data
single_history_quote_bar_df = qb.history(QuoteBar, spy, timedelta(days=3))
subset_history_quote_bar_df = qb.history(QuoteBar, [spy, tlt], timedelta(days=3))
all_history_quote_bar_df = qb.history(QuoteBar, qb.securities.keys(), timedelta(days=3))

# DataFrame of tick data
single_history_tick_df = qb.history(spy, timedelta(days=3), Resolution.TICK)
subset_history_tick_df = qb.history([spy, tlt], timedelta(days=3), Resolution.TICK)
all_history_tick_df = qb.history(qb.securities.keys(), timedelta(days=3), Resolution.TICK)

# Slice objects
all_history_slice = qb.history(timedelta(days=3))

# TradeBar objects
single_history_trade_bars = qb.history[TradeBar](spy, timedelta(days=3))
subset_history_trade_bars = qb.history[TradeBar]([spy, tlt], timedelta(days=3))
all_history_trade_bars = qb.history[TradeBar](qb.securities.keys(), timedelta(days=3))

# QuoteBar objects
single_history_quote_bars = qb.history[QuoteBar](spy, timedelta(days=3), Resolution.MINUTE)
subset_history_quote_bars = qb.history[QuoteBar]([spy, tlt], timedelta(days=3), Resolution.MINUTE)
all_history_quote_bars = qb.history[QuoteBar](qb.securities.keys(), timedelta(days=3), Resolution.MINUTE)

# Tick objects
single_history_ticks = qb.history[Tick](spy, timedelta(days=3), Resolution.TICK)
subset_history_ticks = qb.history[Tick]([spy, tlt], timedelta(days=3), Resolution.TICK)
all_history_ticks = qb.history[Tick](qb.securities.keys(), timedelta(days=3), Resolution.TICK)
```

The preceding calls return the most recent bars or ticks, excluding periods of time when the exchange was closed.

### Defined Period of Time

To get historical data for a specific period of time, call the `history` method with the `Symbol` object(s), a start `datetime`, and an end `datetime`. The start and end times you provide are based in the [notebook time zone](https://www.quantconnect.com/docs/v2/research-environment/initialization.md#04-Set-Time-Zone).

```python
start_time = datetime(2021, 1, 1)
end_time = datetime(2021, 2, 1)

# DataFrame of trade and quote data
single_history_df = qb.history(spy, start_time, end_time)
subset_history_df = qb.history([spy, tlt], start_time, end_time)
all_history_df = qb.history(qb.securities.keys(), start_time, end_time)

# DataFrame of trade data
single_history_trade_bar_df = qb.history(TradeBar, spy, start_time, end_time)
subset_history_trade_bar_df = qb.history(TradeBar, [spy, tlt], start_time, end_time)
all_history_trade_bar_df = qb.history(TradeBar, qb.securities.keys(), start_time, end_time)

# DataFrame of quote data
single_history_quote_bar_df = qb.history(QuoteBar, spy, start_time, end_time)
subset_history_quote_bar_df = qb.history(QuoteBar, [spy, tlt], start_time, end_time)
all_history_quote_bar_df = qb.history(QuoteBar, qb.securities.keys(), start_time, end_time)

# DataFrame of tick data
single_history_tick_df = qb.history(spy, start_time, end_time, Resolution.TICK)
subset_history_tick_df = qb.history([spy, tlt], start_time, end_time, Resolution.TICK)
all_history_tick_df = qb.history(qb.securities.keys(), start_time, end_time, Resolution.TICK)

# TradeBar objects
single_history_trade_bars = qb.history[TradeBar](spy, start_time, end_time)
subset_history_trade_bars = qb.history[TradeBar]([spy, tlt], start_time, end_time)
all_history_trade_bars = qb.history[TradeBar](qb.securities.keys(), start_time, end_time)

# QuoteBar objects
single_history_quote_bars = qb.history[QuoteBar](spy, start_time, end_time, Resolution.MINUTE)
subset_history_quote_bars = qb.history[QuoteBar]([spy, tlt], start_time, end_time, Resolution.MINUTE)
all_history_quote_bars = qb.history[QuoteBar](qb.securities.keys(), start_time, end_time, Resolution.MINUTE)

# Tick objects
single_history_ticks = qb.history[Tick](spy, start_time, end_time, Resolution.TICK)
subset_history_ticks = qb.history[Tick]([spy, tlt], start_time, end_time, Resolution.TICK)
all_history_ticks = qb.history[Tick](qb.securities.keys(), start_time, end_time, Resolution.TICK)
```

The preceding calls return the bars or ticks that have a timestamp within the defined period of time.

## Resolutions

The following table shows the available resolutions and data formats for Equity subscriptions:

| Resolution | TradeBar | QuoteBar | Trade Tick | Quote Tick |
| --- | --- | --- | --- | --- |
| `TICK` | Not supported | Not supported | Supported✓ | Supported✓ |
| `SECOND` | Supported✓ | Supported✓ | Not supported | Not supported |
| `MINUTE` | Supported✓ | Supported✓ | Not supported | Not supported |
| `HOUR` | Supported✓ | Not supported | Not supported | Not supported |
| `DAILY` | Supported✓ | Not supported | Not supported | Not supported |

## Markets

LEAN groups all of the US Equity exchanges under `Market.USA`.

## Data Normalization

The data normalization mode defines how historical data is adjusted for [corporate actions](https://www.quantconnect.com/docs/v2/writing-algorithms/securities/asset-classes/us-equity/corporate-actions.md). By default, LEAN adjusts US Equity data for splits and dividends to produce a smooth price curve, but the following data normalization modes are available:

*Members of `QuantConnect.DataNormalizationMode` (JSON): https://www.quantconnect.com/services/inspector?type=T:QuantConnect.DataNormalizationMode&language=python*

Fields: `Raw`, `RAW`, `Adjusted`, `ADJUSTED`, `SplitAdjusted`, `SPLIT_ADJUSTED`, `TotalReturn`, `TOTAL_RETURN`, `ScaledRaw`, `SCALED_RAW`

If you use `ADJUSTED`, `SPLIT_ADJUSTED`, or `TOTAL_RETURN`, we use the entire split and dividend history to adjust historical prices. This process ensures you get the same adjusted prices, regardless of the `QuantBook` time. If you use `SCALED_RAW`, we use the split and dividend history before the `QuantBook`'s `EndDate` to adjust historical prices.

To set the data normalization mode for a security, pass a `data_normalization_mode` argument to the `add_equity` method.

```python
spy = qb.add_equity("SPY", data_normalization_mode=DataNormalizationMode.RAW).symbol
```

When you request historical data, the `history` method uses the data normalization of your security subscription. To get historical data with a different data normalization, pass a `data_normalization_mode` argument to the `history` method.

```python
history = qb.history(qb.securities.keys(), qb.time-timedelta(days=10), qb.time, dataNormalizationMode=DataNormalizationMode.SPLIT_ADJUSTED)
```

## Wrangle Data

You need some [historical data](https://www.quantconnect.com/docs/v2/research-environment/datasets/us-equity.md#04-Get-Historical-Data) to perform wrangling operations. The process to manipulate the historical data depends on its data type. To display `pandas` objects, run a cell in a notebook with the `pandas` object as the last line. To display other data formats, call the `print` method.

### DataFrame Objects

If the `history` method returns a `DataFrame`, the first level of the `DataFrame` index is the [encoded Equity Symbol](https://www.quantconnect.com/docs/v2/writing-algorithms/key-concepts/security-identifiers.md#02-Encoding-Symbols) and the second level is the `end_time` of the data sample. The columns of the `DataFrame` are the data properties.

| symbol | time | askclose | askhigh | asklow | askopen | asksize | bidclose | bidhigh | bidlow | bidopen | bidsize | close | high | low | open | volume |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| TLT SGNKIKYGE9NP | 2021-01-04 09:31:00 | 152.732434 | 152.820211 | 152.722681 | 152.820211 | 3589.0 | 152.712928 | 152.810458 | 152.712928 | 152.810458 | 718.0 | 152.732434 | 152.810458 | 152.722681 | 152.800705 | 102856.0 |
| TLT SGNKIKYGE9NP | 2021-01-04 09:32:00 | 152.703175 | 152.771446 | 152.683669 | 152.732434 | 3691.0 | 152.693422 | 152.761693 | 152.673916 | 152.712928 | 205.0 | 152.693422 | 152.771446 | 152.683669 | 152.732434 | 39834.0 |
| TLT SGNKIKYGE9NP | 2021-01-04 09:33:00 | 152.703175 | 152.751940 | 152.673916 | 152.703175 | 718.0 | 152.693422 | 152.732434 | 152.664163 | 152.693422 | 103.0 | 152.693422 | 152.732434 | 152.673916 | 152.703175 | 52457.0 |
| TLT SGNKIKYGE9NP | 2021-01-04 09:34:00 | 152.732434 | 152.751940 | 152.693422 | 152.703175 | 820.0 | 152.712928 | 152.742187 | 152.673916 | 152.693422 | 2563.0 | 152.712928 | 152.742187 | 152.683669 | 152.693422 | 64328.0 |
| TLT SGNKIKYGE9NP | 2021-01-04 09:35:00 | 152.800705 | 152.800705 | 152.712928 | 152.732434 | 615.0 | 152.781199 | 152.790952 | 152.703175 | 152.712928 | 2461.0 | 152.781199 | 152.781199 | 152.712928 | 152.722681 | 38442.0 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| SPY R735QTJ8XC9X | 2021-01-29 15:56:00 | 364.542435 | 364.630595 | 364.160408 | 364.170203 | 919.0 | 364.522844 | 364.620800 | 364.140817 | 364.150612 | 2246.0 | 364.532640 | 364.620800 | 364.160408 | 364.165306 | 1460591.0 |
| SPY R735QTJ8XC9X | 2021-01-29 15:57:00 | 364.640391 | 364.914667 | 364.464071 | 364.542435 | 715.0 | 364.630595 | 364.904872 | 364.444479 | 364.522844 | 408.0 | 364.630595 | 364.904872 | 364.464071 | 364.522844 | 1432354.0 |
| SPY R735QTJ8XC9X | 2021-01-29 15:58:00 | 363.993883 | 364.728551 | 363.866540 | 364.640391 | 102.0 | 363.984087 | 364.718756 | 363.856745 | 364.630595 | 1531.0 | 363.954701 | 364.718756 | 363.866540 | 364.630595 | 698148.0 |
| SPY R735QTJ8XC9X | 2021-01-29 15:59:00 | 363.200441 | 363.993883 | 363.151463 | 363.993883 | 306.0 | 363.190646 | 363.984087 | 363.141668 | 363.984087 | 408.0 | 363.190646 | 363.974292 | 363.141668 | 363.974292 | 2216430.0 |
| SPY R735QTJ8XC9X | 2021-01-29 16:00:00 | 362.622502 | 363.562877 | 362.387408 | 363.200441 | 7452.0 | 362.612706 | 363.553082 | 362.377613 | 363.190646 | 95553.0 | 362.504955 | 363.543286 | 362.377613 | 363.190646 | 10077306.0 |

To select the historical data of a single Equity, index the `loc` property of the `DataFrame` with the Equity `Symbol`.

```python
all_history_df.loc[spy]  # or all_history_df.loc['SPY']
```

| time | askclose | askhigh | asklow | askopen | asksize | bidclose | bidhigh | bidlow | bidopen | bidsize | close | high | low | open | volume |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 2021-01-04 09:31:00 | 367.500700 | 367.774976 | 367.451722 | 367.628042 | 102.0 | 367.481109 | 367.765180 | 367.441926 | 367.628042 | 510.0 | 367.481109 | 367.774976 | 367.451722 | 367.628042 | 929595.0 |
| 2021-01-04 09:32:00 | 367.392948 | 367.559473 | 367.383153 | 367.500700 | 1021.0 | 367.373357 | 367.539882 | 367.363562 | 367.481109 | 204.0 | 367.383153 | 367.539882 | 367.383153 | 367.481109 | 302353.0 |
| 2021-01-04 09:33:00 | 367.167650 | 367.402744 | 367.148059 | 367.392948 | 510.0 | 367.148059 | 367.383153 | 367.138263 | 367.373357 | 102.0 | 367.148059 | 367.392948 | 367.138263 | 367.383153 | 228899.0 |
| 2021-01-04 09:34:00 | 366.991330 | 367.187241 | 366.883578 | 367.167650 | 715.0 | 366.971739 | 367.177446 | 366.873783 | 367.148059 | 102.0 | 366.971739 | 367.167650 | 366.883578 | 367.148059 | 331341.0 |
| 2021-01-04 09:35:00 | 366.893374 | 367.040308 | 366.854192 | 366.991330 | 510.0 | 366.873783 | 367.030512 | 366.844396 | 366.971739 | 613.0 | 366.883578 | 367.040308 | 366.844396 | 367.010921 | 306624.0 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 2021-01-29 15:56:00 | 364.542435 | 364.630595 | 364.160408 | 364.170203 | 919.0 | 364.522844 | 364.620800 | 364.140817 | 364.150612 | 2246.0 | 364.532640 | 364.620800 | 364.160408 | 364.165306 | 1460591.0 |
| 2021-01-29 15:57:00 | 364.640391 | 364.914667 | 364.464071 | 364.542435 | 715.0 | 364.630595 | 364.904872 | 364.444479 | 364.522844 | 408.0 | 364.630595 | 364.904872 | 364.464071 | 364.522844 | 1432354.0 |
| 2021-01-29 15:58:00 | 363.993883 | 364.728551 | 363.866540 | 364.640391 | 102.0 | 363.984087 | 364.718756 | 363.856745 | 364.630595 | 1531.0 | 363.954701 | 364.718756 | 363.866540 | 364.630595 | 698148.0 |
| 2021-01-29 15:59:00 | 363.200441 | 363.993883 | 363.151463 | 363.993883 | 306.0 | 363.190646 | 363.984087 | 363.141668 | 363.984087 | 408.0 | 363.190646 | 363.974292 | 363.141668 | 363.974292 | 2216430.0 |
| 2021-01-29 16:00:00 | 362.622502 | 363.562877 | 362.387408 | 363.200441 | 7452.0 | 362.612706 | 363.553082 | 362.377613 | 363.190646 | 95553.0 | 362.504955 | 363.543286 | 362.377613 | 363.190646 | 10077306.0 |

To select a column of the `DataFrame`, index it with the column name.

```python
all_history_df.loc[spy]['close']
```

```python
time
2021-01-04 09:31:00    367.481109
2021-01-04 09:32:00    367.383153
2021-01-04 09:33:00    367.148059
2021-01-04 09:34:00    366.971739
2021-01-04 09:35:00    366.883578
                          ...
2021-01-29 15:56:00    364.532640
2021-01-29 15:57:00    364.630595
2021-01-29 15:58:00    363.954701
2021-01-29 15:59:00    363.190646
2021-01-29 16:00:00    362.504955
Name: close, dtype: float64
```

If you request historical data for multiple Equities, you can transform the `DataFrame` so that it's a time series of close values for all of the Equities. To transform the `DataFrame`, select the column you want to display for each Equity and then call the [unstack](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.unstack.html) method.

```python
all_history_df['close'].unstack(level=0)
```

The `DataFrame` is transformed so that the column indices are the `Symbol` of each Equity and each row contains the close value.

| symbol time | SPY R735QTJ8XC9X | TLT SGNKIKYGE9NP |
| --- | --- | --- |
| 2021-01-04 09:31:00 | 367.481109 | 152.732434 |
| 2021-01-04 09:32:00 | 367.383153 | 152.693422 |
| 2021-01-04 09:33:00 | 367.148059 | 152.693422 |
| 2021-01-04 09:34:00 | 366.971739 | 152.712928 |
| 2021-01-04 09:35:00 | 366.883578 | 152.781199 |
| ... | ... | ... |
| 2021-01-29 15:56:00 | 364.532640 | 148.177770 |
| 2021-01-29 15:57:00 | 364.630595 | 148.148511 |
| 2021-01-29 15:58:00 | 363.954701 | 148.294806 |
| 2021-01-29 15:59:00 | 363.190646 | 148.285053 |
| 2021-01-29 16:00:00 | 362.504955 | 148.246041 |

If you prefer to display the ticker of each `Symbol` instead of the string representation of the `SecurityIdentifier`, follow these steps:

1. Create a dictionary where the keys are the string representations of each `SecurityIdentifier` and the values are the ticker.
   ```python
   tickers_by_id = {str(x.id): x.value for x in qb.securities.keys()}
   ```
2. Get the values of the symbol level of the `DataFrame` index and create a list of tickers.
   ```python
   tickers = set([tickers_by_id[x] for x in all_history_df.index.get_level_values('symbol')])
   ```
3. Set the values of the symbol level of the `DataFrame` index to the list of tickers.
   ```python
   all_history_df.index.set_levels(tickers, 'symbol', inplace=True)
   ```

The new `DataFrame` is keyed by the ticker.

```python
all_history_df.loc[spy.value]  # or all_history_df.loc["SPY"]
```

After the index renaming, the unstacked `DataFrame` has the following format:

| symbol time | SPY | TLT |
| --- | --- | --- |
| 2021-01-04 09:31:00 | 367.481109 | 152.732434 |
| 2021-01-04 09:32:00 | 367.383153 | 152.693422 |
| 2021-01-04 09:33:00 | 367.148059 | 152.693422 |
| 2021-01-04 09:34:00 | 366.971739 | 152.712928 |
| 2021-01-04 09:35:00 | 366.883578 | 152.781199 |
| ... | ... | ... |
| 2021-01-29 15:56:00 | 364.532640 | 148.177770 |
| 2021-01-29 15:57:00 | 364.630595 | 148.148511 |
| 2021-01-29 15:58:00 | 363.954701 | 148.294806 |
| 2021-01-29 15:59:00 | 363.190646 | 148.285053 |
| 2021-01-29 16:00:00 | 362.504955 | 148.246041 |

### Slice Objects

If the `history` method returns `Slice` objects, iterate through the `Slice` objects to get each one. The `Slice` objects may not have data for all of your Equity subscriptions. To avoid issues, check if the `Slice` contains data for your Equity before you index it with the Equity `Symbol`.

```python
for slice in all_history_slice:
        if slice.bars.contains_key(spy):
        trade_bar = slice.bars[spy]
    if slice.quote_bars.contains_key(spy):
        quote_bar = slice.quote_bars[spy]
```

You can also iterate through each `TradeBar` and `QuoteBar` in the `Slice`.

```python
for slice in all_history_slice:
    for kvp in slice.bars:
        symbol = kvp.key
        trade_bar = kvp.value
    for kvp in slice.quote_bars:
        symbol = kvp.key
        quote_bar = kvp.value
```

### TradeBar Objects

If the `history` method returns `TradeBar` objects, iterate through the `TradeBar` objects to get each one.

```python
for trade_bar in single_history_trade_bars:
    print(trade_bar)
```

If the `history` method returns `TradeBars`, iterate through the `TradeBars` to get the `TradeBar` of each Equity. The `TradeBars` may not have data for all of your Equity subscriptions. To avoid issues, check if the `TradeBars` object contains data for your security before you index it with the Equity `Symbol`.

```python
for trade_bars in all_history_trade_bars:
    if trade_bars.contains_key(spy):
        trade_bar = trade_bars[spy]
```

You can also iterate through each of the `TradeBars`.

```python
for trade_bars in all_history_trade_bars:
    for kvp in trade_bars:
        symbol = kvp.key
        trade_bar = kvp.value
```

### QuoteBar Objects

If the `history` method returns `QuoteBar` objects, iterate through the `QuoteBar` objects to get each one.

```python
for quote_bar in single_history_quote_bars:
    print(quote_bar)
```

If the `history` method returns `QuoteBars`, iterate through the `QuoteBars` to get the `QuoteBar` of each Equity. The `QuoteBars` may not have data for all of your Equity subscriptions. To avoid issues, check if the `QuoteBars` object contains data for your security before you index it with the Equity `Symbol`.

```python
for quote_bars in all_history_quote_bars:
    if quote_bars.contains_key(spy):
        quote_bar = quote_bars[spy]
```

You can also iterate through each of the `QuoteBars`.

```python
for quote_bars in all_history_quote_bars:
    for kvp in quote_bars:
        symbol = kvp.key
        quote_bar = kvp.value
```

### Tick Objects

If the `history` method returns `TICK` objects, iterate through the `TICK` objects to get each one.

```python
for tick in single_history_ticks:
    print(tick)
```

If the `history` method returns `Ticks`, iterate through the `Ticks` to get the `TICK` of each Equity. The `Ticks` may not have data for all of your Equity subscriptions. To avoid issues, check if the `Ticks` object contains data for your security before you index it with the Equity `Symbol`.

```python
for ticks in all_history_ticks:
    if ticks.contains_key(spy):
        ticks = ticks[spy]
```

You can also iterate through each of the `Ticks`.

```python
for ticks in all_history_ticks:
    for kvp in ticks:
        symbol = kvp.key
        tick = kvp.value
```

The `Ticks` objects only contain the last tick of each security for that particular [timeslice](https://www.quantconnect.com/docs/v2/writing-algorithms/key-concepts/time-modeling/timeslices.md)

## Plot Data

You need some [historical Equity data](https://www.quantconnect.com/docs/v2/research-environment/datasets/us-equity.md#04-Get-Historical-Data) to produce plots. You can use many of the [supported plotting libraries](https://www.quantconnect.com/docs/v2/research-environment/charting.md) to visualize data in various formats. For example, you can plot candlestick and line charts.

### Candlestick Chart

Follow these steps to plot candlestick charts:

1. Get some [historical data](https://www.quantconnect.com/docs/v2/research-environment/datasets/us-equity.md#04-Get-Historical-Data).
   ```python
   history = qb.history(spy, datetime(2021, 11, 23), datetime(2021, 12, 8), Resolution.DAILY).loc[spy]
   ```
2. Import the `plotly` library.
   ```python
   import plotly.graph_objects as go
   ```
3. Create a `Candlestick` chart.
   ```python
   candlestick = go.Candlestick(x=history.index,
                                open=history['open'],
                                high=history['high'],
                                low=history['low'],
                                close=history['close'])
   ```
4. Create a `Layout`.
   ```python
   layout = go.Layout(title=go.layout.Title(text='SPY OHLC'),
                      xaxis_title='Date',
                      yaxis_title='Price',
                      xaxis_rangeslider_visible=False)
   ```
5. Create the `Figure`.
   ```python
   fig = go.Figure(data=[candlestick], layout=layout)
   ```
6. Show the plot.
   ```python
   fig.show()
   ```
   Candlestick charts display the open, high, low, and close prices of the security.

![Candlestick plot of SPY OHLC](https://cdn.quantconnect.com/i/tu/reserachhistoryequityonesecuritycandlestickplot.png)

### Line Chart

Follow these steps to plot line charts using built-in methods:

1. Get some historical data.
   ```python
   history = qb.history([spy, tlt], datetime(2021, 11, 23), datetime(2021, 12, 8), Resolution.DAILY)
   ```
2. Select the data to plot.
   ```python
   volume = history['volume'].unstack(level=0)
   ```
3. Call the `plot` method on the `pandas` object.
   ```python
   volume.plot(title="Volume", figsize=(15, 10))
   ```
4. Show the plot.
   ```python
   plt.show()
   ```
   Line charts display the value of the property you selected in a time series.

![](https://cdn.quantconnect.com/i/tu/research-env-plot-equity-data.jpg)

## Common Errors

Some factor files have INF split values, which indicate that the stock has so many splits that prices can't be calculated with correct numerical precision. To allow history requests with these symbols, we need to move the starting date forward when reading the data or use raw [data normalization](https://www.quantconnect.com/docs/v2/writing-algorithms/securities/asset-classes/us-equity/requesting-data.md#11-Data-Normalization). If there are numerical precision errors in the factor files for a security in your history request, LEAN throws the following error:

`"Warning: when performing history requests, the start date will be adjusted if there are numerical precision errors in the factor files."`

## Examples

The following examples demonstrate some common practices for applying the US Equity dataset.

### Example 1: 5-Minute Candlestick Plot

The following example studies the candlestick pattern of the SPY. To study the short term pattern, we consolidate the data into 5 minute bars and plot the 5-minute candlestick plot.

```python
# Import plotly library for plotting.
import plotly.graph_objects as go

# Create a QuantBook
qb = QuantBook()

# Request SPY's historical data.
spy = qb.add_equity("SPY")
history = qb.history(spy.symbol,
    start=qb.time - timedelta(days=182),
    end=qb.time,
    resolution=Resolution.MINUTE)

# Drop level 0 index (Symbol index) from the DataFrame
history = history.droplevel([0])

# Select the required columns to obtain the 5-minute OHLC data.
history = history[["open", "high", "low", "close"]].resample("5T").agg({
    "open": "first",
    "high": "max",
    "low": "min",
    "close": "last"
})

# Crete the Candlestick chart using the 5-minute windows.
candlestick = go.Candlestick(x=history.index,
                             open=history['open'],
                             high=history['high'],
                             low=history['low'],
                             close=history['close'])
# Create a Layout as the plot settings.
layout = go.Layout(title=go.layout.Title(text=f'{spy.symbol} OHLC'),
                   xaxis_title='Date',
                   yaxis_title='Price',
                   xaxis_rangeslider_visible=False)
# Create the Figure.
fig = go.Figure(data=[candlestick], layout=layout)
# Display the plot.
fig.show()
```
