Datastream API Tenor in Timeseries Response

Archi
Archi Newcomer

I'm using datastream to get a time series, but I cannot figure out how to get the tenor in the response.

The Below Returns me (Instrument, Datatype, Value, Currency, Dates).

Ideally I would be able to Extract out a tenor column with values 1M, 3M, 6M, 1Y, 3Y without having to try and break it out of the RIC Code. How can this be achived?

Thanks,


Adam


dateString = "2022-07-14"

market_data_df = ds.get_data(tickers='<USYTFRB1M=RR>,<USYTFRB2M=RR>,<USYTFRB3M=RR>,<USYTFRB6M=RR>,<US1YT=RR>,<US2YT=RR>,<US3YT=RR>,<US5YT=RR>,<US7YT=RR>,<US10YT=RR>,<US20YT=RR>,<US30YT=RR>', fields=['RY'], start=f'{dateString}',end=f'{dateString}', kind=1)

market_data_df


Best Answer

  • Jirapongse
    Jirapongse ✭✭✭✭✭
    Answer ✓

    @Archi

    I am unable to find a data type that can provide the tenor but I found that the "NAME" data type contains the tenor.

    df = ds.get_data(tickers='<USYTFRB1M=RR>,<USYTFRB2M=RR>,<USYTFRB3M=RR>,<USYTFRB6M=RR>,<US1YT=RR>,<US2YT=RR>,<US3YT=RR>,<US5YT=RR>,<US7YT=RR>,<US10YT=RR>,<US20YT=RR>,<US30YT=RR>',  fields= ['NAME'],kind=0)

    1657860351663.png

    We can extract the tenor from the NAME data type.

    df["Tenor"] = df["Value"].str.split().str[-1]

    The output is:

    1657860462124.png

    However, please contact the Datastream Webservice support team directly via MyRefinitiv to confirm this.

Answers

  • Archi
    Archi Newcomer

    Pretty good - any way to get that DataType as a column rather than as a set of separate rows.


    1657862138945.png


  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @Archi

    You can use the pivot method to reformat the result.

    dateString = "2022-07-14"

    market_data_df = ds.get_data(tickers='<USYTFRB1M=RR>,<USYTFRB2M=RR>,<USYTFRB3M=RR>,<USYTFRB6M=RR>,<US1YT=RR>,<US2YT=RR>,<US3YT=RR>,<US5YT=RR>,<US7YT=RR>,<US10YT=RR>,<US20YT=RR>,<US30YT=RR>', fields=['RY','NAME'], start=f'{dateString}',end=f'{dateString}', kind=0)

    market_data_df = market_data_df.pivot(index='Instrument', columns='Datatype')['Value']

    market_data_df["Tenor"] = market_data_df["NAME"].str.split().str[-1]

    market_data_df

    The output is:

    1657862514439.png