Kavout
Composite Factor Bundle
Introduction
The Composite Factor Bundle dataset by Kavout provides ensemble scores for popular market factors. Kavout signals are machine-learning enhanced scores that capture the returns of systematic factors such as quality, value, momentum, growth, and low volatility. There are many different anomalies discovered by researchers and practitioners across these factor categories and there is no good common definition of each style across the literature. Kavout creates an ensemble score for each style that gauges the different factors considered in the literature and industry practice.
In this data set, you will find Kavout's proprietary signals for quality, value, momentum, growth, and low volatility, which have been adopted by some of the multi-billion dollar quant funds in New York and London. Each signal is generated by an ensemble model consisting of inputs from hundreds of anomalies. The data is generated on a daily basis and covers all the stocks traded in US major markets such as NYSE and Nasdaq since 2003. You could leverage this abundant set of signals to construct and backtest your strategies.
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 Composite Factor Bundle dataset, including CLI commands and pricing, see the dataset listing.
About the Provider
Kavout was created by ex-Googlers and the founding team used to work at Google, Microsoft, Baidu, and financial firms with a proven track record of building many mission-critical machine learning systems where billions of data points were processed in real-time to predict the best outcome for core search ranking, ads monetization, recommendations, and trading platforms.
Their mission is to build machine investing solutions to find alpha with adaptive learning algorithms and to create an edge by assimilating vast quantities of complex data through the latest AI and Machine Learning methods to generate signals to uncover hidden, dynamic, and nonlinear patterns in the financial markets.
Getting Started
The following snippet demonstrates how to request data from the Composite Factor Bundle dataset:
from QuantConnect.DataSource import * self.aapl = self.add_equity("AAPL", Resolution.DAILY).symbol self.dataset_symbol = self.add_data(KavoutCompositeFactorBundle, self.aapl).symbol
using QuantConnect.DataSource; _symbol = AddEquity("AAPL", Resolution.Daily).Symbol; _datasetSymbol = AddData<KavoutCompositeFactorBundle>(_symbol).Symbol;
Requesting Data
To add Composite Factor Bundle 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 KavoutCompositeFactorBundleAlgorithm(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(KavoutCompositeFactorBundle, self.aapl).symbol
public class KavoutCompositeFactorBundleAlgorithm : 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 & lt; KavoutCompositeFactorBundle & gt; (_symbol).Symbol;
}
}
Accessing Data
To get the current Composite Factor Bundle 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_point = slice[self.dataset_symbol] self.log(f"{self.dataset_symbol} momentum at {slice.time}: {data_point.momentum}")
public override void OnData(Slice slice) { if (slice.ContainsKey(_datasetSymbol)) { var dataPoint = slice[_datasetSymbol]; Log($"{_datasetSymbol} momentum at {slice.Time}: {dataPoint.Momentum}"); } }
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_point in slice.get(KavoutCompositeFactorBundle).items(): self.log(f"{dataset_symbol} momentum at {slice.time}: {data_point.momentum}")
public override void OnData(Slice slice) { foreach (var kvp in slice.Get<KavoutCompositeFactorBundle>()) { var datasetSymbol = kvp.Key; var dataPoint = kvp.Value; Log($"{datasetSymbol} momentum at {slice.Time}: {dataPoint.Momentum}"); } }
Historical Data
To get historical Composite Factor Bundle 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[KavoutCompositeFactorBundle](self.dataset_symbol, 100, Resolution.DAILY)
var history = History<KavoutCompositeFactorBundle>(_datasetSymbol, 100, Resolution.Daily);
For more information about historical data, see History Requests.
Remove Subscriptions
To remove a subscription, call the RemoveSecurity
remove_security
method.
self.remove_security(self.dataset_symbol)
RemoveSecurity(_datasetSymbol);
If you subscribe to Composite Factor Bundle 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 Composite Factor Bundle dataset enables you to access the performance of 5 different factors in order to engineer strategies. Examples include the following strategies:
- Performing return-risk optimization based on performance and volatility scoring.
- Weighing stocks based on regression analysis in factor-vector space.
Classic Algorithm Example
The following example algorithm creates a dynamic universe of the 100 most liquid US Equities. Each day, it then forms a equal-weighted dollar-neutral portfolio of the 10 companies most likely to outperform and the 10 companies most likely to underperform.
from AlgorithmImports import * from QuantConnect.DataSource import * class KavoutCompositeFactorBundleAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2019, 1, 1) self.set_end_date(2020, 6, 1) self.set_cash(100000) # A variable that control the time of rebalancing self.last_time = datetime.min self.add_universe(self.my_coarse_filter_function) self.universe_settings.resolution = Resolution.MINUTE def my_coarse_filter_function(self, coarse: List[CoarseFundamental]) -> List[Symbol]: # Filter for the highly traded stocks for more informed data from frequent market activities, which may translate to more accurate prediction # Factors scores are only available for the ones with fundamentals sorted_by_dollar_volume = sorted([x for x in coarse if x.has_fundamental_data], key=lambda x: x.dollar_volume, reverse=True) selected = [x.symbol for x in sorted_by_dollar_volume[:100]] return selected def on_data(self, slice: Slice) -> None: if self.last_time > self.time: return # Trade only on the factor score data points = slice.Get(KavoutCompositeFactorBundle) # Long the stocks with highest factor scores, which indicate higher return from various factors # Short the ones with lowest factor scores for lower return estimates sorted_by_score = sorted(points.items(), key=self.total_score) long_symbols = [x[0].underlying for x in sorted_by_score[-10:]] short_symbols = [x[0].underlying for x in sorted_by_score[:10]] # Liquidate the stocks with less significant return estimation for better PnL for symbol in [x.symbol for x in self.portfolio.Values if x.invested]: if symbol not in long_symbols + short_symbols: self.liquidate(symbol) # Invest in equal-size and dollar-neutral to evenly dissipate individual capital risk, avoid non-systematic risk, and better margin long_targets = [PortfolioTarget(symbol, 0.05) for symbol in long_symbols] short_targets = [PortfolioTarget(symbol, -0.05) for symbol in short_symbols] self.set_holdings(long_targets + short_targets) self.last_time = Expiry.END_OF_DAY(self.time) def on_securities_changed(self, changes: SecurityChanges) -> None: for security in changes.added_securities: # Requesting factor bundle data for trade signal generation kavout_composite_factor_bundle_symbol= self.add_data(KavoutCompositeFactorBundle, security.symbol).symbol # Historical Data history = self.history(kavout_composite_factor_bundle_symbol, 2, Resolution.DAILY) self.debug(f"We got {len(history)} items from our history request") def total_score(self, value: Tuple[Symbol, KavoutCompositeFactorBundle]) -> float: # Return the total score to integrate overall likelihood to outcompete, take equal weighting for each factor value = value[1] return value.growth + value.low_volatility + value.momentum + value.quality + value.value_factor
public class KavoutCompositeFactorBundleAlgorithm : QCAlgorithm { // A variable that control the time of rebalancing private DateTime _time = DateTime.MinValue; public override void Initialize() { SetStartDate(2003, 1, 10); SetEndDate(2003, 1, 15); SetCash(100000); AddUniverse(MyCoarseFilterFunction); UniverseSettings.Resolution = Resolution.Minute; } private IEnumerable<Symbol> MyCoarseFilterFunction(IEnumerable<CoarseFundamental> coarse) { // Filter for the highly traded stocks for more informed data from frequent market activities, which may translate to more accurate prediction // Factors scores are only available for the ones with fundamentals return (from c in coarse where c.HasFundamentalData orderby c.DollarVolume descending select c.Symbol).Take(100); } public override void OnData(Slice slice) { if (_time > Time) return; // Trade only on the factor score data var points = slice.Get<KavoutCompositeFactorBundle>(); // Long the stocks with highest factor scores, which indicate higher return from various factors // Short the ones with lowest factor scores for lower return estimates var sortedByScore = from s in points.Values orderby TotalScore(s) descending select s.Symbol.Underlying; var longSymbols = sortedByScore.Take(10).ToList(); var shortSymbols = sortedByScore.TakeLast(10).ToList(); // Liquidate the stocks with less significant return estimation for better PnL foreach (var kvp in Portfolio) { var symbol = kvp.Key; if (kvp.Value.Invested && !longSymbols.Contains(symbol) && !shortSymbols.Contains(symbol)) { Liquidate(symbol); } } // Invest in equal-size and dollar-neutral to evenly dissipate individual capital risk, avoid non-systematic risk, and better margin var targets = new List<PortfolioTarget>(); targets.AddRange(longSymbols.Select(symbol => new PortfolioTarget(symbol, 0.05m))); targets.AddRange(shortSymbols.Select(symbol => new PortfolioTarget(symbol, -0.05m))); SetHoldings(targets); _time = Expiry.EndOfDay(Time); } public override void OnSecuritiesChanged(SecurityChanges changes) { foreach(var security in changes.AddedSecurities) { // Requesting factor bundle data for trade signal generation var kavoutCompositeFactorBundleSymbol = AddData<KavoutCompositeFactorBundle>(security.Symbol).Symbol; // Historical Data var history = History(new[]{kavoutCompositeFactorBundleSymbol}, 60, Resolution.Daily); Debug($"We got {history.Count()} items from our history request"); } } private decimal TotalScore(KavoutCompositeFactorBundle value) { // Return the total score to integrate overall likelihood to outcompete, take equal weighting for each factor return value.Growth + value.ValueFactor + value.Quality + value.Momentum + value.LowVolatility; } }
Framework Algorithm Example
The following example algorithm creates a dynamic universe of the 100 most liquid US Equities. Each day, it then forms a equal-weighted dollar-neutral portfolio of the 10 companies most likely to outperform and the 10 companies most likely to underperform.
from AlgorithmImports import * from QuantConnect.DataSource import * class KavoutCompositeFactorBundleAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2019, 1, 1) self.set_end_date(2020, 6, 1) self.set_cash(100000) self.add_universe(self.my_coarse_filter_function) self.universe_settings.resolution = Resolution.MINUTE # Custom alpha model to emit insights based on factor bundle data self.add_alpha(KavoutCompositeFactorBundleAlphaModel()) # Invest in equal-size and dollar-neutral to evenly dissipate individual capital risk, avoid non-systematic risk, and better margin self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel()) self.set_execution(ImmediateExecutionModel()) def my_coarse_filter_function(self, coarse: List[CoarseFundamental]) -> List[Symbol]: # Filter for the highly traded stocks for more informed data from frequent market activities, which may translate to more accurate prediction # Factors scores are only available for the ones with fundamentals sorted_by_dollar_volume = sorted([x for x in coarse if x.has_fundamental_data], key=lambda x: x.dollar_volume, reverse=True) selected = [x.symbol for x in sorted_by_dollar_volume[:100]] return selected class KavoutCompositeFactorBundleAlphaModel(AlphaModel): def __init__(self) -> None: # A variable that control the time of rebalancing self.last_time = datetime.min def update(self, algorithm: QCAlgorithm, slice: Slice) -> List[Insight]: if self.last_time > algorithm.time: return [] # Trade only on the factor score data points = slice.Get(KavoutCompositeFactorBundle) for kvp in points: algorithm.log(f"Symbol: {kvp.Key} - Growth:{kvp.Value.growth} - Low Volatility: {kvp.Value.low_volatility} - Momentum: {kvp.Value.momentum}" f" - Quality: {kvp.Value.quality} - Value Factor: {kvp.Value.value_factor}") # Long the stocks with highest factor scores, which indicate higher return from various factors # Short the ones with lowest factor scores for lower return estimates sorted_by_score = sorted(points.items(), key=self.total_score) long_symbols = [x[0].underlying for x in sorted_by_score[-10:]] short_symbols = [x[0].underlying for x in sorted_by_score[:10]] insights = [] for symbol in long_symbols: insights.append(Insight.price(symbol, Expiry.END_OF_DAY, InsightDirection.UP)) for symbol in short_symbols: insights.append(Insight.price(symbol, Expiry.END_OF_DAY, InsightDirection.DOWN)) self.last_time = Expiry.END_OF_DAY(algorithm.time) return insights def on_securities_changed(self, algorithm: QCAlgorithm, changes: SecurityChanges) -> None: for security in changes.added_securities: # Requesting factor bundle data for trade signal generation kavout_composite_factor_bundle_symbol = algorithm.add_data(KavoutCompositeFactorBundle, security.symbol).symbol # Historical Data history = algorithm.history(kavout_composite_factor_bundle_symbol, 2, Resolution.DAILY) algorithm.debug(f"We got {len(history)} items from our history request") def total_score(self, value: Tuple[Symbol, KavoutCompositeFactorBundle]) -> float: # Return the total score to integrate overall likelihood to outcompete, take equal weighting for each factor value = value[1] return value.growth + value.low_volatility + value.momentum + value.quality + value.value_factor
public class KavoutCompositeFactorBundleAlgorithm : QCAlgorithm { public override void Initialize() { SetStartDate(2003, 1, 10); SetEndDate(2003, 1, 15); SetCash(100000); AddUniverse(MyCoarseFilterFunction); UniverseSettings.Resolution = Resolution.Minute; // Custom alpha model to emit insights based on factor bundle data AddAlpha(new KavoutCompositeFactorBundleAlphaModel()); // Invest in equal-size and dollar-neutral to evenly dissipate individual capital risk, avoid non-systematic risk, and better margin SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel()); SetExecution(new ImmediateExecutionModel()); } private IEnumerable<Symbol> MyCoarseFilterFunction(IEnumerable<CoarseFundamental> coarse) { // Filter for the highly traded stocks for more informed data from frequent market activities, which may translate to more accurate prediction // Factors scores are only available for the ones with fundamentals return (from c in coarse where c.HasFundamentalData orderby c.DollarVolume descending select c.Symbol).Take(100); } } public class KavoutCompositeFactorBundleAlphaModel: AlphaModel { // A variable that control the time of rebalancing public DateTime _time; public KavoutCompositeFactorBundleAlphaModel() { _time = DateTime.MinValue; } public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice slice) { if (_time > algorithm.Time) return new List<Insight>(); // Trade only on the factor score data var points = slice.Get<KavoutCompositeFactorBundle>(); foreach(var kvp in points) { algorithm.Log(@"Symbol: {kvp.Key} - Growth:{kvp.Value.Growth} - Low Volatility: {kvp.Value.LowVolatility} - Momentum: {kvp.Value.Momentum} - Quality: {kvp.Value.Quality} - Value Factor: {kvp.Value.ValueFactor}"); } // Long the stocks with highest factor scores, which indicate higher return from various factors // Short the ones with lowest factor scores for lower return estimates var sortedByScore = from s in points.Values orderby TotalScore(s) descending select s.Symbol.Underlying; var longSymbols = sortedByScore.Take(10).ToList(); var shortSymbols = sortedByScore.TakeLast(10).ToList(); var insights = new List<Insight>(); insights.AddRange(longSymbols.Select(symbol => new Insight(symbol, Expiry.EndOfDay, InsightType.Price, InsightDirection.Up))); insights.AddRange(shortSymbols.Select(symbol => new Insight(symbol, Expiry.EndOfDay, InsightType.Price, InsightDirection.Down))); _time = Expiry.EndOfDay(algorithm.Time); return insights; } public override void OnSecuritiesChanged(QCAlgorithm algorithm, SecurityChanges changes) { foreach(var security in changes.AddedSecurities) { // Requesting factor bundle data for trade signal generation var kavoutCompositeFactorBundleSymbol = algorithm.AddData<KavoutCompositeFactorBundle>(security.Symbol).Symbol; // Historical Data var history = algorithm.History(new[]{kavoutCompositeFactorBundleSymbol}, 60, Resolution.Daily); algorithm.Debug($"We got {history.Count()} items from our history request"); } } private decimal TotalScore(KavoutCompositeFactorBundle value) { // Return the total score to integrate overall likelihood to outcompete, take equal weighting for each factor return value.Growth + value.ValueFactor + value.Quality + value.Momentum + value.LowVolatility; } }