Brain ML Stock Ranking


The Brain ML Stock Ranking dataset by Brain generates a daily ranking for US Equities based on their predicted ranking of future returns relative to the universe median across four-time horizons: next 2, 3, 5, 10, and 30 days (one trading month). The data covers 1,000 US Equities (universe updated yearly by including the largest 1,000 US companies of the previous year), starts in January 2010, and is delivered on a daily frequency. This dataset is created by a voting scheme of machine learning classifiers that non-linearly combine a variety of features with a series of techniques aimed at mitigating the well-known overfitting problem for financial data with a low signal-to-noise ratio. Examples of features are time-varying stock-specific features like price and volume-related metrics or fundamentals; time-fixed stock-specific features like the sector and other database information; market regime features such as volatility and other financial stress indicators; calendar features representing possible anomalies, for example, the month of the year.

More precisely the ML Stock Ranking score is related to the confidence of a Machine Learning classifier in predicting top or bottom quintile returns for the next N trading days (e.g. next 21 trading days) for a stock with the respect to the median of the universe and ranges from -1 to +1.

A negative score means that the system is more confident that the stock belongs to the lower returns quintile, a positive score means that the system is more confident that the stock belongs to the higher returns quintile. It is important to note that the score has a meaning only if used to compare different stocks to perform a ranking.

Typical use is to download the score for a large stock universe for a given day, e.g. 500 stocks or the full universe of 1000 stocks, order the stocks by mlAlpha score and go long the top K stocks, or build a long-short strategy going long the top K and short the bottom K stocks.

For more information, refer to 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 ML Stock Ranking 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 ML Stock Ranking dataset:

self.symbol = self.AddEquity("AAPL", Resolution.Daily).Symbol
self.dataset_symbol = self.AddData(BrainStockRanking2Day, self.symbol).Symbol

self.AddUniverse(BrainStockRankingUniverse, "BrainStockRankingUniverse", Resolution.Daily, self.UniverseSelectionMethod)
_symbol = AddEquity("AAPL", Resolution.Daily).Symbol;
_datasetSymbol = AddData<BrainStockRanking2Day>(_symbol).Symbol;

AddUniverse<BrainStockRankingUniverse>("BrainStockRankingUniverse", Resolution.Daily, UniverseSelectionMethod);

Data Summary

The following table describes the dataset properties:

Start DateJanuary 2010
Asset Coverage1,000 US Equities
Data DensitySparse

Data Point Attributes

The Brain ML Stock Ranking dataset provides BrainStockRankingBase and BrainStockRankingUniverse objects.

BrainStockRankingBase Attributes

BrainStockRankingBase objects have the following attributes:

BrainStockRankingUniverse Attributes

BrainStockRankingUniverse objects have the following attributes:

Requesting Data

To add Brain ML Stock Ranking data to your algorithm, call the AddData method. Save a reference to the dataset Symbol so you can access the data later in your algorithm.

class BrainMLRankingDataAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self.SetStartDate(2021, 1, 1)
        self.SetEndDate(2021, 7, 8)
        self.symbol = self.AddEquity("AAPL", Resolution.Daily).Symbol
        self.two_day_symbol = self.AddData(BrainStockRanking2Day, self.symbol).Symbol
        self.three_day_symbol = self.AddData(BrainStockRanking3Day, self.symbol).Symbol
        self.five_day_symbol = self.AddData(BrainStockRanking5Day, self.symbol).Symbol
        self.ten_day_symbol = self.AddData(BrainStockRanking10Day, self.symbol).Symbol
        self.thirty_day_symbol = self.AddData(BrainStockRanking30Day, self.symbol).Symbol
namespace QuantConnect
    public class BrainMLRankingDataAlgorithm : QCAlgorithm
    	private Symbol _symbol, _2DaySymbol, _3DaySymbol, _5DaySymbol, _10DaySymbol, _30DaySymbol;
        public override void Initialize()
            SetStartDate(2021, 1, 1);
            SetEndDate(2021, 7, 8);
            _symbol = AddEquity("AAPL", Resolution.Daily).Symbol;
            _2DaySymbol = AddData<BrainStockRanking2Day>(_symbol).Symbol;
            _3DaySymbol = AddData<BrainStockRanking3Day>(_symbol).Symbol;
            _5DaySymbol = AddData<BrainStockRanking5Day>(_symbol).Symbol;
            _10DaySymbol = AddData<BrainStockRanking10Day>(_symbol).Symbol;
            _30DaySymbol = AddData<BrainStockRanking30Day>(_symbol).Symbol;

Accessing Data

To get the current Brain ML Stock Ranking 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 OnData(self, slice: Slice) -> None:
    if slice.ContainsKey(self.two_day_symbol):
        data_point = slice[self.two_day_symbol]
        self.Log(f"{self.two_day_symbol} rank at {slice.Time}: {data_point.Rank}")

    if slice.ContainsKey(self.three_day_symbol):
        data_point = slice[self.three_day_symbol]
        self.Log(f"{self.three_day_symbol} rank at {slice.Time}: {data_point.Rank}")

    if slice.ContainsKey(self.five_day_symbol):
        data_point = slice[self.five_day_symbol]
        self.Log(f"{self.five_day_symbol} rank at {slice.Time}: {data_point.Rank}")

    if slice.ContainsKey(self.ten_day_symbol):
        data_point = slice[self.ten_day_symbol]
        self.Log(f"{self.ten_day_symbol} rank at {slice.Time}: {data_point.Rank}")

    if slice.ContainsKey(self.thirty_day_symbol):
        data_point = slice[self.thirty_day_symbol]
        self.Log(f"{self.thirty_day_symbol} rank at {slice.Time}: {data_point.Rank}")
public override void OnData(Slice slice)
    if (slice.ContainsKey(_2DaySymbol))
        var dataPoint = slice[_2DaySymbol];
        Log($"{_2DaySymbol} rank at {slice.Time}: {dataPoint.Rank}");

    if (slice.ContainsKey(_3DaySymbol))
        var dataPoint = slice[_3DaySymbol];
        Log($"{_3DaySymbol} rank at {slice.Time}: {dataPoint.Rank}");

    if (slice.ContainsKey(_5DaySymbol))
        var dataPoint = slice[_5DaySymbol];
        Log($"{_5DaySymbol} rank at {slice.Time}: {dataPoint.Rank}");

    if (slice.ContainsKey(_10DaySymbol))
        var dataPoint = slice[_10DaySymbol];
        Log($"{_10DaySymbol} rank at {slice.Time}: {dataPoint.Rank}");

    if (slice.ContainsKey(_30DaySymbol))
        var dataPoint = slice[_30DaySymbol];
        Log($"{_30DaySymbol} rank at {slice.Time}: {dataPoint.Rank}");

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

def OnData(self, slice: Slice) -> None:
    for dataset_symbol, data_point in slice.Get(BrainStockRanking2Day).items():
        self.Log(f"{dataset_symbol} rank at {slice.Time}: {data_point.Rank}")

    for dataset_symbol, data_point in slice.Get(BrainStockRanking3Day).items():
        self.Log(f"{dataset_symbol} rank at {slice.Time}: {data_point.Rank}")

    for dataset_symbol, data_point in slice.Get(BrainStockRanking5Day).items():
        self.Log(f"{dataset_symbol} rank at {slice.Time}: {data_point.Rank}")

    for dataset_symbol, data_point in slice.Get(BrainStockRanking10Day).items():
        self.Log(f"{dataset_symbol} rank at {slice.Time}: {data_point.Rank}")

    for dataset_symbol, data_point in slice.Get(BrainStockRanking30Day).items():
        self.Log(f"{dataset_symbol} rank at {slice.Time}: {data_point.Rank}")
public override void OnData(Slice slice)
    foreach (var kvp in slice.Get<BrainStockRanking2Day>())
        var datasetSymbol = kvp.Key;
        var dataPoint = kvp.Value;
        Log($"{datasetSymbol} rank at {slice.Time}: {dataPoint.Rank}");

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

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

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

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

Historical Data

To get historical Brain ML Stock Ranking data, call the History method with the dataset Symbol. If there is no data in the period you request, the history result is empty.

# DataFrames
two_day_history_df = self.History(self.two_day_symbol, 100, Resolution.Daily)
three_day_history_df = self.History(self.three_day_symbol, 100, Resolution.Daily)
five_day_history_df = self.History(self.five_day_symbol, 100, Resolution.Daily)
ten_day_history_df = self.History(self.ten_day_symbol, 100, Resolution.Daily)
thirty_day_history_df = self.History(self.thirty_day_symbol, 100, Resolution.Daily)
history_df = self.History([self.two_day_symbol, 
                           thirty_day_symbol], 100, Resolution.Daily)

# Dataset objects
two_day_history_bars = self.History[BrainStockRanking2Day](self.two_day_symbol, 100, Resolution.Daily)
three_day_history_bars = self.History[BrainStockRanking3Day](self.three_day_symbol, 100, Resolution.Daily)
five_day_history_bars = self.History[BrainStockRanking5Day](self.five_day_symbol, 100, Resolution.Daily)
ten_day_history_bars = self.History[BrainStockRanking10Day](self.ten_day_symbol, 100, Resolution.Daily)
thirty_day_history_bars = self.History[BrainStockRanking30Day](self.thirty_day_symbol, 100, Resolution.Daily)
// Dataset objects
var twoDayHistory = History<BrainStockRanking2Day>(_2DaySymbol, 100, Resolution.Daily);
var threeDayHistory = History<BrainStockRanking3Day>(_3DaySymbol, 100, Resolution.Daily);
var fiveDayHistory = History<BrainStockRanking5Day>(_5DaySymbol, 100, Resolution.Daily);
var tenDayHistory = History<BrainStockRanking10Day>(_10DaySymbol, 100, Resolution.Daily);
var thirtyDayHistory = History<BrainStockRanking30Day>(_30DaySymbol, 100, Resolution.Daily);

// Slice objects
var history = History(new[] {_2DaySymbol, _3DaySymbol, _5DaySymbol, 
                             _10DaySymbol, _30DaySymbol}, 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 ML Stock Ranking data, call the AddUniverse method with the BrainStockRankingUniverse class and a selection function.

def Initialize(self) -> None:
    self.AddUniverse(BrainStockRankingUniverse, "BrainStockRankingUniverse", Resolution.Daily, self.UniverseSelection)

def UniverseSelection(self, alt_coarse: List[BrainStockRankingUniverse]) -> List[Symbol]:
    return [d.Symbol for d in alt_coarse \
                if d.Rank2Days > 0 \
                and d.Rank3Days > 0 \
                and d.Rank5Days > 0]
AddUniverse<BrainStockRankingUniverse>("BrainStockRankingUniverse", Resolution.Daily, altCoarse =>
    return from d in altCoarse 
        where d.Rank2Days > 0m && d.Rank3Days > 0m  && d.Rank5Days > 0m
        select d.Symbol;

For more information about dynamic universes, see Universes.

Remove Subscriptions

To remove a subscription, call the RemoveSecurity method.


If you subscribe to Brain ML Stock Ranking 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 ML Stock Ranking dataset enables you to test strategies using the machine learning ranking provided by Brain. Examples include the following strategies:

  • Constructing a portfolio of securities with each security's weight in the portfolio reflecting its Brain ML Stock Ranking
  • Buying stocks with the largest Brain ML Stock Ranking
  • Building a market-neutral strategy based on the top N and bottom N stocks in the Brain ML Stock Ranking

Disclaimer: The dataset is provided by the data provider for informational purposes only and do 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: