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:

self.aapl = self.add_equity("AAPL", Resolution.DAILY).symbol
self.dataset_symbol = self.add_data(ExtractAlphaTrueBeats, self.aapl).symbol
_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 companies based on their predicted earnings per share.

from AlgorithmImports import *

class ExtractAlphaTrueBeatsDataAlgorithm(QCAlgorithm):

    _true_beats = None

    def initialize(self) -> None:
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        self.set_cash(100_000)
        # Seed the price of each asset with its last known price to avoid trading errors.
        self.set_security_initializer(
            BrokerageModelSecurityInitializer(
                self.brokerage_model, 
                FuncSecuritySeeder(self.get_last_known_prices)
            )
        )
        # Add a universe that runs at the start of each month.
        spy = Symbol.create('SPY', SecurityType.EQUITY, Market.USA)
        date_rule = self.date_rules.month_start(spy)
        self.universe_settings.schedule.on(date_rule)
        self.add_universe(self._select_assets)
        # Add a Scheduled Event to rebalance the portfolio at the start of each month.
        self.schedule.on(date_rule, self.time_rules.before_market_close(spy, 30), self._rebalance)
        
    def _select_assets(self, coarse: List[Fundamental]) -> 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
        )
        return [x.symbol for x in sorted_by_dollar_volume[-100:]]

    def on_data(self, slice: Slice) -> None:
        # Get the current data from the true beats dataset.
        points = slice.get(ExtractAlphaTrueBeats)
        ## Demonstrate how to iterate through the data and access its members:
        #for dataset_symbol, true_beats in points.items():
        #    for true_beat in true_beats:
        #        self.quit(
        #            f"{self.time} -- "
        #            f"Asset Symbol: {dataset_symbol.underlying}; " 
        #            f"Fiscal Year: {true_beat.fiscal_period.fiscal_year} "
        #            f"Fiscal Quarter: {true_beat.fiscal_period.fiscal_quarter} "
        #            f"True Beat: {true_beat.true_beat} "
        #        )
        if points: 
            self._true_beats = points
    
    def _rebalance(self):
        eps_prediction_by_symbol = {}
        for dataset_symbol, true_beats in self._true_beats.items():
            # Select the subset of TrueBeat objects that have the EPS earnings metric, 
            # a value for the fiscal year, and a value for the fiscal quarter.
            true_beats = [
                tb for tb in true_beats 
                if (tb.earnings_metric == ExtractAlphaTrueBeatEarningsMetric.EPS and
                    tb.fiscal_period.fiscal_quarter)
            ]
            if not true_beats:
                continue
            # Select the TrueBeat object of the closest fiscal quarter.
            eps_prediction_by_symbol[dataset_symbol.underlying] = sorted(
                true_beats, 
                key=lambda tb: (tb.fiscal_period.fiscal_year, tb.fiscal_period.fiscal_quarter)
            )[0].true_beat

        # 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
        # Invest equally and dollar-neutral to evenly dissipate capital risk and hedge systematic risk
        sorted_by_eps_prediction = sorted(eps_prediction_by_symbol.items(), key=lambda kvp: kvp[1])
        long_targets = [PortfolioTarget(symbol, 0.05) for symbol, _ in sorted_by_eps_prediction[-10:]]
        short_targets = [PortfolioTarget(symbol, -0.05) for symbol, _ in sorted_by_eps_prediction[:10]]
        self.set_holdings(long_targets + short_targets, True)
        
    def on_securities_changed(self, changes: SecurityChanges) -> None:
        for security in changes.added_securities:
            # Requesting true beats data for trading signal generation
            security.true_beats = self.add_data(ExtractAlphaTrueBeats, security.symbol).symbol
            # Historical Data
            history = self.history(security.true_beats, 10, Resolution.DAILY, flatten=True)
        for security in changes.removed_securities:
            # Remove the true beats data for this asset when it leaves the universe.
            self.remove_security(security.true_beats)
public class ExtractAlphaTrueBeatsDataAlgorithm : QCAlgorithm
{
    private DataDictionary<ExtractAlphaTrueBeats> _trueBeats;
    
    public override void Initialize()
    {
        SetStartDate(2024, 9, 1);
        SetEndDate(2024, 12, 31);
        SetCash(100000);
        // Seed the price of each asset with its last known price to avoid trading errors.
        SetSecurityInitializer(
            new BrokerageModelSecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices))
        );
        // Add a universe that runs at the start of each month.
        var spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
        var dateRule = DateRules.MonthStart(spy);
        UniverseSettings.Schedule.On(dateRule);
        AddUniverse(SelectAssets);
        // Add a Scheduled Event to rebalance the portfolio at the start of each month.
        Schedule.On(dateRule, TimeRules.BeforeMarketClose(spy, 30), Rebalance);
    }
    
    private IEnumerable<Symbol> SelectAssets(IEnumerable<Fundamental> 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)
    {        
        // Get the current data from the true beats dataset.
        var points = slice.Get<ExtractAlphaTrueBeats>();
        if (!points.IsNullOrEmpty())
        {
            _trueBeats = points;
        }
    }

    public void Rebalance()
    {
        var epsPredictionBySymbol = new Dictionary<Symbol, decimal>();
        foreach (var kvp in _trueBeats)
        {
            var datasetSymbol = kvp.Key;
            // Select the subset of TrueBeat objects that have the EPS earnings metric, 
            // a value for the fiscal year, and a value for the fiscal quarter.
            var trueBeats = kvp.Value
                .Select(tb => (ExtractAlphaTrueBeat)tb)
                .Where(tb =>
                    tb.EarningsMetric == ExtractAlphaTrueBeatEarningsMetric.EPS &&
                    tb.FiscalPeriod.FiscalQuarter != null
                )
                .OrderBy(tb => tb.FiscalPeriod.FiscalYear)
                .ThenBy(tb => tb.FiscalPeriod.FiscalQuarter)
                .ToList();
            if (trueBeats.Count == 0) 
                continue;
            // Select the TrueBeat object of the closest fiscal quarter.
            epsPredictionBySymbol[datasetSymbol.Underlying] = trueBeats.First().TrueBeat;
        }

        // 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
        // Invest equally and dollar-neutral to evenly dissipate capital risk and hedge systematic risk
        var sortedByEpsPrediction = epsPredictionBySymbol.OrderBy(kvp => kvp.Value).ToList();
        var shortTargets = sortedByEpsPrediction.Take(10).Select(kvp => new PortfolioTarget(kvp.Key, -0.05m));
        var longTargets = sortedByEpsPrediction.TakeLast(10).Select(kvp => new PortfolioTarget(kvp.Key, 0.05m));
        SetHoldings(longTargets.Concat(shortTargets).ToList(), true);
    }
    
    public override void OnSecuritiesChanged(SecurityChanges changes)
    {
        foreach(dynamic security in changes.AddedSecurities)
        {
            // Requesting true beats data for trading signal generation
            security.TrueBeats = AddData<ExtractAlphaTrueBeats>(security.Symbol).Symbol;
            // Historical Data
            var history = History(security.TrueBeats, 10, Resolution.Daily);
        }
        foreach (dynamic security in changes.RemovedSecurities)
        {
            // Remove the true beats data for this asset when it leaves the universe.
            RemoveSecurity(security.TrueBeats);
        }
    }
}

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 companies based on their predicted earnings per share.

from AlgorithmImports import *

class ExtractAlphaTrueBeatsDataAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        self.set_cash(100_000)
        # Seed the price of each asset with its last known price to avoid trading errors.
        self.set_security_initializer(
            BrokerageModelSecurityInitializer(
                self.brokerage_model, 
                FuncSecuritySeeder(self.get_last_known_prices)
            )
        )
        # Add a universe that runs at the start of each month.
        spy = Symbol.create('SPY', SecurityType.EQUITY, Market.USA)
        date_rule = self.date_rules.month_start(spy)
        self.universe_settings.schedule.on(date_rule)
        self.add_universe_selection(LiquidEquitiesUniverseSelectionModel())
        # 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())


class LiquidEquitiesUniverseSelectionModel(FundamentalUniverseSelectionModel):

    def select(self, algorithm: QCAlgorithm, fundamentals: List[Fundamental]) -> 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 true beats data
        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 ExtractAlphaTrueBeatsAlphaModel(AlphaModel):

    _month = -1
    _insights = []

    def update(self, algorithm: QCAlgorithm, slice: Slice) -> List[Insight]:
        # Rebalance at the start of each month.
        if self._month == algorithm.time.month: 
            return []
        # Trade only based on the updated true beats data
        points = slice.get(ExtractAlphaTrueBeats)
        ## Demonstrate how to iterate through the data and access its members:
        #for dataset_symbol, true_beats in points.items():
        #    for true_beat in true_beats:
        #        algorithm.quit(
        #            f"{algorithm.time} -- "
        #            f"Asset Symbol: {dataset_symbol.underlying}; " 
        #            f"Fiscal Year: {true_beat.fiscal_period.fiscal_year} "
        #            f"Fiscal Quarter: {true_beat.fiscal_period.fiscal_quarter} "
        #            f"True Beat: {true_beat.true_beat} "
        #        )
        if not points: 
            return []
        self._month = algorithm.time.month

        # Get the EPS prediction of each asset.
        eps_prediction_by_symbol = {}
        for dataset_symbol, true_beats in points.items():
            # Select the subset of TrueBeat objects that have the EPS earnings metric, 
            # a value for the fiscal year, and a value for the fiscal quarter.
            true_beats = [
                tb for tb in true_beats 
                if (tb.earnings_metric == ExtractAlphaTrueBeatEarningsMetric.EPS and
                    tb.fiscal_period.fiscal_quarter)
            ]
            if not true_beats:
                continue
            # Select the TrueBeat object of the closest fiscal quarter.
            eps_prediction_by_symbol[dataset_symbol.underlying] = sorted(
                true_beats, 
                key=lambda tb: (tb.fiscal_period.fiscal_year, tb.fiscal_period.fiscal_quarter)
            )[0].true_beat

        # Cancel the previous insights.
        algorithm.insights.cancel(self._insights)
        # Emit the new insights.
        # 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
        # Invest equally and dollar-neutral to evenly dissipate capital risk and hedge systematic risk
        self._insights = []
        sorted_by_eps_prediction = sorted(eps_prediction_by_symbol.items(), key=lambda kvp: kvp[1])
        for symbol, _ in sorted_by_eps_prediction[-10:]:
            self._insights.append(Insight.price(symbol, timedelta(35), InsightDirection.UP))
        for symbol, _ in sorted_by_eps_prediction[:10]:
            self._insights.append(Insight.price(symbol, timedelta(35), InsightDirection.DOWN))
        return self._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
            security.true_beats = algorithm.add_data(ExtractAlphaTrueBeats, security.symbol).symbol
            # Historical Data
            history = algorithm.history(security.true_beats, 10, Resolution.DAILY, flatten=True)
        for security in changes.removed_securities:
            # Remove the true beats data for this asset when it leaves the universe.
            algorithm.remove_security(security.true_beats)
public class ExtractAlphaTrueBeatsDataAlgorithm : QCAlgorithm
{
    public override void Initialize()
    {
        SetStartDate(2024, 9, 1);
        SetEndDate(2024, 12, 31);
        SetCash(100000);
        // Seed the price of each asset with its last known price to avoid trading errors.
        SetSecurityInitializer(
            new BrokerageModelSecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices))
        );
        // Add a universe that runs at the start of each month.
        var spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
        var dateRule = DateRules.MonthStart(spy);
        UniverseSettings.Schedule.On(dateRule);
        AddUniverseSelection(new LiquidEquitiesUniverseSelectionModel());
        // 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());
    }
}

public class LiquidEquitiesUniverseSelectionModel : FundamentalUniverseSelectionModel
{
    public override IEnumerable<Symbol> Select(QCAlgorithm algorithm, IEnumerable<Fundamental> fundamentals)
    {
        // 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 true beats data
        return (from f in fundamentals
                where f.HasFundamentalData
                orderby f.DollarVolume descending
                select f.Symbol).Take(100);
    }
}

public class ExtractAlphaTrueBeatsAlphaModel: AlphaModel
{
    private int _month = -1;
    private List<Insight> _insights = new();

    public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice slice)
    {
        // Rebalance at the start of each month.
        if (_month == algorithm.Time.Month)
        {
            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>();
        }
        _month = algorithm.Time.Month;

        // Get the EPS prediction of each asset.
        var epsPredictionBySymbol = new Dictionary<Symbol, decimal>();
        foreach (var kvp in points)
        {
            var datasetSymbol = kvp.Key;
            // Select the subset of TrueBeat objects that have the EPS earnings metric, 
            // a value for the fiscal year, and a value for the fiscal quarter.
            var trueBeats = kvp.Value
                .Select(tb => (ExtractAlphaTrueBeat)tb)
                .Where(tb =>
                    tb.EarningsMetric == ExtractAlphaTrueBeatEarningsMetric.EPS &&
                    tb.FiscalPeriod.FiscalQuarter != null
                )
                .OrderBy(tb => tb.FiscalPeriod.FiscalYear)
                .ThenBy(tb => tb.FiscalPeriod.FiscalQuarter)
                .ToList();
            if (trueBeats.Count == 0) 
                continue;
            // Select the TrueBeat object of the closest fiscal quarter.
            epsPredictionBySymbol[datasetSymbol.Underlying] = trueBeats.First().TrueBeat;
        }

        // Cancel the previous insights.
        algorithm.Insights.Cancel(_insights);

        // Emit the new insights.
        // 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
        // Invest equally and dollar-neutral to evenly dissipate capital risk and hedge systematic risk
        _insights.Clear();
        var sortedByEpsPrediction = epsPredictionBySymbol.OrderBy(kvp => kvp.Value).ToList();
        _insights.AddRange(sortedByEpsPrediction.TakeLast(10).Select(kvp => Insight.Price(kvp.Key, TimeSpan.FromDays(35), InsightDirection.Up)));
        _insights.AddRange(sortedByEpsPrediction.Take(10).Select(kvp => Insight.Price(kvp.Key, TimeSpan.FromDays(35), InsightDirection.Down)));
        return _insights;
    }

    public override void OnSecuritiesChanged(QCAlgorithm algorithm, SecurityChanges changes)
    {
        foreach(dynamic security in changes.AddedSecurities)
        {
            // Requesting true beats data for trading signal generation
            security.TrueBeats = algorithm.AddData<ExtractAlphaTrueBeats>(security.Symbol).Symbol;
            // Historical Data
            var history = algorithm.History(security.TrueBeats, 10, Resolution.Daily);
        }
        foreach (dynamic security in changes.RemovedSecurities)
        {
            // Remove the true beats data for this asset when it leaves the universe.
            algorithm.RemoveSecurity(security.TrueBeats);
        }
    }
}

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: