How to Download Historical Data from Yahoo Finance: A Guide for Beginners
[How to Download Historical Data from Yahoo Finance]
Yahoo Finance is a powerful tool that provides free access to a wide range of financial data, including stocks, indices, and exchange rates. In this post, we will introduce a method for downloading historical data from Yahoo Finance using Python. You can easily get the data you want by running the code yourself without a complicated process.
A Guide to Downloading Yahoo Finance Data Using Python
1. Essential Preparations for Using the Program
Before you run the provided code, there are a few essential preparation steps. Please follow the order below.
1) Install Python
First, Python must be installed on your computer. Please download and install Python from the official website at the link below.
▶ Reference: Go to the Python Official Download Page
2) Install Required Libraries
For the code to work properly, you need to install the necessary libraries. Open the Command Prompt (Windows) or Terminal (macOS), enter the command below, and press Enter.
pip install pyside6 pandas yfinance
This command installs three libraries: PySide6, pandas, and yfinance. Specifically, yfinance
is the core tool that allows you to easily retrieve Yahoo Finance data in Python.
2. How to Download and Run the Code File
Once all the preparations are complete, it's time to download and run the code.
📋 Attachment: Download stock.py
- Running the code: Save the downloaded file to your desired location. When you run it through Python, the data download program will start.

▲ Initial screen of the program
As shown in the image above, when you run the program, a screen for downloading data appears. You will see fields to enter the 'Stock Code,' 'Select Market' (Kospi, Kosdaq, USA), 'Start Date,' and 'End Date.'
3. Data Entry and Download Process
Now let's look at the process of entering and downloading the actual data.
- Enter Stock: In the 'Stock Code' field, enter the ticker of the desired stock. For example, enter `005930` for Samsung Electronics.
- Select Market: Choose the desired market from 'KOSPI,' 'KOSDAQ,' or 'USA.'
- Set Period: Enter the desired period in the 'Start Date' and 'End Date' fields in 'YYYYMMDD' format.
- Run: After entering all the information, press the 'Lookup Closing Price by Period' button to view the closing price data. The data download proceeds by clicking 'Save as CSV.'

▲ Execution screen with Samsung Electronics ticker entered
The screen above is an example of entering information to download data for Samsung Electronics (005930).
4. Checking the Downloaded Data
Once the download is complete, a file named `ticker_market_period.csv` (e.g., 005930_KOSPI_2025-08-06.csv) will be created in the designated folder. If you open this file, you can check the stock price data retrieved from Yahoo Finance, as shown in the image below.

▲ Stock price data saved as a CSV file
Note: This program is provided as a `.py` source code file and must be run using Python.
The program on this blog was created for educational purposes. Also, the content of this blog is for reference in making investment decisions, and investment decisions must be made under the individual's judgment and responsibility. In no case shall the information on this blog be used as legal evidence for the outcome of an investment.
댓글
댓글 쓰기