---
title: "Commitments of Traders"
description: "Commitments of Traders dataset from Commodity Futures Trading Commission."
canonical: https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/commodity-futures-trading-commission/commitments-of-traders
markdown: https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/commodity-futures-trading-commission/commitments-of-traders.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/03%20Writing%20Algorithms/14%20Datasets/11%20Commodity%20Futures%20Trading%20Commission/01%20Commitments%20of%20Traders
modified: 2026-10-26
index: https://www.quantconnect.com/llms.txt
---

# Commitments of Traders

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Writing Algorithms](https://www.quantconnect.com/docs/v2/writing-algorithms.md) > Datasets > [Commodity Futures Trading Commission](https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/commodity-futures-trading-commission.md) > Commitments of Traders

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

## Introduction

The Commitments of Traders dataset by the Commodity Futures Trading Commission (CFTC) tracks the long and short positions that each type of trader holds in US futures markets. The data covers 942 futures markets, starts in January 1998, and is delivered on a weekly frequency. This dataset is created by processing the weekly Commitments of Traders reports.

For more information about the Commitments of Traders dataset, including CLI commands and pricing, see the [dataset listing](https://www.quantconnect.com/datasets/cftc-cot).

## About the Provider

The Commodity Futures Trading Commission (CFTC) is an independent agency of the US government, created by Congress in 1974. It regulates the US derivatives markets, including futures and swaps. Its mission is to promote the integrity of these markets through sound regulation.

## Getting Started

The following snippet demonstrates how to request data from the CFTC Commitments of Traders dataset:

```python
self.dataset_symbol = self.add_data(CFTCLegacy, CFTC.Markets.E_MINI_SP_500).symbol
```

## Data Summary

The following table describes the dataset properties:

| Property | Value |
| --- | --- |
| Start Date | January 1998 |
| Asset Coverage | 942 Futures Markets |
| Data Density | Sparse |
| Resolution | Daily* |
| Timezone | New York |

* Weekly data we fetch daily.

## Requesting Data

To add CFTC Commitments of Traders 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 CFTCDataAlgorithm(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2020, 1, 1)
        self.set_end_date(2020, 6, 1)
        self.set_cash(100000)
        self._spy = self.add_equity("SPY", Resolution.DAILY).symbol
        self._legacy = self.add_data(CFTCLegacy, CFTC.Markets.E_MINI_SP_500, Resolution.DAILY).symbol
        self._disaggregated = self.add_data(CFTCDisaggregated, CFTC.Markets.GOLD, Resolution.DAILY).symbol
        self._tff = self.add_data(CFTCFinancialFutures, CFTC.Markets.E_MINI_SP_500, Resolution.DAILY).symbol
```

## Accessing Data

To get the current CFTC Commitments of Traders 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._legacy):
        data_point = slice[self._legacy]
        self.log(f"{self._legacy} non-commercial net at {slice.time}: {data_point.non_commercial_net}")
```

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(CFTCDisaggregated).items():
        self.log(f"{dataset_symbol} managed money net at {slice.time}: {data_point.managed_money_net}")
```

## Historical Data

To get historical CFTC Commitments of Traders 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
# DataFrames
legacy_history_df = self.history(self._legacy, 100, Resolution.DAILY)
history_df = self.history([self._legacy, self._disaggregated, self._tff], 100, Resolution.DAILY)
# Dataset objects
legacy_history_bars = self.history[CFTCLegacy](self._legacy, 100, Resolution.DAILY)
disaggregated_history_bars = self.history[CFTCDisaggregated](self._disaggregated, 100, Resolution.DAILY)
tff_history_bars = self.history[CFTCFinancialFutures](self._tff, 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 CFTC Commitments of Traders data, call the `remove_security` method.

```python
self.remove_security(self._legacy)
```

## Supported Markets

The `CFTC.Markets` helper covers every market in the reports. The following table shows the accessor code you need to add some of the markets to your algorithm:

| Constant | Market |
| --- | --- |
| `CFTC.Markets.E_MINI_SP_500` | E-mini S&P 500 |
| `CFTC.Markets.GOLD` | Gold |
| `CFTC.Markets.CRUDE_OIL_BRENT` | Crude Oil, Brent |
| `CFTC.Markets.NATURAL_GAS` | Natural Gas |
| `CFTC.Markets.CORN` | Corn |

## Example Applications

The Commitments of Traders dataset enables you to follow how different types of traders are positioned in the futures markets. Examples include the following strategies:

- Trading with non-commercial traders when their net position turns from short to long
- Fading a market when speculator positioning reaches a multi-year extreme
- Ranking commodities by the weekly change in speculator positions

### Classic Algorithm Example

The following example algorithm buys SPY when non-commercial traders are net long the E-mini S&P 500. When they are net short, it short sells SPY.

```python
from AlgorithmImports import *

class CFTCDataAlgorithm(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2020, 1, 1)
        self.set_end_date(2020, 6, 1)
        self.set_cash(100000)

        self._spy = self.add_equity("SPY", Resolution.DAILY).symbol
        self._legacy = self.add_data(CFTCLegacy, CFTC.Markets.E_MINI_SP_500, Resolution.DAILY).symbol
        history = self.history(CFTCLegacy, self._legacy, 60, Resolution.DAILY)

        self.debug(f"We got {len(history)} items from our history request")

    def on_data(self, slice):
        legacy = slice.get(CFTCLegacy)
        if not legacy or self._legacy not in legacy:
            return

        net = legacy[self._legacy].non_commercial_net
        if net is None:
            return

        # Go long when the non-commercial traders are net long the E-mini S&P 500
        if net > 0:
            self.set_holdings(self._spy, 1)

        # Go short when they are net short
        elif net < 0:
            self.set_holdings(self._spy, -1)
```

### Framework Algorithm Example

The following example algorithm buys SPY when non-commercial traders are net long the E-mini S&P 500. When they are net short, it short sells SPY.

```python
from AlgorithmImports import *

class CFTCFrameworkAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2020, 1, 1)
        self.set_end_date(2020, 6, 1)
        self.set_cash(100000)

        self.universe_settings.resolution = Resolution.DAILY
        # Trade SPY as the proxy of the E-mini S&P 500 futures the report covers
        symbols = [Symbol.create("SPY", SecurityType.EQUITY, Market.USA)]
        self.add_universe_selection(ManualUniverseSelectionModel(symbols))
        # A custom alpha model that emits trade insights based on CFTC positioning data
        self.add_alpha(CFTCAlphaModel(self))
        # Equally invest to dissipate non-systematic capital concentration risk on individual stock
        self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel())

class CFTCAlphaModel(AlphaModel):

    def __init__(self, algorithm: QCAlgorithm) -> None:
        self.tradable_symbols = []

        # Request the Legacy report for the E-mini S&P 500 for trade signal generation
        self.cftc_symbol = algorithm.add_data(CFTCLegacy, CFTC.Markets.E_MINI_SP_500, Resolution.DAILY).symbol

        # Historical data
        history = algorithm.history(CFTCLegacy, self.cftc_symbol, 60, Resolution.DAILY)
        algorithm.debug(f"We got {len(history)} items from our history request")

    def update(self, algorithm: QCAlgorithm, slice: Slice) -> List[Insight]:
        # Skip the slices that carry no new report
        points = slice.get(CFTCLegacy)
        if self.cftc_symbol not in points:
            return []

        # Read the net position of the non-commercial traders
        net = points[self.cftc_symbol].non_commercial_net
        if net is None:
            return []

        insights = []

        for symbol in self.tradable_symbols:
            # Emit an up insight when the non-commercial traders are net long
            if net > 0:
                insights += [Insight.price(symbol, timedelta(days=7), InsightDirection.UP)]

            # Emit a down insight when they are net short
            elif net < 0:
                insights += [Insight.price(symbol, timedelta(days=7), InsightDirection.DOWN)]

        return insights

    def on_securities_changed(self, algorithm: QCAlgorithm, changes: SecurityChanges) -> None:
        for security in changes.added_securities:
            self.tradable_symbols.append(security.symbol)
```

## Data Point Attributes

The CFTC Commitments of Traders dataset provides `CFTCLegacy`, `CFTCDisaggregated` and `CFTCFinancialFutures` objects.

### CFTCLegacy

`CFTCLegacy` objects have the following attributes:

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

### CFTCDisaggregated

`CFTCDisaggregated` objects have the following attributes:

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

### CFTCFinancialFutures

`CFTCFinancialFutures` objects have the following attributes:

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