How to get sector average data for specific stock, e.g., find average P/E ratio for the sector that AAPL.O is in? Is there an example?
For a deeper look into our Eikon Data API, look into:
Overview | Quickstart | Documentation | Downloads | Tutorials | Articles
How to get sector average data for specific stock, e.g., find average P/E ratio for the sector that AAPL.O is in? Is there an example?
Yes, with the use of screening functions (for sector) or peer service (for peers). The following code gives you an average historic p/e for all companies in Apple Inc. sector, headquartered in US with market cap > $1B:
import eikon as tr tr.set_app_id('your_app_id') expression = 'SCREEN(U(IN(Equity(active,public,primary))), \ IN(TR.GICSSectorCode,45), IN(TR.HQCountryCode,US), \ TR.CompanyMarketCap>=1000000000, CURN=USD)' df, e = tr.get_data([exp], ['TR.CompanyName','TR.HistPE']) df.dropna() df['Historic P/E'].mean()