---
title: "Fear and Greed"
description: "Fear and Greed dataset from QuantConnect."
canonical: https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quantconnect/fear-and-greed
markdown: https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quantconnect/fear-and-greed.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/03%20Writing%20Algorithms/14%20Datasets/02%20QuantConnect/15%20Fear%20and%20Greed
modified: 2026-12-06
index: https://www.quantconnect.com/llms.txt
---

# Fear and Greed

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Writing Algorithms](https://www.quantconnect.com/docs/v2/writing-algorithms.md) > Datasets > [QuantConnect](https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quantconnect.md) > Fear and Greed

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

## Introduction

The Fear and Greed dataset by QuantConnect provides data points to quantify the degree of fear and greed in the US Equity market. The data starts in 2014 and is delivered on a daily frequency, delayed by two days. This dataset is created by aggregating seven indicators, including market volatility, stock market breadth, and put-call ratios.

For more information about the Fear and Greed dataset, including CLI commands and pricing, see the [dataset listing](https://www.quantconnect.com/datasets/quantconnect-fear-and-greed).

## About the Provider

QuantConnect was founded in 2012 to serve quants everywhere with the best possible algorithmic trading technology. Seeking to disrupt a notoriously closed-source industry, QuantConnect takes a radically open-source approach to algorithmic trading. Through the QuantConnect web platform, more than 50,000 quants are served every month.

## Getting Started

The following snippet demonstrates how to request data from the Fear and Greed dataset:

```python
self._dataset_symbol = self.add_data(FearGreedIndex, 'FG').symbol
```

## Data Summary

The following table describes the dataset properties:

| Property | Value |
| --- | --- |
| Start Date | July 2014 |
| Data Density | Dense |
| Resolution | Daily |
| Timezone | New York |

The latest daily data points are about two days since the VIX and SPX prices are inputs into the index and their latest daily prices are also two days old. New data is available at 9 AM EST.

## Requesting Data

To add Fear and Greed 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 FearAndGreedDataAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self.set_start_date(2019, 1, 1)
        self.set_end_date(2020, 6, 1)
        self.set_cash(100000)

        self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
        self._dataset_symbol = self.add_data(FearGreedIndex, "FG").symbol
```

## Accessing Data

To get the current Fear and Greed 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 at {slice.time}: {data_point.value}")
```

## Historical Data

To get historical Fear and Greed 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 = self.history[FearGreedIndex](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 Subscription

To remove a subscription to the Fear and Greed dataset, call the `remove_security` method.

```python
self.remove_security(self._dataset_symbol)
```

## Example Applications

The Fear and Greed dataset quantifies the degree of fear and greed in the US Equity market. Example use cases include the following strategies:

- Accumulate long-term positions when the market is fearful (the index is low).
- Short risky assets when the market is greedy.
- Trade [butterfly Option strategies](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/option-strategies/long-call-butterfly.md) based on the market volatility indicator.

### Classic Algorithm Example

The following example algorithm buys SPY when the Fear and Greed index is less than 25 (extreme fear) and sells when it's above 75 (extreme greed).

```python
from AlgorithmImports import *

class FearAndGreedExampleAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        self.set_cash(100000)

        # Add the market index to trade.
        self._equity = self.add_equity('SPY', Resolution.DAILY)
        # Add the Fear and Greed dataset.
        self._dataset_symbol = self.add_data(FearGreedIndex, 'FG').symbol

    def on_data(self, data: Slice) -> None:
        # Wait until the Fear and Greed dataset has new data.
        if self._dataset_symbol not in data:
            return
        value = data[self._dataset_symbol].value
        # Buy when the market is fearful.
        if not self._equity.invested and value < 25:
            self.set_holdings(self._equity.symbol, 1)
        # Sell when the market is greedy.
        elif self._equity.invested and value > 75:
            self.liquidate()
```

### Framework Example

The following example algorithm buys SPY when the Fear and Greed index is less than 25 (extreme fear) and sells when it's above 75 (extreme greed).

```python
from AlgorithmImports import *

class FearAndGreedExampleAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        self.set_cash(100000)

        # Trade SPY on a daily basis.
        self.universe_settings.resolution = Resolution.DAILY
        symbols = [Symbol.create('SPY', SecurityType.EQUITY, Market.USA)]
        self.add_universe_selection(ManualUniverseSelectionModel(symbols))
        # Add a custom Alpha model that emits insights based on the Fear and Greed dataset.
        self.add_alpha(FearAndGreedAlphaModel(self))
        # Set the equal weighted PCM so the algorithm places trades.
        self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel())

# Define the custom alpha model.
class FearAndGreedAlphaModel(AlphaModel):

    def __init__(self, algorithm):
        # Create a list to track the current universe.
        self._securities = []
        # Add the Fear and Greed dataset.
        self._dataset_symbol = algorithm.add_data(FearGreedIndex, 'FG').symbol

    def update(self, algorithm: QCAlgorithm, data: Slice) -> List[Insight]:
        # Wait until the Fear and Greed dataset has new data.
        if self._dataset_symbol not in data:
            return []
        # Wait until the Fear and Greed index is extreme.
        value = data[self._dataset_symbol].value
        if 25 <= value <= 75:
            return []
        insights = []
        for security in self._securities:
            # Buy when the market is fearful.
            if not security.invested and value < 25:
                direction = InsightDirection.UP
            # Sell when the market is greedy.
            elif security.invested and value > 75:
                direction = InsightDirection.FLAT
            else:
                continue
            insights.append(Insight.price(security.symbol, timedelta(2*365), direction))
        return insights

    def on_securities_changed(self, algorithm: QCAlgorithm, changes: SecurityChanges) -> None:
        # When assets enter the universe, save them.
        for security in changes.added_securities:
            self._securities.append(security)
        # When assets leave the universe, remove them.
        for security in changes.removed_securities:
            if security in self._securities:
                self._securities.remove(security)
```

## Data Point Attributes

The Fear and Greed dataset provides `FearGreedIndex` objects, which have the following attributes:

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