Login

Reset password

Bulk API

12:55 AM    /       /    7 min read    /       /   

Minimal working example:

import pandas as pd

url = "https://api.corrgrid.com/v2/2025-02-26/corr/raw/relation?token=demo"
correlation_matrix = pd.read_json(url, storage_options = {"User-Agent": "api"}, orient='split')
print(correlation_matrix)

Core Concept:

  • Please see the FAQ for a detailed introduction to basic concepts.
  • API provides bulk access to pre-calculated tables representing pairwise relationships (correlation, cointegration, hurst exponent, etc.) between a universe of approximately 3,5001 liquid US stocks and ETFs for a specific historical date.
  • Each table (except for the instruments endpoint) is provided as a square matrix in JSON format, designed for straightforward import into a Pandas DataFrame.
  • This guide provides instructions for accessing the CorrGrid API endpoints. While the underlying data is provided as gzipped JSON files (suitable for loading from any client), this guide focuses on retrieving bulk data directly into Python Pandas DataFrames.  

API Endpoints

API Base URL: https://api.corrgrid.com/v2

Path Template:

.../v2/YYYY-MM-DD/{ corr coi }/{ raw ex_spy ex_etf }/{ relation beta hurst hedge_ratio half_life ... }?token={access_token}



Authentication

For evaluation, use the provided demo token by appending ?token=demo to the API endpoint URL.

For production use, it is strongly recommended to pass your API key via the X-API-TOKEN header.

  • Rate Limiting: Demo access is rate-limited. Exceeding the limit may result in a 429 Too Many Requests error or a response containing an error message.
  • Limitation: Demo access is strictly limited to the fixed date: 2025-02-26. Requests for other dates using ?token=demo will return an error.


Instruments Identifiers and Table Structure

We will refer to the combination of two financial instruments (’legs’), where a long position in one is hedged by a short position in the other (scaled by β), as a spread or synthetic instrument (more common) or two-legged (hedged) position. Its value is calculated as:

Spread = Leg A - β × Leg B

  • The row index represents ‘Leg A’, and the column index (or labels) represent ‘Leg B’.
  • The key identifier for instruments within these tables (rows, columns) is the PIT-Symbol (Point-In-Time Symbol), ensuring consistency regardless of market ticker changes over time. See more.
  • In raw mode, both Leg A and Leg B refer to specific stock or ETF instruments identified by their unique PIT-Symbols ( Point-In-Time Symbols ).
  • In ex_spy mode, Leg A and Leg B effectively represent the instruments from ‘raw’ mode but adjusted to remove the broad market influence (proxied by SPY), thereby filtering out this source of systematic noise. See What are ex-SPY and ex-ETF?
  • In ex_etf mode, Leg A and Leg B effectively represent the instruments from ‘raw’ mode but adjusted to remove sector-specific influence (‘sector noise’), using each instrument’s most relevant sector ETF as the proxy. See How is the ETF selected for ex-ETF calculations?
  • The mapping from PIT-Symbols to the date-specific market ticker is available via the /instruments endpoint (described below).

To optimize data transfer, the API returns integer values for most tables. You must divide these integers by the specified multiplier (e.g., 100.0 or 1000.0) to obtain the actual floating-point metric values. Multipliers are listed below for each metric.

Raw Mode (.../raw/...)


Examples for Correlations (.../corr/raw/...)


Let’s assume we have the symbols for MSFT and CSCO for the demo date (2025-02-26).

Example: Find the correlation between MSFT and CSCO.
import pandas as pd
symbol_leg_A='MSFT...'
symbol_leg_B='CSCO...'
url = "https://api.corrgrid.com/v2/2025-02-26/corr/raw/relation?token=demo"
# Divide by multiplier (100.0 for correlations)
corr_matrix = pd.read_json(url,
          storage_options = {"User-Agent": "api"}, 
          orient='split') / 100.0
print('MSFT vs CSCO correlation: ',corr_matrix.loc[symbol_leg_A,symbol_leg_B])

Example: Find the β coefficient for hedging MSFT with CSCO.

This β is used to construct the two-legged position (spread): MSFTβ × CSCO.

url = "https://api.corrgrid.com/v2/2025-02-26/corr/raw/beta?token=demo"
# Divide by multiplier (100.0 for beta)
betas = pd.read_json(url, storage_options = {"User-Agent": "api"}, orient='split') / 100.0
print('Beta in MSFT - beta*CSCO. Beta:',betas.loc[symbol_leg_A,symbol_leg_B])

Example: Find the volatility reduction (R²) for the hedged position.

This shows the percentage reduction in volatility for MSFTβ × CSCO compared to an unhedged MSFT position.

url = "https://api.corrgrid.com/v2/2025-02-26/corr/raw/R2?token=demo"
R2s = pd.read_json(url, storage_options = {"User-Agent": "api"}, orient='split')
print('R2:',R2s.loc[symbol_leg_A,symbol_leg_B])

Example: Find the Beta coefficient for hedging CSCO with MSFT.

This beta (denoted as β*) is for the position: CSCOβ* × MSFT.

# Get the beta for hedging Leg B (CSCO) with Leg A (MSFT)
# Note the order: index=Leg B, column=Leg A
url = "https://api.corrgrid.com/v2/2025-02-26/corr/raw/beta?token=demo"
betas = pd.read_json(url, storage_options = {"User-Agent": "api"}, orient='split') / 100.0
print('Beta for CSCO - β* * MSFT. β*:', betas.loc[symbol_leg_B, symbol_leg_A])
# Note: Beta(A, B) is generally NOT equal to 1 / Beta(B, A) in the correlation context.

Example: Find the Hurst Exponent for the hedged position MSFTβ × CSCO.

This indicates the tendency towards Mean Reversion ( H < 0.5 ) or Trending behavior ( H > 0.5 ) for the spread between the two assets based on the calculated β-hedge.

url = "https://api.corrgrid.com/v2/2025-02-26/corr/raw/hurst?token=demo"
hurst_exponents = pd.read_json(url,
                    storage_options = {"User-Agent": "api"},
                    orient='split') / 100.0
print('Hurst Exponent:', hurst_exponents.loc[symbol_leg_A,symbol_leg_B])

Example: Find the effective Bid-Ask Spread (%) of the synthetic position:

This estimates the typical bid-ask spread if the two-legged hedged position MSFTβ × CSCO were treated as a single synthetic instrument.

url = "https://api.corrgrid.com/v2/2025-02-26/corr/raw/bidask_spread?token=demo"
bidask_spreads = pd.read_json(url,
                    storage_options = {"User-Agent": "api"},
                    orient='split') / 1000.0
print('Effective Bid-Ask Spread:', bidask_spreads.loc[symbol_leg_A,symbol_leg_B])

Available Tables2 ( …/corr/…):

   
   relation / 100.0   Correlation3 of returns(Δ) between Leg A and Leg B.
   beta / 100.0   Optimal4 β coefficients for hedging Long (Leg A) with Short (β × Leg B).
   hurst / 100.0   Hurst Exponent of Leg A - β × Leg B.
   R2     (R-squared)   Volatility reduction of returns (Δ) for Long (Leg A) with Short (β × Leg B).
   half_life    Half-life (in days) of Leg A - β × Leg B
   bidask_spread / 1000.0   Effective bid-ask spread of Leg A - β × Leg B.
   range_to_bidask_spread   RS tradability metric: What is Range to Bid-Ask ( hedged_std / bidask_spread )
   hurst_boost / 100.0   Hurst Boost: H(Leg A - β × Leg B) - min(H(Leg A), H(Leg B)).
   hedged_std / 1000.0   Standard deviation (std) of returns for Leg A - β × Leg B.



Examples for Cointegrations (.../coi/raw/...)


Example: Find the cointegration strength between BRK.A and BRK.B:
import pandas as pd
symbol_leg_A='BRK.A...'
symbol_leg_B='BRK.B...'
url = "https://api.corrgrid.com/v2/2025-02-26/coi/raw/relation?token=demo"
# Divide by multiplier (100.0 for coi relations)
cointegration_matrix = pd.read_json(url, storage_options = {"User-Agent": "api"}, orient='split') / 100.0
# The resulting `cointegration_matrix` DataFrame contains the 'Cointegration Strength' (from Johansen test max eigenvalue).
# A value of 0 indicates that cointegration was not detected or was statistically insignificant.
print('BRK.A ~ BRK.B cointegration: ',cointegration_matrix.loc[symbol_leg_A,symbol_leg_B])

Example: Find the Hedge Ratio ( hr ) for the cointegrated pair:

This hr is derived from the Johansen test and is used to form the stationary spread: BRK.Ahr × BRK.B.

import pandas as pd
symbol_leg_A='BRK.A...'
symbol_leg_B='BRK.B...'
url = "https://api.corrgrid.com/v2/2025-02-26/coi/raw/hedge_ratio?token=demo"
# Divide by multiplier (100.0 for coi hedge ratios)
hedge_ratios = pd.read_json(url, storage_options = {"User-Agent": "api"}, orient='split') / 100.0
print('BRK.A - hr * BRK.B hedge ratio. hr =: ',hedge_ratios.loc[symbol_leg_A,symbol_leg_B])
# Note: If cointegration strength is 0, this hedge ratio is set to 0.

Available Tables2 (.../coi/...):

   
   relation / 100.0   Cointegration5 between Leg A and Leg B.
   hedge_ratio / 100.0   Hedge Ratio (hr) in Leg A - hr × Leg B.
   hurst / 100.0   Hurst Exponent of Leg A - hr × Leg B.
   half_life    Half-life (in days) of Leg A - hr × Leg B
   bidask_spread / 1000.0   Effective bid-ask spread of Leg A - hr × Leg B.
   range_to_bidask_spread   RS tradability metric: What is Range to Bid-Ask ( hedged_std / bidask_spread )
   hurst_boost / 100.0   Hurst Boost: H(Leg A - hr × Leg B) - min(H(Leg A), H(Leg B)).


Instruments endpoint



.../v2/YYYY-MM-DD/instruments?token={access_token}



Example: Getting the PITSymbol for a Symbol as of a Date
import pandas as pd

url = "https://api.corrgrid.com/v2/2025-02-26/instruments?token=demo"

instruments = pd.read_json(url,  storage_options = {"User-Agent": "api"})
symbol_to_PITSymbol = instruments.set_index('symbol')['PITsymbol'].to_dict()
symbol_leg_A = symbol_to_PITSymbol['MSFT']
symbol_leg_B = symbol_to_PITSymbol['CSCO']
print('PITSymbol for MSFT as of 2025-02-26', symbol_leg_A)
print('PITSymbol for CSCO as of 2025-02-26', symbol_leg_B)

  1. Survivorship bias free ↩︎

  2. All tables return integer values; divide by the specified multiplier (if any) to get the actual floating-point value. ↩︎ ↩︎

  3. Kendall Tau scaled to Pearson Why is Kendall’s Tau used ↩︎

  4. Minimizing the variability of ΔLeg A - β × ΔLeg B ↩︎

  5. 0 indicates not detected or insignificant. ↩︎


March 31, 2025  
Disclaimer

The provided content and materials are not designed to serve as financial, investment, trading, or any other form of advice, nor should they be interpreted as recommendations endorsed or verified by CorrGrid or its affiliates. For more information, please visit Terms of Use