We are updating access to this course!
Welcome to the lesson on the essentials of fetching Data from a website!
In this chapter, we will discuss how we can use the Yahoo Finance Website to get the stock data we want. We will be using the Yahoo Finance Website as it is one of the most widely accepted and one of the most exhaustive websites for Stock Data that there is!
However, before we discuss how to use the Yahoo finance website to obtain historical stock data, it is important that we learn how to analyse any financial website from which we want to obtain any financial data we desire. This is essential because we cannot directly fetch any data from any website in MATLAB. We must analyse the website and its URL properly before we can begin thinking about using it for data retrieval. Therefore, we will be using the information on the analysing websites that we gather in this lesson, later in MATLAB.
Specifically, in this lesson, you will learn the tips and tricks associated with locating essential information on a financial website and understanding the URL for such websites.
Analysing a website
Analysing any website for some data can be made fairly straightforward. Just Search, Observe and Examine! We will specifically focus on explaining how the URL might change when specific components on the website are manipulated.
The First Step in analysing a website is Searching the website for data. Try and find any search tabs on the Homepage and type in some text relevant to the data you are looking for. If the website returns any proper data, you can proceed to the next step. Otherwise, it is time to switch the website!
Let us look at an example of how we can search for data on a financial website.
Example: CNN Business website
To open the CNN Business website, just look it up on any search engine or just type in the following link in the URL tab of your application or click on the link below:
Once the home-page opens, you can search any stock company by using the search tab under MARKETS. Always remember to use the search tabs below or around some heading that indicates financial activity of some sort.
You can check the following image above wherein the stock company Google has been searched from the search tab and a list of results corresponding to that has been displayed by the website.
Now, in the next step, we will observe how choosing certain components on the webpage actually changes the website URL as well as the webpage layout.
This step requires you to Observe the website as well as the website URL for changes in it as you search for data by manipulating elements on the webpage. We are specifically interested in analysing the URL because we will need to use the URL in MATLAB. Besides, we will also need to change the URL depending upon what data we wish to fetch from the website.
To get better insights into how the URL changes, let us continue our previous example of CNN Business and observe what changes are introduced in it as we manipulate the components on the webpage.
Example: CNN Business website
Here, in this example, we will assume that we have successfully searched for the Amazon stock company on the home page and we have opened the stock quote for the Amazon.com Inc stock company. Thereafter we have explored the website by changing tabs on the quotes webpage. Following images show the changes that we observe as we change the tabs.
In the first image, you can see the default setup of the quotes webpage. The quote tab is open by default and the URL is as shown, i.e. https://money.cnn.com/quote/quote.html?symb=AMZN.
The second image shows how the URL and the content on the webpage change when the Financials tab is chosen. The URL has changed to https://money.cnn.com/quote/financials/financials.html?symb=AMZN.
In the third image, you can see how the content on the webpage as well as the URL has changed when we chose the Charts Tab. The URL has changed to https://money.cnn.com/quote/chart/chart.html?symb=AMZN.
So, we observed how the URL changed depending upon the changes we introduced in the webpage. Now, in the next step, we will examine the changes in the URLs that we observed corresponding to the changes we made, and try and establish any patterns that emerge.
One caveat before we progress though:
The arrangement of data as well as the changes in the URL that we observe for changes made on the webpage changes from one website to the next. Therefore, the whole process needs to be repeated if you switch from one website to another. Further, some websites gets upgraded and even changes their webpages links. This could be somewhat cumbersome at first blush. Nevertheless, the steps for analysing any website will remain the same.
Finally, try and establish any patterns that emerge from observing the URL. Try to identify how changing the components on the webpage affects particular components of the URL. This will enable us to use the URL in a manner that best suits our needs!
Let us continue our previous example and examine the changes in the URL we observed.
Example: CNN Business website
Let's begin with, the webpage of Amazon Quote, which can be opened with the URL https://money.cnn.com/quote/quote.html?symb=AMZN. Here, as you will have observed in the previous step, the URL section https://money.cnn.com/quote/ does not change no matter which tab we choose. So, we will concentrate our attention on the remaining bit of the URL.
The first observation we made was regarding the default URL when the stock quote for any stock company is opened. Since we opened the stock quote for Amazon.com Inc, we have the symb=AMZN in the URL. Here, the term symbol refers to the stock symbol for that company. In other words, AMZN is actually the stock symbol for the Amazon.com Inc stock company.
Moreover, the term quote.html in the URL indicates that we are viewing the Quotes tab. The question mark ? after quote.html indicates that the website will search for the term following the question mark. In this case, the website searches for the stock quote of the stock company with symbol AMZN or for the Amazon.com Inc.
The second observation we made was when we changed the tab from quote to Financials. This does not cause any changes in the symbol part of the URL however, quote.html has been replaced with financials.html indicating that we have now switched the tabs from the Quote tab to the Financials tab.
The third observation we made was when we changed the tab from quote to Chart. This, again, does not cause any changes in the symbol part of the URL however, financials.html has been replaced with chart.html indicating that we have now switched the tabs from the Quote tab to the Financials tab.
Now that we know how we can analyse any website, we can start our discussion of fetching historical stock data for our application. We will analyse the Yahoo Finance website and extract our historical data. We will start the discussion in the next lesson!
We are updating access to this course! Happy MATLABing!