Question
I.FidelityStock Market The Fidelity Investmentswebpage (https://eresearch.fidelity.com/eresearch/goto/markets_sectors/landing.jhtml) reports the stock marketchanges by sector in an HTML table at the rightof the page. The table contains the
I.FidelityStock Market
The Fidelity Investmentswebpage (https://eresearch.fidelity.com/eresearch/goto/markets_sectors/landing.jhtml) reports the stock marketchanges by sector in an HTML table at the rightof the page. The table contains the name of the sector, a link to a sector detail page, and the percentage change for that sector over the course of the day (the change is updated in real time).
Each sector detail page (e.g.,https://eresearch.fidelity.com/eresearch/markets_sectors/sectors/sectors_in_market.jhtml?tab=learn§or=50)contains specific information about that sector including a table titled 'Sector Fundamentals'. The table contains a list of financial metricsthat help investors know how that specificsectoris doing in terms of market performance, such as its P/E ratio, its Enterprive Value, etc.
Since the webpages tend to change, please do not try to scrape the real url and use instead the files provided in your local working environment(see note below).
Write a functionfidelity_sector_report()that returns adictionarycontaining the following information about each sector:
1. The sector name
2. The enterprise value (in USD billions)
3. The Return on Equity TTM (trailing twelve months, in percentages)
4. The dividend yield (in percentages)
The structure of thedictionary should be:
{'results':{
'Communication Services': {
'enterprise_value': 286.81,
'return_on_equity': 15.82,
'dividend_yield': 3.91},
'Consumer Discretionary': {
'enterprise_value': 279.53,
'return_on_equity': -293.98,
'dividend_yield': 2.32},
'Consumer Staples': {
'enterprise_value': 164.55,
'return_on_equity': -5.36,
'dividend_yield': 2.75}}}
Your function only needs to return the dictionary. Make sure that you returnthe correct numbers in floating format.
Finally,afterrunning the function you just created, you need to fill in the blanks and assign 2 variables a string. Forgetting will carry a score penalization.
Notes:
1.Use theBeautifulSoup Library to parse the pages.
2. Note that the result return byf.readlines()is a list of strings!
PLEASE ONLY USE THE FILES PROVIDED. DO NOT SCRAPE THE LATEST DATA FROM THE FINANCE PAGE.
You will find 12 different files in your workspace. Oneis thelanding page (that has all sector names) and the other 11 have information on each specific sector.
Each sector page will have informationon its "Sector Fundamentals" metrics.
The files you will need are already provided to you in the Work folder. Download and open them to have a look, since they are basic HTML some elements may be broken but will not hamper you in any way.
The main page (Sector Performance.htm) has the list of all sectors, their latest market moves and the links to the detailed pages:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started