Quiver Quantitative
CNBC Trading
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 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.
About the Provider
Quiver Quantitative 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:
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)
_symbol = AddEquity("AAPL", Resolution.Daily).Symbol; _datasetSymbol = AddData<QuiverCNBCs>(_symbol).Symbol; _universe = AddUniverse<QuiverCNBCsUniverse>(UniverseSelection);
Requesting Data
To add CNBC Trading data to your algorithm, call the AddData
add_data
method. Save a reference to the dataset Symbol
so you can access the data later in your algorithm.
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
public class QuiverCNBCDataAlgorithm: QCAlgorithm { private Symbol _symbol, _datasetSymbol; public override void Initialize() { SetStartDate(2019, 1, 1); SetEndDate(2020, 6, 1); SetCash(100000); _symbol = AddEquity("AAPL", Resolution.Daily).Symbol; _datasetSymbol= AddData<QuiverCNBCs>(_symbol).Symbol; } }
Accessing Data
To get the current CNBC Trading data, index the current Slice
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.
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}")
public override void OnData(Slice slice) { if (slice.ContainsKey(_datasetSymbol)) { var dataPoints = slice[_datasetSymbol]; foreach (var dataPoint in dataPoints) { Log($"{_datasetSymbol} direction at {slice.Time}: {dataPoint.Direction}"); } } }
To iterate through all of the dataset objects in the current Slice
, call the Get
get
method.
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}")
public override void OnData(Slice slice) { foreach (var kvp in slice.Get<QuiverCNBCs>()) { var datasetSymbol = kvp.Key; var dataPoints = kvp.Value; foreach(var dataPoint in dataPoints) { Log($"{datasetSymbol} direction at {slice.Time}: {dataPoint.Direction}"); } } }
Historical Data
To get historical CNBC Trading data, call the History
history
method with the dataset Symbol
. If there is no data in the period you request, the history result is empty.
# DataFrame history_df = self.history(self.dataset_symbol, 100, Resolution.DAILY) # Dataset objects history_bars = self.history[QuiverCNBCs](self.dataset_symbol, 100, Resolution.DAILY)
var history = History<QuiverCNBCs>(_datasetSymbol, 100, Resolution.Daily);
For more information about historical data, see History Requests.
Universe Selection
To select a dynamic universe of US Equities based on CNBC Trading data, call the AddUniverse
add_universe
method with the QuiverCNBCsUniverse
class and a selection function.
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]
private Universe _universe; public override void Initialize() { _universe = AddUniverse<QuiverCNBCsUniverse>(altCoarse => { var cnbcDataBySymbol = new Dictionary<Symbol, List<QuiverCNBCsUniverse>>(); foreach (var datum in altCoarse.OfType<QuiverCNBCsUniverse>()) { var symbol = datum.Symbol; if (!cnbcDataBySymbol.ContainsKey(symbol)) { cnbcDataBySymbol.Add(symbol, new List<QuiverCNBCsUniverse>()); } cnbcDataBySymbol[symbol].Add(datum); } // define our selection criteria return from kvp in cnbcDataBySymbol where kvp.Value.Where(x => x.Direction == OrderDirection.Buy) >= 3 select kvp.Key; }); }
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
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.
var universeHistory = History(universe, 30, Resolution.Daily); foreach (var cnbcs in universeHistory) { foreach (QuiverCNBCsUniverse cnbc in cnbcs) { Log($"{cnbc.Symbol} traders at {cnbc.EndTime}: {cnbc.Traders}"); } }
# 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 UniverseHistory
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.
var universeHistory = qb.UniverseHistory(universe, qb.Time.AddDays(-30), qb.Time); foreach (var cnbcs in universeHistory) { foreach (QuiverCNBCsUniverse cnbc in cnbcs) { Console.WriteLine($"{cnbc.Symbol} traders at {cnbc.EndTime}: {cnbc.Traders}"); } }
# 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
history
method in Research.
Remove Subscriptions
To remove a subscription, call the RemoveSecurity
remove_security
method.
self.remove_security(self.dataset_symbol)
RemoveSecurity(_datasetSymbol);
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.
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.
from AlgorithmImports import * from QuantConnect.DataSource import * class QuiverCNBCsAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2021, 10, 1) #Set Start Date self.set_end_date(2021, 10, 31) #Set End Date self.aapl = self.add_equity("AAPL", Resolution.DAILY).symbol # Subscribe to CNBC data for AAPL to generate trade signal self.dataset_symbol = self.add_data(QuiverCNBCs, self.aapl).symbol # history request 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, slice: Slice) -> None: for cnbcs in slice.Get(QuiverCNBCs).values(): # Using mean prediction from CNBC analysts to be the trade signal # If the average CNBC insight is upward movement, invest AAPL if np.mean([cnbc.direction for cnbc in cnbcs]) > 0: self.set_holdings(self.aapl, 1) else: self.set_holdings(self.aapl, 0)
public class QuiverCNBCsAlgorithm : QCAlgorithm { private Symbol _symbol, _datasetSymbol; public override void Initialize() { SetStartDate(2021, 10, 1); //Set Start Date SetEndDate(2021, 10, 31); //Set End Date _symbol = AddEquity("AAPL").Symbol; // Subscribe to CNBC data for AAPL to generate trade signal _datasetSymbol = AddData<QuiverCNBCs>(_symbol).Symbol; // history request var history = History<QuiverCNBCs>(new[] {_datasetSymbol}, 10, Resolution.Daily); Debug($"We got {history.Count()} items from historical data request of {_datasetSymbol}."); } public override void OnData(Slice slice) { foreach (var kvp in slice.Get<QuiverCNBCs>()) { // Using mean prediction from CNBC analysts to be the trade signal // If the average CNBC insight is upward movement, invest AAPL if (kvp.Value.Average(x => (int) (x as QuiverCNBC).Direction) > 0) { SetHoldings(_symbol, 1); } else { SetHoldings(_symbol, 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.
from AlgorithmImports import * from QuantConnect.DataSource import * class QuiverCNBCsDataAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2021, 1, 1) self.set_end_date(2021, 6, 1) 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)
public class QuiverCNBCsDataAlgorithm : QCAlgorithm { private Dictionary<Symbol, Symbol> _datasetSymbolBySymbol = new(); public override void Initialize() { SetStartDate(2021, 1, 1); SetEndDate(2021, 6, 1); SetCash(100000); // Filter universe based on CNBC data AddUniverse<QuiverCNBCsUniverse>(data => { var cnbcDataBySymbol = new Dictionary<Symbol, List<QuiverCNBCsUniverse>>(); foreach (var datum in data.OfType<QuiverCNBCsUniverse>()) { var symbol = datum.Symbol; if (!cnbcDataBySymbol.ContainsKey(symbol)) { cnbcDataBySymbol.Add(symbol, new List<QuiverCNBCsUniverse>()); } cnbcDataBySymbol[symbol].Add(datum); } // Select the stocks with at least 3 CNBC analysts to suggest buy, reassuring the signal return from kvp in cnbcDataBySymbol where kvp.Value.Where(x => x.Direction == OrderDirection.Buy).Count() >= 3 select kvp.Key; }); AddAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromDays(1))); // Invest equally to evenly dissipate the capital concentration risk SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel()); } public override void OnSecuritiesChanged(SecurityChanges changes) { foreach (var security in changes.AddedSecurities) { // Requesting CNBC Data var symbol = security.Symbol; var datasetSymbol = AddData<QuiverCNBCs>(symbol).Symbol; _datasetSymbolBySymbol.Add(symbol, datasetSymbol); // History request var history = History<QuiverCNBCs>(datasetSymbol, 10, Resolution.Daily); Debug($"We get {history.Count()} items in historical data of {datasetSymbol}"); } foreach (var security in changes.RemovedSecurities) { var symbol = security.Symbol; if (_datasetSymbolBySymbol.ContainsKey(symbol)) { // Remove subscription of CNBC data to release computation resources _datasetSymbolBySymbol.Remove(symbol, out var datasetSymbol); RemoveSecurity(datasetSymbol); } } } }
Research Example
The following example lists US Equities mentioned by Jim Cramer.
#r "../QuantConnect.DataSource.QuiverCNBC.dll" using QuantConnect.DataSource; var qb = new QuantBook(); // Requesting data var aapl = qb.AddEquity("AAPL", Resolution.Daily).Symbol; var symbol = qb.AddData<QuiverCNBCs>(aapl).Symbol; // Historical data var history = qb.History<QuiverCNBCs>(symbol, 60, Resolution.Daily); foreach (var cnbcs in history) { foreach (QuiverCNBC cnbc in cnbcs) { Console.WriteLine($"{cnbc.Symbol} traders at {cnbc.EndTime}: {cnbc.Traders}"); } } // Add Universe Selection IEnumerable<Symbol> UniverseSelection(IEnumerable<BaseData> altCoarse) { return from d in altCoarse.OfType<QuiverCNBCsUniverse>() where d.Traders.Contains("Cramer") select d.Symbol; } var universe = qb.AddUniverse<QuiverCNBCsUniverse<(UniverseSelection); // Historical Universe data var universeHistory = qb.UniverseHistory(universe, qb.Time.AddDays(-60), qb.Time); foreach (var cnbcs in universeHistory) { foreach (QuiverCNBCsUniverse cnbc in cnbcs) { Console.WriteLine($"{cnbc.Symbol} traders at {cnbc.EndTime}: {cnbc.Traders}"); } }
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:
QuiverCNBC
QuiverCNBC
objects have the following attributes:
QuiverCNBCsUniverse
QuiverCNBCsUniverse
objects have the following attributes: