$npx -y skills add himself65/finance-skills --skill yfinance-dataFetch financial and market data using the yfinance Python library. Use this skill whenever the user asks for stock prices, historical data, financial statements, options chains, dividends, earnings, analyst recommendations, or any market data. Triggers include: any mention of sto
| 1 | # yfinance Data Skill |
| 2 | |
| 3 | Fetches financial and market data from Yahoo Finance using the [yfinance](https://github.com/ranaroussi/yfinance) Python library. |
| 4 | |
| 5 | **Important**: yfinance is not affiliated with Yahoo, Inc. Data is for research and educational purposes. |
| 6 | |
| 7 | --- |
| 8 | |
| 9 | ## Step 1: Ensure yfinance Is Available |
| 10 | |
| 11 | **Current environment status:** |
| 12 | |
| 13 | ``` |
| 14 | !`python3 -c "import yfinance; print('yfinance ' + yfinance.__version__ + ' installed')" 2>/dev/null || echo "YFINANCE_NOT_INSTALLED"` |
| 15 | ``` |
| 16 | |
| 17 | If `YFINANCE_NOT_INSTALLED`, install it before running any code: |
| 18 | |
| 19 | ```python |
| 20 | import subprocess, sys |
| 21 | subprocess.check_call([sys.executable, "-m", "pip", "install", "-q", "yfinance"]) |
| 22 | ``` |
| 23 | |
| 24 | If yfinance is already installed, skip the install step and proceed directly. |
| 25 | |
| 26 | --- |
| 27 | |
| 28 | ## Step 2: Identify What the User Needs |
| 29 | |
| 30 | Match the user's request to one or more data categories below, then use the corresponding code from `references/api_reference.md`. |
| 31 | |
| 32 | | User Request | Data Category | Primary Method | |
| 33 | |---|---|---| |
| 34 | | Stock price, quote | Current price | `ticker.info` or `ticker.fast_info` | |
| 35 | | Price history, chart data | Historical OHLCV | `ticker.history()` or `yf.download()` | |
| 36 | | Balance sheet | Financial statements | `ticker.balance_sheet` | |
| 37 | | Income statement, revenue | Financial statements | `ticker.income_stmt` | |
| 38 | | Cash flow | Financial statements | `ticker.cashflow` | |
| 39 | | Dividends | Corporate actions | `ticker.dividends` | |
| 40 | | Stock splits | Corporate actions | `ticker.splits` | |
| 41 | | Options chain, calls, puts | Options data | `ticker.option_chain()` | |
| 42 | | Earnings, EPS | Analysis | `ticker.earnings_history` | |
| 43 | | Analyst price targets | Analysis | `ticker.analyst_price_targets` | |
| 44 | | Recommendations, ratings | Analysis | `ticker.recommendations` | |
| 45 | | Upgrades/downgrades | Analysis | `ticker.upgrades_downgrades` | |
| 46 | | Institutional holders | Ownership | `ticker.institutional_holders` | |
| 47 | | Insider transactions | Ownership | `ticker.insider_transactions` | |
| 48 | | Company overview, sector | General info | `ticker.info` | |
| 49 | | Compare multiple stocks | Bulk download | `yf.download()` | |
| 50 | | Screen/filter stocks | Screener | `yf.Screener` + `yf.EquityQuery` | |
| 51 | | Sector/industry data | Market data | `yf.Sector` / `yf.Industry` | |
| 52 | | News | News | `ticker.news` | |
| 53 | |
| 54 | --- |
| 55 | |
| 56 | ## Step 3: Write and Execute the Code |
| 57 | |
| 58 | ### General pattern |
| 59 | |
| 60 | ```python |
| 61 | import subprocess, sys |
| 62 | subprocess.check_call([sys.executable, "-m", "pip", "install", "-q", "yfinance"]) |
| 63 | |
| 64 | import yfinance as yf |
| 65 | |
| 66 | ticker = yf.Ticker("AAPL") |
| 67 | # ... use the appropriate method from the reference |
| 68 | ``` |
| 69 | |
| 70 | ### Key rules |
| 71 | |
| 72 | 1. **Always wrap in try/except** — Yahoo Finance may rate-limit or return empty data |
| 73 | 2. **Use `yf.download()` for multi-ticker comparisons** — it's faster with multi-threading |
| 74 | 3. **For options, list expiration dates first** with `ticker.options` before calling `ticker.option_chain(date)` |
| 75 | 4. **For quarterly data**, use `quarterly_` prefix: `ticker.quarterly_income_stmt`, `ticker.quarterly_balance_sheet`, `ticker.quarterly_cashflow` |
| 76 | 5. **For large date ranges**, be mindful of intraday limits — 1m data only goes back ~7 days, 1h data ~730 days |
| 77 | 6. **Print DataFrames clearly** — use `.to_string()` or `.to_markdown()` for readability, or select key columns |
| 78 | 7. **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. |
| 79 | |
| 80 | ### Valid periods and intervals |
| 81 | |
| 82 | | Periods | `1d`, `5d`, `1mo`, `3mo`, `6mo`, `1y`, `2y`, `5y`, `10y`, `ytd`, `max` | |
| 83 | |---|---| |
| 84 | | **Intervals** | `1m`, `2m`, `5m`, `15m`, `30m`, `60m`, `90m`, `1h`, `1d`, `5d`, `1wk`, `1mo`, `3mo` | |
| 85 | |
| 86 | --- |
| 87 | |
| 88 | ## Step 4: Present the Data |
| 89 | |
| 90 | After fetching data, present it clearly: |
| 91 | |
| 92 | 1. **Summarize key numbers** in a brief text response (current price, market cap, P/E, etc.) |
| 93 | 2. **Show tabular data** formatted for readability — use markdown tables or formatted DataFrames |
| 94 | 3. **Highlight notable items** — earnings beats/misses, unusual volume, dividend changes |
| 95 | 4. **Provide context** — compare to sector averages, historical ranges, or analyst consensus when relevant |
| 96 | |
| 97 | If the user seems to want a chart or visualization, combine with an appropriate v |