How to use RICs under a chain in a code without typing all underlying rics of a chain?


Is there a way to pull the cop xccy basis data for the whole curve in codebook without pulling each individual tenor ric? Example below, I have to enter all the RICs under COPCBS=TRNY. Can we just use COPCBS=TRNY and pull all necessary data like Bid and Ask across all tenors?


Currently i am using: df_cop_xccy_curve = ek.get_timeseries(['COPCBS3M=TRNY','COPCBS6M=TRNY','COPCBS3M=TRNY','COPCBS9M=TRNY','COPCBS1Y=TRNY','COPCBS18M=TRNY','COPCBS2Y=TRNY','COPCBS3Y=TRNY','COPCBS4Y=TRNY', 'COPCBS5Y=TRNY',,'COPCBS6Y=TRNY','COPCBS7Y=TRNY']) df_cop_xccy_curve


but this is quite long. I need to do this for every currency so would appreciate a way to speed this up basically im trying to pull the cross currency curves into python for all currencies so wondering if there's a way to do this quickly

Best Answer

  • Jirapongse
    Jirapongse ✭✭✭✭✭
    Answer ✓

    @HannaCP

    Thank you for reaching out to us.

    Please try this code:

    LONGNEXTLR = 'COPCBS=TRNY'
    fields = ['LONGLINK{}'.format(x) for x in range(1, 15)]
    fields.append('LONGNEXTLR')
    all_components = []
    while LONGNEXTLR!='':
        df,e = ek.get_data(LONGNEXTLR,fields)
        LONGNEXTLR = df.iloc[0]['LONGNEXTLR'] if pd.notnull(df.iloc[0]['LONGNEXTLR']) else ''
        for x in range(1, 15):
            currentField = 'LONGLINK{}'.format(x)
            all_components.append(df.iloc[0][currentField]) if pd.notnull(df.iloc[0][currentField]) else None
            
    ts = ek.get_timeseries(all_components[1:])
    ts

    The code gets the underlying RICs from this chain by accessing the LONGLINK fields directly. Then, it passes the list of underlying RICs to the get_timeseries method.



Answers

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.