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:

from QuantConnect.DataSource import *

# For premium datasets, provide your API Key
# NasdaqDataLink.set_auth_pre(self.get_parameter("nasdaq-data-link-api-key"))

self.pe_ratio_symbol = self.add_data(NasdaqDataLink, "MULTPL/SP500_PE_RATIO_MONTH", Resolution.DAILY).symbol
# This dataset has one data column ("Value")

self.position_change_symbol = self.add_data(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.value_column_name = "open interest - change"
using QuantConnect.DataSource;

// For premium datasets, provide your API Key
// NasdaqDataLink.SetAuthCode(GetParameter("nasdaq-data-link-api-key"));

_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") { }
}

Our Nasdaq Data Link integration supports any dataset from Nasdaq that has a URL starting with data.nasdaq.com/data/. To import a dataset from Data Link, you need to get the dataset code. Follow these steps to get the dataset code:

  1. Open the Data Link catalog.
  2. (Optional) Use the filters on the left side bar to narrow down the catalog results.
  3. Click one of the data products.
  4. On the data product page, click one of the table names.
  5. In the top-right corner of the dataset page, copy the Nasdaq Data Link Code.

Data Summary

The data summary depends on the specific Data Link dataset you use. Follow these steps to view the data summary of a dataset:

  1. Open the Data Link catalog.
  2. Click one of the data products.
  3. On the data product page, click one of the table names.
  4. View the data frequency and description in the left sidebar.
  5. Above the chart, click Table to view the start date, end date, and data point attributes.

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.

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.

For more example algorithms, see Examples.

Requesting Data

To add Data Link 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. 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 ValueColumnNamevalue_column_name property to the column name.

class NasdaqDataLinkDataAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self.set_start_date(2022, 1, 1)
        self.set_end_date(2022, 7, 1)
        self.set_cash(100000)

        # For premium datasets, provide your API Key
        # NasdaqDataLink.set_auth_pre(self.get_parameter("nasdaq-data-link-api-key"))

        self.pe_ratio_symbol = self.add_data(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.add_data(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.value_column_name = "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(GetParameter("nasdaq-data-link-api-key"));

            _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 Valuevalue property. To get the value of a specific column in the dataset, call the GetStorageDictionaryget_storage_dictionary method and index the result with the column name.

def on_data(self, slice: Slice) -> None:
    if slice.contains_key(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.contains_key(self.position_change_symbol):
        data_point = slice[self.position_change_symbol]
        open_interest_change = data_point.value
        storage_dictionary = data_point.get_storage_dictionary()
        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 Getget method.

def on_data(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

The process to get historical Data Link data depends on your environment.

In Algorithms

To get historical Data Link data in an algorithm, call the Historyhistory 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.

In Research Notebooks

To get historical Data Link data in the Research Environment, call the Downloaddownload method with the data URL.

from io import StringIO
data = qb.download("data.nasdaq.com/api/v3/datasets/MULTPL/SP500_PE_RATIO_MONTH.csv?")
df = pd.read_csv(StringIO(data), index_col=0)
var data = qb.Download("data.nasdaq.com/api/v3/datasets/MULTPL/SP500_PE_RATIO_MONTH.csv?");

To receive a notification when you can use the Historyhistory method in the Research Environment to get data from Data Link, subscribe to Lean.DataSource.NasdaqDataLink GitHub Issue #10.

Remove Subscriptions

To remove a subscription, call the RemoveSecurityremove_security method.

self.remove_security(self.pe_ratio_symbol)
self.remove_security(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.

For more example algorithms, see Examples.

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: