How to Download Historical Stock Market Data for Analysis using Python Programming Language?

Xavier Navarro
4 min readMay 11, 2022

Hi, there! This is a Transfer Knowledge on an efficient way to download a lot of data from Yahoo Finance for all the Stocks (Underlying Assets) we would want.

Python Programing Language is amazing for Data Analysis. It has a lot of tools to work with, and a big community to help each other. Yahoo Finance has developed a maintained their modules that retrieve the data from their API. I will show how to use them in this story. We can extract this data locally as well as in Google Colab and even save it in Google Drive. At the end of this post, you should be able to view data as shown below.

Let us start off by installing yfinance and yahoofinancials in Google Colab.

!pip install yfinance
!pip install yahoofinancials

Next, Let’s import the needed libraries:

import pandas as pd
import numpy as np
import yfinance as yf
from yahoofinancials import YahooFinancials

After that, we will be declaring the startDate, and the Symbols that we are interested on. Optionally, we can declare the endDate. If endDate is not declared, it will just supposed it is the last day the market was open.
Also, anything after the ‘#’ character is not read by the console. This is what we we know…

--

--

Xavier Navarro

Reliable Friend. Data Scientist. Polyglot. Investor. Application Developer. Leader. Mentor. Support my work at www.paypal.com/paypalme/Xaviernavarro23891