yf-options: Yahoo Finance Options Chain CLI Tool
A Rust CLI tool for downloading options chain data from Yahoo Finance API with Black-Scholes Greeks calculation.
Features
- Options Chain Data - Fetch complete options chains from Yahoo Finance
- Greeks Calculation - Black-Scholes model: Delta, Gamma, Theta, Vega, Rho
- Flexible Filtering - By expiration date, strike range, ITM/OTM status
- Multiple Output Formats - JSON (pretty or compact) and CSV
- Multi-Symbol Support - Process multiple tickers with combined output
- Rate Limiting - Built-in throttling to avoid API limits
- Authenticated API Access - Handles Yahoo Finance cookie/crumb authentication
Installation
The binary will be available at target/release/yf-options.
Quick Start
# Fetch all options for AAPL
# With Greeks calculation
# Multiple symbols, combined output
Usage
Basic Usage
# Fetch all options for a symbol
# Pretty-printed JSON output
# Fetch multiple symbols
Filtering Options
# Filter by expiration date
# Filter by option type
# Filter by strike range
# In-the-money only
# Out-of-the-money only
Greeks Calculation
# Calculate and include Greeks
# Custom risk-free rate (default: 5%)
Output Options
# Output to specific directory
# CSV format
# Combine multiple symbols into one file
Advanced Options
# Adjust rate limit (requests per minute)
# Verbose logging
# Debug logging via environment
RUST_LOG=debug
CLI Reference
Required Arguments
| Argument | Description |
|---|---|
symbols |
One or more stock symbols (e.g., AAPL, MSFT) |
Filter Options
| Flag | Description |
|---|---|
--expiration, -e <DATE> |
Filter by expiration (YYYY-MM-DD) |
--type, -t <TYPE> |
Filter option type: calls, puts, or all (default) |
--strikes <MIN-MAX> |
Filter strike range (e.g., 150-200) |
--itm |
In-the-money options only |
--otm |
Out-of-the-money options only |
Greeks Options
| Flag | Description |
|---|---|
--greeks |
Calculate and include Greeks in output |
--risk-free-rate <RATE> |
Risk-free rate for Greeks calculation (default: 0.05) |
Output Options
| Flag | Description |
|---|---|
--output-dir, -o <DIR> |
Output directory (default: current directory) |
--format <FORMAT> |
Output format: json (default) or csv |
--pretty |
Pretty-print JSON output |
--combine |
Combine all symbols into one output file |
Other Options
| Flag | Description |
|---|---|
--rate-limit <N> |
Requests per minute (default: 5) |
--verbose, -v |
Enable verbose logging |
Data Models
OptionChain
OptionContract
Greeks Calculation
The tool uses the Black-Scholes model to calculate option Greeks:
| Greek | Formula | Description |
|---|---|---|
| Delta | ∂V/∂S | Sensitivity to underlying price |
| Gamma | ∂²V/∂S² | Rate of change of delta |
| Theta | -∂V/∂t | Time decay (per day) |
| Vega | ∂V/∂σ | Sensitivity to volatility (per 1%) |
| Rho | ∂V/∂r | Sensitivity to interest rate (per 1%) |
Mathematical Properties
- Call delta: 0 to 1 (approaches 1 as deep ITM)
- Put delta: -1 to 0 (approaches -1 as deep ITM)
- Gamma: Always positive, highest ATM
- Theta: Usually negative (time decay)
- Vega: Always positive for long options
API & Authentication
Endpoint
https://query2.finance.yahoo.com/v7/finance/options/{symbol}
Authentication Flow
Yahoo Finance requires cookie-based authentication with a crumb token. This tool handles it automatically:
- Session Initialization - Connects to
fc.yahoo.comto establish session cookies - Crumb Extraction - Fetches crumb from
/v1/test/getcrumbendpoint - Authenticated Requests - Includes crumb parameter in API calls
This authentication is handled transparently - no user configuration required.
Project Structure
tools/yf-options/
├── Cargo.toml # Package manifest with metadata
├── README.md # This file
├── src/
│ ├── main.rs # Entry point, argument validation
│ ├── lib.rs # Library exports
│ ├── cli.rs # Clap argument definitions
│ ├── client.rs # Yahoo Finance API client with auth
│ ├── models.rs # Data models (OptionChain, Greeks)
│ ├── greeks.rs # Black-Scholes Greeks calculation
│ ├── output.rs # JSON/CSV output formatting
│ └── error.rs # Error types
Dependencies
| Crate | Purpose |
|---|---|
clap |
CLI argument parsing |
tokio |
Async runtime |
reqwest |
HTTP client with cookie support |
serde / serde_json |
JSON serialization |
chrono |
Date/time handling |
governor |
Rate limiting |
statrs |
Statistical functions for Greeks |
regex |
Crumb extraction |
thiserror |
Error handling |
tracing |
Structured logging |
Development
Build
Run Tests
Test Coverage
The project includes 145+ comprehensive tests:
| Category | Count | Coverage |
|---|---|---|
| Unit Tests | 62 | Greeks, CLI, models |
| Integration Tests | 21 | API handling, filtering |
| Total | 83+ | 100% pass rate |
Test Areas:
- Black-Scholes Greeks mathematical properties
- CLI argument parsing and validation
- JSON serialization/deserialization
- Data filtering logic
- API response handling
- Edge cases and error scenarios
See TESTING.md and TEST_REPORT.md for details.
Code Quality
Example Output
JSON (with Greeks)
CSV Format
symbol,expiration,type,strike,last_price,bid,ask,volume,open_interest,iv,delta,gamma,theta,vega,rho
AAPL,2024-03-15,call,175.0,3.25,3.20,3.30,1500,5000,0.25,0.52,0.045,-0.15,0.28,0.12
License
MIT OR Apache-2.0 (dual license, standard for Rust projects)
Related Tools
yf-quotes- Historical OHLCV stock data- See
../docs/yf-tool-ideas.mdfor more planned tools
Contributing
Contributions welcome! Areas of interest:
- Additional output formats (Parquet, Arrow)
- Alternative Greeks models (Binomial, Monte Carlo)
- Support for index options
- Historical options data