Equity
Alternative Data Universes
Examples
The following examples demonstrate some common alternative data universes.
Example 1: Brain Sentiment Universe
The following algorithm uses the Brain Sentiment Indicator dataset to create a universe of US Equities that have some article mentions and the most positive sentiment:
public class BrainSentimentUniverseAlgorithm : QCAlgorithm { public override void Initialize() { AddUniverse<BrainSentimentIndicatorUniverse>( altData => altData.OfType<BrainSentimentIndicatorUniverse>() // Filter out assets with `null` factor values. .Where(x => x.TotalArticleMentions7Days.HasValue && x.Sentiment7Days.HasValue) // Select assets with some mentions and the greatest sentiment. .Where(x => x.TotalArticleMentions7Days > 0) .OrderByDescending(x => x.Sentiment7Days) .Take(20) // Return the symbols for the selected assets. .Select(x => x.Symbol) ); } }
class BrainSentimentUniverseAlgorithm(QCAlgorithm): def initialize(self): self.add_universe(BrainSentimentIndicatorUniverse, self._select_assets) def _select_assets(self, alt_data: List[BrainSentimentIndicatorUniverse]) -> List[Symbol]: # Filter out assets with `None` factor values. alt_data = [ x for x in alt_data if (x.total_article_mentions_7_days is not None and x.sentiment_7_days is not None) ] # Select assets with some mentions and the greatest sentiment. selected = sorted( [x for x in alt_data if x.total_article_mentions_7_days > 0], key=lambda x: x.sentiment_7_days )[-20:] # Return the symbols for the selected assets. return [x.symbol for x in selected]
Example 2: Insiders Trading Universe
Insiders have more information to evaluate the overall prospect of the company, so following their trades can be useful. The following algorithm uses the Insider Trading to create a universe of US Equities that insiders have recently purchased:
public class InsiderTradingUniverseAlgorithm : QCAlgorithm { public override void Initialize() { AddUniverse<QuiverInsiderTradingUniverse>(altData => { // Select assets that insiders have purchased. return from d in altData.OfType<QuiverInsiderTradingUniverse>() where d.Shares != null select d.Symbol; }); } }
class InsiderTradingUniverseAlgorithm(QCAlgorithm): def initialize(self): # Select a universe of assets that insiders have bought. self.add_universe( QuiverInsiderTradingUniverse, lambda alt_data: [x.symbol for x in alt_data if x.shares] )
Example 3: Share Buyback Universe
The following algorithm uses the Corporate Buybacks dataset to create a universe of US Equities that have announced an upcoming share buyback program:
public class InsiderBuyBackUniverseAlgorithm : QCAlgorithm { public override void Initialize() { // Select all assets that have announced a buyback. AddUniverse<SmartInsiderIntentionUniverse>(); } }
class InsiderBuyBackUniverseAlgorithm(QCAlgorithm): def initialize(self): # Select all assets that have announced a buyback. self.add_universe(SmartInsiderIntentionUniverse)