---
title: "GDP by Industry"
description: "GDP by Industry dataset from US Bureau of Economic Analysis."
canonical: https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/us-bureau-of-economic-analysis/gdp-by-industry
markdown: https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/us-bureau-of-economic-analysis/gdp-by-industry.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/03%20Writing%20Algorithms/14%20Datasets/29%20US%20Bureau%20of%20Economic%20Analysis/01%20GDP%20by%20Industry
modified: 2026-10-25
index: https://www.quantconnect.com/llms.txt
---

# GDP by Industry

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Writing Algorithms](https://www.quantconnect.com/docs/v2/writing-algorithms.md) > Datasets > [US Bureau of Economic Analysis](https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/us-bureau-of-economic-analysis.md) > GDP by Industry

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

## Introduction

The GDP by Industry dataset by the US Bureau of Economic Analysis (BEA) tracks how much each US industry contributes to gross domestic product. The data covers 100 US industries, starts in January 2005, and is delivered on a quarterly frequency. This dataset is created by processing the BEA Industry Economic Accounts.

For more information about the GDP by Industry dataset, including CLI commands and pricing, see the [dataset listing](https://www.quantconnect.com/datasets/bea-gdp-by-industry).

## About the Provider

The Bureau of Economic Analysis (BEA) is an agency of the US Department of Commerce. It produces the official statistics on the US economy, including gross domestic product. Its mission is to give a clear and accurate picture of the US economy through timely economic data.

## Getting Started

The following snippet demonstrates how to request data from the GDP by Industry dataset:

```python
self.dataset_symbol = self.add_data(BEAGDPByIndustry, BEA.Industries.MANUFACTURING, Resolution.DAILY).symbol
```

## Data Summary

The following table describes the dataset properties:

| Property | Value |
| --- | --- |
| Start Date | January 2005 |
| Asset Coverage | 100 US Industries |
| Data Density | Sparse |
| Resolution | Daily* |
| Timezone | New York |

* Quarterly data we fetch daily.

## Requesting Data

To add GDP by Industry 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 BEAGDPByIndustryDataAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self.set_start_date(2019, 1, 1)
        self.set_end_date(2020, 12, 31)
        self.set_cash(100000)

        self.dataset_symbol = self.add_data(BEAGDPByIndustry, BEA.Industries.MANUFACTURING, Resolution.DAILY).symbol
```

## Accessing Data

To get the current GDP by Industry 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} value added at {slice.time}: {data_point.value_added}")
```

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(BEAGDPByIndustry).items():
        self.log(f"{dataset_symbol} value added at {slice.time}: {data_point.value_added}")
```

## Historical Data

To get historical GDP by Industry 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)

# Dataset objects
history_bars = self.history[BEAGDPByIndustry](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 your subscription to GDP by Industry data, call the `remove_security` method.

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

## Supported Industries

The following table shows the accessor code you need to add some example industries to your algorithm:

| Constant | Industry |
| --- | --- |
| `BEA.Industries.MANUFACTURING` | Manufacturing |
| `BEA.Industries.CONSTRUCTION` | Construction |
| `BEA.Industries.FINANCE_AND_INSURANCE` | Finance and insurance |
| `BEA.Industries.RETAIL_TRADE` | Retail trade |
| `BEA.Industries.OIL_AND_GAS_EXTRACTION` | Oil and gas extraction |
| `BEA.Industries.GROSS_DOMESTIC_PRODUCT` | Gross domestic product (all industries) |

## Example Applications

The GDP by Industry dataset enables you to see which parts of the US economy are growing. Examples include the following strategies:

- Rotating into sectors when their industry output starts to grow again
- Tilting a sector portfolio toward the fastest-growing industries
- Using industry price indexes to gauge inflation in each sector

### Classic Algorithm Example

The following example algorithm buys SPY when Manufacturing real value added rises quarter over quarter. Otherwise, it liquidates the position.

```python
from AlgorithmImports import *

class BEAGDPByIndustryDataAlgorithm(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2019, 1, 1)
        self.set_end_date(2020, 12, 31)
        self.set_cash(100000)

        self._spy = self.add_equity("SPY", Resolution.DAILY).symbol
        self._manufacturing = self.add_data(BEAGDPByIndustry, BEA.Industries.MANUFACTURING, Resolution.DAILY).symbol
        self._previous_real_value_added = None

    def on_data(self, slice):
        if not slice.contains_key(self._manufacturing):
            return

        # Buy SPY when real value added rises quarter over quarter. Otherwise, liquidate.
        real = slice[self._manufacturing].real_value_added
        if self._previous_real_value_added is not None and real is not None:
            if real > self._previous_real_value_added:
                self.set_holdings(self._spy, 1)
            else:
                self.liquidate(self._spy)
        self._previous_real_value_added = real
```

### Framework Algorithm Example

The following example algorithm emits up insights for SPY when Manufacturing real value added rises quarter over quarter. Otherwise, it emits down insights.

```python
from AlgorithmImports import *

class BEAGDPByIndustryFrameworkAlgorithm(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2019, 1, 1)
        self.set_end_date(2020, 12, 31)
        self.set_cash(100000)

        self.universe_settings.resolution = Resolution.DAILY
        symbols = [Symbol.create("SPY", SecurityType.EQUITY, Market.USA)]
        self.set_universe_selection(ManualUniverseSelectionModel(symbols))
        self.add_alpha(BEAGDPByIndustryAlphaModel(self))
        self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel())

class BEAGDPByIndustryAlphaModel(AlphaModel):
    def __init__(self, algorithm):
        self._manufacturing = algorithm.add_data(BEAGDPByIndustry, BEA.Industries.MANUFACTURING, Resolution.DAILY).symbol
        self._previous_real_value_added = None
        self._tradable_symbols = []

    def update(self, algorithm, slice):
        insights = []
        if not slice.contains_key(self._manufacturing):
            return insights

        real = slice[self._manufacturing].real_value_added
        if self._previous_real_value_added is not None and real is not None:
            direction = InsightDirection.UP if real > self._previous_real_value_added else InsightDirection.DOWN
            insights = [Insight.price(symbol, timedelta(days=90), direction) for symbol in self._tradable_symbols]
        self._previous_real_value_added = real
        return insights

    def on_securities_changed(self, algorithm, changes):
        for security in changes.added_securities:
            if security.symbol != self._manufacturing:
                self._tradable_symbols.append(security.symbol)
        for security in changes.removed_securities:
            if security.symbol in self._tradable_symbols:
                self._tradable_symbols.remove(security.symbol)
```

## Data Point Attributes

The GDP by Industry dataset provides `BEAGDPByIndustry` objects, which have the following attributes:

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