Extension of yfinance package to download wide-form stock data from Yahoo! Finance
Project description
yfinance Package with Wide-Form Data Support and Data Export
yfinance-extended
extends yfinance
package by Ran Aroussi and make it easier to:
- Retrieve multiple-ticker intraday price data in a wide-form
pandas
dataframe; - Read options data for all available expiration dates;
- Retrieve top-of-the-book bid-ask prices and sizes; and,
- Store data in the parquet format with the following structure:
./saved_data
├── AAPL
│ ├── AAPL-2023-04-24.parquet
│ ├── AAPL-2023-04-25.parquet
│ ├── AAPL-2023-04-26.parquet
│ ├── AAPL-2023-04-27.parquet
│ └── AAPL-2023-04-28.parquet
└── TSM
└── TSM-2023-04-24.parquet
└── TSM-2023-04-25.parquet
└── TSM-2023-04-26.parquet
└── TSM-2023-04-27.parquet
└── TSM-2023-04-28.parquet
Sample Usage
Get Historical Data
Getting past five days of minute-by-minute prices of Apple, Inc., including pre-/post-market data.
import yfinance-extended as yfe
loader = yfe.YahooBatchLoader()
price_df = get_historical_prices("AAPL", period="5d", interval="1m", prepost=True)
prices_df = get_historical_prices(["AAPL", "GOOGL"], period="5d", interval="1m", prepost=True)
Read all Available Options Information
options_df = loader.options_data("AAPL")
Get Top-of-the-Book Data
live_prices_df = loader.get_prices("AAPL")
live_prices_df = loader.get_prices(["AAPL", "GOOGL"])
Save to and Read Data from Parquet Files
Save files:
prices_df = get_historical_prices(["AAPL", "GOOGL"], period="5d", interval="1m", prepost=True)
yfe.to_parquet(prices_df, root_dir="./data")
Read files:
prices_df = yfe.read_parquet(root_dir="./data")
Alternatively, if you wish to save all data into one file:
# Write to one file
yfe.to_parquet(prices_df, filepath="./data/datafile.parquet")
# Read from the file
prices_df = yfe.read_parquet(filepath="./data/datafile.parquet")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.