yfinance Data Skill
If your host has not already executed the shell probes below (for example, in Codex), run the commands inside the ! wrappers with its shell tool before choosing a setup path. Use the actual output; if shell access is unavailable, report that limitation.
Fetches financial and market data from Yahoo Finance using the yfinance Python library.
Important: yfinance is not affiliated with Yahoo, Inc. Data is for research and educational purposes.
Step 1: Ensure yfinance Is Available
Current environment status:
!`python3 -c "exec('try:\n import yfinance\n print(\'yfinance \' + yfinance.__version__ + \' installed\')\nexcept Exception:\n print(\'YFINANCE_NOT_INSTALLED\')')"`
If YFINANCE_NOT_INSTALLED, install it before running any code:
import subprocess, sys
subprocess.check_call([sys.executable, "-m", "pip", "install", "-q", "yfinance"])
If yfinance is already installed, skip the install step and proceed directly.
Step 2: Identify What the User Needs
Match the user's request to one or more data categories below, then use the corresponding code from references/api_reference.md.
Step 3: Write and Execute the Code
General pattern
import yfinance as yf
ticker = yf.Ticker("AAPL")
# ... use the appropriate method from the reference
Key rules
- Always wrap in try/except — Yahoo Finance may rate-limit or return empty data
- Use
yf.download() for multi-ticker comparisons — it's faster with multi-threading
- For options, list expiration dates first with
ticker.options before calling ticker.option_chain(date)
- For quarterly data, use
quarterly_ prefix: ticker.quarterly_income_stmt, ticker.quarterly_balance_sheet, ticker.quarterly_cashflow
- For large date ranges, be mindful of intraday limits — 1m data only goes back ~7 days, 1h data ~730 days
- Print DataFrames clearly — use
.to_string() or .to_markdown() for readability, or select key columns
- Timezone handling — yfinance returns tz-aware datetime indices (e.g.,
America/New_York). When comparing dates, always use pd.Timestamp(..., tz=...) or strip timezones with .tz_localize(None). See the reference file for details.
Valid periods and intervals
Step 4: Present the Data
Answer with the numbers the user asked for first, then the supporting table (markdown, or a trimmed DataFrame with the key columns). Call out anything notable in the data — an earnings beat or miss, unusual volume, a dividend change — and add context such as sector averages, historical ranges, or analyst consensus where it changes how the numbers read. If the user wants a chart, pair the data with a visualization.
Reference Files
references/api_reference.md — Complete yfinance API reference with code examples for every data category
Read the reference file when you need exact method signatures or edge case handling.