yahoo-finance
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseYahoo 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 - an extremely fast Python package manager. Check if it's installed:
uvbash
uv --versionIf not installed, install it using one of these methods:
本脚本需要——一款极速Python包管理器。检查是否已安装:
uvbash
uv --version如果未安装,可通过以下方式之一安装:
macOS / Linux
macOS / Linux
bash
curl -LsSf https://astral.sh/uv/install.sh | shbash
curl -LsSf https://astral.sh/uv/install.sh | shmacOS (Homebrew)
macOS(Homebrew)
bash
brew install uvbash
brew install uvWindows
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 uvAfter installation, restart your terminal or run:
bash
source ~/.bashrc # or ~/.zshrc on macOSbash
pip install uv安装完成后,重启终端或运行:
bash
source ~/.bashrc # 或macOS上的~/.zshrcInstallation
安装
The script uses PEP 723 inline script metadata - dependencies are auto-installed on first run.
yfbash
undefinedyfbash
undefinedMake 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 AAPLbash
yf AAPL # price的简写
yf price AAPLQuote (detailed)
报价(详细信息)
bash
yf quote MSFTbash
yf quote MSFTFundamentals
基本面数据
bash
yf fundamentals NVDAShows: PE ratios, EPS, market cap, margins, ROE/ROA, analyst targets.
bash
yf fundamentals NVDA展示:市盈率、每股收益、市值、利润率、净资产收益率/资产收益率、分析师目标价。
Earnings
收益数据
bash
yf earnings TSLAShows: Next earnings date, EPS estimates, earnings history with surprises.
bash
yf earnings TSLA展示:下一次收益日期、每股收益预期、带有超预期情况的收益历史。
Company Profile
公司概况
bash
yf profile GOOGLShows: Sector, industry, employees, website, address, business description.
bash
yf profile GOOGL展示:行业板块、细分行业、员工数量、官网、地址、业务描述。
Dividends
股息
bash
yf dividends KOShows: Dividend rate/yield, ex-date, payout ratio, recent dividend history.
bash
yf dividends KO展示:股息率/收益率、除息日、派息率、近期股息历史。
Analyst Ratings
分析师评级
bash
yf ratings AAPLShows: Buy/hold/sell distribution, mean rating, recent upgrades/downgrades.
bash
yf ratings AAPL展示:买入/持有/卖出分布、平均评级、近期上调/下调评级情况。
Options Chain
期权链
bash
yf options SPYShows: 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 daysRanges: 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.NSSide-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
undefinedbash
undefinedQuick 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
undefinedyf ratings AAPL
undefinedTroubleshooting
故障排除
"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值,提供回退方案