---
title: "Alternative Data"
description: "Learn how to request and handle alternative data in the research environment in QuantConnect"
canonical: https://www.quantconnect.com/docs/v2/research-environment/datasets/alternative-data
markdown: https://www.quantconnect.com/docs/v2/research-environment/datasets/alternative-data.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/04%20Research%20Environment/03%20Datasets/24%20Alternative%20Data
modified: 2026-10-29
index: https://www.quantconnect.com/llms.txt
---

# Alternative Data

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

> 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 alternative data. This tutorial uses the [VIX Daily Price](https://www.quantconnect.com/datasets/cboe-vix-daily) dataset from the CBOE as the example dataset.

## Create Subscriptions

Follow these steps to subscribe to an alternative dataset from the [Dataset Market](https://www.quantconnect.com/datasets):

1. Create a `QuantBook`.
   ```python
   qb = QuantBook()
   ```
2. Call the `add_data` method with the dataset class, a ticker, and a resolution and then save a reference to the alternative data `Symbol`.
   ```python
   vix = qb.add_data(CBOE, "VIX", Resolution.DAILY).symbol
   v3m = qb.add_data(CBOE, "VIX3M", Resolution.DAILY).symbol
   ```
   To view the arguments that the `add_data` method accepts for each dataset, see the [dataset listing](https://www.quantconnect.com/datasets).
   If you don't pass a resolution argument, the default resolution of the dataset is used by default. To view the supported resolutions and the default resolution of each dataset, see the [dataset listing](https://www.quantconnect.com/datasets).

## Get Historical Data

You need a [subscription](https://www.quantconnect.com/docs/v2/research-environment/datasets/alternative-data.md#03-Create-Subscriptions) before you can request historical data for a dataset. 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 dataset dimension, you can request historical data for a single dataset subscription, a subset of the dataset subscriptions you created in your notebook, or all of the dataset subscriptions 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
single_history_df = qb.history(vix, 10)
subset_history_df = qb.history([vix, v3m], 10)
all_history_df = qb.history(qb.securities.keys(), 10)

# Slice objects
all_history_slice = qb.history(10)

# CBOE objects
single_history_data_objects = qb.history[CBOE](vix, 10)
subset_history_data_objects = qb.history[CBOE]([vix, v3m], 10)all_history_data_objects = qb.history[CBOE](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
single_history_df = qb.history(vix, timedelta(days=3))
subset_history_df = qb.history([vix, v3m], timedelta(days=3))
all_history_df = qb.history(qb.securities.keys(), timedelta(days=3))

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

# CBOE objects
single_history_data_objects = qb.history[CBOE](vix, timedelta(days=3))subset_history_data_objects = qb.history[CBOE]([vix, v3m], timedelta(days=3))all_history_data_objects = qb.history[CBOE](qb.securities.keys(), timedelta(days=3))
```

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, 3, 1)

# DataFrame
single_history_df = qb.history(vix, start_time, end_time)
subset_history_df = qb.history([vix, v3m], start_time, end_time)
all_history_df = qb.history(qb.securities.keys(), start_time, end_time)

# Slice objects
all_history_slice = qb.history(start_time, end_time)

# CBOE objects
single_history_data_objects = qb.history[CBOE](vix, start_time, end_time)subset_history_data_objects = qb.history[CBOE]([vix, v3m], start_time, end_time)all_history_data_objects = qb.history[CBOE](qb.securities.keys(), start_time, end_time)
```

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

If you do not pass a resolution to the `history` method, the `history` method uses the resolution that the `add_data` method used when you created the [subscription](https://www.quantconnect.com/docs/v2/research-environment/datasets/alternative-data.md#03-Create-Subscriptions).

## Wrangle Data

You need some [historical data](https://www.quantconnect.com/docs/v2/research-environment/datasets/alternative-data.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 dataset 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 | close | datasourceid | high | low | open | value |
| --- | --- | --- | --- | --- | --- | --- | --- |
| VIX3M.CBOE 2S | 2021-01-05 | 28.26 | 2001 | 29.23 | 25.32 | 25.32 | 28.26 |
| VIX3M.CBOE 2S | 2021-01-06 | 27.25 | 2001 | 28.73 | 26.68 | 28.64 | 27.25 |
| VIX3M.CBOE 2S | 2021-01-07 | 26.79 | 2001 | 27.67 | 25.15 | 26.73 | 26.79 |
| VIX3M.CBOE 2S | 2021-01-08 | 25.02 | 2001 | 25.65 | 25.02 | 25.46 | 25.02 |
| VIX3M.CBOE 2S | 2021-01-09 | 24.90 | 2001 | 25.98 | 24.66 | 24.98 | 24.90 |
| ... | ... | ... | ... | ... | ... | ... | ... |
| VIX.CBOE 2S | 2021-02-23 | 23.45 | 2001 | 25.09 | 21.96 | 24.46 | 23.45 |
| VIX.CBOE 2S | 2021-02-24 | 23.11 | 2001 | 27.01 | 22.50 | 22.82 | 23.11 |
| VIX.CBOE 2S | 2021-02-25 | 21.34 | 2001 | 25.04 | 21.31 | 23.76 | 21.34 |
| VIX.CBOE 2S | 2021-02-26 | 28.89 | 2001 | 31.16 | 21.52 | 21.73 | 28.89 |
| VIX.CBOE 2S | 2021-02-27 | 27.95 | 2001 | 30.82 | 25.23 | 28.73 | 27.95 |

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

```python
all_history_df.loc[vix]  # or all_history_df.loc['VIX']
```

| time | close | datasourceid | high | low | open | value |
| --- | --- | --- | --- | --- | --- | --- |
| 2021-01-05 | 22.75 | 2001 | 25.09 | 22.47 | 23.31 | 22.75 |
| 2021-01-06 | 24.09 | 2001 | 27.63 | 22.43 | 22.64 | 24.09 |
| 2021-01-07 | 22.95 | 2001 | 24.47 | 22.27 | 23.57 | 22.95 |
| 2021-01-08 | 21.57 | 2001 | 23.05 | 21.47 | 22.93 | 21.57 |
| 2021-01-09 | 21.27 | 2001 | 22.73 | 21.16 | 21.65 | 21.27 |
| ... | ... | ... | ... | ... | ... | ... |
| 2021-02-23 | 23.45 | 2001 | 25.09 | 21.96 | 24.46 | 23.45 |
| 2021-02-24 | 23.11 | 2001 | 27.01 | 22.50 | 22.82 | 23.11 |
| 2021-02-25 | 21.34 | 2001 | 25.04 | 21.31 | 23.76 | 21.34 |
| 2021-02-26 | 28.89 | 2001 | 31.16 | 21.52 | 21.73 | 28.89 |
| 2021-02-27 | 27.95 | 2001 | 30.82 | 25.23 | 28.73 | 27.95 |

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

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

```python
time
2021-01-05    22.75
2021-01-06    24.09
2021-01-07    22.95
2021-01-08    21.57
2021-01-09    21.27
              ...
2021-02-23    23.45
2021-02-24    23.11
2021-02-25    21.34
2021-02-26    28.89
2021-02-27    27.95
Name: close, dtype: float64
```

If you request historical data for multiple tickers, you can transform the `DataFrame` so that it's a time series of close values for all of the tickers. To transform the `DataFrame`, select the column you want to display for each ticker 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 ticker and each row contains the close value.

| symbol time | VIX.CBOE 2S | VIX3M.CBOE 2S |
| --- | --- | --- |
| 2021-01-05 | 22.75 | 28.26 |
| 2021-01-06 | 24.09 | 27.25 |
| 2021-01-07 | 22.95 | 26.79 |
| 2021-01-08 | 21.57 | 25.02 |
| 2021-01-09 | 21.27 | 24.90 |
| ... | ... | ... |
| 2021-02-23 | 23.45 | 24.56 |
| 2021-02-24 | 23.11 | 24.23 |
| 2021-02-25 | 21.34 | 23.87 |
| 2021-02-26 | 28.89 | 28.45 |
| 2021-02-27 | 27.95 | 27.30 |

### 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 dataset subscriptions. To avoid issues, check if the `Slice` contains data for your ticker before you index it with the dataset `Symbol`.

```python
for slice in all_history_slice:
        if slice.contains_key(vix):
        data = slice[vix]
```

## Plot Data

You need some [historical alternative data](https://www.quantconnect.com/docs/v2/research-environment/datasets/alternative-data.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

You can only create candlestick charts for alternative datasets that have open, high, low, and close properties.

Follow these steps to plot candlestick charts:

1. Get some [historical data](https://www.quantconnect.com/docs/v2/research-environment/datasets/alternative-data.md#04-Get-Historical-Data).
   ```python
   history = qb.history(vix, datetime(2021, 1, 1), datetime(2021, 2, 1)).loc[vix]
   ```
2. Import the `plotly` library.
   ```python
   import plotly.graph_objects as go
   ```
3. Create a `Candlestick`.
   ```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='VIX from CBOE OHLC'),
                      xaxis_title='Date',
                      yaxis_title='Price',
                      xaxis_rangeslider_visible=False)
   ```
5. Create a `Figure`.
   ```python
   fig = go.Figure(data=[candlestick], layout=layout)
   ```
6. Show the `Figure`.
   ```python
   fig.show()
   ```
   Candlestick charts display the open, high, low, and close prices of the alternative data.

![Candlestick plot of VIX from CBOE dataset OHLC](https://cdn.quantconnect.com/i/tu/research-history-alternative-onesecurity-candlestickplot.png)

### Line Chart

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

1. Get some historical data.
   ```python
   history = qb.history([vix, v3m], datetime(2021, 1, 1), datetime(2021, 2, 1))
   ```
2. Select the data to plot.
   ```python
   values = history['close'].unstack(0)
   ```
3. Call the `plot` method on the `pandas` object.
   ```python
   values.plot(title = 'Close', figsize=(15, 10))
   ```
4. Show the plot.
   ```python
   plt.show()
   ```
   Line charts display the value of the property you selected in a time series.

![Line chart of VIX closes from CBOE dataset](https://cdn.quantconnect.com/i/tu/research-env-alt-data-vix-plot.jpg)

## Examples

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

### Example 1: PE Ratio Line Chart

The following example studies the trend of 10-year yield curve using a line chart.

```python
# Create a QuantBook
qb = QuantBook()

# Request 10-year US Yield Curve historical data.
symbol = qb.add_data(USTreasuryYieldCurveRate, "USTYCR").symbol
history = qb.history(
    USTreasuryYieldCurveRate,
    symbol,
    start=qb.time - timedelta(days=365),
    end=qb.time,
    resolution=Resolution.DAILY,
    flatten=True
)

# Select the 10-year US Yield Rate to study.
pe_ratio = history.droplevel([0]).tenyear
# Plot the 10-year US Yield Rate line chart.
pe_ratio.plot(title=f"10-year US Yield Rate by Time of {symbol}", ylabel="Yield Rate")
```
