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?
Upgrade from Eikon -> Workspace. Learn about programming differences.
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?
Hello @luyu
Thank you for your participation in the forum. Is the reply below satisfactory in resolving your query?
If yes, please click the 'Accept' text next to the reply. This will guide all community members who have a similar question. Otherwise please post again offering further insight into your question.
Thanks,
AHS
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()