FinanceDataReader
FinanceDataReader is a Python library for retrieving various financial data, including stock prices, stock lists for multiple markets (Korea, US, etc.), and macroeconomic data. It currently supports version 0.9.110 and is actively maintained with frequent updates to adapt to changing data sources and improve functionality.
Common errors
-
RemoteDataError: No data found for specified query, url:
cause The data source did not return any data for the requested ticker, date range, or the underlying website structure changed. This is common if the ticker is wrong, the dates are out of range for the source, or the source has updated its layout.fixDouble-check the ticker symbol and date range for correctness. Ensure `finance-datareader` is updated to the latest version (`pip install --upgrade finance-datareader`). If the problem persists, the data source may have changed or the data is genuinely unavailable. -
ModuleNotFoundError: No module named 'FinanceDataReader'
cause The library is either not installed, or the import statement has a typo (e.g., incorrect casing or trying to import a submodule directly).fixInstall the library: `pip install finance-datareader`. Ensure the import statement is `import FinanceDataReader as fdr`. -
ValueError: Invalid 'start' or 'end' date format.
cause The start or end date provided to `fdr.DataReader` is not in a recognized format (e.g., 'YYYY-MM-DD').fixEnsure dates are provided as strings in 'YYYY-MM-DD' format, or as `datetime.date` or `pandas.Timestamp` objects. For example: `fdr.DataReader('005930', '2023-01-01', '2023-12-31')`.
Warnings
- gotcha Data availability and consistency can vary significantly across different sources and tickers. Some tickers may not have data for the full requested period, or data quality/granularity might differ.
- breaking Underlying data sources (websites, APIs) can change their structure or access methods without notice, leading to `RemoteDataError` or incorrect data fetching. This library frequently updates to adapt, but intermittent issues are possible.
- gotcha Performance can be slow when requesting very large datasets or making many sequential calls, as it often involves web scraping. Data for US stocks via Yahoo Finance can be slower compared to Korean data.
Install
-
pip install finance-datareader
Imports
- FinanceDataReader
import FinanceDataReader as fdr
Quickstart
import FinanceDataReader as fdr
import pandas as pd
# Get a list of KOSPI stocks
kospistock_list = fdr.StockListing('KOSPI')
print(f"First 5 KOSPI stocks:\n{kospistock_list.head()}")
# Get Samsung Electronics (005930) historical prices from 2017 to 2018
df = fdr.DataReader('005930', '2017-01-01', '2018-12-31')
print(f"\nSamsung Electronics prices (2017-2018):\n{df.head()}")
# Get Apple (AAPL) historical prices for the last year
# Using pd.Timestamp.now() for dynamic date calculation
today = pd.Timestamp.now()
oneyear_ago = today - pd.DateOffset(years=1)
apple_df = fdr.DataReader('AAPL', oneyear_ago.strftime('%Y-%m-%d'), today.strftime('%Y-%m-%d'))
print(f"\nApple prices (last year):\n{apple_df.head()}")