Skip to content
This repository was archived by the owner on Nov 15, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion INVENTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ copy's drift can be checked.
| `analizy-pl-data` | Programmatic access to Polish investment fund data from analizy.pl |
| `atlasetf-scraper` | Scrape ETF data from atlasetf.pl (screener of ~13k funds, per-ISIN detail, prices) via its JSON API |
| `gpw-benchmark-scraper` | Scrape gpwbenchmark.pl (WIBID/WIBOR reference rates, index list with ISINs, per-index OHLC history) |
| `market-datasets` | Fetch market data from Stooq, NBP, Yahoo, FRED, Tiingo, CCXT, FinancialData |
| `market-datasets` | Fetch market data from EODHD, NBP, Yahoo, FRED, Tiingo, CCXT, FinancialData (stooq removed 2026-09-30) |
| `pipeline-docs` | 4-doc pattern (instruction / dataset / methodology / reference) |

### Engineering (`engineering/`, 1)
Expand Down
10 changes: 2 additions & 8 deletions claude/skills/quant/market-datasets/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ TIINGO_API_KEY=
# Get your free API key at: https://fred.stlouisfed.org/docs/api/api_key.html
FRED_API_KEY=

# =============================================================================
# FIRECRAWL (Web scraping for corporate actions)
# =============================================================================
# Used for scraping Stooq corporate actions pages
# Get your API key at: https://www.firecrawl.dev/
FIRECRAWL_API_KEY=

# =============================================================================
# FINANCIALDATA.NET (Stocks, fundamentals, options, insider trading)
# =============================================================================
Expand All @@ -46,5 +39,6 @@ FINANCIAL_DATA_API_KEY=
# IEX Cloud (US equities)
# IEX_API_KEY=

# EODHD (eodhd.com) — UCITS/ETF + global multi-exchange; paid ~$20/mo for full history
# EODHD (eodhd.com) — UCITS/ETF, GPW (.WAR), indices (.INDX); auto-routed first for
# Polish instruments when set. Personal-use plans only — see references/eodhd.md
EODHD_API_KEY=
46 changes: 28 additions & 18 deletions claude/skills/quant/market-datasets/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: market-datasets
description: Fetch market data, fundamentals, and financial datasets from multiple sources (EODHD, Stooq, NBP, Yahoo Finance, FRED, Tiingo, CCXT, FinancialData.Net) with intelligent routing, plus long-history construction patterns for investment research. Use when users request stock prices, indices, FX rates, economic indicators, cryptocurrency data, fundamentals, options, financial statements, or need to build multi-decade return series for backtesting.
description: Fetch market data, fundamentals, and financial datasets from multiple sources (EODHD, NBP, Yahoo Finance, FRED, Tiingo, CCXT, FinancialData.Net) with intelligent routing, plus long-history construction patterns for investment research. Use when users request stock prices, indices, FX rates, economic indicators, cryptocurrency data, fundamentals, options, financial statements, or need to build multi-decade return series for backtesting.
argument-hint: "[ticker] [start-date] [end-date]"
allowed-tools: Bash, Read
---
Expand All @@ -20,10 +20,9 @@ Unified market data fetching with intelligent source selection, plus long-histor

| Source | Best For | Auth | Coverage |
|--------|----------|------|----------|
| **EODHD** | UCITS/ETF + global multi-exchange; datacenter-reachable (**opt-in** — `source='eodhd'`, paid) | API key | US/EU/GPW stocks, ETFs, indices, ISIN-keyed; splits/div-adjusted |
| **Stooq** | Polish market | Free | Stocks, indices, FX, commodities |
| **EODHD** | **Polish market (auto-routed first when the key is set)**; UCITS/ETF + global multi-exchange; datacenter-reachable (paid, personal-use plans) | API key | GPW `.WAR`, WIG-family `.INDX`, US/EU stocks, ETFs, FX, ISIN-keyed; splits/div-adjusted |
| **NBP** | Official PLN FX | Free | PLN exchange rates |
| **Yahoo** | Global equities (**ad-hoc primary**) | Free | Stocks, ETFs, indices worldwide |
| **Yahoo** | Global equities (**ad-hoc primary**); Polish fallback without an EODHD key (`.WA`) | Free | Stocks, ETFs, indices, FX worldwide |
| **Tiingo** | Yahoo fallback | API key | US stocks/ETFs, 30+ years |
| **CCXT/Binance** | Crypto OHLCV | Free | All crypto pairs, multiple timeframes |
| **CoinGecko** | Crypto price/market-cap by coin id | Free (opt-in) | Daily price, mcap, volume |
Expand All @@ -36,10 +35,11 @@ Unified market data fetching with intelligent source selection, plus long-histor

| Source | Price Type | Use For |
|--------|------------|---------|
| Stooq | Adjusted only | Total return calculations |
| Yahoo | Both (close + adj_close) | P&L (close), returns (adj_close) |
| Yahoo | Both (`Close` raw + `Adj_Close`) | P&L (`Close`), returns (`Adj_Close`) |
| EODHD | Both (`Close` raw + `Adj_Close`) | Same — but `Adj_Close` is recomputed on every dividend |

**Key insight**: Stooq `Close` = Yahoo `adj_close` (validated 95.8% match rate).
**Key trap**: an adjusted series is rewritten backwards at each dividend, so an
incrementally APPENDED adjusted history loses dividends — chain returns instead.
See [references/dividend_treatment.md](references/dividend_treatment.md).

## Core Workflow
Expand All @@ -49,9 +49,10 @@ See [references/dividend_treatment.md](references/dividend_treatment.md).
| Need | Approach |
|------|----------|
| Current/recent prices (ad-hoc) | Auto-routing via unified fetcher — **Yahoo primary** |
| ETF / UCITS / GPW-listed prices | **EODHD, opt-in** — force `source='eodhd'` (paid; confirm cost) |
| Datacenter/VPS where Stooq/Yahoo blocked | EODHD (REST, no geo-block) — force `source='eodhd'` |
| Official PLN FX rates | Force NBP source |
| Polish stocks / WIG indices / `.WA` tickers | Auto-routed: **EODHD** (`.WAR`, `.INDX`) when `EODHD_API_KEY` is set. Without the key: stocks/ETFs fall back to Yahoo (`.WA`); a WSE **index raises** — Yahoo has no history for them (keyless alternative: `gpw-benchmark-scraper`) |
| ETF / UCITS prices | **EODHD, opt-in** — force `source='eodhd'` (paid; confirm cost) |
| Datacenter/VPS where Yahoo is blocked | EODHD (REST, no geo-block) — force `source='eodhd'` |
| PLN FX rates | Auto-routed: NBP first, then Yahoo (`USDPLN=X`) |
| Multi-decade backtest series | Long-history construction (see below) |
| ISIN-based lookups | TickerRegistry + Yahoo Direct API |
| Crypto data | CCXT/Binance routing |
Expand All @@ -61,10 +62,10 @@ See [references/dividend_treatment.md](references/dividend_treatment.md).
**CLI** (all scripts are self-contained with PEP 723 inline dependencies):
```bash
uv run scripts/fetch_unified.py PKO 2024-01-01 2024-12-31
uv run scripts/fetch_stooq.py WIG20 2024-01-01
uv run scripts/fetch_eodhd.py WIG20.INDX 2024-01-01 # Polish index (EODHD)
uv run scripts/fetch_nbp.py USD 2024-01-01 2024-12-31
uv run scripts/fetch_yahoo.py AAPL 2024-01-01
uv run scripts/fetch_eodhd.py SPY 2024-01-01 # ETF/UCITS/GPW (EODHD)
uv run scripts/fetch_eodhd.py SPY 2024-01-01 # ETF/UCITS (EODHD)
uv run scripts/fetch_financialdata.py AAPL 2024-01-01 2024-12-31
```

Expand All @@ -73,7 +74,7 @@ uv run scripts/fetch_financialdata.py AAPL 2024-01-01 2024-12-31
import sys; sys.path.append('market-datasets/scripts')
from fetch_unified import fetch_market_data

df = fetch_market_data('pko', start_date='2024-01-01') # Polish → Stooq
df = fetch_market_data('pko', start_date='2024-01-01') # Polish → EODHD PKO.WAR, else Yahoo PKO.WA
df = fetch_market_data('AAPL', start_date='2024-01-01') # US → Yahoo
df = fetch_market_data('USD', source='nbp', table='A') # FX → NBP
df = fetch_market_data('BTC/USDT', start_date='2024-01-01') # Crypto → CCXT
Expand All @@ -89,7 +90,7 @@ All fetchers return pandas DataFrames with standardized columns:
| `Date` | datetime |
| `Open`, `High`, `Low`, `Close` | OHLC prices |
| `Volume` | Trading volume (if available) |
| `Adj_Close` | Adjusted close (Yahoo only) |
| `Adj_Close` | Adjusted close (Yahoo, EODHD) |

Economic data (FRED, NBP): `Date`, `Value`, `Currency`/`Series_ID`.

Expand All @@ -102,7 +103,7 @@ df = fetch_market_data('pko', start_date='2024-01-01', end_date='2024-12-31')
# 2. Multi-source comparison
from fetch_unified import UnifiedMarketDataFetcher
fetcher = UnifiedMarketDataFetcher()
comparison = fetcher.compare_sources('pko', ['stooq', 'yahoo'], start_date='2024-01-01')
comparison = fetcher.compare_sources('PKO.WA', ['eodhd', 'yahoo'], start_date='2024-01-01')

# 3. ISIN batch fetch
from fetch_yahoo_direct import fetch_by_isin
Expand Down Expand Up @@ -132,7 +133,7 @@ Academic data (synthetic, 1928+) ← BACKFILL: extends history
| **Equity** | VFINX (yfinance) | Shiller S&P 500 price+dividends | ~1976 |
| **FI_AGG** (core bonds) | VBMFX (yfinance) | Shiller 10Y yield → synthetic bond return | ~1987 |
| **FI_SHORT** (short duration) | 50% SHV + 50% VFISX | 50% FRED TB3MS + 50% synthetic dur-2Y | ~1991 |
| **Commodities** (gold) | Stooq XAUUSD | Same source (1968+) | N/A |
| **Commodities** (gold) | EODHD `XAUUSD.FOREX` | From 1990-01-02 (probed 2026-09-30); `GC=F` is not on EODHD | N/A |

### Key Construction Patterns

Expand Down Expand Up @@ -163,8 +164,8 @@ Reference implementation: `research/strategic-asset-allocation/build_asset_data_

| Source | Example | Format |
|--------|---------|--------|
| Stooq | `pko`, `wig20`, `usdpln` | lowercase |
| Yahoo | `PKO.WA`, `^GSPC`, `AAPL` | uppercase, suffix/caret |
| EODHD | `PKO.WAR`, `WIG20.INDX`, `USDPLN.FOREX`, `SPY.US` | `SYMBOL.EXCHANGE` |
| Yahoo | `PKO.WA`, `^GSPC`, `AAPL`, `USDPLN=X` | uppercase, suffix/caret |
| NBP | `USD`, `EUR` | 3-letter ISO |
| FRED | `GDP`, `UNRATE`, `TB3MS` | exact series ID |
| CCXT | `BTC/USDT`, `ETHUSDT` | pair format |
Expand All @@ -191,6 +192,7 @@ fetcher = UnifiedMarketDataFetcher(cache_hours=48) # Custom TTL
| FRED | `export FRED_API_KEY="..."` or `config/fred_api_key.txt` | For macro data |
| Tiingo | `export TIINGO_API_KEY="..."` | For Yahoo fallback |
| FinancialData.Net | `export FINANCIAL_DATA_API_KEY="..."` | For fundamentals, options, insider data |
| EODHD | `export EODHD_API_KEY="..."` | For Polish routing (else Yahoo), UCITS/ETF |

See [references/api_setup.md](references/api_setup.md).

Expand All @@ -213,6 +215,14 @@ except Exception as e:
4. **Batch requests** — loop with fetcher instance, don't re-instantiate
5. **Respect rate limits** — 1-2s delay between requests (built in)

## Removed Sources

- **Stooq** — removed 2026-09-30. It blocks datacenter IPs (Hetzner, since
2026-04-21) and serves a JavaScript browser challenge ("This site requires
JavaScript to verify your browser") to any non-browser client, so no agent or
LLM session can fetch from it. `source='stooq'` raises `ValueError` saying so;
Polish instruments now route to EODHD / Yahoo, PLN FX to NBP / Yahoo.

## Reference Documentation

Load these when needed for detailed information:
Expand Down
69 changes: 34 additions & 35 deletions claude/skills/quant/market-datasets/references/api_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Configuration instructions for data sources requiring authentication or setup.
## Overview

Most data sources work out-of-the-box without configuration:
- **Stooq**: No setup required
- **NBP API**: No setup required
- **Yahoo Finance**: No setup required (via yfinance)
- **CCXT/Crypto**: No setup required (via ccxt package)
Expand Down Expand Up @@ -484,7 +483,7 @@ If integrating into an existing project (like the performance attribution system
By default, data is cached in:
```
data/cache/market_data/
├── stooq/
├── eodhd/
├── nbp/
├── yahoo/
├── fred/
Expand Down Expand Up @@ -535,7 +534,7 @@ Manually clear cache:
rm -rf data/cache/market_data/*

# Clear specific source
rm -rf data/cache/market_data/stooq/*
rm -rf data/cache/market_data/yahoo/*
```

---
Expand Down Expand Up @@ -690,7 +689,7 @@ def test_all_sources():

# Test each source
tests = [
('Stooq (Polish stock)', 'pko', 'stooq'),
('EODHD (Polish stock)', 'PKO.WAR', 'eodhd'),
('NBP (PLN rate)', 'USD', 'nbp'),
('Yahoo (US stock)', 'AAPL', 'yahoo'),
('Tiingo (US stock)', 'MSFT', 'tiingo'),
Expand Down Expand Up @@ -732,7 +731,6 @@ python test_config.py
- **CCXT**: https://github.com/ccxt/ccxt/wiki
- **yfinance**: https://github.com/ranaroussi/yfinance
- **pandas-datareader**: https://pandas-datareader.readthedocs.io/
- **Stooq**: https://stooq.pl/
- **NBP API**: http://api.nbp.pl/

### Support
Expand All @@ -744,33 +742,34 @@ For issues with:
- **CCXT**: https://github.com/ccxt/ccxt/issues
- **yfinance**: https://github.com/ranaroussi/yfinance/issues
- **pandas-datareader**: https://github.com/pydata/pandas-datareader/issues

## EODHD API Setup

EODHD (eodhd.com) is the primary UCITS/ETF + global multi-exchange source —
reachable from datacenters/VPS where Stooq is geo-blocked and Yahoo is
rate-limited.

### Step 1: Get an API key
Register at https://eodhd.com/. Free tier (~1yr history, 20 calls/day) is for
validation only; the paid EOD Historical Data plan (~$20/mo) gives full history
and 100k calls/day.

### Step 2: Configure

```bash
# Option 1: environment variable (recommended)
export EODHD_API_KEY="your_key"
echo 'export EODHD_API_KEY="your_key"' >> ~/.bashrc

# Option 2: .env file at the skill/scripts root
echo 'EODHD_API_KEY=your_key' >> .env
```

### Step 3: Verify

```bash
uv run scripts/fetch_eodhd.py # self-tests (US/.LSE/.WAR/.INDX)
# check account tier/limits:
curl -s "https://eodhd.com/api/user?api_token=$EODHD_API_KEY&fmt=json"
```

## EODHD API Setup

EODHD (eodhd.com) is the primary UCITS/ETF + global multi-exchange source —
reachable from datacenters/VPS where Yahoo is rate-limited — and the auto-routed
first source for Polish instruments (GPW `.WAR`, WIG-family `.INDX`) once the key
is set. All eodhd.com/pricing plans are personal-use only; see eodhd.md § Licensing.

### Step 1: Get an API key
Register at https://eodhd.com/. Free tier (~1yr history, 20 calls/day) is for
validation only; the paid EOD Historical Data plan (~$20/mo) gives full history
and 100k calls/day.

### Step 2: Configure

```bash
# Option 1: environment variable (recommended)
export EODHD_API_KEY="your_key"
echo 'export EODHD_API_KEY="your_key"' >> ~/.bashrc

# Option 2: .env file at the skill/scripts root
echo 'EODHD_API_KEY=your_key' >> .env
```

### Step 3: Verify

```bash
uv run scripts/fetch_eodhd.py # self-tests (US/.LSE/.WAR/.INDX)
# check account tier/limits:
curl -s "https://eodhd.com/api/user?api_token=$EODHD_API_KEY&fmt=json"
```
Loading
Loading