Upgrade from Eikon -> Workspace. Learn about programming differences.

For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
17 1 4 5

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'])


eikoneikon-data-apirefinitiv-dataplatform-eikonworkspaceworkspace-data-api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Any ideas here? Is there a more intuitive way to do what I'm trying to accomplish?

1 Answer

· Write an Answer
Upvotes
Accepted
18.2k 21 13 21

Hi @Corey.Stewart

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)
df
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

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.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.