Brain

Brain Sentiment Indicator

Introduction

The Brain Sentiment Indicator dataset by Brain tracks the public sentiment around US Equities. The data covers 4,500 US Equities, starts in August 2016, and is delivered on a daily frequency. This dataset is created by analyzing financial news using Natural Language Processing techniques while taking into account the similarity and repetition of news on the same topic. The sentiment score assigned to each stock ranges from -1 (most negative) to +1 (most positive). The sentiment score corresponds to the average sentiment for each piece of news. The score is updated daily and is available on two time scales: 7 days and 30 days. For more information, see Brain's summary paper.

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 Brain Sentiment Indicator dataset, including CLI commands and pricing, see the dataset listing.

About the Provider

Brain is a Research Company that creates proprietary datasets and algorithms for investment strategies, combining experience in financial markets with strong competencies in Statistics, Machine Learning, and Natural Language Processing. The founders share a common academic background of research in Physics as well as extensive experience in Financial markets.

Getting Started

The following snippet demonstrates how to request data from the Brain Sentiment Indicator dataset:

from QuantConnect.DataSource import *

self.aapl = self.add_equity("AAPL", Resolution.DAILY).symbol
self.dataset_7day_symbol = self.add_data(BrainSentimentIndicator7Day, self.aapl).symbol
self.dataset_30day_symbol = self.add_data(BrainSentimentIndicator30Day, self.aapl).symbol

self._universe = self.add_universe(BrainSentimentIndicatorUniverse, self.universe_selection)
using QuantConnect.DataSource;

_symbol = AddEquity("AAPL", Resolution.Daily).Symbol;
_dataset7DaySymbol = AddData<BrainSentimentIndicator7Day>(_symbol).Symbol;
_dataset30DaySymbol = AddData<BrainSentimentIndicator30Day>(_symbol).Symbol;

_universe = AddUniverse<BrainSentimentIndicatorUniverse>(UniverseSelection);

Data Summary

The following table describes the dataset properties:

PropertyValue
Start DateAugust 2016
Asset Coverage*4,500 US Equities
Data DensitySparse
ResolutionDaily
TimezoneUTC
The coverage includes all assets since the start date. It increases over time.

Example Applications

The Brain Sentiment Indicator dataset enables you to incorporate sentiment from financial news sources into your strategies. Examples include the following strategies:

  • Buying when the public sentiment for a security is increasing
  • Short selling when the public sentiment for a security is decreasing
  • Scaling the position sizing of securities based on how many times they are mentioned in financial news articles
  • Sector rotation based on news sentiment

Disclaimer: The dataset is provided by the data provider for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor do they constitute an offer to provide investment advisory or other services by the data provider.

Data Point Attributes

The Brain Sentiment Indicator dataset provides BrainSentimentIndicatorBase and BrainSentimentIndicatorUniverse objects.

BrainSentimentIndicatorBase Attributes

BrainSentimentIndicatorBase objects have the following attributes:

BrainSentimentIndicatorUniverse Attributes

BrainSentimentIndicatorUniverse objects have the following attributes:

Requesting Data

To add Brain Sentiment Indicator 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 BrainSentimentDataAlgorithm(QCAlgorithm):
    
    def initialize(self) -> None:
        self.set_start_date(2019, 1, 1)
        self.set_end_date(2021, 7, 8)
        self.set_cash(100000)
        
        self._symbol = self.add_equity("AAPL", Resolution.DAILY).symbol
        self.dataset_7day_symbol = self.add_data(BrainSentimentIndicator7Day, self.symbol).symbol
        self.dataset_30day_symbol = self.add_data(BrainSentimentIndicator30Day, self.symbol).symbol
namespace QuantConnect
{
    public class BrainSentimentDataAlgorithm : QCAlgorithm
    {
        private Symbol _symbol, _dataset7DaySymbol, _dataset30DaySymbol;
    	
        public override void Initialize()
        {
            SetStartDate(2019, 1, 1);
            SetEndDate(2021, 7, 8);
            SetCash(100000);
            
            _symbol = AddEquity("AAPL", Resolution.Daily).Symbol;
            _dataset7DaySymbol = AddData<BrainSentimentIndicator7Day>(_symbol).Symbol;
            _dataset30DaySymbol = AddData<BrainSentimentIndicator30Day>(_symbol).Symbol;
        }
    }
}

Accessing Data

To get the current Brain Sentiment Indicator 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_7day_symbol):
        data_point = slice[self.dataset_7day_symbol]
        self.log(f"{self.dataset_7day_symbol} sentiment at {slice.time}: {data_point.sentiment}")

    if slice.contains_key(self.dataset_30day_symbol):
        data_point = slice[self.dataset_30day_symbol]
        self.log(f"{self.dataset_30day_symbol} sentiment at {slice.time}: {data_point.sentiment}")
public override void OnData(Slice slice)
{
    if (slice.ContainsKey(_dataset7DaySymbol))
    {
        var dataPoint = slice[_dataset7DaySymbol];
        Log($"{_dataset7DaySymbol} sentiment at {slice.Time}: {dataPoint.Sentiment}");
    }

    if (slice.ContainsKey(_dataset30DaySymbol))
    {
        var dataPoint = slice[_dataset30DaySymbol];
        Log($"{_dataset30DaySymbol} sentiment at {slice.Time}: {dataPoint.Sentiment}");
    }
}

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(BrainSentimentIndicator7Day).items():
        self.log(f"{dataset_symbol} sentiment at {slice.time}: {data_point.sentiment}")

    for dataset_symbol, data_point in slice.get(BrainSentimentIndicator30Day).items():
        self.log(f"{dataset_symbol} sentiment at {slice.time}: {data_point.sentiment}")
public override void OnData(Slice slice)
{
    foreach (var kvp in slice.Get<BrainSentimentIndicator7Day>())
    {
        var datasetSymbol = kvp.Key;
        var dataPoint = kvp.Value;
        Log($"{datasetSymbol} sentiment at {slice.Time}: {dataPoint.Sentiment}");
    }

    foreach (var kvp in slice.Get<BrainSentimentIndicator30Day>())
    {
        var datasetSymbol = kvp.Key;
        var dataPoint = kvp.Value;
        Log($"{datasetSymbol} sentiment at {slice.Time}: {dataPoint.Sentiment}");
    }
}

Historical Data

To get historical Brain Sentiment Indicator data, call the Historyhistory method with the dataset Symbol. If there is no data in the period you request, the history result is empty.

# DataFrames
week_history_df = self.history(self.dataset_7day_symbol, 100, Resolution.DAILY)
month_history_df = self.history(self.dataset_30day_symbol, 100, Resolution.DAILY)
history_df = self.history([self.dataset_7day_symbol, self.dataset_30day_symbol], 100, Resolution.DAILY)

# Dataset objects
week_history_bars = self.history[BrainSentimentIndicator7Day](self.dataset_7day_symbol, 100, Resolution.DAILY)
month_history_bars = self.history[BrainSentimentIndicator30Day](self.dataset_30day_symbol, 100, Resolution.DAILY)
// Dataset objects
var weekHistory = History<BrainSentimentIndicator7Day>(_dataset7DaySymbol, 100, Resolution.Daily);
var monthHistory = History<BrainSentimentIndicator30Day>(_dataset30DaySymbol, 100, Resolution.Daily);

// Slice objects
var history = History(new[] {_dataset7DaySymbol, _dataset30DaySymbol}, 100, Resolution.Daily);

For more information about historical data, see History Requests.

Universe Selection

To select a dynamic universe of US Equities based on Brain Sentiment Indicator data, call the AddUniverseadd_universe method with the BrainSentimentIndicatorUniverse class and a selection function.

def initialize(self) -> None:
    self._universe = self.add_universe(BrainSentimentIndicatorUniverse, self.universe_selection)

def universe_selection(self, alt_coarse: List[BrainSentimentIndicatorUniverse]) -> List[Symbol]:
    return [d.symbol for d in alt_coarse \
                if d.total_article_mentions7_days > 0 \
                and d.sentiment7_days]
private Universe _universe;
public override void Initialize()
{
    _universe = AddUniverse<BrainSentimentIndicatorUniverse>(altCoarse=>
    {
        return from d in altCoarse.OfType<BrainSentimentIndicatorUniverse>()
            where d.TotalArticleMentions7Days > 0m && d.Sentiment7Days > 0m
            select d.Symbol;
    });
}

The Brain Sentiment Indicator universe runs at 7 AM Eastern Time (ET) in live trading. For more information about dynamic universes, see Universes.

Universe History

You can get historical universe data in an algorithm and in the Research Environment.

Historical Universe Data in Algorithms

To get historical universe data in an algorithm, call the Historyhistory method with the Universe object and the lookback period. If there is no data in the period you request, the history result is empty.

var universeHistory = History(_universe, 30, Resolution.Daily);
foreach (var sentiments in universeHistory)
{
    foreach (BrainSentimentIndicatorUniverse sentiment in sentiments)
    {
        Log($"{sentiment.Symbol} 7-day sentiment at {sentiment.EndTime}: {sentiment.Sentiment7Days}");
    }
}
universe_history = self.history(self.universe, 30, Resolution.DAILY)
for (_, time), sentiments in universe_history.items():
    for sentiment in sentiments:
        self.log(f"{sentiment.symbol} 7-day sentiment at {sentiment.end_time}: {sentiment.sentiment7_days}")

Historical Universe Data in Research

To get historical universe data in research, call the UniverseHistoryuniverse_history method with the Universe object, a start date, and an end date. This method returns the filtered universe. If there is no data in the period you request, the history result is empty.

var universeHistory = qb.UniverseHistory(universe, qb.Time.AddDays(-30), qb.Time);
foreach (var sentiments in universeHistory)
{
    foreach (BrainSentimentIndicatorUniverse sentiment in sentiments)
    {
        Console.WriteLine($"{sentiment.Symbol} 7-day sentiment at {sentiment.EndTime}: {sentiment.Sentiment7Days}");
    }
}
universe_history = qb.universe_history(universe, qb.time-timedelta(30), qb.time)
for (_, time), sentiments in universe_history.items():
    for sentiment in sentiments:
        print(f"{sentiment.symbol} 7-day sentiment at {sentiment.end_time}: {sentiment.sentiment7_days}")

You can call the History method in Research.

Remove Subscriptions

To remove a subscription, call the RemoveSecurityremove_security method.

self.remove_security(self.dataset_7day_symbol)
self.remove_security(self.dataset_30day_symbol)
RemoveSecurity(_dataset7DaySymbol);
RemoveSecurity(_dataset30DaySymbol);

If you subscribe to Brain Sentiment Indicator 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 Brain Sentiment Indicator dataset enables you to incorporate sentiment from financial news sources into your strategies. Examples include the following strategies:

  • Buying when the public sentiment for a security is increasing
  • Short selling when the public sentiment for a security is decreasing
  • Scaling the position sizing of securities based on how many times they are mentioned in financial news articles
  • Sector rotation based on news sentiment

Disclaimer: The dataset is provided by the data provider for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor do they constitute an offer to provide investment advisory or other services by the data provider.

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: