Quiver Quantitative
Corporate Lobbying
Introduction
The Corporate Lobbying dataset by Quiver Quantitative tracks the lobbying activity of US Equities. The Lobbying Disclosure Act of 1995 requires lobbyists in the United States to disclose information about their activities, such as their clients, which issues they are lobbying on, and how much they are being paid. Quiver Quantiative scrapes this data and maps it to stock tickers to track which companies are spending money for legislative influence.
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 Corporate Lobbying 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 Corporate Lobbying dataset:
self.aapl = self.add_equity("AAPL", Resolution.DAILY).symbol
self.dataset_symbol = self.add_data(QuiverLobbyings, self.symbol).symbol
self._universe = self.add_universe(QuiverLobbyingUniverse, self.universe_selection_filter)
_symbol = AddEquity("AAPL", Resolution.Daily).Symbol;
_datasetSymbol = AddData<QuiverLobbyings>(_symbol).Symbol;
_universe = AddUniverse<QuiverLobbyingUniverse>(UniverseSelectionFilter);
Requesting Data
To add Corporate Lobbying 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 QuiverLobbyingDataAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2019, 1, 1)
self.set_end_date(2020, 6, 1)
self.set_cash(100000)
symbol = self.add_equity("AAPL", Resolution.DAILY).symbol
self.dataset_symbol = self.add_data(QuiverLobbyings, symbol).symbol public class QuiverLobbyingDataAlgorithm: QCAlgorithm
{
private Symbol _datasetSymbol;
public override void Initialize()
{
SetStartDate(2019, 1, 1);
SetEndDate(2020, 6, 1);
SetCash(100000);
var symbol = AddEquity("AAPL", Resolution.Daily).Symbol;
_datasetSymbol= AddData<QuiverLobbyings>(symbol).Symbol;
}
}
Accessing Data
To get the current Corporate Lobbying 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} amount at {slice.time}: {data_point.amount}") public override void OnData(Slice slice)
{
if (slice.ContainsKey(_datasetSymbol))
{
var dataPoints = slice[_datasetSymbol];
foreach (var dataPoint in dataPoints)
{
Log($"{_datasetSymbol} amount at {slice.Time}: {dataPoint.Amount}");
}
}
}
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(QuiverLobbyings).items():
for data_point in data_points:
self.log(f"{dataset_symbol} amount at {slice.time}: {data_point.amount}")
public override void OnData(Slice slice)
{
foreach (var kvp in slice.Get<QuiverLobbyings>())
{
var datasetSymbol = kvp.Key;
var dataPoints = kvp.Value;
foreach(var dataPoint in dataPoints)
{
Log($"{datasetSymbol} amount at {slice.Time}: {dataPoint.Amount}");
}
}
}
Historical Data
To get historical Corporate Lobbying 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[QuiverLobbyings](self.dataset_symbol, 100, Resolution.DAILY)
var history = History<QuiverLobbyings>(_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 Corporate Lobbying data, call the AddUniverseadd_universe method with the QuiverLobbyingUniverse class and a selection function.
def initialize(self):
self._universe = self.add_universe(QuiverLobbyingUniverse, "QuiverLobbyingUniverse", Resolution.DAILY, self.universe_selection)
def universe_selection(self, alt_coarse: List[QuiverLobbyingUniverse]) -> List[Symbol]:
lobby_data_by_symbol = {}
for datum in alt_coarse:
symbol = datum.symbol
if symbol not in lobby_data_by_symbol:
lobby_data_by_symbol[symbol] = []
lobby_data_by_symbol[symbol].append(datum)
return [symbol for symbol, d in lobby_data_by_symbol.items()
if sum([x.amount for x in d]) >= 100000] private Universe _universe;
public override void Initialize()
{
_universe = AddUniverse<QuiverLobbyingUniverse>("QuiverLobbyingUniverse", Resolution.Daily, altCoarse =>
{
var lobbyDataBySymbol = new Dictionary<Symbol, List<QuiverLobbyingUniverse>>();
foreach (var datum in altCoarse.OfType<QuiverLobbyingUniverse>())
{
var symbol = datum.Symbol;
if (!lobbyDataBySymbol.ContainsKey(symbol))
{
lobbyDataBySymbol.Add(symbol, new List<QuiverLobbyingUniverse>());
}
lobbyDataBySymbol[symbol].Add(datum);
}
return from kvp in lobbyDataBySymbol
where kvp.Value.Sum(x => x.Amount) >= 100000
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 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 lobbyings in universeHistory)
{
foreach (QuiverLobbyingUniverse lobbying in lobbyings)
{
Log($"{lobbying.Symbol} issue at {lobbying.EndTime}: {lobbying.Issue}");
}
} # DataFrame example where the columns are the QuiverLobbyingUniverse attributes:
history_df = self.history(self._universe, 30, Resolution.DAILY, flatten=True)
# Series example where the values are lists of QuiverLobbyingUniverse objects:
universe_history = self.history(self._universe, 30, Resolution.DAILY)
for (symbol, time), lobbyings in universe_history.items():
for lobbying in lobbyings:
print(f"{lobbying.symbol} issue at {lobbying.end_time}: {lobbying.issue}")
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 (var lobbyings in universeHistory)
{
foreach (QuiverLobbyingUniverse lobbying in lobbyings)
{
Consolte.WriteLine($"{lobbying.Symbol} issue at {lobbying.EndTime}: {lobbying.Issue}");
}
} # DataFrame example where the columns are the QuiverLobbyingUniverse attributes:
history_df = qb.universe_history(universe, qb.time-timedelta(30), qb.time, flatten=True)
# Series example where the values are lists of QuiverLobbyingUniverse objects:
universe_history = qb.universe_history(universe, qb.time-timedelta(30), qb.time)
for (symbol, time), lobbyings in universe_history.items():
for lobbying in lobbyings:
print(f"{lobbying.symbol} issue at {lobbying.end_time}: {lobbying.issue}")
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 Corporate Lobbying 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 Corporate Lobbying dataset enables you to create strategies using the latest information on lobbying activity. Examples include the following strategies:
- Trading securities that have spent the most on lobbying over the last quarter
- Trading securities that have had the biggest change in lobbying spend for privacy legislation over the last year
Classic Algorithm Example
The following example algorithm tracks the lobbying activity of Apple. When the company initiates a lobbying activity worth more than $50K, the algorithm buys Apple stock. When the company initiates a lobbying activity worth less than $10K, the algorithm short sells Apple stock.
from AlgorithmImports import *
class QuiverLobbyingDataAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2024, 9, 1)
self.set_end_date(2024, 12, 31)
self._symbol = self.add_equity("AAPL", Resolution.DAILY).symbol
# Subscribe to lobbying data for AAPL to generate trade signal
self._dataset_symbol = self.add_data(QuiverLobbyings, self._symbol).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:
# Trade only base on lobbying data
for lobbyings in slice.get(QuiverLobbyings).values():
# Buy if over 50000 lobbying amount, suggesting a favored political prospect and sentiment
if any([lobbying.amount > 50000 for lobbying in lobbyings]):
self.set_holdings(self._symbol, 1)
# Sell if below 10000 lobbying amount, suggesting a less favorable political prospect and sentiment
elif any([lobbying.amount < 10000 for lobbying in lobbyings]):
self.set_holdings(self._symbol, -1) public class QuiverLobbyingAlgorithm : QCAlgorithm
{
private Symbol _symbol, _datasetSymbol;
public override void Initialize()
{
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
_symbol = AddEquity("AAPL").Symbol;
// Subscribe to lobbying data for AAPL to generate trade signal
_datasetSymbol = AddData<QuiverLobbyings>(_symbol).Symbol;
// history request
var history = History<QuiverLobbyings>(new[] {_datasetSymbol}, 10, Resolution.Daily);
Debug($"We got {history.Count()} items from historical data request of {_datasetSymbol}.");
}
public override void OnData(Slice slice)
{
// Trade only base on lobbying data
foreach (var kvp in slice.Get<QuiverLobbyings>())
{
var lobbyings = kvp.Value;
// Buy if over 50000 lobbying amount, suggesting a favored political prospect and sentiment
if (lobbyings.Any(lobbying => ((QuiverLobbying) lobbying).Amount >= 50000m))
{
SetHoldings(_symbol, 1);
}
// Sell if below 10000 lobbying amount, suggesting a less favorable political prospect and sentiment
else if (lobbyings.Any(lobbying => ((QuiverLobbying) lobbying).Amount <= 10000m))
{
SetHoldings(_symbol, -1);
}
}
}
}
Framework Algorithm Example
The following example algorithm creates a dynamic universe of US Equities that have at least $100K worth of new lobbying activity. Each day, it then forms an equal-weighted portfolio with all of the securities in the universe.
from AlgorithmImports import *
class QuiverLobbyingDataAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2024, 9, 1)
self.set_end_date(2024, 12, 31)
self.set_cash(100000)
# To hold the lobbying dataset symbol for managing subscription
self.dataset_symbol_by_symbol = {}
# Filter universe based on the lobbying data
self.add_universe(QuiverLobbyingUniverse, 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[QuiverLobbyingUniverse]) -> List[Symbol]:
lobby_data_by_symbol = {}
for datum in data:
symbol = datum.symbol
if symbol not in lobby_data_by_symbol:
lobby_data_by_symbol[symbol] = []
lobby_data_by_symbol[symbol].append(datum)
# Select and invest all stocks with lobbying amount above 100000, suggesting a more favorable political prospect and sentiment
return [symbol for symbol, d in lobby_data_by_symbol.items()
if sum([x.amount for x in d if x.amount]) >= 100000]
def on_securities_changed(self, changes: SecurityChanges) -> None:
for security in changes.added_securities:
# Requesting lobbying data for trading
symbol = security.symbol
dataset_symbol = self.add_data(QuiverLobbyings, symbol).symbol
self.dataset_symbol_by_symbol[symbol] = dataset_symbol
# Historical Data
history = self.history(dataset_symbol, 10, Resolution.DAILY)
for security in changes.removed_securities:
dataset_symbol = self.dataset_symbol_by_symbol.pop(security.symbol, None)
if dataset_symbol:
# Remove lobbying data subscription to release computation resources
self.remove_security(dataset_symbol) public class QuiverLobbyingDataAlgorithm : QCAlgorithm
{
// To hold the lobbying dataset symbol for managing subscription
private Dictionary<Symbol, Symbol> _datasetSymbolBySymbol = new();
public override void Initialize()
{
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
// Filter universe based on the lobbying data
AddUniverse<QuiverLobbyingUniverse>( data =>
{
var lobbyDataBySymbol = new Dictionary<Symbol, List<QuiverLobbyingUniverse>>();
foreach (var datum in data.OfType<QuiverLobbyingUniverse>())
{
var symbol = datum.Symbol;
if (!lobbyDataBySymbol.ContainsKey(symbol))
{
lobbyDataBySymbol.Add(symbol, new List<QuiverLobbyingUniverse>());
}
lobbyDataBySymbol[symbol].Add(datum);
}
// Select and invest all stocks with lobbying amount above 100000, suggesting a more favorable political prospect and sentiment
return from kvp in lobbyDataBySymbol
where kvp.Value.Sum(x => x.Amount) >= 100000m
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 lobbying data for trading
var symbol = security.Symbol;
var datasetSymbol = AddData<QuiverLobbyings>(symbol).Symbol;
_datasetSymbolBySymbol .Add(symbol, datasetSymbol);
// History request
var history = History<QuiverLobbyings>(datasetSymbol, 10, Resolution.Daily);
}
foreach (var security in changes.RemovedSecurities)
{
var symbol = security.Symbol;
if (_datasetSymbolBySymbol .ContainsKey(symbol))
{
// Remove lobbying data subscription to release computation resources
_datasetSymbolBySymbol .Remove(symbol, out var datasetSymbol);
RemoveSecurity(datasetSymbol);
}
}
}
}
Research Example
The following example lists US Equities that have brought health related issues.
#r "../QuantConnect.DataSource.QuiverLobbying.dll"
using QuantConnect.DataSource;
var qb = new QuantBook();
// Requesting data
var aapl = qb.AddEquity("AAPL", Resolution.Daily).Symbol;
var symbol = qb.AddData<QuiverLobbyings>(aapl).Symbol;
// Historical data
var history = qb.History<QuiverLobbyings>(symbol, 60, Resolution.Daily);
foreach (var lobbyings in history)
{
foreach (QuiverLobbying lobbying in lobbyings)
{
Console.WriteLine($"{lobbying.Symbol} issue at {lobbying.EndTime}: {lobbying.Issue}");
}
}
// Add Universe Selection
IEnumerable<Symbol> UniverseSelection(IEnumerable<BaseData> altCoarse)
{
return from d in altCoarse.OfType<QuiverLobbyingUniverse>()
where d.Issue.ToLower().Contains("health") select d.Symbol;
}
var universe = qb.AddUniverse(UniverseSelection);
// Historical Universe data
var universeHistory = qb.UniverseHistory(universe, qb.Time.AddDays(-60), qb.Time);
foreach (var lobbyings in universeHistory)
{
foreach (QuiverLobbyingUniverse lobbying in lobbyings)
{
Console.WriteLine($"{lobbying.Symbol} issue at {lobbying.EndTime}: {lobbying.Issue}");
}
} qb = QuantBook()
# Requesting Data
aapl = qb.add_equity("AAPL", Resolution.DAILY).symbol
symbol = qb.add_data(QuiverLobbyings, aapl).symbol
# Historical data
history = qb.history(QuiverLobbyings, symbol, 60, Resolution.DAILY)
for (symbol, time), lobbyings in history.items():
for lobbying in lobbyings:
print(f"{lobbying.symbol} issue at {lobbying.end_time}: {lobbying.issue}")
# Add Universe Selection
def universe_selection(alt_coarse: List[QuiverLobbyingUniverse]) -> List[Symbol]:
return [d.symbol for d in alt_coarse if 'health' in d.issue.lower()]
universe = qb.add_universe(QuiverLobbyingUniverse, universe_selection)
# Historical Universe data
history = qb.universe_history(universe, qb.time-timedelta(60), qb.time)
for (symbol, time), lobbyings in history.items():
for lobbying in lobbyings:
print(f"{lobbying.symbol} issue at {lobbying.end_time}: {lobbying.issue}")
Data Point Attributes
The Quiver Quantitative Corporate Lobbying dataset provides QuiverLobbyings, QuiverLobbying, and QuiverLobbyingUniverse objects.
QuiverLobbyings
QuiverLobbyings objects have the following attributes:
QuiverLobbying
QuiverLobbying objects have the following attributes:
QuiverLobbyingUniverse
QuiverLobbyingUniverse objects have the following attributes: