Python code for 3K ISIN

Options

What I want is to download the data for 3K ISINs. That can be done using Python.if I use python I don't get auto-imputed data.

Below is the Python code client is refering

import refinitiv.data as rdfrom tqdm import tqdmfor isin in tqdm(isins):try:response = rd.get_history(universe=[isin.strip()],fields=["TR.DividendYield","TR.F.ComStockBuybackNet","TR.NumberofSharesOutstandingActual","TR.NetDebtToEBITDA","TR.FreeCashFlow","TR.SharesOutstanding","TR.F.PriceToCFPerShr","TR.PCReturnOnInvestedCapPct","TR.WACC","TR.CompanyMarketCap","AVAIL(TR.F.IntrCovRatioTTM(AlignType=PeriodEndDate),TR.F.IntrCovRatio(AlignType=PeriodEndDate, Period=FY0))","AVAIL(TR.DPSMean( AlignType=PeriodEndDate, Methodology=InterimSum, Period=NTM),TR.DPSMean(AlignType=PeriodEndDate, Methodology=WeightedAnnual, Period=NTM))","TR.F.DPSComGrossIssue5YrCAGR(AlignType=PeriodEndDate, InstrumentType=Primary)","AVAIL(TR.F.EVToLeveredFOCFTTM(AlignType=PeriodEndDate),TR.F.EVToLeveredFOCF(AlignType=PeriodEndDate, Period=FY0))","AVAIL(TR.F.FOCFYldPctTTM(AlignType=PeriodEndDate),TR.F.FOCFYldPct(AlignType=PeriodEndDate, Period=FY0))","TR.FreeFloatPct","TR.Volume",],start="2015-05-29",end="2025-06-03",interval = "monthly")response.to_csv(f"historic_data/historic_refinitv_data_{isin}.csv")except Exception as ex:print(ex)with open("historic_data/errores.csv", "a") as file:file.write(f"{isin}\n")

Answers

  • Gurpreet
    Gurpreet admin
    edited August 5

    @UdayP_K45

    Please see the Data Limits guideline document on the dev portal, and implement the recommendations.

    You can also see the example usage of get_history API call in the code samples. The fields being used are for get_data and not available for historical data.

  • @Gurpreet Client has follow up

    I believe there seems to be a misunderstanding. We aim to obtain 10 years of 19 characteristics from 3,000 companies (some of which we know support historical series and some do not):

     

    • Supports historical series:
      • "TR.DividendYield"
      • "TR.F.ComStockBuybackNet"
      • "TR.NumberofSharesOutstandingActual"
      • "TR.NetDebtToEBITDA"
      • "TR.FreeCashFlow"
      • "TR.SharesOutstanding"
      • "TR.F.PriceToCFPerShr"
      • "TR.PCReturnOnInvestedCapPct"
      • "TR.WACC"
      • "TR.CompanyMarketCap"
      • "AVAIL(TR.F.IntrCovRatioTTM(AlignType=PeriodEndDate),TR.F.IntrCovRatio(AlignType=PeriodEndDate, Period=FY0))"
      • "AVAIL(TR.DPSMean(AlignType=PeriodEndDate, Methodology=InterimSum, Period=NTM),TR.DPSMean(AlignType=PeriodEndDate, Methodology=WeightedAnnual, Period=NTM))"
      • "TR.F.DPSComGrossIssue5YrCAGR(AlignType=PeriodEndDate, InstrumentType=Primary)"
      • "AVAIL(TR.F.EVToLeveredFOCFTTM(AlignType=PeriodEndDate),TR.F.EVToLeveredFOCF(AlignType=PeriodEndDate, Period=FY0))"
      • "AVAIL(TR.F.FOCFYldPctTTM(AlignType=PeriodEndDate),TR.F.FOCFYldPct(AlignType=PeriodEndDate, Period=FY0))"
      • "TR.FreeFloatPct"
      • "TR.Volume"
    • Does not support historical series:
      • "TR.HQCountryCode"
      • "TR.GICSSector"

     

    We have two methods to mass obtain this data:

    Using Excel:

    =@RDP .Data($B$7:$B$40;D$1:V$1;"Sdate=#1 EDate=#2 Frq=CM Curn:USD RH:Calcdate Null=BLANK CH:FD,IN";C2;$B$4;$B$5)

     

    Using Python:

    import refinitiv.data as rd

    from tqdm import tqdm

     

    for isin in tqdm(isins):

        try:

            response = rd.get_history(

                universe=[isin.strip()],

                fields=[

                    "TR.DividendYield",

                    "TR.F.ComStockBuybackNet",

                    "TR.NumberofSharesOutstandingActual",

                    "TR.NetDebtToEBITDA",

                    "TR.FreeCashFlow",

                    "TR.SharesOutstanding",

                    "TR.F.PriceToCFPerShr",

                    "TR.PCReturnOnInvestedCapPct",

                    "TR.WACC",

                    "TR.CompanyMarketCap",

                    "AVAIL(TR.F.IntrCovRatioTTM(AlignType=PeriodEndDate),TR.F.IntrCovRatio(AlignType=PeriodEndDate, Period=FY0))",

                    "AVAIL(TR.DPSMean( AlignType=PeriodEndDate, Methodology=InterimSum, Period=NTM),TR.DPSMean(AlignType=PeriodEndDate, Methodology=WeightedAnnual, Period=NTM))",

                    "TR.F.DPSComGrossIssue5YrCAGR(AlignType=PeriodEndDate, InstrumentType=Primary)",

                    "AVAIL(TR.F.EVToLeveredFOCFTTM(AlignType=PeriodEndDate),TR.F.EVToLeveredFOCF(AlignType=PeriodEndDate, Period=FY0))",

                    "AVAIL(TR.F.FOCFYldPctTTM(AlignType=PeriodEndDate),TR.F.FOCFYldPct(AlignType=PeriodEndDate, Period=FY0))",

                    "TR.FreeFloatPct",

                    "TR.Volume",

                ],

                start="2015-05-29",

                end="2025-06-03",

                interval="monthly"

            )

            response.to_csv(f"historic_data/historic_refinitv_data_{isin}.csv")

        except Exception as ex:

            print(ex)

            with open("historic_data/errores.csv", "a") as file:

                file.write(f"{isin}\n")

    Client

    • A way to download the data using Python with auto-imputing of the data as done in Excel.
  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @Uday_PK

    What does the client mean by "auto-imputing of the data"?

    Python doesn't support the RH, Null, and CH parameter used in Excel.

    RH:Calcdate Null=BLANK CH:FD,IN
    

    The library returns a pandas dataframe. Typically, the client can use the dataframe's functions to manipulate the dataframe.