Forward curve using get_data
If I want a forward curve, for, say, NYMEX WTI I can enter:
wti, err = ek.get_data('0#CL:', fields=['CF_Last','EXPIR_Date'])
and get the forward curve as it is right now. But is there a way to use get_data to get it for another date? For example, how the curve was 3 weeks ago (I'm ignoring rolls, etc.)?
I can use get_timeseries to pull CLc1, CLc2, etc. and build a dataframe to get the snapshots in time that I need, but that approach is not very efficient.
Example:
wti_rics = ['CLc1','CLc2','CLc3','CLc4','CLc5','CLc6','CLc7',
'CLc8','CLc9','CLc10','CLc11','CLc12']
wti = ek.get_timeseries(wti_rics,
fields=['TIMESTAMP','Close'],
start_date = (date.today()-timedelta(days=31)).strftime("%Y-%m-%d"),
end_date = (date.today()).strftime("%Y-%m-%d"),
interval = "daily"
)
c1 = wti.iloc[20][0]
c2 = wti.iloc[20][1]
c3 = wti.iloc[20][2]
c4 = wti.iloc[20][3]
c5 = wti.iloc[20][4]
c6 = wti.iloc[20][5]
c7 = wti.iloc[20][6]
c8 = wti.iloc[20][7]
c9 = wti.iloc[20][8]
c10 = wti.iloc[20][9]
c11 = wti.iloc[20][10]
c12 = wti.iloc[20][11]
w1 = wti.iloc[15][0]
w2 = wti.iloc[15][1]
w3 = wti.iloc[15][2]
w4 = wti.iloc[15][3]
w5 = wti.iloc[15][4]
w6 = wti.iloc[15][5]
w7 = wti.iloc[15][6]
w8 = wti.iloc[15][7]
w9 = wti.iloc[15][8]
w10 = wti.iloc[15][9]
w11 = wti.iloc[15][10]
w12 = wti.iloc[15][11]
t1 = wti.iloc[5][0]
t2 = wti.iloc[5][1]
t3 = wti.iloc[5][2]
t4 = wti.iloc[5][3]
t5 = wti.iloc[5][4]
t6 = wti.iloc[5][5]
t7 = wti.iloc[5][6]
t8 = wti.iloc[5][7]
t9 = wti.iloc[5][8]
t10 = wti.iloc[5][9]
t11 = wti.iloc[5][10]
t12 = wti.iloc[5][11]
wti_data = [['Mo1',c1,w1,t1],['Mo2',c2,w2,t2],['Mo3',c3,w3,t3],['Mo4',c4,w4,t4],['Mo5',c5,w5,t5],['Mo6',c6,w6,t6],['Mo7',c7,w7,t7],
['Mo8',c8,w8,t8],['Mo9',c9,w9,t9],['Mo10',c10,w10,t10],['Mo11',c11,w11,t11],['Mo12',c12,w12,t12]]
wti_evolution = pd.DataFrame(wti_data, columns = ['Contract','Current','1 Week Ago','3 Weeks Ago'])
Best Answer
-
I am not sure if this is what you are looking for?
wti_rics = ['CLc1','CLc2','CLc3','CLc4','CLc5','CLc6','CLc7','CLc8','CLc9','CLc10','CLc11','CLc12']
fields = ['TR.ClosePrice.date','TR.ClosePrice',
'TR.ClosePrice(SDate=2021-06-23).date','TR.ClosePrice(SDate=2021-06-23)',
'TR.ClosePrice(SDate=2021-06-09).date','TR.ClosePrice(SDate=2021-06-09)']
df,e = ek.get_data(wti_rics, fields)
df0
Answers
-
Any ideas here? Is there a more intuitive way to do what I'm trying to accomplish?
0 -
Yes, much more efficient - thank you. I've never worked with TR.ClosePrice, so I'll need to modify what you have to have dynamic, rather than static, dates, but otherwise this is perfect.0
Categories
- All Categories
- 6 AHS
- 39 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 60 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛