---
title: "CNBC Trading"
description: "CNBC Trading dataset from Quiver Quantitative."
canonical: https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quiver-quantitative/cnbc-trading
markdown: https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quiver-quantitative/cnbc-trading.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/03%20Writing%20Algorithms/14%20Datasets/23%20Quiver%20Quantitative/01%20CNBC%20Trading
modified: 2026-10-30
index: https://www.quantconnect.com/llms.txt
---

# CNBC Trading

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Writing Algorithms](https://www.quantconnect.com/docs/v2/writing-algorithms.md) > Datasets > [Quiver Quantitative](https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quiver-quantitative.md) > CNBC Trading

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

## Introduction

The CNBC Trading dataset by Quiver Quantitative tracks the recommendations made by media personalities on CNBC and their historical performance. The data covers over 1,500 US Equities, starts in December 2020, and is delivered on a daily frequency. This dataset covers recommendations made on Mad Money, Halftime Report, and Fast Money.

This dataset depends on the [US Equity Security Master](https://www.quantconnect.com/datasets/quantconnect-us-equity-security-master) dataset because the US Equity Security Master dataset contains information on splits, dividends, and symbol changes.

For more information about the CNBC Trading dataset, including CLI commands and pricing, see the [dataset listing](https://www.quantconnect.com/datasets/quiver-quantitative-cnbc-trading).

## About the Provider

[Quiver Quantitative](https://www.quiverquant.com/) was founded by two college students in February 2020 with the goal of bridging the information gap between Wall Street and non-professional investors. Quiver allows retail investors to tap into the power of big data and have access to actionable, easy to interpret data that hasn’t already been dissected by Wall Street.

## Getting Started

The following snippet demonstrates how to request data from the CNBC Trading dataset:

```python
self.aapl = self.add_equity("AAPL", Resolution.DAILY).symbol
self.dataset_symbol = self.add_data(QuiverCNBCs, self.aapl).symbol

self._universe = self.add_universe(QuiverCNBCsUniverse, self.universe_selection)
```

## Data Summary

The following table describes the dataset properties:

| Property | Value |
| --- | --- |
| Start Date | December 25, 2020 |
| Asset Coverage | 1,515 US Equities |
| Data Density | Sparse |
| Resolution | Daily |
| Timezone | UTC |

## Requesting Data

To add CNBC Trading data to your algorithm, call the `add_data` method. Save a reference to the dataset `Symbol` so you can access the data later in your algorithm.

```python
class QuiverCNBCDataAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self.set_start_date(2019, 1, 1)
        self.set_end_date(2020, 6, 1)
        self.set_cash(100000)

        self.aapl = self.add_equity("AAPL", Resolution.DAILY).symbol
        self.dataset_symbol = self.add_data(QuiverCNBCs, self.aapl).symbol
```

## Accessing Data

To get the current CNBC Trading data, index the current [`Slice`](https://www.quantconnect.com/docs/v2/writing-algorithms/key-concepts/time-modeling/timeslices.md) with the dataset `Symbol`. `Slice` objects deliver unique events to your algorithm as they happen, but the `Slice` may not contain data for your dataset at every time step. To avoid issues, check if the `Slice` contains the data you want before you index it.

```python
def on_data(self, slice: Slice) -> None:
    if slice.contains_key(self.dataset_symbol):
        data_points = slice[self.dataset_symbol]
        for data_point in data_points:
            self.log(f"{self.dataset_symbol} direction at {slice.time}: {data_point.direction}")
```

To iterate through all of the dataset objects in the current `Slice`, call the `get` method.

```python
def on_data(self, slice: Slice) -> None:
    for dataset_symbol, data_points in slice.get(QuiverCNBCs).items():
        for data_point in data_points:
            self.log(f"{dataset_symbol} direction at {slice.time}: {data_point.direction}")
```

## Historical Data

To get historical CNBC Trading data, call the `history` method with the dataset `Symbol`. If there is no data in the period you request, the history result is empty.

```python
# DataFrame
history_df = self.history(self.dataset_symbol, 100, Resolution.DAILY)

# Dataset objects
history_bars = self.history[QuiverCNBCs](self.dataset_symbol, 100, Resolution.DAILY)
```

For more information about historical data, see [History Requests](https://www.quantconnect.com/docs/v2/writing-algorithms/historical-data/history-requests.md).

## Universe Selection

To select a dynamic universe of US Equities based on CNBC Trading data, call the `add_universe` method with the `QuiverCNBCsUniverse` class and a selection function.

```python
def initialize(self):
    self._uinverse = self.add_universe(QuiverCNBCsUniverse, self.universe_selection)

def universe_selection(self, alt_coarse: List[QuiverCNBCsUniverse]) -> List[Symbol]:
    cnbc_data_by_symbol = {}

    for datum in alt_coarse:
        symbol = datum.symbol

        if symbol not in cnbc_data_by_symbol:
            cnbc_data_by_symbol[symbol] = []
        cnbc_data_by_symbol[symbol].append(datum)

    # define our selection criteria
    return [symbol for symbol, d in cnbc_data_by_symbol.items()
            if len([x for x in d if x.direction == OrderDirection.BUY]) >= 3]
```

## Universe History

You can get historical universe data in an algorithm and in the Research Environment.

### Historical Universe Data in Algorithms

To get historical universe data in an algorithm, call the `history` method with the `Universe` object and the lookback period. If there is no data in the period you request, the history result is empty.

```python
# DataFrame example where the columns are the QuiverCNBCsUniverse attributes:
history_df = self.history(self._universe, 30, Resolution.DAILY, flatten=True)

# Series example where the values are lists of QuiverCNBCsUniverse objects:
universe_history = self.history(self._universe, 30, Resolution.DAILY)
for (_, time), cbncs in universe_history.items():
    for cbnc in cbncs:
        self.log(f"{cbnc.symbol} traders at {cbnc.end_time}: {cbnc.traders}")
```

### Historical Universe Data in Research

To get historical universe data in research, call the `universe_history` method with the `Universe` object, a start date, and an end date. This method returns the filtered universe. If there is no data in the period you request, the history result is empty.

```python
# DataFrame example where the columns are the QuiverCNBCsUniverse attributes:
history_df = qb.universe_history(universe, qb.time-timedelta(30), qb.time, flatten=True)

# Series example where the values are lists of QuiverCNBCsUniverse objects:
universe_history = qb.universe_history(universe, qb.time-timedelta(30), qb.time)
for (_, time), cbncs in universe_history.items():
    for cbnc in cbncs:
        print(f"{cbnc.symbol} traders at {cbnc.end_time}: {cbnc.traders}")
```

You can call the `history` method in Research.

## Remove Subscriptions

To remove a subscription, call the `remove_security` method.

```python
self.remove_security(self.dataset_symbol)
```

If you subscribe to CNBC Trading data for assets in a dynamic universe, remove the dataset subscription when the asset leaves your universe. To view a common design pattern, see [Track Security Changes](https://www.quantconnect.com/docs/v2/writing-algorithms/algorithm-framework/alpha/key-concepts.md#05-Track-Security-Changes).

## Example Applications

The Quiver Quantitative CNBC Trading dataset enables you to create strategies using the latest recommendations made by media personalities on CNBC. Examples include the following strategies:

- Taking short positions in securities that were mentioned by Jim Cramer (CNBC commentator) in the last week
- Trading securities that were most/least discussed across CNBC programs over the last year

### Classic Algorithm Example

The following example algorithm buys Apple stock if the net recommendation of media personalities on CNBC for Apple is positive. Otherwise, it holds cash.

```python
from AlgorithmImports import *

class QuiverCNBCsAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        self._equity = self.add_equity("AAPL", Resolution.DAILY)
        # Subscribe to CNBC data for AAPL to generate the trade signal.
        self._dataset_symbol = self.add_data(QuiverCNBCs, self._equity).symbol
        # Normalize order directions into numeric signals.
        self._int_by_direction = {
            OrderDirection.BUY: 1,
            OrderDirection.HOLD: 0,
            OrderDirection.SELL: -1
        }
        # Historical data
        history = self.history(self._dataset_symbol, 10, Resolution.DAILY)
        self.debug(f"We got {len(history)} items from historical data request of {self._dataset_symbol}.")

    def on_data(self, data: Slice) -> None:
        for cnbcs in data.get(QuiverCNBCs).values():
            # Use the mean CNBC analyst prediction as the trade signal.
            # Invest in AAPL when the average CNBC insight is positive.
            if np.mean([self._int_by_direction[cnbc.direction] for cnbc in cnbcs]) > 0:
                self.set_holdings(self._equity, 1)
            else:
                self.set_holdings(self._equity, 0)
```

### Framework Algorithm Example

The following example algorithm creates a dynamic universe of US Equities that have at least 3 positive opinions from CNBC sources. Each day, it then forms a equal-weighted portfolio with all the securities in the universe.

```python
from AlgorithmImports import *

class QuiverCNBCsDataAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        self.set_cash(100000)

        self.dataset_symbol_by_symbol = {}
        # Filter universe based on CNBC data
        self.add_universe(QuiverCNBCsUniverse, self.universe_selection)

        self.add_alpha(ConstantAlphaModel(InsightType.PRICE, InsightDirection.UP, timedelta(1)))

        # Invest equally to evenly dissipate the capital concentration risk
        self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel())

    def universe_selection(self, data: List[QuiverCNBCsUniverse]) -> List[Symbol]:
        cnbc_data_by_symbol = {}

        for datum in data:
            symbol = datum.symbol

            if symbol not in cnbc_data_by_symbol:
                cnbc_data_by_symbol[symbol] = []
            cnbc_data_by_symbol[symbol].append(datum)

        # Select the stocks with at least 3 CNBC analysts to suggest buy, reassuring the signal
        return [symbol for symbol, d in cnbc_data_by_symbol.items()
                if len([x for x in d if x.direction == OrderDirection.BUY]) >= 3]

    def on_securities_changed(self, changes: SecurityChanges) -> None:
        for security in changes.added_securities:
            # Requesting CNBC Data
            symbol = security.symbol
            dataset_symbol = self.add_data(QuiverCNBCs, symbol).symbol
            self.dataset_symbol_by_symbol[symbol] = dataset_symbol

            # Historical Data
            history = self.history(dataset_symbol, 10, Resolution.DAILY)
            self.debug(f"We got {len(history)} items from our history request on {dataset_symbol}.")

        for security in changes.removed_securities:
            dataset_symbol = self.dataset_symbol_by_symbol.pop(security.symbol, None)
            if dataset_symbol:
                # Remove subscription of CNBC data to release computation resources
                self.remove_security(dataset_symbol)
```

### Research Example

The following example lists US Equities mentioned by Jim Cramer.

```python
qb = QuantBook()

# Requesting Data
aapl = qb.add_equity("AAPL", Resolution.DAILY).symbol
symbol = qb.add_data(QuiverCNBCs, aapl).symbol

# Historical data
history = qb.history(QuiverCNBCs, symbol, 60, Resolution.DAILY)
for (symbol, time), cbncs in history.items():
    for cbnc in cbncs:
        print(f"{cbnc.symbol} traders at {cbnc.end_time}: {cbnc.traders}")

# Add Universe Selection
def universe_selection(alt_coarse: List[QuiverCNBCsUniverse]) -> List[Symbol]:
    return [d.symbol for d in alt_coarse if 'Cramer' in d.traders]

universe = qb.add_universe(QuiverCNBCsUniverse, universe_selection)

# Historical Universe data
universe_history = qb.universe_history(universe, qb.time-timedelta(60), qb.time)
for (_, time), cbncs in universe_history.items():
    for cbnc in cbncs:
        print(f"{cbnc.symbol} traders at {cbnc.end_time}: {cbnc.traders}")
```

## Data Point Attributes

The Quiver Quantitative CNBC Trading dataset provides `QuiverCNBCs`, `QuiverCNBC`, and `QuiverCNBCsUniverse` objects.

### QuiverCNBCs

`QuiverCNBCs` objects have the following attributes:

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

### QuiverCNBC

`QuiverCNBC` objects have the following attributes:

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

### QuiverCNBCsUniverse

`QuiverCNBCsUniverse` objects have the following attributes:

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