Nasdaq

Data Link

Introduction

The Data Link dataset by Nasdaq, previously known as Quandl, is a collection of alternative data sets. It has indexed millions of time-series datasets from over 400 sources, which start in different years. This dataset is delivered on several frequencies, but the free data sets have often a daily frequency.

For more information about the Data Link dataset, including CLI commands and pricing, see the dataset listing.

About the Provider

"Nasdaq" was initially an acronym for the National Association of Securities Dealers Automated Quotations. It was founded in 1971 by the National Association of Securities Dealers (NASD), now known as the Financial Industry Regulatory Authority (FINRA), with the goal to provide financial services and operate stock exchanges.

On Dec. 4th, 2018, Nasdaq announced it had acquired Quandl, Inc., a leading provider of alternative and core financial data. Quandl was founded by Tammer Kamel in 2012, with goal of making it easy for anyone to find and use high-quality data effectively in their professional decision-making. In 2021, Quandl was replaced by Nasdaq Data Link.

Getting Started

The following snippet demonstrates how to request data from the Data Link dataset:

# For premium datasets, provide your API Key
# NasdaqDataLink.SetAuthCode("<apiKey>")

self.pe_ratio_symbol = self.AddData(NasdaqDataLink, "MULTPL/SP500_PE_RATIO_MONTH", Resolution.Daily).Symbol
# This dataset has one data column ("Value")

self.position_change_symbol = self.AddData(NasdaqCustomColumns, "CFTC/066393_FO_L_CHG", Resolution.Daily).Symbol
# This dataset has multiple data columns. Create a subclass to set the default value column.

class NasdaqCustomColumns(NasdaqDataLink):
    def __init__(self) -> None:
        # Select the column "open interest - change".
        self.ValueColumnName = "open interest - change"
// For premium datasets, provide your API Key
// NasdaqDataLink.SetAuthCode("<apiKey>");

_peRatioSymbol = AddData<NasdaqDataLink>("MULTPL/SP500_PE_RATIO_MONTH", Resolution.Daily).Symbol;
// This dataset has one data column ("Value")

_positionChangeSymbol = AddData<NasdaqCustomColumns>("CFTC/066393_FO_L_CHG", Resolution.Daily).Symbol;
// This dataset has multiple data columns. Create a subclass to set the default value column.

public class NasdaqCustomColumns : NasdaqDataLink
{
    // Select the column "open interest - change"
    public NasdaqCustomColumns() : base(valueColumnName: "open interest - change") { }
}

Data Summary

Nasdaq Data Link provides several data sets that can't fit into one table. For more information about their datasets, see the catalog on the Nasdaq website.

Backward Compatibility

QuantConnect/LEAN has supported Quandl since 2015. On January, 12, 2022, we moved the implementation from the LEAN GitHub repository to the Lean.DataSource.NasdaqDataLink GitHub repository. Through this transition, we maintained backward compatibility. All of the preceding code snippets work if you replace NasdaqDataLink with Quandl.

Requesting Data

To add Data Link 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. If there is more than one value column in the Data Link dataset, to set the Value property of the data objects, create a sublcass of the NasdaqDataLink class and set its ValueColumnName property to the column name.

class NasdaqDataLinkDataAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self.SetStartDate(2022, 1, 1)
        self.SetEndDate(2022, 7, 1)
        self.SetCash(100000)

        # For premium datasets, provide your API Key
        # NasdaqDataLink.SetAuthCode("<apiKey>")

        self.pe_ratio_symbol = self.AddData(NasdaqDataLink, "MULTPL/SP500_PE_RATIO_MONTH", Resolution.Daily).Symbol
        # This dataset has one data column ("Value")
        # Source : https://data.nasdaq.com/data/MULTPL/SP500_PE_RATIO_MONTH-sp-500-pe-ratio-by-month

        self.position_change_symbol = self.AddData(NasdaqCustomColumns, "CFTC/066393_FO_L_CHG", Resolution.Daily).Symbol
        # This dataset has multiple data columns
        # Source: https://data.nasdaq.com/data/CFTC/066393_FO_L_CHG-commitment-of-traders-propane-argus-far-east-mini-ifed-futures-and-options-change-in-positions-legacy-format-066393

class NasdaqCustomColumns(NasdaqDataLink):
    def __init__(self) -> None:
        # Select the column "open interest - change".
        self.ValueColumnName = "open interest - change"
namespace QuantConnect.Algorithm.CSharp.AltData
{
    public class NasdaqDataLinkDataAlgorithm : QCAlgorithm
    {
        private Symbol _peRatioSymbol, _positionChangeSymbol;

        public override void Initialize()
        {
            SetStartDate(2022, 1, 1);
            SetEndDate(2022, 7, 1);
            SetCash(100000);

            // For premium datasets, provide your API Key
            // NasdaqDataLink.SetAuthCode("<apiKey>");

            _peRatioSymbol = AddData<NasdaqDataLink>("MULTPL/SP500_PE_RATIO_MONTH", Resolution.Daily).Symbol;
            // This dataset has one data column ("Value")
            // Source : https://data.nasdaq.com/data/MULTPL/SP500_PE_RATIO_MONTH-sp-500-pe-ratio-by-month

            _positionChangeSymbol = AddData<NasdaqCustomColumns>("CFTC/066393_FO_L_CHG", Resolution.Daily).Symbol;
            // This dataset has multiple data columns
            // Source: https://data.nasdaq.com/data/CFTC/066393_FO_L_CHG-commitment-of-traders-propane-argus-far-east-mini-ifed-futures-and-options-change-in-positions-legacy-format-066393
        }
    }

    public class NasdaqCustomColumns : NasdaqDataLink
    {
        // Select the column "open interest - change".
        public NasdaqCustomColumns() : base(valueColumnName: "open interest - change") { }
    }
}

Accessing Data

To get the current Data Link 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.

To get the default value of the dataset, use the Value property. To get the value of a specific column in the dataset, call the GetStorageDictionary method and index the result with the column name.

def OnData(self, slice: Slice) -> None:
    if slice.ContainsKey(self.pe_ratio_symbol):
        value = slice[self.pe_ratio_symbol].Value
        self.Log(f"{self.pe_ratio_symbol} PE ratio at {slice.Time}: {value}")

    if slice.ContainsKey(self.position_change_symbol):
        data_point = slice[self.position_change_symbol]
        open_interest_change = data_point.Value
        storage_dictionary = data_point.GetStorageDictionary()
        longs_change = storage_dictionary["noncommercial longs - change"]        
        self.Log(f"{self.position_change_symbol} open interest change at {slice.Time}: {open_interest_change}")
public override void OnData(Slice slice)
{
    if (slice.ContainsKey(_peRatioSymbol))
    {
        var value = slice[_peRatioSymbol].Value;
        Log($"{_peRatioSymbol} PE ratio at {slice.Time}: {value}");
    }

    if (slice.ContainsKey(_positionChangeSymbol))
    {
        var dataPoint = slice[_positionChangeSymbol];
        var openInterestChange = dataPoint.Value;
        var storageDictionary = dataPoint.GetStorageDictionary();
        var longsChange = storageDictionary["noncommercial longs - change"];
        Log($"{_positionChangeSymbol} open interest change at {slice.Time}: {openInterestChange}");
    }
}

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(NasdaqDataLink).items():
        self.Log(f"{dataset_symbol} PE ratio at {slice.Time}: {data_point.Value}")

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

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

Historical Data

To get historical Data Link 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
pe_ratio_history_df = self.History(self.pe_ratio_symbol, 100, Resolution.Daily)
position_change_history_df = self.History(self.position_change_symbol, 100, Resolution.Daily)

# Dataset objects
pe_ratio_history_df = self.History[NasdaqDataLink](self.pe_ratio_symbol, 100, Resolution.Daily)
position_change_history_df = self.History[NasdaqCustomColumns](self.position_change_symbol, 100, Resolution.Daily)
var peRatioHistory = History<NasdaqDataLink>(_peRatioSymbol, 100, Resolution.Daily);
var positionChangeHistory = History<NasdaqDataLink>(_positionChangeSymbol, 100, Resolution.Daily);

For more information about historical data, see History Requests.

Remove Subscriptions

To remove a subscription, call the RemoveSecurity method.

self.RemoveSecurity(self.pe_ratio_symbol)
self.RemoveSecurity(self.position_change_symbol)
RemoveSecurity(_peRatioSymbol);
RemoveSecurity(_positionChangeSymbol);

Example Applications

The Nasdaq Data Link sources allow you to explore different kinds of data in their database to develop trading strategies. Examples include the following strategies:

  • Using alternative data to regress market regime/asset price.
  • Backtesting exotic derivatives or private Equity investments.

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: