Method to pull all Corporate Bonds in country using Python

Is there a way to pull all corporate bonds in a given country with a Python script? I haven't been able to find any method on this forum. The script would ideally interact with the Eikon data API and pull the list directly from Eikon.

Currently, I can extract a list of bonds, but this involves downloading an excel file and pulling in the values from that excel file. Another problem with this method is the Excel file export is limited to 1000 bonds and extracting all the necessary bonds would require several exports.

Any help is appreciated.

Best Answer

  • chavalit-jintamalit
    Answer ✓

    Hi @cchen01

    You can try using RDP Lib(Python).

    You have to install it first:

    pip install refinitiv.dataplatform


    Then import it to your codebook or python code, you can use the same appkey with eikon data api:

    import refinitiv.dataplatform as rdp
    rdp.open_desktop_session('a_valid_appkey')


    And call it:

    filterStr = "DerivedCategory eq 'BOND' and Country eq 'TH'"
    srchfields = "Country, RIC, FullName, CommonName,CompanyName, SeniorityType, NativeIdentifier, DerivedCategory, OriginalIssueCurrency, ParentIndustrySector, CouponCurrency, CouponTypeDescription"
    GroupSize = 10000 #max at 10000

    data = rdp.search(view=rdp.SearchViews.GovCorpInstruments, filter=filterStr, top=GroupSize, select=srchfields)
    data


Answers

  • You can add several filter to the "filterStr" sample such as:

    image

  • Hi @cchen01,

    I would suggest you review the Search article on the developer community to better understand the capability of what you can do with Search, such as some tips and tricks to get the most out of the service. In addition, I would also suggest you review the Debt Structure Analysis article as it utilizes Search to retrieve a list of Corporate bonds. For example, to retrieve a list of active bonds that have not matured within a country, you can try this:

    df = rdp.Search.search(
        # The 'view' represents a specific domain of content we wish to 
        # search across.  
        view = rdp.SearchViews.GovCorpInstruments,
        
        # The 'filter' parameter is a powerful, criteria-based, syntax 
        # that allows us to filter for specific results.
        #
        # Disclaimer: The following expression includes bonds that are 
        #             in 'default'.  If you choose to ignore these from 
        #             your result set, simply modify the expression 
        #             below as follows:
        #
        #             "..not(AssetStatus in ('MAT' 'DEF'))"
        #
        filter = "IsActive eq true and RCSIssuerCountryLeaf xeq 'United States' \
                  and ISIN ne null and MaturityDate ne null and \
                  not(AssetStatus in ('MAT')) and EOMAmountOutstanding ne null \
                  and CouponRate ne null and NextCallDate ne null",

        # Define the upper limit of rows within our result set.  This is a 
        # system imposed maximum value.
        top = 10000,

        # The 'select' parameter determines the fields of interest in our 
        # output.  The logic below takes our list of properties defined and 
        # creates the appropriate comma-separated list of properties required 
        # by the service.
        select = "ISIN, DBSTicker, IssueDate, Currency, FaceIssuedTotal, \
                  EOMAmountOutstanding, NextCallDate, CouponRate, MaturityDate, \
                  CdsSeniorityEquivalentDescription"
    )

    If you noticed, I put in place a number of filters. This you will need to discover as you go through your journey of searching out content. The Search article talks about how to manage large data sets. Because you are interested in bonds issued for a whole country, expect the results to be in the hundreds of thousands. However, many of those bonds may contain details that are not relevant and should not be in your result set. This you will need to fine-tune based on your specific requirements.

  • I am running into issues with the installation of refinitiv.dataplatform. After running pip install and receiving the "Successfully installed refinitiv.dataplatform-1.0.0a8.post2" message and attempting to import the module, I receive the following error:

    ImportError: DLL load failed: The specified module could not be found.

    Additional Warning Messages:

    WARNING: Ignoring invalid distribution -yzmq (c:\programdata\anaconda3\lib\site-packages)

    WARNING: Ignoring invalid distribution -penpyxl (c:\programdata\anaconda3\lib\site-packages)

    Any insight into why this error may be occurring? I copied the pip install and import statements from the reply above.

    Thanks,

  • Hi @cchen01,

    Can you include your specific code segment that results in this error. I just tried it within the Jupyter environment with no issues.

  • ImportError Traceback (most recent call last) <ipython-input-1-c3185ee3f92b> in <module>

    2 import numpy as np

    3 import eikon as ek

    ----> 4 import refinitiv.dataplatform as rdp

    5 rdp.open_desktop_session("eikon_api_appkey")


    It seems like there is an issue with the installation of the module. The module is installed successfully because the requirements are all satisfied, but the error still occurs. I've also attempted un-installing and re-installing the module too, but that is unsuccessful too.

  • Hi @cchen01,

    Just to confirm, you have these statements:

    import refinitiv.dataplatform as rdp 
    rdp.open_desktop_session("<your generated eikon app key>")

    And it's resulting in this:

    ImportError: DLL load failed: The specified module could not be found. 

    Please confirm so I can follow up with development. Also, I would suggest you use CodeBook in the meantime.

  • Yes, those lines of code result in that error message. I'll look into CodeBook
  • @nick.zincone.1


    Hi Nick,

    Just following up on this thread, I got RDP working after reinstalling anaconda and I implemented the code above. I was wondering why after using these lines of code, there seem to be a large number of bonds missing when comparing the results pulled from using Search in RDP and the Search option in the FING app in Eikon. To give you an idea, the RDP returns ~10,000 bonds while the FING app returns ~36,000.

    Would you have an idea why there is this discrepancy?

    Regards

  • @cchen01

    Most likely this is because RDP Search returns a max of 10K results (the max value you can set for the "top" parameter is 10K). See the Search article @nick.zincone.1 pointed you to, which among other things discusses the limits RDP Search service imposes and what you can do to work around them.