How to Find Microsoft Stock Price with Python

In this Python article we want to learn How to Find Microsoft Stock Price with Python, as Python developer, you may want to access real time financial data for different purposes such as stock analysis, portfolio management or trading. in this article we want to learn how to use Python to retrieve current stock price of Microsoft (MSFT) using yfinance library.

 

 

How to Find Microsoft Stock Price with Python

First of we need to install yfinance library and you can use pip for that

 

 

Now this is the complete code for this article

When you run this code, it will print the current stock price of Microsoft to the console. Note that the stock price may be different throughout the day, so this price may not be up to date by the time you see it.

 

 

So this is the result by the time

How to Find Microsoft Stock Price with Python
How to Find Microsoft Stock Price with Python

 

 

You can modify the code to display more data from the historical market data. this is an example that retrieves the data for the past 5 days and displays Open, High, Low and Close prices for each day:

This code retrieves historical market data for the past 5 days using history() function. after that it uses for loop to iterate through the data and extract the Open, High, Low and Close prices for each day. strftime() function is used to format the date in more readable format. and at the end prices are printed to the console using formatted strings.

 

 

This will be the result

How to Find Microsoft Stock Price with Python
How to Find Microsoft Stock Price with Python

 

 

Learn More on Python GUI

Leave a Comment