Historical CDS Data for a certain time range

Hey I used the __Examples__/03. Quantitative Analytics/03.05. Credit Derivatives/CDS.ipynb codebook in the Workspace for some information's on CDS Data. What I need is the historical CDS Spreads from Single Name CDS that were traded by non-sovereign from the time range 01.01.2006 until 31.12.2010. How do I get this data could someone please help me out what line of codes I have to write in order to get this data ? All the codes I saw in this forum did not work on my case and I also need the code for a specific time range.

Best Answer

  • [Deleted User]
    [Deleted User] Newcomer
    Answer ✓

    Hi @sahin.yigit,

    Is this what you're after?

    import pandas as pd
    from datetime import datetime
    import refinitiv.data as rd
    rd.open_session()


    # Find info on the fields we can use in `select` & `filter`:
    response: rd.delivery._data._response.Response = rd.content.search.metadata.Definition(
    view = rd.content.search.Views.CDS_INSTRUMENTS).get_data()
    # Export metadata to a spreadsheet for easy viewing:
    response.data.df.to_excel("CDS_INSTRUMENTS.xlsx")


    I looked in the outputed excel doc to find the fields I thought would be interesting.

    Note that all the fields in that show up in that Excel Workbook are not nessesrily useful for CDSs; I used a lot of them in search requests (below) and found the ones returning data through quick trial and error proccesses.


    srch_resp: rd.delivery._data._response.Response  = rd.content.search.Definition(
    view = rd.content.search.Views.CDS_QUOTES, # for info on `SearchViews`, you can use `help(rd.content.search.SearchViews)`
    query="GE5YUSAX*", # Search all CDS that start with AMZN, which is Amazon's RIC
    filter="IsSovereign eq false", # "((AcquirerCompanyName ne 'Creditors' and AcquirerCompanyName ne 'Shareholder') and (TargetCountry eq 'US' or TargetCountry eq 'UK') and TransactionValueIncludingNetDebtOfTarget ge 100 and TargetPublicStatus eq 'Public') and (TransactionStatus eq 'Completed' or TransactionStatus eq 'Pending' or TransactionStatus eq 'Withdrawn')" # and InsertDateTime lt 2010-12-31
    select="RIC, IsSovereign, BuildDateTime, InsertDateTime,ContractCdsRicRoot,IntradayConstituentRICExists,IsBenchmarkRic,IsContractTrancheRic,IsPrimaryRIC,IssuerEquityPrimaryRIC,LiquidityRIC,PriceSource,RefEntityFamilyValuationRic,RefEntityImmediateParentIssueValuationRic,RefEntityIssueValuationRic,RICLength,RicRoot,RICUsageCount",
    top = 100, # max is 10000
    order_by = 'InsertDateTime asc').get_data()
    srch_resp_df: pd.DataFrame = srch_resp.data.df
    srch_resp_df


    1699549331773.png


    IPODate_df: pd.DataFrame = rd.get_data(
    universe=srch_resp_df.IssuerEquityPrimaryRIC.iloc[0],
    fields=["TR.IPODate"])
    IPODate_df["IPO Date"][0]

    Timestamp('1892-06-23 00:00:00')

    if IPODate_df["IPO Date"][0] < datetime.strptime("2006-01-01", "%Y-%m-%d"):
    df: pd.DataFrame = rd.get_history(
    universe=srch_resp_df.RIC.iloc[5],
    start="2006-01-01",
    end="2010-12-31",
    fields=["TR.PARMIDSPREAD",
    "BID", "ASK", "TR.ASKSPREAD", "TR.BIDSPREAD",
    "TR.ASSETSWAPSPREAD", "TR.BENCHMARKSPREAD",
    "ASK_SPREAD", "MID_SPREAD"]) # You can find the `fields`` you are after in the DIB: https://developers.lseg.com/en/video-catalog/data-item-browser
    _df: pd.DataFrame = df[["Ask Spread", "Bid Spread"]]


    df["Par Mid Spread"].dropna()


    Date

    2007-10-17 27.802

    2007-10-18 29.111

    ...

    2010-12-30 112.256

    2010-12-31 112.881

    Name: Par Mid Spread, Length: 574, dtype: Float64



    I found the `fields` in the `get_history` call as below:

    1699549252880.png


Answers