---
title: "True Beats"
description: "True Beats dataset from ExtractAlpha."
canonical: https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/extractalpha/true-beats
markdown: https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/extractalpha/true-beats.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/03%20Writing%20Algorithms/14%20Datasets/16%20ExtractAlpha/04%20True%20Beats
modified: 2026-10-31
index: https://www.quantconnect.com/llms.txt
---

# True Beats

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Writing Algorithms](https://www.quantconnect.com/docs/v2/writing-algorithms.md) > Datasets > [ExtractAlpha](https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/extractalpha.md) > True Beats

> Code examples are shown in Python. Append `?lang=csharp` to this URL for the C# version of this page.

## 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](https://www.quantconnect.com/datasets/quantconnect-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](https://www.quantconnect.com/datasets/extractalpha-true-beats).

## About the Provider

[ExtractAlpha](https://extractalpha.com/) 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:

```python
self.aapl = self.add_equity("AAPL", Resolution.DAILY).symbol
self.dataset_symbol = self.add_data(ExtractAlphaTrueBeats, self.aapl).symbol
```

## Data Summary

The following table describes the dataset properties:

| Property | Value |
| --- | --- |
| Start Date | January 2000 |
| Asset Coverage | Over 5,000 US Equities |
| Data Density | Sparse |
| Resolution | Daily |
| Timezone | New York |
| Timestamp | 12:30 PM |

## Requesting Data

To add True Beats data to your algorithm, call the `add_data` method. Save a reference to the dataset `Symbol` so you can access the data later in your algorithm.

```python
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
```

## Accessing Data

To get the current True Beats data, index the current [`Slice`](https://www.quantconnect.com/docs/v2/writing-algorithms/key-concepts/time-modeling/timeslices.md) 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.

```python
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}")
```

To iterate through all of the dataset objects in the current `Slice`, call the `get` method.

```python
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}")
```

## Historical Data

To get historical True Beats data, call the `history` method with the dataset `Symbol`. If there is no data in the period you request, the history result is empty.

```python
# 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)
```

For more information about historical data, see [History Requests](https://www.quantconnect.com/docs/v2/writing-algorithms/historical-data/history-requests.md).

## Remove Subscriptions

To remove a subscription, call the `remove_security` method.

```python
self.remove_security(self.dataset_symbol)
```

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](https://www.quantconnect.com/docs/v2/writing-algorithms/algorithm-framework/alpha/key-concepts.md#05-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.

```python
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, 9, 30)
        self.set_cash(100_000)
        # Seed the price of each asset with its last known price to avoid trading errors.
        self.settings.seed_initial_prices = True
        # 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)
```

### 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.

```python
from AlgorithmImports import *

class ExtractAlphaTrueBeatsDataAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 9, 30)
        self.set_cash(100_000)
        # Seed the price of each asset with its last known price to avoid trading errors.
        self.settings.seed_initial_prices = True
        # 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)
```

## Data Point Attributes

The True Beats dataset provides `ExtractAlphaTrueBeats` and `ExtractAlphaTrueBeat` objects.

### ExtractAlphaTrueBeats

`ExtractAlphaTrueBeats` objects have the following attributes:

*Members of `QuantConnect.DataSource.ExtractAlphaTrueBeats` (JSON): https://www.quantconnect.com/services/inspector?type=T:QuantConnect.DataSource.ExtractAlphaTrueBeats&language=python*

### ExtractAlphaTrueBeat

`ExtractAlphaTrueBeat` objects have the following attributes:

*Members of `QuantConnect.DataSource.ExtractAlphaTrueBeat` (JSON): https://www.quantconnect.com/services/inspector?type=T:QuantConnect.DataSource.ExtractAlphaTrueBeat&language=python*
