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:
self.aapl = self.add_equity("AAPL", Resolution.DAILY).symbol
self.dataset_symbol = self.add_data(KavoutCompositeFactorBundle, self.aapl).symbol _symbol = AddEquity("AAPL", Resolution.Daily).Symbol;
_datasetSymbol = AddData<KavoutCompositeFactorBundle>(_symbol).Symbol;
Requesting Data
To add Composite Factor Bundle 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 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 Getget 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 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[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 RemoveSecurityremove_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 *
class KavoutCompositeFactorBundleAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2024, 9, 1)
self.set_end_date(2024, 12, 31)
self.set_cash(100000)
self.add_universe(self._select_assets)
def _select_assets(self, fundamentals: List[Fundamental]) -> 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 fundamentals if x.has_fundamental_data],
key=lambda x: x.dollar_volume
)
return [x.symbol for x in sorted_by_dollar_volume[-100:]]
def on_data(self, slice: Slice) -> None:
# Get the current data from the Kavout dataset.
points = slice.get(KavoutCompositeFactorBundle)
## Demonstrate how to iterate through the data and access its members:
#for dataset_symbol, factors in points.items():
# self.quit(
# f"{self.time} -- "
# f"Asset Symbol: {dataset_symbol.underlying}; "
# f"Growth factor: {factors.growth} "
# )
# Drop factors for assets that have no price.
points = [x for x in points.items() if self.securities[x[0].underlying].price]
# Only rebalance when there are new Kavout factors.
if not points:
return
# 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, 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]]
# 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, True)
def on_securities_changed(self, changes: SecurityChanges) -> None:
for security in changes.added_securities:
# Requesting factor bundle data for trade signal generation
security.kavout_symbol = self.add_data(KavoutCompositeFactorBundle, security.symbol).symbol
# Historical Data
history = self.history(security.kavout_symbol, 2, Resolution.DAILY)
for security in changes.removed_securities:
# Remove the factor bundle data for this asset when it leaves the universe.
self.remove_security(security.kavout_symbol)
def _total_score(self, value) -> 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(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
AddUniverse(SelectAssets);
}
private IEnumerable<Symbol> SelectAssets(IEnumerable<Fundamental> fundamentals)
{
// 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 f in fundamentals
where f.HasFundamentalData
orderby f.DollarVolume descending
select f.Symbol).Take(100);
}
public override void OnData(Slice slice)
{
// Get the current data from the Kavout dataset.
var points = slice.Get<KavoutCompositeFactorBundle>()
// Drop factors for assets that have no price.
.Where(kvp => Securities[kvp.Key.Underlying].Price != 0);
//// Demonstrate how to iterate through the data and access its members:
//foreach(var kvp in points)
//{
// var datasetSymbol = kvp.Key;
// var factors = kvp.Value;
// Quit(
// $"{Time} -- " +
// $"Asset Symbol: {datasetSymbol.Underlying}; " +
// $"Growth factor: {factors.Growth}"
// );
//}
// Only rebalance when there are new Kavout factors.
if (points.Count() == 0)
{
return;
}
// 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 = points.OrderBy(kvp => TotalScore(kvp.Value))
.Select(kvp => kvp.Key.Underlying);
var longSymbols = sortedByScore.TakeLast(10);
var shortSymbols = sortedByScore.Take(10);
// 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, true);
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach(dynamic security in changes.AddedSecurities)
{
// Requesting factor bundle data for trade signal generation
security.kavoutSymbol = AddData<KavoutCompositeFactorBundle>(security.Symbol).Symbol;
// Historical Data
var history = History(security.kavoutSymbol, 60, Resolution.Daily);
}
foreach (dynamic security in changes.RemovedSecurities)
{
// Remove the factor bundle data for this asset when it leaves the universe.
RemoveSecurity(security.kavoutSymbol);
}
}
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 *
class KavoutCompositeFactorBundleAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2024, 9, 1)
self.set_end_date(2024, 12, 31)
self.set_cash(100000)
self.add_universe_selection(LiquidEquitiesUniverseSelectionModel())
# 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())
class LiquidEquitiesUniverseSelectionModel(FundamentalUniverseSelectionModel):
def select(self, algorithm: QCAlgorithm, fundamentals: List[Fundamental]) -> 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 fundamentals if x.has_fundamental_data],
key=lambda x: x.dollar_volume
)
return [x.symbol for x in sorted_by_dollar_volume[-100:]]
class KavoutCompositeFactorBundleAlphaModel(AlphaModel):
def update(self, algorithm: QCAlgorithm, slice: Slice) -> List[Insight]:
# Get the current data from the Kavout dataset.
points = slice.get(KavoutCompositeFactorBundle)
## Demonstrate how to iterate through the data and access its members:
#for dataset_symbol, factors in points.items():
# algorithm.quit(
# f"{algorithm.time} -- "
# f"Asset Symbol: {dataset_symbol.underlying}; "
# f"Growth factor: {factors.growth} "
# )
# Drop factors for assets that have no price.
points = [x for x in points.items() if algorithm.securities[x[0].underlying].price]
# Only rebalance when there are new Kavout factors.
if not points:
return []
# 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, 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))
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
security.kavout_symbol = algorithm.add_data(KavoutCompositeFactorBundle, security.symbol).symbol
# Historical Data
history = algorithm.history(security.kavout_symbol, 10, Resolution.DAILY)
for security in changes.removed_securities:
# Remove the factor bundle data for this asset when it leaves the universe.
algorithm.remove_security(security.kavout_symbol)
def _total_score(self, value) -> 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(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
AddUniverseSelection(new LiquidEquitiesUniverseSelectionModel());
// 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());
}
}
public class LiquidEquitiesUniverseSelectionModel : FundamentalUniverseSelectionModel
{
public override IEnumerable<Symbol> Select(QCAlgorithm algorithm, IEnumerable<Fundamental> fundamentals)
{
// 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 f in fundamentals
where f.HasFundamentalData
orderby f.DollarVolume descending
select f.Symbol).Take(100);
}
}
public class KavoutCompositeFactorBundleAlphaModel: AlphaModel
{
public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice slice)
{
// Get the current data from the Kavout dataset.
var points = slice.Get<KavoutCompositeFactorBundle>()
// Drop factors for assets that have no price.
.Where(kvp => algorithm.Securities[kvp.Key.Underlying].Price != 0);
//// Demonstrate how to iterate through the data and access its members:
//foreach(var kvp in points)
//{
// var datasetSymbol = kvp.Key;
// var factors = kvp.Value;
// algorithm.Quit(
// $"{algorithm.Time} -- " +
// $"Asset Symbol: {datasetSymbol.Underlying}; " +
// $"Growth factor: {factors.Growth}"
// );
//}
// Only rebalance when there are new Kavout factors.
if (points.Count() == 0)
{
return new List<Insight>();
}
// 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 = points.OrderBy(kvp => TotalScore(kvp.Value))
.Select(kvp => kvp.Key.Underlying);
var longSymbols = sortedByScore.TakeLast(10);
var shortSymbols = sortedByScore.Take(10);
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)));
return insights;
}
public override void OnSecuritiesChanged(QCAlgorithm algorithm, SecurityChanges changes)
{
foreach(dynamic security in changes.AddedSecurities)
{
// Requesting factor bundle data for trade signal generation
security.kavoutSymbol = algorithm.AddData<KavoutCompositeFactorBundle>(security.Symbol).Symbol;
// Historical Data
var history = algorithm.History(security.kavoutSymbol, 10, Resolution.Daily);
}
foreach (dynamic security in changes.RemovedSecurities)
{
// Remove the factor bundle data for this asset when it leaves the universe.
algorithm.RemoveSecurity(security.kavoutSymbol);
}
}
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;
}
}