book
Checkout our new book! Hands on AI Trading with Python, QuantConnect, and AWS Learn More arrow

QuantConnect

Cash Indices

Introduction

The Cash Indices dataset by QuantConnect covers 125 US Indices and 3 International indices. The data starts on various dates from January 1998 and is delivered on any frequency from minute to daily.

For more information about the Cash Indices dataset, including CLI commands and pricing, see the dataset listing.

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.

Live Data

The Cash Indices dataset does not provide a live data feed. To receive Cash Indices' data in your live algorithm, you must add a brokerage or a third-party data provider (see Cloud Platform > Datasets).

Getting Started

The following snippet demonstrates how to request data from the Cash Indices dataset:

self.vix = self.add_index("VIX", Resolution.DAILY).symbol
_symbol = AddIndex("VIX", Resolution.Daily).Symbol;

Data Summary

The following table describes the dataset properties:

PropertyValue
Start DateJanuary 1998
Coverage125 US Indices and 3 International indices (HSI, SX5E and N225)
Data DensityDense
ResolutionMinute, Hour, & Daily
TimezoneNew York for US Indices, refer to Supported Assets below for International indices
Market HoursRegular Only

Example Applications

The Cash Indices enables you to incorporate popular indices into your trading algorithms. Examples include the following use cases:

  • Exploring the difference between the Index and the ETF that tracks it
  • Using these indices as the underlying asset fo Index Options strategies
  • Understanding the stock market's level of expected forward-looking volatility, also known as the "fear index". When the VIX starts moving higher, it is telling you that traders are getting nervous. When the VIX starts moving lower, it is telling you that traders are gaining confidence.

For more example algorithms, see Examples.

Data Point Attributes

The Cash Indices dataset provides TradeBar object.

TradeBar Attributes

TradeBar objects have the following attributes:

Supported Indices

US Cash Indices

The following table shows the US Cash indices with Index Option support:

TickerIndexExpiryStart Date
VIXS&P50030 DaysJul 2003
SPXS&P500-Jan 1998
NDXNASDAQ-100-Jan 1998
RUTRussell 2000-Jan 2008
VIX - CBOE Volatility Index

The Cboe Volatility Index (VIX) is a real-time index that represents the market's expectations for the relative strength of near-term price changes of the S&P 500 Index (SPX). Because it's derived from the prices of SPX index Options with near-term expiration dates, it generates a 30-day forward projection of volatility. Volatility, or how fast prices change, is often seen as a way to gauge market sentiment, and in particular, the degree of fear among market participants.

SPX - S&P 500 Index

The S&P 500 Index, or the Standard & Poor's 500 Index, is a market-capitalization-weighted index of the 500 largest publicly-traded companies in the U.S. It is not an exact list of the top 500 U.S. companies by market capitalization because there are other criteria included in the index. The index is widely regarded as the best gauge of large-cap U.S. Equities.

NDX - Nasdaq 100 Index

The Nasdaq-100 Index is a modified market-capitalization-weighted index composed of securities issued by 100 of the largest non-financial companies listed on the Nasdaq Stock Market (Nasdaq). The index includes companies from various industries except for the financial industry, like commercial and investment banks. These non-financial sectors include retail, biotechnology, industrial, technology, health care, and others.

RUT - Russell 2000 Index

The Russell 2000 Index is a small-cap U.S. stock market index that makes up the smallest 2,000 stocks in the Russell Index. It was started by the Frank Russell Company in 1984. The index is maintained by FTSE Russell, a subsidiary of the London Stock Exchange Group (LSEG).

All US Cash Indices
The following table shows all US Cash indices:

International Cash Indices

The following table shows the International Cash indices:

TickerIndexStart DateTime ZoneCurrency
HSIHang Seng Index Dec 2006Asia/Hong KongHKD
SX5EEUREX EU STOXXJul 2003Europe/BerlinEUR
N225Nikkei 225 Jul 2003Asia/TokyoJPY

Requesting Data

To add Cash Indices data to your algorithm, call the AddIndexadd_index method. Save a reference to the Index Symbol so you can access the data later in your algorithm.

class CashIndexAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2020, 6, 1)
        self.set_end_date(2021, 6, 1)
        self.set_cash(100000)

        self.vix = self.add_index("VIX").symbol
namespace QuantConnect
{
    public class CashIndexAlgorithm : QCAlgorithm
    {
        private Symbol _symbol;
        
        public override void Initialize()
        {
            SetStartDate(2020, 6, 1);
            SetEndDate(2021, 6, 1);
            SetCash(100000);
            
            _symbol = AddIndex("VIX").Symbol;
        }
    }
}

For more information about creating Index subscriptions, see Requesting Data.

Accessing Data

To get the current Cash Indices data, index the Barsbars property of the current Slice with the Index Symbol. Slice objects deliver unique events to your algorithm as they happen, but the Slice may not contain data for your security 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 self.vix in slice.bars:
        trade_bar = slice.bars[self.vix]
        self.log(f"{self.vix} close at {slice.time}: {trade_bar.close}")
public override void OnData(Slice slice)
{
    if (slice.Bars.ContainsKey(_symbol))
    {
        var tradeBar = slice.Bars[_symbol];
        Log($"{_symbol} price at {slice.Time}: {tradeBar.Close}");
    }
}

You can also iterate through all of the data objects in the current Slice.

def on_data(self, slice: Slice) -> None:
    for symbol, trade_bar in slice.bars.items():
        self.log(f"{symbol} close at {slice.time}: {trade_bar.close}")
public override void OnData(Slice slice)
{
    foreach (var kvp in slice.Bars)
    {
        var symbol = kvp.Key;
        var tradeBar = kvp.Value;
        Log($"{symbol} price at {slice.Time}: {tradeBar.Close}");
    }
}

For more information about accessing Index data, see Handling Data.

Historical Data

To get historical Cash Indices data, call the Historyhistory method with the Index Symbol. If there is no data in the period you request, the history result is empty.

# DataFrame
history_df = self.history(self.vix, 100, Resolution.DAILY)

# TradeBar objects
history_bars = self.history[TradeBar](self.vix, 100, Resolution.DAILY)
// TradeBar objects
var historyBars = History(_symbol, 100, Resolution.Daily);

For more information about historical data, see History Requests.

Remove Subscriptions

To remove an Index subscription, call the RemoveSecurityremove_security method.

self.remove_security(self.vix)
RemoveSecurity(_symbol);

Example Applications

The Cash Indices enables you to incorporate popular indices into your trading algorithms. Examples include the following use cases:

  • Exploring the difference between the Index and the ETF that tracks it
  • Using these indices as the underlying asset fo Index Options strategies
  • Understanding the stock market's level of expected forward-looking volatility, also known as the "fear index". When the VIX starts moving higher, it is telling you that traders are getting nervous. When the VIX starts moving lower, it is telling you that traders are gaining confidence.

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: