book
Checkout our new book! Hands on AI Trading with Python, QuantConnect, and AWS Learn More arrow

ExtractAlpha

True Beats

Introduction

The True Beats dataset by ExtractAlpha provides quantitative predictions of EPS and Revenues for US Equities. The data covers a dynamic universe of around 4,000-5,000 US-listed Equities on a daily average. The data starts in January 2000 and is delivered on a daily frequency. This dataset is created by incorporating the opinions of expert analysts, historical earnings, revenue trends for the company and its peers, and metrics on company earnings management.

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 True Beats 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 True Beats dataset:

from QuantConnect.DataSource import *

self.aapl = self.add_equity("AAPL", Resolution.DAILY).symbol
self.dataset_symbol = self.add_data(ExtractAlphaTrueBeats, self.aapl).symbol
using QuantConnect.DataSource;

_symbol = AddEquity("AAPL", Resolution.Daily).Symbol;
_datasetSymbol = AddData<ExtractAlphaTrueBeats>(_symbol).Symbol;

Data Summary

The following table describes the dataset properties:

PropertyValue
Start DateJanuary 2000
Asset CoverageOver 5,000 US Equities
Data DensitySparse
ResolutionDaily
TimezoneUTC

Requesting Data

To add True Beats 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 ExtractAlphaTrueBeatsDataAlgorithm(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(ExtractAlphaTrueBeats, self.aapl).symbol
public class ExtractAlphaTrueBeatsDataAlgorithm: 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<ExtractAlphaTrueBeats>(_symbol).Symbol;
    }
}

Accessing Data

To get the current True Beats 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} True beat at {slice.time}: {data_point.True_beat}")
public override void OnData(Slice slice)
{
    if (slice.ContainsKey(_datasetSymbol))
    {
        var dataPoint = slice[_datasetSymbol];
        Log($"{_datasetSymbol} True beat at {slice.Time}: {dataPoint.TrueBeat}");
    }
}

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(ExtractAlphaTrueBeats).items():
        self.log(f"{dataset_symbol} True beat at {slice.time}: {data_point.True_beat}")
public override void OnData(Slice slice)
{
    foreach (var kvp in slice.Get<ExtractAlphaTrueBeats>())
    {
        var datasetSymbol = kvp.Key;
        var dataPoint = kvp.Value;
        Log($"{datasetSymbol} True beat at {slice.Time}: {dataPoint.TrueBeat}");
    }
}

Historical Data

To get historical True Beats 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, flatten=True)

# Series
history_series = self.history(self.dataset_symbol, 100, Resolution.DAILY)

# Dataset objects
history_bars = self.history[ExtractAlphaTrueBeats](self.dataset_symbol, 100, Resolution.DAILY)
var history = History<ExtractAlphaTrueBeats>(_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 True Beats 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 True Beats dataset enables you to predict EPS and revenue of US-listed Equities for trading. Examples include the following strategies:

  • Finding surprise in EPS or revenue for sentiment/arbitrage trading
  • Stock or sector selections based on EPS or revenue predictions
  • Calculate expected return by valuation models based on EPS or revenue predictions (e.g. Black-Litterman)

Classic Algorithm Example

The following example algorithm creates a dynamic universe of the 100 most liquid US Equities. Each day, it then forms an equal-weighted dollar-neutral portfolio of the 10 best and 10 worst surprising companies on their financials.

from AlgorithmImports import *
from QuantConnect.DataSource import *

class ExtractAlphaTrueBeatsDataAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2019, 1, 1)
        self.set_end_date(2020, 1, 1)
        self.set_cash(100000)
        # A variable to 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]:
        # Select the stocks with highest dollar volume due to better informed information from more market activities
        # Only the ones with fundamental data are supported by True beats data
        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.time > self.time: return
        
        # Trade only based on the updated True beats data
        points = slice.Get(ExtractAlphaTrueBeats)
        if not points: return
        
        # Extract the True beats data (earning and revenue estimates) as trading signals
        True_beats = {point.Key: TrueBeat for point in points for TrueBeat in point.Value}

        # Long the ones with the highest earning and revenue estimates due to fundamental factor may bring stock price up
        # Short the lowest that predicted to bring stock price down
        sorted_by_True_beat = sorted(True_beats.items(), key=lambda x: x[1].True_beat)
        long_symbols = [x[0].underlying for x in sorted_by_True_beat[-10:]]
        short_symbols = [x[0].underlying for x in sorted_by_True_beat[:10]]
        
        # Liquidate the ones without a strong earning and revenue that support stock price direction
        for symbol in self.portfolio.Keys:
            if self.portfolio[symbol].invested \
                and symbol not in long_symbols \
                and symbol not in short_symbols:
                self.liquidate(symbol)
        
        # Invest equally and dollar-neutral to evenly dissipate capital risk and hedge systematic risk
        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 True beats data for trading signal generation
            extract_alpha_True_beats_symbol = self.add_data(ExtractAlphaTrueBeats, security.symbol).symbol
            
            # Historical Data
            history = self.history(extract_alpha_True_beats_symbol, 10, Resolution.DAILY)
            self.log(f"We got {len(history)} items from our history request for {security.symbol} ExtractAlpha True Beats data")
public class ExtractAlphaTrueBeatsDataAlgorithm : QCAlgorithm
{
            // A variable to control the time of rebalancing
    private DateTime _time = DateTime.MinValue;
    
    public override void Initialize()
    {
        SetStartDate(2021, 1, 1);
        SetEndDate(2021, 7, 1);
        SetCash(100000);
        
        AddUniverse(MyCoarseFilterFunction);
        UniverseSettings.Resolution = Resolution.Minute;
    }
    
    private IEnumerable<Symbol> MyCoarseFilterFunction(IEnumerable<CoarseFundamental> coarse)
    {
                    // Select the stocks with highest dollar volume due to better informed information from more market activities
                    // Only the ones with fundamental data are supported by True beats data
        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 based on the updated True beats data
        var points = slice.Get<ExtractAlphaTrueBeats>();
        if (points.IsNullOrEmpty()) return;

        // Extract the True beats data (earning and revenue estimates) as trading signals
        List<ExtractAlphaTrueBeat> TrueBeats = new List<ExtractAlphaTrueBeat>(
            points.SelectMany(point => point.Value.Select(x => (ExtractAlphaTrueBeat)x))
        );

                    // Long the ones with the highest earning and revenue estimates due to fundamental factor may bring stock price up
                    // Short the lowest that predicted to bring stock price down
        var sortedByTrueBeat = from TrueBeat in TrueBeats
                                where (TrueBeat.TrueBeat != None)
                                orderby TrueBeat.TrueBeat descending
                                select TrueBeat.Symbol.Underlying;

        var longSymbols = sortedByTrueBeat.Take(10).ToList();
        var shortSymbols = sortedByTrueBeat.TakeLast(10).ToList();

        // Liquidate the ones without a strong earning and revenue that support stock price direction
        foreach (var kvp in Portfolio)
        {
            var symbol = kvp.Key;
            if (kvp.Value.Invested && 
            !longSymbols.Contains(symbol) && 
            !shortSymbols.Contains(symbol))
            {
                Liquidate(symbol);
            }
        }

        // Invest equally and dollar-neutral to evenly dissipate capital risk and hedge systematic risk
        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 True beats data for trading signal generation
            var extractAlphaTrueBeatsSymbol = AddData<ExtractAlphaTrueBeats>(security.Symbol).Symbol;
            
            // Historical Data
            var history = History(new[]{extractAlphaTrueBeatsSymbol}, 10, Resolution.Daily);
            Log($"We got {history.Count()} items from our history request for {security.Symbol} ExtractAlpha True Beats data");
        }
    }
}

Framework Algorithm Example

The following example algorithm creates a dynamic universe of the 100 most liquid US Equities. Each day, it then forms an equal-weighted dollar-neutral portfolio of the 10 best and 10 worst surprising companies on their financials.

from AlgorithmImports import *
from QuantConnect.DataSource import *

class ExtractAlphaTrueBeatsDataAlgorithm(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 to trade based on True beats data signals
        self.add_alpha(ExtractAlphaTrueBeatsAlphaModel())
        
        # 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 the stocks with highest dollar volume due to better informed information from more market activities
        # Only the ones with fundamental data are supported by True beats data
        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 ExtractAlphaTrueBeatsAlphaModel(AlphaModel):
    
    def __init__(self) -> None:
        # A variable to 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 based on the updated True beats data
        points = slice.Get(ExtractAlphaTrueBeats)
        if not points: return []

        # Extract the True beats data (earning and revenue estimates) as trading signals
        True_beats = {point.Key: TrueBeat for point in points for TrueBeat in point.Value}

        # Long the ones with the highest earning and revenue estimates due to fundamental factor may bring stock price up
        # Short the lowest that predicted to bring stock price down
        sorted_by_True_beat = sorted(True_beats.items(), key=lambda x: x[1].True_beat)
        long_symbols = [x[0].underlying for x in sorted_by_True_beat[-10:]]
        short_symbols = [x[0].underlying for x in sorted_by_True_beat[: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 True beats data for trading signal generation
            extract_alpha_True_beats_symbol = algorithm.add_data(ExtractAlphaTrueBeats, security.symbol).symbol
            
            # Historical Data
            history = algorithm.history(extract_alpha_True_beats_symbol, 10, Resolution.DAILY)
            algorithm.log(f"We got {len(history)} items from our history request for {security.symbol} ExtractAlpha True Beats data")
public class ExtractAlphaTrueBeatsFrameworkAlgorithm : QCAlgorithm
{
    public override void Initialize()
    {
        SetStartDate(2021, 1, 1);
        SetEndDate(2021, 7, 1);
        SetCash(100000);
        
        AddUniverse(MyCoarseFilterFunction);
        UniverseSettings.Resolution = Resolution.Minute;

            // Custom alpha model to trade based on True beats data signals
        AddAlpha(new ExtractAlphaTrueBeatsAlphaModel());

        // 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 the stocks with highest dollar volume due to better informed information from more market activities
                    // Only the ones with fundamental data are supported by True beats data
        return (from c in coarse
                where c.HasFundamentalData
                orderby c.DollarVolume descending
                select c.Symbol).Take(100);
    }
}

public class ExtractAlphaTrueBeatsAlphaModel: AlphaModel
{
            // A variable to control the time of rebalancing
    private DateTime _time;
    
    public ExtractAlphaTrueBeatsAlphaModel()
    {
        _time = DateTime.MinValue;
    }
    
    public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice slice)
    {
        if (_time > algorithm.Time) return new List<Insight>();
        
        // Trade only based on the updated True beats data
        var points = slice.Get<ExtractAlphaTrueBeats>();
        if (points.IsNullOrEmpty()) return new List<Insight>();
        
                    // Extract the True beats data (earning and revenue estimates) as trading signals
        List<ExtractAlphaTrueBeat> TrueBeats = new List<ExtractAlphaTrueBeat>(
            points.SelectMany(point => point.Value.Select(x => (ExtractAlphaTrueBeat)x))
        );

        // Long the ones with the highest earning and revenue estimates due to fundamental factor may bring stock price up
                    // Short the lowest that predicted to bring stock price down
        var sortedByTrueBeat = from s in TrueBeats
                        where (s.TrueBeat != None)
                        orderby s.TrueBeat descending
                        select s.Symbol.Underlying;
        var longSymbols = sortedByTrueBeat.Take(10).ToList();
        var shortSymbols = sortedByTrueBeat.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 True beats data for trading signal generation
            var extractAlphaTrueBeatsSymbol = algorithm.AddData<ExtractAlphaTrueBeats>(security.Symbol).Symbol;
            
            // Historical Data
            var history = algorithm.History(new[]{extractAlphaTrueBeatsSymbol}, 10, Resolution.Daily);
            algorithm.Debug($"We got {history.Count()} items from our history request");
        }
    }
}

Data Point Attributes

The True Beats dataset provides ExtractAlphaTrueBeats and ExtractAlphaTrueBeat objects.

ExtractAlphaTrueBeats

ExtractAlphaTrueBeats objects have the following attributes:

ExtractAlphaTrueBeat

ExtractAlphaTrueBeat objects have the following attributes:

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: