Best way to get the price for the next expiring Dow Jones and NASDAQ future contracts?

I am trying to get the price for the next expiring future contract on a given date for Dow Jones and NASDAQ through python API? I am having a hard time figuring it out. Any help is appreciated. Thanks
Best Answer
-
@tmohann In Eikon we have instruments called continuation futures which are the front month future and takes into account futures rolls. Please look at the RICs : YMc1 (Mini Dow future) & NQc1 (NASDAQ Mini future). Following expiry futures are also available by replacing the 1 (ie 1st expiring future) with a 2 (ie 2nd expiring future) or a 3 (3rd expiring future). The great thing is you can get a series of such values:
ek.get_timeseries(['YMc1','NQc1'], start_date='01-01-2017', end_date='01-01-2019', interval='daily')
0
Answers
-
Jason - Thank you. This works great. Any chance you have how to get the number of days left to the expiry? For ex, number of trading days to YMc1? Appreciate your help! Thank you
0 -
There is a field EXPIR_DATE you can use to calc the number of days to expiry
future, err = ek.get_data('NQc1','EXPIR_DATE')
0 -
Thanks James. I am trying to get EXPIR_DATE on historical basis i.e. for each date, what the next expiry date for YMc1 over the course of the last 2 years. I am not able to get the historical data with get_data for EXPIR_DATE. Is that even possible? Thanks
0 -
We do store expired Futures data contracts .. by using a ^ after the RIC we do display the data and you can pull time series. That being said the historical Expiry Date field does not seem to be available yet in Eikon DAPI (although it is in the desktop GUI).
0 -
I'm not a python expert but was able to work through the calculation of days until expiry as follows (the simplification is at the end).
I used datetime to do the subtraction of dates between today and the expiration.
You won't see the output of the code here, except for the last one, but it works for me in my jupyter notebook, and would encourage you to try it out.
#Do the imports...
import eikon as ek
import configparser as cp
import pandas as pd
import datetime as dt
from datetime import datetime, date, time#Get the app key setup
cfg = cp.ConfigParser()
cfg.read('eikon.cfg')
#Eikon.cfg must be in the same folder as script here, and contains the key
key = cfg['eikon']['key']
ek.set_app_key(key)#Get the Eikon data - in this case a future expiry date
future, err = ek.get_data('NQc1','EXPIR_DATE')
future#The above puts out a pandas dataframe but we want a string so we can parse it into a datetime format
stringExpDate = future["EXPIR_DATE"][0]
stringExpDatedateTimeExpDate = datetime.strptime(stringExpDate, "%Y-%m-%d")
dateTimeExpDatedateExpDate = dateTimeExpDate.date() # convert exDate to date from datetime
dateExpDatetodayDate = dt.date.today() #Get today's date
todayDate#Now a simple subtraction is supported with datetime
difference = dateExpDate - todayDate
differencedifference.days # use the days attribute to get the days from this timedetla datatype...
#Here is the simplification
future, err = ek.get_data('NQc1','EXPIR_DATE') # get the Eikon data, in this case an expiration date for an option
days = (datetime.strptime(future["EXPIR_DATE"][0], "%Y-%m-%d").date() - dt.date.today()).days #get the number of days until it expiration
days10
0 -
Thanks Jon. That looks great. I needed the historical pricing and the date to expiry over time. Looks like data API doesn't provide EXPIR_DATE for prior contracts. For now, I ended up building a hack to project expiry date based on the contract pricing date and the next 3rd Friday of the quarter. That seems to work. Thanks for all the help!
0 -
That is a good workaround. Just keep in mind that each exchange and contract have different expiry rules (am assuming already factored into your analysis). If you ever need to check you can reference contract trading details by exchange/instrument.
0
Categories
- All Categories
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 682 Datastream
- 1.4K DSS
- 613 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 248 ETA
- 552 WebSocket API
- 37 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 626 Refinitiv Data Platform Libraries
- 5 LSEG Due Diligence
- 1 LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 26 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 191 TREP Infrastructure
- 228 TRKD
- 915 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 83 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛