question

Upvotes
Accepted
22 1 0 4

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("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")
workspace#technologypython apiscreener
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
84.6k 287 53 77

@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
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
22 1 0 4

It does work, thanks! However, the input to `rd.get_data()` is identical.

syntax2 = (
  '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)'
)

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)']

>>> syntax2 == "".join(syntax)
True

What am I missing?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

You are correct. They return the same string.

The problem could be the rd.get_data method returns only one value which is a dataframe.

df = rd.get_data("".join(syntax), fields)

It doesn't return df, e.

Ah, so clear :D Thanks!

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.