← All one-liners·#045·data·self contained·power

Analyze yesterday's S&P 500 performance with Claude

Fetches recent S&P 500 index data from Yahoo Finance, extracts yesterday's metrics, and uses Claude to summarize the market sentiment.

Setup
  • → npm install -g @anthropic-ai/claude-cli
  • → export ANTHROPIC_API_KEY='sk-ant-...'
Cost per run
<$0.01
The one-liner
$ curl -fsSL -A 'Mozilla/5.0' "https://query1.finance.yahoo.com/v8/finance/chart/SPY?range=5d&interval=1d" | \
  jq '.chart.result[0] | {symbol: .meta.symbol, recent_closes: .indicators.quote[0].close[-2:]}' | \
  claude "Summarize yesterday's S&P 500 performance based on these recent closing prices."
What each stage does
  1. [01] curlcurl -fsSL -A 'Mozilla/5.0' "https://query1.finance.yahoo.com/v8/finance/chart/S…
    Fetches the last 5 days of S&P 500 (SPY) market data from Yahoo Finance's public API. The `-A 'Mozilla/5.0'` user-agent is required — Yahoo's edge layer returns HTTP 429 'Too Many Requests' to bare curl/libcurl. `-f` surfaces 4xx/5xx as a curl error instead of piping the HTML body into jq (which would fail with 'Invalid numeric literal').
  2. [02] jqjq '.chart.result[0] | {symbol: .meta.symbol, recent_closes: .indicators.quote[0…
    Parses the verbose API response to extract only the ticker symbol and the closing prices for the last two trading days.
  3. [03] claudeclaude "Summarize yesterday's S&P 500 performance based on these recent closing …
    Takes the filtered JSON data from stdin and prompts Claude to generate a concise, human-readable financial summary.
Expected output (sample)
Based on the provided data, the S&P 500 (SPY) experienced a slight downturn yesterday, closing at $524.12 compared to the previous close of $525.40.
This represents a minor pullback of approximately 0.24%, likely reflecting typical market consolidation after recent gains.
Caveats & tips
  • Yahoo Finance API endpoints are undocumented and may change or apply rate-limits without notice. The Mozilla user-agent is mandatory; bare curl gets blocked at the edge.
  • Requires an active Anthropic API key and incurs minor token costs for the prompt and completion.