How to Find Google Stock Price with Python

In this Python article we want to learn How to Find Google Stock Price with Python, for this we are going to use Yahoo Finance API (yfinance) library, so first of all let’s talk about Yahoo Finance API.

 

What is Yahoo Finance API (yfinance) ?

yfinance is popular Python library that provides easy API for accessing historical market data and live financial data from Yahoo Finance. it allows users to fetch data for stock quotes, options, mutual funds, exchange traded funds (ETFs) and cryptocurrencies. yfinance is built on top of the Pandas library and is widely used for financial analysis and data science.

 

 

How to Find Google Stock Price with Python

First of all we need to install this library and you can use pip for this 

 

 

Now this is our code

In the above code we have created Ticker object for the Google stock by passing its ticker symbol GOOGL as an argument to the Ticker constructor. history method of the Ticker object is then called with the period parameter set to 5d to retrieve historical stock prices for the past 5 days. and final line of code assigns the Close prices to the stock_price variable and prints it to the console.

 

 

Run the code and this is the result

How to Find Google Stock Price with Python
How to Find Google Stock Price with Python

 

 

Now let’s visualize the data using Matplotlib

This code will first retrieve the Google stock price using yfinance API, after that we use matplotlib to create simple line graph of the stock price over the past 5 days. resulting graph will be displayed in new window when you run the code.

 

 

 

This will be the result

How to Find Google Stock Price with Python
How to Find Google Stock Price with Python

 

 

Learn More on Python GUI

Leave a Comment