Python refinitiv.data Screener not working

I have the following screener code in python ...

import refinitiv.data as rd
rd.open_session()

syntax = (
'SCREEN('
'U(IN(Equity(active,public,primary))),'
'TR.CompanyMarketCap(Scale=6)>=300,'
'TR.F.NetDebtToEBITDA(Period=FY0)<=3,'
'NOT_IN(TR.GICSIndustryGroupCode,4010,4020,4030),'
'IN(TR.RegCountryCode,IN),'
'AVG(TR.Volume(SDate=0D,EDate=0D-29D))>=3,'
'CURN=USD)'
)
fields = [
"TR.CommonName",
"TR.CompanyMarketCap(Scale=6)",
"TR.F.NetDebtToEBITDA(Period=FY0)",
"TR.GICSIndustryGroup",
"TR.RegistrationCountry",
"AVG(TR.Volume(SDate=0D,EDate=0D-29D))"]

df, e = rd.get_data(syntax, fields)


....which produces the following error:

Traceback (most recent call last):
File "<string>", line 1, in <module>
ValueError: too many values to unpack (expected 2)


The Excel equivalent is as follows:

=@TR(&quot;SCREEN(U(IN(Equity(active,public,primary))/*UNV:Public*/), TR.CompanyMarketCap(Scale=6)>=300, TR.F.NetDebtToEBITDA(Period=FY0)<=3, NOT_IN(TR.GICSIndustryGroupCode,""4010"",""4020"",""4030""), IN(TR.RegCountryCode,""IN""), AVG(TR.Volume"&"(SDate=0D,EDate=0D-29D))/*Avg Volume last 30 days*/>=3, CURN=USD)";"TR.CommonName;TR.CompanyMarketCap(Scale=6);TR.F.NetDebtToEBITDA(Period=FY0);TR.GICSIndustryGroup;TR.RegistrationCountry;AVG(TR.Volume(SDate=0D,EDate=0D-29D))/*Avg Volu"&"me last 30 days*/";"curn=USD RH=In CH=Fd")

Best Answer

  • Jirapongse
    Jirapongse ✭✭✭✭✭
    Answer ✓

    @fabian.echterling

    Thank you for reaching out to us.

    The screen formula should be a string and the get_data method returns a dataframe so the code should look like this:

    syntax = [
      'SCREEN(',
      'U(IN(Equity(active,public,primary))),',
      'TR.CompanyMarketCap(Scale=6)>=300,' ,
      'TR.F.NetDebtToEBITDA(Period=FY0)<=3,' ,
      'NOT_IN(TR.GICSIndustryGroupCode,4010,4020,4030),' ,
      'IN(TR.RegCountryCode,IN),' ,
      'AVG(TR.Volume(SDate=0D,EDate=0D-29D))>=3,',
    'CURN=USD)']

    fields = [
      "TR.CommonName",
      "TR.CompanyMarketCap(Scale=6)",
      "TR.F.NetDebtToEBITDA(Period=FY0)",
      "TR.GICSIndustryGroup",
      "TR.RegistrationCountry",
      "AVG(TR.Volume(SDate=0D,EDate=0D-29D))"]
     
    df = rd.get_data("".join(syntax), fields)
    df

Answers