Financial data fetcher for alpha research with S3 backend and local caching
Project description
QuantDL
Financial data library for alpha research. Fetches data from S3, returns wide tables, includes local caching and composable operators.
Installation
pip install quantdl
Quick Start
from quantdl import QuantDLClient
from quantdl.operators import ts_mean, rank, zscore
# Initialize client
client = QuantDLClient()
# Get daily closing prices for multiple symbols
prices = client.ticks(["AAPL", "MSFT", "GOOGL"], "close", "2024-01-01", "2024-12-31")
# Returns wide table: timestamp | AAPL | MSFT | GOOGL
# Apply operators
ma_20 = ts_mean(prices, 20) # 20-day moving average
ranked = rank(ma_20) # Cross-sectional rank
standardized = zscore(ma_20) # Cross-sectional z-score
Features
- Wide Table Format: Returns DataFrames with dates as rows, symbols as columns
- Local Caching: LRU disk cache with configurable TTL (default 24h, 10GB)
- Point-in-Time Resolution: Handles symbol changes and corporate actions
- Alpha Operators: Time-series and cross-sectional transformations
- Polars-Native: Built on Polars for fast data operations
API Reference
Client
client = QuantDLClient(
bucket="us-equity-datalake", # S3 bucket
cache_dir="~/.quantdl/cache", # Local cache directory
cache_ttl_seconds=86400, # Cache TTL (24 hours)
cache_max_size_bytes=10*1024**3, # Max cache size (10GB)
max_concurrency=10, # Concurrent S3 requests
)
Data Methods
# Daily prices (OHLCV)
df = client.ticks(
symbols=["AAPL", "MSFT"], # Symbol(s)
field="close", # open, high, low, close, volume
start="2024-01-01",
end="2024-12-31"
)
# Fundamentals (balance sheet items use quarterly, income/cash flow use TTM by default)
df = client.fundamentals(
symbols=["AAPL"],
concept="rev", # rev, net_inc, ta, tl, etc.
start="2024-01-01",
end="2024-12-31",
source="ttm" # "ttm" (trailing 12mo) or "raw" (quarterly)
)
# Derived metrics
df = client.metrics(
symbols=["AAPL"],
metric="pe_ratio", # pe_ratio, pb_ratio, roe, roa
start="2024-01-01",
end="2024-12-31"
)
# Load universe
symbols = client.universe("top3000")
# Resolve symbol to security info
info = client.resolve("AAPL", as_of=date(2024, 1, 1))
# Request tracking
count = client.request_count() # S3 requests this session
stats = client.request_stats() # Detailed stats with daily breakdown
Operators
Time-Series (Column-wise)
from quantdl.operators import ts_mean, ts_sum, ts_std, ts_min, ts_max, ts_delta, ts_delay
ts_mean(df, 20) # 20-day rolling mean
ts_sum(df, 10) # 10-day rolling sum
ts_std(df, 20) # 20-day rolling standard deviation
ts_min(df, 20) # 20-day rolling minimum
ts_max(df, 20) # 20-day rolling maximum
ts_delta(df, 1) # 1-day difference
ts_delay(df, 5) # Lag by 5 days
Cross-Sectional (Row-wise)
from quantdl.operators import rank, zscore, demean, scale
rank(df) # Cross-sectional rank (1 to N)
zscore(df) # Cross-sectional z-score
demean(df) # Subtract row mean
scale(df, 1.0) # Scale so |sum| = 1 (dollar-neutral)
Composing Operators
# Alpha = rank(20-day momentum z-score)
momentum = ts_delta(prices, 20) / ts_delay(prices, 20)
alpha = rank(zscore(momentum))
Data Structure
All data methods return wide Polars DataFrames:
timestamp | AAPL | MSFT | GOOGL
------------|---------|---------|--------
2024-01-02 | 185.50 | 375.00 | 140.25
2024-01-03 | 186.00 | 376.50 | 141.00
...
Configuration
Set AWS credentials via environment variables:
export AWS_ACCESS_KEY_ID=your_key
export AWS_SECRET_ACCESS_KEY=your_secret
export AWS_DEFAULT_REGION=us-east-1
Development
# Install dev dependencies
uv sync --all-extras
# Run tests
uv run pytest
# Lint and type check
uv run ruff check .
uv run mypy src/
# Build
uv build
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
quantdl-0.2.1.tar.gz
(107.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
quantdl-0.2.1-py3-none-any.whl
(43.0 kB
view details)
File details
Details for the file quantdl-0.2.1.tar.gz.
File metadata
- Download URL: quantdl-0.2.1.tar.gz
- Upload date:
- Size: 107.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0af76fd54341d65962161b698347354ed3a9bf6254654354163fe4b46bb1d450
|
|
| MD5 |
558337231c843696c2ce6496c5f72d0c
|
|
| BLAKE2b-256 |
43011c7a857f35cb2131fc3ac613f9dd423ee0f1501c2f19039133819305b74a
|
File details
Details for the file quantdl-0.2.1-py3-none-any.whl.
File metadata
- Download URL: quantdl-0.2.1-py3-none-any.whl
- Upload date:
- Size: 43.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c90daa5363115b96e6cfdf1924abb479baba0d4465e038a1afcfcee706649ca9
|
|
| MD5 |
c272937f57008216c1f023d9a4418de8
|
|
| BLAKE2b-256 |
2a63fd0920036879bf2c097c2cd92917bc2b7813ea1dd1104c7558b6084f9fc9
|