How to download monthly frequency stock closing price from yahoo finance using python?

Member

by kimberly , in category: Trading and Technical Analysis , a year ago

How to download monthly frequency stock closing price from yahoo finance using python?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by gabriel.kutch , 10 months ago

@kimberly 

You can use the yfinance library in Python to download stock closing prices from Yahoo Finance. You can install the library using pip:

1
pip install yfinance


Then, you can use the following code snippet to download monthly frequency stock closing prices for a specific stock (e.g., AAPL) from Yahoo Finance:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import yfinance as yf

# Define the ticker symbol
ticker_symbol = 'AAPL'

# Create a Ticker object
ticker = yf.Ticker(ticker_symbol)

# Get historical data for the stock with monthly frequency
data = ticker.history(period='1mo')

# Print the closing prices
print(data['Close'])


This code will download the monthly closing prices for the specified stock (AAPL in this case) and print them to the console. You can modify the code to save the data to a file or perform further analysis on it as needed.