Quiver Quantitative
WallStreetBets
Introduction
The WallStreetBets dataset by Quiver Quantitative tracks daily mentions of different equities on Reddit’s popular WallStreetBets forum. The data covers 6,000 Equities, starts in August 2018, and is delivered on a daily frequency. The dataset is created by scraping the daily discussion threads on r/WallStreetBets and parsing the comments for ticker mentions.
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 WallStreetBets 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 WallStreetBets dataset:
self.aapl = self.add_equity("AAPL", Resolution.DAILY).symbol
self.dataset_symbol = self.add_data(QuiverWallStreetBets, self.aapl).symbol
self._universe = self.add_universe(QuiverWallStreetBetsUniverse, self.universe_selection) _symbol = AddEquity("AAPL", Resolution.Daily).Symbol;
_datasetSymbol = AddData<QuiverWallStreetBets>(_symbol).Symbol;
_universe = AddUniverse<QuiverWallStreetBetsUniverse>(UniverseSelection);
Requesting Data
To add WallStreetBets data to your algorithm, call the AddDataadd_data method. Save a reference to the dataset Symbol so you can access the data later in your algorithm.
class QuiverWallStreetBetsDataAlgorithm(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(QuiverWallStreetBets, self.aapl).symbol public class QuiverWallStreetBetsDataAlgorithm : 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<QuiverWallStreetBets>(_symbol).Symbol;
}
}
Accessing Data
To get the current WallStreetBets 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} mentions at {slice.time}: {data_point.mentions}") public override void OnData(Slice slice)
{
if (slice.ContainsKey(_datasetSymbol))
{
var dataPoints = slice[_datasetSymbol];
foreach (var dataPoint in dataPoints)
{
Log($"{_datasetSymbol} mentions at {slice.Time}: {dataPoint.Mentions}");
}
}
}
To iterate through all of the dataset objects in the current Slice, call the Getget method.
def on_data(self, slice: Slice) -> None:
for dataset_symbol, data_points in slice.get(QuiverWallStreetBets).items():
for data_point in data_points:
self.log(f"{dataset_symbol} mentions at {slice.time}: {data_point.mentions}") public override void OnData(Slice slice)
{
foreach (var kvp in slice.Get<QuiverWallStreetBets>())
{
var datasetSymbol = kvp.Key;
var dataPoints = kvp.Value;
foreach (var dataPoint in dataPoints)
{
Log($"{datasetSymbol} mentions at {slice.Time}: {dataPoint.Mentions}");
}
}
}
Historical Data
To get historical WallStreetBets data, call the Historyhistory 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[QuiverWallStreetBets](self.dataset_symbol, 100, Resolution.DAILY)
var history = History<QuiverWallStreetBets>(_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 WallStreetBets data, call the AddUniverseadd_universe method with the QuiverWallStreetBetsUniverse class and a selection function.
def initialize(self) -> None:
self.universe = self.add_universe(QuiverWallStreetBetsUniverse, self.universe_selection)
def universe_selection(self, alt_coarse: List[QuiverWallStreetBetsUniverse]) -> List[Symbol]:
return [d.symbol for d in alt_coarse if d.mentions > 100 and d.rank < 100] private Universe _universe;
public override void Initialize()
{
_universe = AddUniverse<QuiverWallStreetBetsUniverse>(altCoarse =>
{
return from d in altCoarse.OfType<QuiverWallStreetBetsUniverse>()
where d.Mentions > 10 && d.Rank > 10 select d.Symbol;
});
}
For more information about dynamic universes, see Universes.
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 Historyhistory 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 bets in universeHistory)
{
foreach (QuiverWallStreetBetsUniverse bet in bets)
{
Log($"{bet.Symbol} mentions at {bet.EndTime}: {bet.Mentions}");
}
} # DataFrame example where the columns are the QuiverWallStreetBetsUniverse attributes:
history_df = self.history(self._universe, 30, Resolution.DAILY, flatten=True)
# Series example where the values are lists of QuiverWallStreetBetsUniverse objects:
universe_history = self.history(self._universe, 30, Resolution.DAILY)
for (univere_symbol, time), bets in universe_history.items():
for bet in bets:
self.log(f"{bet.symbol} mentions at {bet.end_time}: {bet.mentions}")
Historical Universe Data in Research
To get historical universe data in research, call the UniverseHistoryuniverse_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 (QuiverWallStreetBetsUniverse bet in bets)
{
Log($"{bet.Symbol} rank at {bet.EndTime}: {bet.Rank}");
}
} # DataFrame example where the columns are the QuiverWallStreetBetsUniverse attributes:
history_df = qb.universe_history(universe, qb.time-timedelta(30), qb.time, flatten=True)
# Series example where the values are lists of QuiverWallStreetBetsUniverse objects:
universe_history = qb.universe_history(universe, qb.time-timedelta(30), qb.time)
for (univere_symbol, time), bets in universe_history.items():
for bet in bets:
print(f"{bet.symbol} rank at {bet.end_time}: {bet.rank}")
You can call the Historyhistory method in Research.
Remove Subscriptions
To remove a subscription, call the RemoveSecurityremove_security method.
self.remove_security(self.dataset_symbol)
RemoveSecurity(_datasetSymbol);
If you subscribe to WallStreetBets 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 WallStreetBets dataset enables you to create strategies using the latest activity on the WallStreetBets daily discussion thread. Examples include the following strategies:
- Trading any security that is being mentioned
- Trading securities that are receiving more/less mentions than they were previously
- Trading the security that is being mentioned the most/least for the day
Classic Algorithm Example
The following example algorithm creates a dynamic universe of US Equities based on daily WallStreetBets data. When a security is mentioned on r/WallStreetBets more than five times in a day, the algorithm buys the security. When a security is mentioned five time in a day or less, the algorithm short sells the security.
from AlgorithmImports import *
class QuiverWallStreetBetsDataAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2024, 9, 1)
self.set_end_date(2024, 12, 31)
self.set_cash(100000)
# Seed the price of each asset with its last known price to avoid trading errors.
self.set_security_initializer(
BrokerageModelSecurityInitializer(
self.brokerage_model,
FuncSecuritySeeder(self.get_last_known_prices)
)
)
self.universe_settings.resolution = Resolution.DAILY
# Filter using wall street bet insights
self._universe = self.add_universe(QuiverWallStreetBetsUniverse, self.universe_selection)
def on_data(self, slice: Slice) -> None:
points = slice.Get(QuiverWallStreetBets)
for point in points.Values:
symbol = point.symbol.underlying
security = self.securities[symbol]
if not security.is_tradable:
continue
# Buy if the stock was mentioned more than 5 times in the WallStreetBets daily discussion, which translate into high popularity of rise
if point.mentions > 5 and not security.holdings.is_long:
self.market_order(symbol, 1)
# Otherwise, short sell
elif point.mentions <= 5 and not security.holdings.is_short:
self.market_order(symbol, -1)
def on_securities_changed(self, changes: SecurityChanges) -> None:
for added in changes.added_securities:
# Requesting wall street bet data to obtain the trader's insights
quiver_wsb_symbol = self.add_data(QuiverWallStreetBets, added.symbol).symbol
# Historical data
history = self.history(QuiverWallStreetBets, quiver_wsb_symbol, 60, Resolution.DAILY)
def universe_selection(self, alt_coarse: List[QuiverWallStreetBetsUniverse]) -> List[Symbol]:
# Select the ones with popularity (mentions) of better-than-others performance (rank)
return [d.symbol for d in alt_coarse \
if d.mentions > 10 \
and d.rank < 100] public class QuiverWallStreetBetsDataAlgorithm : QCAlgorithm
{
private Universe _universe;
public override void Initialize()
{
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
// Seed the price of each asset with its last known price to avoid trading errors.
SetSecurityInitializer(
new BrokerageModelSecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices))
);
UniverseSettings.Resolution = Resolution.Daily;
// Filter using wall street bet insights
_universe = AddUniverse<QuiverWallStreetBetsUniverse>(altCoarse =>
{
// Select the ones with popularity (mentions) of better-than-others performance (rank)
return from d in altCoarse.OfType<QuiverWallStreetBetsUniverse>()
where d.Mentions > 10 && d.Rank < 100
select d.Symbol;
});
}
public override void OnData(Slice slice)
{
var points = slice.Get<QuiverWallStreetBets>();
foreach (var point in points.Values)
{
var symbol = point.Symbol.Underlying;
var security = Securities[symbol];
if (!security.IsTradable)
{
continue;
}
// Buy if the stock was mentioned more than 5 times in the WallStreetBets daily discussion, which translate into high popularity of rise
if (point.Mentions > 5 && !security.Holdings.IsLong)
{
MarketOrder(symbol, 1);
}
// Otherwise, short sell
else if (point.Mentions <= 5 && !security.Holdings.IsShort)
{
MarketOrder(symbol, -1);
}
}
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach(var added in changes.AddedSecurities)
{
// Requesting wall street bet data to obtain the trader's insights
var quiverWSBSymbol = AddData<QuiverWallStreetBets>(added.Symbol).Symbol;
// Historical data
var history = History<QuiverWallStreetBets>(quiverWSBSymbol, 60, Resolution.Daily);
}
}
}
Framework Algorithm Example
The following example algorithm creates a dynamic universe of US Equities based on daily WallStreetBets data. When a security is mentioned on r/WallStreetBets more than five times in a day, the algorithm buys the security. When a security is mentioned five time in a day or less, the algorithm short sells the security.
from AlgorithmImports import *
class QuiverWallStreetBetsDataAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2024, 9, 1)
self.set_end_date(2024, 12, 31)
self.set_cash(100000)
self.universe_settings.resolution = Resolution.DAILY
# Filter using wall street bet insights
self._universe = self.add_universe(QuiverWallStreetBetsUniverse, self.universe_selection)
self.add_alpha(WallStreamBetsAlphaModel())
self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel())
self.add_risk_management(NullRiskManagementModel())
self.set_execution(ImmediateExecutionModel())
def universe_selection(self, alt_coarse: List[QuiverWallStreetBetsUniverse]) -> List[Symbol]:
# Select the ones with popularity (mentions) of better-than-others performance (rank)
return [d.symbol for d in alt_coarse
if d.mentions > 10 and d.rank < 100]
class WallStreamBetsAlphaModel(AlphaModel):
symbol_data_by_symbol = {}
def __init__(self, mentions_threshold: int = 5) -> None:
self.mentions_threshold = mentions_threshold
def update(self, algorithm: QCAlgorithm, slice: Slice) -> List[Insight]:
insights = []
points = slice.Get(QuiverWallStreetBets)
for point in points.Values:
# Buy if the stock was mentioned more than 5 times in the WallStreetBets daily discussion, which translate into high popularity of rise
# Otherwise short sell
target_direction = InsightDirection.UP if point.mentions > self.mentions_threshold else InsightDirection.DOWN
self.symbol_data_by_symbol[point.symbol.underlying].target_direction = target_direction
for symbol, symbol_data in self.symbol_data_by_symbol.items():
# Ensure we have security data for the current Slice to avoid stale fill
if not (slice.contains_key(symbol) and slice[symbol] is not None):
continue
if symbol_data.target_direction is not None:
insights += [Insight.price(symbol, timedelta(1), symbol_data.target_direction)]
symbol_data.target_direction = None
return insights
def on_securities_changed(self, algorithm: QCAlgorithm, changes: SecurityChanges) -> None:
for security in changes.added_securities:
symbol = security.symbol
self.symbol_data_by_symbol[symbol] = SymbolData(algorithm, symbol)
for security in changes.removed_securities:
symbol_data = self.symbol_data_by_symbol.pop(security.symbol, None)
if symbol_data:
symbol_data.dispose()
class SymbolData:
target_direction = None
def __init__(self, algorithm: QCAlgorithm, symbol: Symbol) -> None:
self.algorithm = algorithm
# Requesting wall street bet data to obtain the trader's insights
self.quiver_wsb_symbol = algorithm.add_data(QuiverWallStreetBets, symbol).symbol
# Historical data
history = algorithm.history(self.quiver_wsb_symbol, 60, Resolution.DAILY)
def dispose(self) -> None:
# Unsubscribe from the Quiver WallStreetBets feed for this security to release computationa resources
self.algorithm.remove_security(self.quiver_wsb_symbol) public class QuiverWallStreetBetsDataAlgorithm : QCAlgorithm
{
private Universe _universe;
public override void Initialize()
{
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
UniverseSettings.Resolution = Resolution.Daily;
// Filter using wall street bet insights
_universe = AddUniverse<QuiverWallStreetBetsUniverse>(altCoarse =>
{
// Select the ones with popularity (mentions) of better-than-others performance (rank)
return from d in altCoarse.OfType<QuiverWallStreetBetsUniverse>()
where d.Mentions > 10 && d.Rank < 100
select d.Symbol;
});
AddAlpha(new WallStreamBetsAlphaModel());
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
AddRiskManagement(new NullRiskManagementModel());
SetExecution(new ImmediateExecutionModel());
}
}
public class WallStreamBetsAlphaModel : AlphaModel
{
private Dictionary<Symbol, SymbolData> _symbolDataBySymbol = new Dictionary<Symbol, SymbolData>();
private int _mentionsThreshold;
public WallStreamBetsAlphaModel(int mentionsThreshold=5)
{
_mentionsThreshold = mentionsThreshold;
}
public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice slice)
{
var insights = new List<Insight>();
var points = slice.Get<QuiverWallStreetBets>();
foreach (var point in points.Values)
{
// Buy if the stock was mentioned more than 5 times in the WallStreetBets daily discussion, which translate into high popularity of rise
// Otherwise short sell
var targetDirection = point.Mentions > _mentionsThreshold ? InsightDirection.Up : InsightDirection.Down;
_symbolDataBySymbol[point.Symbol.Underlying].targetDirection = targetDirection;
}
foreach (var kvp in _symbolDataBySymbol)
{
var symbol = kvp.Key;
var symbolData = kvp.Value;
// Ensure we have security data for the current Slice to avoid stale fill
if (!(slice.ContainsKey(symbol) && slice[symbol] != null))
{
continue;
}
if (symbolData.targetDirection != null)
{
insights.Add(Insight.Price(symbol, TimeSpan.FromDays(1), (InsightDirection)symbolData.targetDirection));
symbolData.targetDirection = null;
}
}
return insights;
}
public override void OnSecuritiesChanged(QCAlgorithm algorithm, SecurityChanges changes)
{
foreach (var security in changes.AddedSecurities)
{
var symbol = security.Symbol;
_symbolDataBySymbol.Add(symbol, new SymbolData(algorithm, symbol));
}
foreach (var security in changes.RemovedSecurities)
{
var symbol = security.Symbol;
if (_symbolDataBySymbol.ContainsKey(symbol))
{
_symbolDataBySymbol[symbol].dispose();
_symbolDataBySymbol.Remove(symbol);
}
}
}
}
public class SymbolData
{
private Symbol _quiverWSBSymbol;
private QCAlgorithm _algorithm;
public InsightDirection? targetDirection = null;
public SymbolData(QCAlgorithm algorithm, Symbol symbol)
{
_algorithm = algorithm;
// Requesting wall street bet data to obtain the trader's insights
_quiverWSBSymbol = algorithm.AddData<QuiverWallStreetBets>(symbol).Symbol;
// Historical data
var history = algorithm.History<QuiverWallStreetBets>(_quiverWSBSymbol, 60, Resolution.Daily);
}
public void dispose()
{
// Unsubscribe from the Quiver WallStreetBets feed for this security to release computationa resources
_algorithm.RemoveSecurity(_quiverWSBSymbol);
}
}
Research Example
The following example lists low-ranking US Equities that are mentioned more than ten times on r/WallStreetBets.
#r "../QuantConnect.DataSource.QuiverWallStreetBets.dll"
using QuantConnect.DataSource;
var qb = new QuantBook();
// Requesting data
var aapl = qb.AddEquity("AAPL", Resolution.Daily).Symbol;
var symbol = qb.AddData<QuiverWallStreetBets>(aapl).Symbol;
// Historical data
var history = qb.History<QuiverWallStreetBets>(symbol, 60, Resolution.Daily);
foreach (var bet in history.OfType<QuiverWallStreetBets>())
{
Console.WriteLine($"{bet.Symbol} rank at {bet.EndTime}: {bet.Rank}");
}
// Add Universe Selection
IEnumerable<Symbol> UniverseSelection(IEnumerable<BaseData> altCoarse)
{
return from d in altCoarse.OfType<QuiverWallStreetBetsUniverse>()
where d.Mentions > 10 && d.Rank < 100 select d.Symbol;
}
var universe = qb.AddUniverse<QuiverWallStreetBetsUniverse>(UniverseSelection);
// Historical Universe data
var universeHistory = qb.UniverseHistory(universe, qb.Time.AddDays(-60), qb.Time);
foreach (var bets in universeHistory)
{
foreach (QuiverWallStreetBetsUniverse bet in bets)
{
Console.WriteLine($"{bet.Symbol} rank at {bet.EndTime}: {bet.Rank}");
}
} qb = QuantBook()
# Requesting data
aapl = qb.add_equity("AAPL", Resolution.DAILY).symbol
symbol = qb.add_data(QuiverWallStreetBets, aapl).symbol
# Historical data
history = qb.history(QuiverWallStreetBets, symbol, 60, Resolution.DAILY)
for (symbol, time), bet in history.iterrows():
print(f"{symbol} rank at {time}: {bet['rank']}")
# Add Universe Selection
def universe_selection(alt_coarse: List[QuiverWallStreetBetsUniverse]) -> List[Symbol]:
return [d.symbol for d in alt_coarse if d.mentions > 10 and d.rank < 100]
universe = qb.add_universe(QuiverWallStreetBetsUniverse, universe_selection)
# Historical Universe data
universe_history = qb.universe_history(universe, qb.time-timedelta(60), qb.time)
for (univere_symbol, time), bets in universe_history.items():
for bet in bets:
print(f"{bet.symbol} rank at {bet.end_time}: {bet.rank}")
Data Point Attributes
The WallStreetBets dataset provides QuiverWallStreetBets and QuiverWallStreetBetsUniverse objects.
QuiverWallStreetBets Attributes
QuiverWallStreetBets objects have the following attributes:
QuiverWallStreetBetsUniverse Attributes
QuiverWallStreetBetsUniverse objects have the following attributes: