How to Find Amazon Stock Price with Python

In this article we want to learn about How to Find Amazon Stock Price with Python, are you interested in tracking stock price of Amazon, one of the world largest ecommerce and cloud computing companies ? Do you want to automate this process using Python, powerful and popular programming language for data analysis and visualization ? If so you are in the right place. in this tutorial we want to learn how to use Python and the yfinance library to fetch and display the current and historical stock price data of Amazon, and how to visualize this data using popular libraries such as Matplotlib and Pandas. No prior knowledge of Python or finance is required, but some familiarity with programming concepts and tools will be helpful.

 

 

 

How to Find Amazon Stock Price with Python

First of all we need to install required libraries

 

 

So now let’s fetch the data, we want to use yfinance library to fetch Amazon stock price data. yfinance is Python library that allows us to download financial data from Yahoo Finance.

So this code imports yfinance library and after that fetches the stock data for Amazon (AMZN) using yf.Ticker() method. data is stored in a pandas DataFrame named data. after that we calculates two moving averages, one for 30 day period and another for 100 day period, using the rolling() method. moving averages are stored in new columns in the data DataFrame named MA30 and MA100.

this code also calculates daily returns by using pct_change() method on the Close column of the data DataFrame. daily returns are stored in new column named Daily_Return.

and lastly we prints the summary statistics for the data DataFrame using the describe() method. summary statistics includes count, mean, standard deviation, minimum, maximum, and quartile values for each column in the DataFrame.

 

 

This will be the result

How to Find Amazon Stock Price with Python
How to Find Amazon Stock Price with Python

 

 

 

So in the previous example we have just printed the data, now we want to visualize the data and for that we will use the matplotlib library to visualize the fetched data. matplotlib is  plotting library for the Python programming language and its numerical mathematics extension NumPy.

 

 

 

Run the code and this will be the result

How to Find Amazon Stock Price with Python
How to Find Amazon Stock Price with Python

 

Amazon Stock Price Data
Amazon Stock Price Data

 

 

 

Learn More on Python 

Leave a Comment