The Python Bible Volume 5: Python For Finance (Stock Analysis, Trading, Share Prices) by Florian Dedov

The Python Bible Volume 5: Python For Finance (Stock Analysis, Trading, Share Prices) by Florian Dedov

Author:Florian Dedov [Dedov, Florian]
Language: eng
Format: azw3
Publisher: UNKNOWN
Published: 2019-08-12T16:00:00+00:00


6 – S&P 500 Index

When we talk about how the markets are doing, we are usually looking at indices. One of the most important indices is the so-called S&P 500 index which measures the stock performance of the 500 largest companies listed on the US stock exchanges.

Up until now, we always downloaded financial data for individual stocks from the internet. But when we are doing larger calculations many times, it would be preferable to not need to bother the Yahoo Finance API every time.

For this reason, we can download the stock data of the 500 companies which are represented in the S&P 500 right now and save them into files. We can then use these files instead of making requests to the API all the time.

Webscraping

The Yahoo Finance API doesn’t offer any possibilities to request all the companies of the S&P 500 index. Therefore, we will need to get the information about which companies are represented from somewhere else. And for this, we will need something called webscraping .

With webscraping we are reading the HTML files of a website, in order to extract some specific information we are looking for. In this case, we are going to use the Wikipedia page of the list of S&P 500 companies to get the information we need.

Link: https://en.wikipedia.org/wiki/List_of_S%26P_500_companies

On this page, we can find a table with all the 500 companies and different information about them. We can see the name of the company, the industry, the headquarters location and some more things. What we need however is the ticker symbol, which we can find in the first column (make sure you take a look at the page yourself, since the structure of the table might change from time to time).

To now understand how we can extract the information out of this website, we need to look at the HTML code. For this, we go into our browser, make a right click and view the source code of the page.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.