Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribedimage text in transcribedimage text in transcribed
U.S. Sectors & Industries Performance AS OF 05:06 PM ET 06/24/2019 Research Sectors & Industries View Weighting Recommendations Sector Last % Change Communication Services 5 Industries 0.11% Consumer Discretionary 11 Industries -0.51% Consumer Staples 6 Industries 0.27% Energy 2 Industries -0.93% Financials 7 Industries -0.33% Health Care 6 Industries -0.50% Industrials 14 Industries -0.23% Information Technology. 0.15% 6 Industries Materials 5 Industries 0.45% Real Estate 2 Industries -0.46% Utilities 5 Industries 0.02%Sector Fundamentals AS OF 06/21/2019 P/E (Last Year GAAP Actual) 24.01 P/E (This Year's Estimate) 27.97 Enterprise Value $286.81B EPS (TTM) $9.99 EPS Growth (TTM vs. Prior TTM) 135.32% Revenue Growth (TTM vs. Prior TTM) 17.33% Return on Equity (TTM) 15.82% Return on Investment (TTM) 10.22% Total Debt/Equity_(TTM) 96.34 Dividend Yield 3.91%jupyter fidelity_sector_report (autosaved) Control Panel File Edit View Insert Cell Kernel Widgets Help Trusted |Python 3 [3.6] O B + 4 5 + + HC Markdown In [ ] : man Check the following pages to inspect the structure of the site (right click -> inspect): 1. https://eresearch. fidelity. com/eresearch/goto/markets_sectors/ landing. jhtml 2. https://eresearch. fidelity . com/eresearch/markets_sectors/sectors/sectors_in_market. jhtml?tab=learn§or=50 Modify the following fidelity_sector_report so that it returns a dictionary that contains 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 the ditionary is given in the assignment description on Edx. You should expect outputs like following for the first 3 sectors: {'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}}} Note: To read files, use; with open( ' filename' ) as f: lines = f. readlines() # do not change anything that is originally written in here # write the solution in suggested area In [ ]: # Run this cell and do not change it with open( 'Sector Performance. htm' ) as f: filed = f. readlines( ) from bs4 import Beautifulsoup Beautifulsoup ("". join(filel), "1xml") In [ ]: def fidelity_sector_report(file1) : ### ### YOUR CODE HERE ### return ref_json In [ ]: # Try out your code fidelity_sector_report(file1) In [ ]: # If you were to invest in the highest ROE (return on equity) sector, that would be: highest_roe_sector = "" # CHANGE VARIABLE CONTENT: e.g. "Utilities" # If you were to invest in the highest dividend yield sector, that would be

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions