How to Download Historical Data from Yahoo Finance: A Guide for Beginners

How to Download Historical Data from Yahoo Finance: A Guide to Using the Python Program

[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 Python program

▲ 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.'
Screen for entering and downloading the Samsung Electronics ticker

▲ 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.

Contents of the downloaded CSV file

▲ 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.

댓글

이 블로그의 인기 게시물

스테그플레이션 뜻, 경제 위기 속 생존 전략: 원인, 영향, 대처법 완벽 분석

원/달러 환율 2025년 하반기 전망(1부): 환율 전망, 환율 상승 주요 원인 분

비트코인 2025년 6월 시장 전망 및 투자 분석