Skip to main content

Financial data fetcher for alpha research with S3 backend and local caching

Project description

QuantDL

CI Python 3.12+ License: MIT Coverage Ruff mypy Polars Hatch uv GitHub last commit Code style: ruff pre-commit AWS S3 Typed

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


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.3.0.tar.gz (107.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quantdl-0.3.0-py3-none-any.whl (43.3 kB view details)

Uploaded Python 3

File details

Details for the file quantdl-0.3.0.tar.gz.

File metadata

  • Download URL: quantdl-0.3.0.tar.gz
  • Upload date:
  • Size: 107.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for quantdl-0.3.0.tar.gz
Algorithm Hash digest
SHA256 2e6de17af899869ffdba9a6ce4119d07b73cc88b800b173477886432d499136a
MD5 da971e6fd034d8cef4f3f78942a883be
BLAKE2b-256 6fa5a5e681f271c36ae4beb1bc851ef6f05d455b9ae19c57ed27520bdd8175a7

See more details on using hashes here.

File details

Details for the file quantdl-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: quantdl-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 43.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for quantdl-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 411dfd4c133ffa6c73a163b45749c4aa9ebcd6dec79ad8784dc2dad9fa50860a
MD5 40f38b8e2bc68e4608ef1bfb21e30801
BLAKE2b-256 0cf44715fe73319e27e633aa4f98f105c509391ed9788fe399b638285b53502c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page