ExtractAlpha
Cross Asset Model
Introduction
The Cross Asset Model by ExtractAlpha provides stock scoring values based on the trading activity in the Options market. Since the Options market has a higher proportion of institutional traders than the Equities market, the Options market is composed of investors who are more informed and information-driven on average. The data covers a dynamic universe of over 3,000 US Equities, starts in July 2005, and is delivered on a daily frequency. This dataset is created by feature engineering on the Options market put-call spread, volatility skewness, and volume.
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 Cross Asset Model dataset, including CLI commands and pricing, see the dataset listing.
About the Provider
ExtractAlpha was founded by Vinesh Jha in 2013 with the goal of providing alternative data for investors. ExtractAlpha's rigorously researched data sets and quantitative stock selection models leverage unique sources and analytical techniques, allowing users to gain an investment edge.
Getting Started
The following snippet demonstrates how to request data from the Cross Asset Model dataset:
from QuantConnect.DataSource import * self.aapl = self.add_equity("AAPL", Resolution.DAILY).symbol self.dataset_symbol = self.add_data(ExtractAlphaCrossAssetModel, self.aapl).symbol
using QuantConnect.DataSource; _symbol = AddEquity("AAPL", Resolution.Daily).Symbol; _datasetSymbol = AddData<ExtractAlphaCrossAssetModel>(_symbol).Symbol;
Requesting Data
To add Cross Asset Model 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 ExtractAlphaCrossAssetModelDataAlgorithm(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(ExtractAlphaCrossAssetModel, self.aapl).symbol
public class ExtractAlphaCrossAssetModelDataAlgorithm : 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<ExtractAlphaCrossAssetModel>(_symbol).Symbol; } }
Accessing Data
To get the current Cross Asset Model 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} score at {slice.time}: {data_point.score}")
public override void OnData(Slice slice) { if (slice.ContainsKey(_datasetSymbol)) { var dataPoint = slice[_datasetSymbol]; Log($"{_datasetSymbol} score at {slice.Time}: {dataPoint.Score}"); } }
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(ExtractAlphaCrossAssetModel).items(): self.log(f"{dataset_symbol} score at {slice.time}: {data_point.score}")
public override void OnData(Slice slice) { foreach (var kvp in slice.Get<ExtractAlphaCrossAssetModel>()) { var datasetSymbol = kvp.Key; var dataPoint = kvp.Value; Log($"{datasetSymbol} score at {slice.Time}: {dataPoint.Score}"); } }
Historical Data
To get historical Cross Asset Model 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[ExtractAlphaCrossAssetModel](self.dataset_symbol, 100, Resolution.DAILY)
var history = History<ExtractAlphaCrossAssetModel>(_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 Cross Asset Model 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 Cross Asset Model dataset by ExtractAlpha enables you to utilize Options market information to extract alpha. Examples include the following strategies:
- Predicting price and volatility changes in Equities.
- Signaling arbitrage opportunities between Options and underlying assets.
- Using it as a stock selection indicator.
Classic Algorithm Example
The following example algorithm creates a dynamic universe of the 100 most liquid US Equities. Each day, the algorithm forms an 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 ExtractAlphaCrossAssetModelAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2019, 1, 1) self.set_end_date(2019, 12, 31) self.set_cash(100000) # A variable to control the rebalance time self.last_time = datetime.min self.add_universe(self.my_coarse_filter_function) self.dataset_symbol_by_symbol = {} self.points = {} def my_coarse_filter_function(self, coarse: List[CoarseFundamental]) -> List[Symbol]: # Select non-penny stocks with highest dollar volume due to better informed information from more market activities # Only the ones with fundamental data are supported by cross asset model data sorted_by_dollar_volume = sorted([x for x in coarse if x.has_fundamental_data and x.price > 4], 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 based on corss asset model data points = slice.Get(ExtractAlphaCrossAssetModel) if points: self.points = points # Avoid too frequent trades if slice.time.time() < time(10): return # Long the ones with the highest return estimates based on option trade data # Short the lowest return ones sorted_by_score = sorted([x for x in self.points.items() if x[1].score != None], key=lambda x: x[1].score, reverse=True) 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 ones without a strong trading signal # Invest equally and dollar-neutral to evenly dissipate capital risk and hedge systematic risk portfolio_targets = [] for symbol, security_holding in self.portfolio.items(): weight = 0 if symbol in long_symbols: weight = 0.05 elif symbol in short_symbols: weight = -0.05 elif not security_holding.invested: continue portfolio_targets.append(PortfolioTarget(symbol, weight)) self.set_holdings(portfolio_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 cross asset model data for trading signal generation self.dataset_symbol_by_symbol[security.symbol] = self.add_data(ExtractAlphaCrossAssetModel, security.symbol).symbol for security in changes.removed_securities: dataset_symbol = self.dataset_symbol_by_symbol.pop(security.symbol, None) if dataset_symbol: self.remove_security(dataset_symbol)
public class ExtractAlphaCrossAssetModelAlgorithm : QCAlgorithm { // A variable to control the rebalance time private DateTime _time = DateTime.MinValue; private Dictionary<Symbol, Symbol> _datasetSymbolBySymbol = new Dictionary<Symbol, Symbol>(); private DataDictionary<ExtractAlphaCrossAssetModel> _points = new DataDictionary<ExtractAlphaCrossAssetModel>(); public override void Initialize() { SetStartDate(2019, 1, 1); SetEndDate(2019, 12, 31); SetCash(100000); AddUniverse(MyCoarseFilterFunction); } private IEnumerable<Symbol> MyCoarseFilterFunction(IEnumerable<CoarseFundamental> coarse) { // Select non-penny stocks with highest dollar volume due to better informed information from more market activities // Only the ones with fundamental data are supported by cross asset model data return (from c in coarse where c.HasFundamentalData && c.Price > 4 orderby c.DollarVolume descending select c.Symbol).Take(100); } public override void OnData(Slice slice) { if (_time > Time) return; // Trade only based on corss asset model data var points = slice.Get<ExtractAlphaCrossAssetModel>(); if (points.Count > 0) { _points = points; } // Avoid too frequent trades if (Time.TimeOfDay < TimeSpan.FromHours(10)) { return; } // Long the ones with the highest return estimates based on option trade data // Short the lowest return ones var sortedByScore = from s in _points.Values where (s.Score != None) orderby s.Score descending select s.Symbol.Underlying; var longSymbols = sortedByScore.Take(10).ToList(); var shortSymbols = sortedByScore.TakeLast(10).ToList(); // Liquidate the ones without a strong trading signal // Invest equally and dollar-neutral to evenly dissipate capital risk and hedge systematic risk var portfolioTargets = new List<PortfolioTarget>(); foreach (var kvp in Portfolio) { var symbol = kvp.Key; var securityHolding = kvp.Value; var weight = 0.0m; if (longSymbols.Contains(symbol)) { weight = 0.05m; } else if (shortSymbols.Contains(symbol)) { weight = -0.05m; } else if (!securityHolding.Invested) { continue; } portfolioTargets.Add(new PortfolioTarget(symbol, weight)); } SetHoldings(portfolioTargets); _time = Expiry.EndOfDay(Time); } public override void OnSecuritiesChanged(SecurityChanges changes) { foreach(var security in changes.AddedSecurities) { // Requesting cross asset model data for trading signal generation _datasetSymbolBySymbol[security.Symbol] = AddData<ExtractAlphaCrossAssetModel>(security.Symbol).Symbol; } foreach(var security in changes.RemovedSecurities) { Symbol datasetSymbol; if (_datasetSymbolBySymbol.TryGetValue(security.Symbol, out datasetSymbol)) { RemoveSecurity(datasetSymbol); _datasetSymbolBySymbol.Remove(security.Symbol); } } } }
Framework Algorithm Example
The following example algorithm creates a dynamic universe of the 100 most liquid US Equities. Each day, the algorithm forms an 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 ExtractAlphaCrossAssetModelAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2019, 1, 1) self.set_end_date(2020, 1, 1) self.set_cash(100000) self.add_universe(self.my_coarse_filter_function) self.universe_settings.resolution = Resolution.MINUTE # Custom alpha model emits insights based on cross asset model data self.add_alpha(ExtractAlphaCrossAssetModelAlphaModel()) # Invest equally and dollar-neutral to evenly dissipate capital risk and hedge systematic risk self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel()) self.set_execution(ImmediateExecutionModel()) def my_coarse_filter_function(self, coarse: List[CoarseFundamental]) -> List[Symbol]: # Select non-penny stocks with highest dollar volume due to better informed information from more market activities # Only the ones with fundamental data are supported by cross asset model data sorted_by_dollar_volume = sorted([x for x in coarse if x.has_fundamental_data and x.price > 4], key=lambda x: x.dollar_volume, reverse=True) selected = [x.symbol for x in sorted_by_dollar_volume[:100]] return selected class ExtractAlphaCrossAssetModelAlphaModel(AlphaModel): def __init__(self) -> None: # A variable to control the rebalance time self.last_time = datetime.min def update(self, algorithm: QCAlgorithm, slice: Slice) -> List[Insight]: if self.last_time > algorithm.time: return [] # Trade only based on corss asset model data points = slice.Get(ExtractAlphaCrossAssetModel) # Long the ones with the highest return estimates based on option trade data # Short the lowest return ones sorted_by_score = sorted([x for x in points.items() if x[1].score], key=lambda x: x[1].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 cross asset model data for trading signal generation extract_alpha_cross_asset_model_symbol = algorithm.add_data(ExtractAlphaCrossAssetModel, security.symbol).symbol # Historical Data history = algorithm.history(extract_alpha_cross_asset_model_symbol , 60, Resolution.DAILY) algorithm.debug(f"We got {len(history)} items from our history request")
public class ExtractAlphaCrossAssetModelAlgorithm : QCAlgorithm { public override void Initialize() { SetStartDate(2019, 1, 1); SetEndDate(2021, 1, 1); SetCash(100000); AddUniverse(MyCoarseFilterFunction); UniverseSettings.Resolution = Resolution.Minute; // Custom alpha model emits insights based on cross asset model data AddAlpha(new ExtractAlphaCrossAssetModelAlphaModel()); // Invest equally and dollar-neutral to evenly dissipate capital risk and hedge systematic risk SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel()); SetExecution(new ImmediateExecutionModel()); } private IEnumerable<Symbol> MyCoarseFilterFunction(IEnumerable<CoarseFundamental> coarse) { // Select non-penny stocks with highest dollar volume due to better informed information from more market activities // Only the ones with fundamental data are supported by cross asset model data return (from c in coarse where c.HasFundamentalData && c.Price > 4 orderby c.DollarVolume descending select c.Symbol).Take(100); } } public class ExtractAlphaCrossAssetModelAlphaModel: AlphaModel { // A variable to control the rebalance time public DateTime _time; public ExtractAlphaCrossAssetModelAlphaModel() { _time = DateTime.MinValue; } public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice slice) { if (_time > algorithm.Time) return new List<Insight>(); // Trade only based on corss asset model data var points = slice.Get<ExtractAlphaCrossAssetModel>(); // Long the ones with the highest return estimates based on option trade data // Short the lowest return ones var sortedByScore = from s in points.Values where (s.Score != None) orderby s.Score 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 cross asset model data for trading signal generation var extractAlphaCrossAssetModelSymbol = algorithm.AddData<ExtractAlphaCrossAssetModel>(security.Symbol).Symbol; // Historical Data var history = algorithm.History(new[]{extractAlphaCrossAssetModelSymbol}, 60, Resolution.Daily); algorithm.Debug($"We got {history.Count()} items from our history request"); } } }