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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
17 1 1 3

Forward curves using a loop.

So, I can use get_data to pull forward curves. For example:

fields = ['EXPIR_DATE','CF_LAST']

fwd_lls, err = ek.get_data('0#LLSUSSWD:',fields)
fwd_mars, err = ek.get_data('0#MRSUSSWD:',fields)
fwd_wti, err = ek.get_data('0#WTICAL:',fields)

But I have a significant amount of RICs that I need to pull curves for. Is there a way to employ a loop to accomplish this? I'm new to Python.

eikon-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.

1 Answer

Upvote
Accepted
49.4k 123 44 61

@Corey.Stewart

The code should look like this:

from time import sleep
import pandas as pd

fields = ['EXPIR_DATE','CF_LAST']
rics = ["0#LLSUSSWD:","0#MRSUSSWD:","0#WTICAL:"]
df_list = []

for ric in rics:
    print("Request: ",ric)
    df, err = ek.get_data(ric,fields)
    if err != None:
        print(err)
    else:
        df_list.append(df)

    sleep(0.05)
pd.concat(df_list)

The rics variable contains a list of RICs.


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.

Thank you!