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.

Tagged:

Best Answer

  • Jirapongse
    Jirapongse admin
    Answer ✓

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


Answers