Getting Historical Futures Data

abrohit
Say I have the tradingsymbol: RELIANCE26JANFUT (instrument token: 12798210) from the current snapshot of instruments. If I got historical data with continuous=True for this instrument token for the dates: start_date = "2025-01-01" ; end_date = "2025-05-31", why do I get OHLCV data past JAN expiry date?

Since I am getting historical data it's getting data for RELIANCE25JANFUT (not RELIANCE26JANFUT) which definitely expires in Jan, but I see valid data past JAN, why is that?
Tagged:
  • abrohit
    Additionally, when I get historical data for instruments:
    1. RELIANCE26JANFUT (instrument token: 12798210)
    2. RELIANCE26FEBFUT (instrument token: 15221762)

    For the specific date: "2025-02-18"(==start_date==end_date), interval="day" and continuous=True, the OHLCV data is not the same.
  • nagavenij
    nagavenij edited January 23
    To understand the continuous=True parameter in more detail, refer to the official documentation.

    Please note that the OHLC values will not be identical to those of individual futures contracts. Continuous futures charts aggregate historical data across contracts by categorizing them into current, near, and far months.
    When fetching historical data for the current month, data from all historically current-month contracts is combined. Similarly, fetching data for the near month aggregates data from all historically near-month contracts, and the same logic applies to the far month.
  • abrohit
    Since I was using Jan 2026 Futures' instrument token to retrieve data for the futures pricing in Jan 2025, I used continuous=True, which I did refer to the linked documentation prior to this thread.

    I guess my question now is how is the OHLCV data combined after Jan 2025's expiry date? Also, in instruments I see that the Jan 2026 futures expire 2026-01-27. Shouldn't Futures expire on the last Thursday of the month?
  • abrohit
    Also, is there a way of knowing when the historical contract expired? For the Jan 2025 futures contract, how do I know when it expired?
  • abrohit
    I see that this token expires on the last Tuesday of the month, nvm. But I am still very confused about how the data is combined.

    To provide more context for my confusion.

    Instrument token mapping:
    RELIANCE26JANFUT = 12798210
    RELIANCE26FEBFUT = 15221762
    RELIANCE26MARFUT = 13317890
    Here, I am getting data for the three above instruments for the same date in Feb:
    jan_data = get_historical_data(12798210, "2025-02-18", "2025-02-18", "day", continuous=True) 
    feb_data = get_historical_data(15221762, "2025-02-18", "2025-02-18", "day", continuous=True)
    mar_data = get_historical_data(13317890, "2025-02-18", "2025-02-18", "day", continuous=True)
    When I print them in that order, I get:


    Why do they all disagree?

    Now for the same 3 instruments for a date in March:
    jan_data = get_historical_data(12798210, "2025-03-18", "2025-03-18", "day", continuous=True)
    feb_data = get_historical_data(15221762, "2025-03-18", "2025-03-18", "day", continuous=True)
    mar_data = get_historical_data(13317890, "2025-03-18", "2025-03-18", "day", continuous=True)
    And I print them in that same order, I get:


    Both Jan and Feb should have expired here, but they both return different data. Why?
  • nagavenij
    NIFTY futures expire on the last Tuesday of every month. You may refer to the provided link for further details.

    There are no API endpoints available to fetch information on expired historical contracts. This data can be obtained directly from the NSE website.

    You may refer to this link for more information on how continuous data works.
Sign In or Register to comment.