yahoo-finance

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Yahoo Finance CLI

Yahoo Finance CLI

A Python CLI for fetching comprehensive stock data from Yahoo Finance using yfinance.
一个基于Python的命令行工具,通过yfinance库从Yahoo Finance获取全面的股票数据。

Requirements

要求

  • Python 3.11+
  • uv (for inline script dependencies)
  • Python 3.11及以上版本
  • uv(用于处理内联脚本依赖)

Installing uv

安装uv

The script requires
uv
- an extremely fast Python package manager. Check if it's installed:
bash
uv --version
If not installed, install it using one of these methods:
本脚本需要
uv
——一款极速Python包管理器。检查是否已安装:
bash
uv --version
如果未安装,可通过以下方式之一安装:

macOS / Linux

macOS / Linux

bash
curl -LsSf https://astral.sh/uv/install.sh | sh
bash
curl -LsSf https://astral.sh/uv/install.sh | sh

macOS (Homebrew)

macOS(Homebrew)

bash
brew install uv
bash
brew install uv

Windows

Windows

powershell
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
powershell
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

pip (any platform)

pip(全平台)

bash
pip install uv
After installation, restart your terminal or run:
bash
source ~/.bashrc  # or ~/.zshrc on macOS
bash
pip install uv
安装完成后,重启终端或运行:
bash
source ~/.bashrc  # 或macOS上的~/.zshrc

Installation

安装

The
yf
script uses PEP 723 inline script metadata - dependencies are auto-installed on first run.
bash
undefined
yf
脚本使用PEP 723内联脚本元数据——首次运行时会自动安装依赖。
bash
undefined

Make executable

赋予可执行权限

chmod +x /path/to/skills/yahoo-finance/yf
chmod +x /path/to/skills/yahoo-finance/yf

Optionally symlink to PATH for global access

可选:创建符号链接到PATH以实现全局访问

ln -sf /path/to/skills/yahoo-finance/yf /usr/local/bin/yf

First run will install dependencies (yfinance, rich) to uv's cache. Subsequent runs are instant.
ln -sf /path/to/skills/yahoo-finance/yf /usr/local/bin/yf

首次运行时会将依赖(yfinance、rich)安装到uv的缓存中。后续运行将瞬间完成。

Commands

命令

Price (quick check)

价格(快速查询)

bash
yf AAPL              # shorthand for price
yf price AAPL
bash
yf AAPL              # price的简写
yf price AAPL

Quote (detailed)

报价(详细信息)

bash
yf quote MSFT
bash
yf quote MSFT

Fundamentals

基本面数据

bash
yf fundamentals NVDA
Shows: PE ratios, EPS, market cap, margins, ROE/ROA, analyst targets.
bash
yf fundamentals NVDA
展示:市盈率、每股收益、市值、利润率、净资产收益率/资产收益率、分析师目标价。

Earnings

收益数据

bash
yf earnings TSLA
Shows: Next earnings date, EPS estimates, earnings history with surprises.
bash
yf earnings TSLA
展示:下一次收益日期、每股收益预期、带有超预期情况的收益历史。

Company Profile

公司概况

bash
yf profile GOOGL
Shows: Sector, industry, employees, website, address, business description.
bash
yf profile GOOGL
展示:行业板块、细分行业、员工数量、官网、地址、业务描述。

Dividends

股息

bash
yf dividends KO
Shows: Dividend rate/yield, ex-date, payout ratio, recent dividend history.
bash
yf dividends KO
展示:股息率/收益率、除息日、派息率、近期股息历史。

Analyst Ratings

分析师评级

bash
yf ratings AAPL
Shows: Buy/hold/sell distribution, mean rating, recent upgrades/downgrades.
bash
yf ratings AAPL
展示:买入/持有/卖出分布、平均评级、近期上调/下调评级情况。

Options Chain

期权链

bash
yf options SPY
Shows: Near-the-money calls and puts with strike, bid/ask, volume, OI, IV.
bash
yf options SPY
展示:平值看涨和看跌期权的执行价、买价/卖价、成交量、持仓量、隐含波动率。

History

历史数据

bash
yf history GOOGL 1mo     # 1 month history
yf history TSLA 1y       # 1 year
yf history BTC-USD 5d    # 5 days
Ranges: 1d, 5d, 1mo, 3mo, 6mo, 1y, 2y, 5y, 10y, ytd, max
bash
yf history GOOGL 1mo     # 1个月历史数据
yf history TSLA 1y       # 1年历史数据
yf history BTC-USD 5d    # 5天历史数据
时间范围:1d、5d、1mo、3mo、6mo、1y、2y、5y、10y、ytd(年初至今)、max(全部)

Compare

对比

bash
yf compare AAPL,MSFT,GOOGL
yf compare RELIANCE.NS,TCS.NS,INFY.NS
Side-by-side comparison with price, change, 52W range, market cap.
bash
yf compare AAPL,MSFT,GOOGL
yf compare RELIANCE.NS,TCS.NS,INFY.NS
并排对比价格、涨跌幅、52周区间、市值。

Search

搜索

bash
yf search "reliance industries"
yf search "bitcoin"
yf search "s&p 500 etf"
bash
yf search "reliance industries"
yf search "bitcoin"
yf search "s&p 500 etf"

Symbol Format

证券代码格式

  • US stocks: AAPL, MSFT, GOOGL, TSLA
  • Indian NSE: RELIANCE.NS, TCS.NS, INFY.NS
  • Indian BSE: RELIANCE.BO, TCS.BO
  • Crypto: BTC-USD, ETH-USD
  • Forex: EURUSD=X, GBPUSD=X
  • ETFs: SPY, QQQ, VOO
  • 美股: AAPL, MSFT, GOOGL, TSLA
  • 印度NSE: RELIANCE.NS, TCS.NS, INFY.NS
  • 印度BSE: RELIANCE.BO, TCS.BO
  • 加密货币: BTC-USD, ETH-USD
  • 外汇: EURUSD=X, GBPUSD=X
  • ETF: SPY, QQQ, VOO

Examples

示例

bash
undefined
bash
undefined

Quick price check

快速查询价格

yf AAPL
yf AAPL

Get valuation metrics

获取估值指标

yf fundamentals NVDA
yf fundamentals NVDA

Next earnings date + history

下一次收益日期及历史数据

yf earnings TSLA
yf earnings TSLA

Options chain for SPY

SPY的期权链

yf options SPY
yf options SPY

Compare tech giants

对比科技巨头

yf compare AAPL,MSFT,GOOGL,META,AMZN
yf compare AAPL,MSFT,GOOGL,META,AMZN

Find Indian stocks

查找印度股票

yf search "infosys"
yf search "infosys"

Dividend info for Coca-Cola

可口可乐的股息信息

yf dividends KO
yf dividends KO

Analyst ratings for Apple

苹果的分析师评级

yf ratings AAPL
undefined
yf ratings AAPL
undefined

Troubleshooting

故障排除

"command not found: uv"

"command not found: uv"

Install uv using the instructions above.
按照上述说明安装uv。

Rate limiting / connection errors

速率限制/连接错误

Yahoo Finance may rate limit excessive requests. Wait a few minutes and try again.
Yahoo Finance可能会对过多请求进行速率限制。请等待几分钟后重试。

"No data" for a symbol

某证券代码显示“无数据”

  • Verify the symbol exists:
    yf search "company name"
  • Some data (options, dividends) isn't available for all securities
  • 验证代码是否存在:
    yf search "公司名称"
  • 部分数据(期权、股息)并非适用于所有证券

Technical Notes

技术说明

  • Uses PEP 723 inline script metadata for uv dependencies
  • Rich library provides colored, formatted tables
  • First run installs deps to uv cache (~5 seconds)
  • Subsequent runs are instant (cached environment)
  • Handles NaN/None values gracefully with fallbacks
  • 使用PEP 723内联脚本元数据管理uv依赖
  • Rich库提供彩色格式化表格
  • 首次运行安装依赖到uv缓存(约5秒)
  • 后续运行瞬间完成(缓存环境)
  • 优雅处理NaN/None值,提供回退方案