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.2.0.tar.gz (107.2 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.2.0-py3-none-any.whl (43.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: quantdl-0.2.0.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

Hashes for quantdl-0.2.0.tar.gz
Algorithm Hash digest
SHA256 16d23e81b5b596a42d057e561c361aa37ab0580b715706fdeb61a246c7a69a91
MD5 9cb42bf7cb6df7e2235162c49a5dd1a4
BLAKE2b-256 a01c1fec694dac47aaa5fe80ec2b5860bc69c040bbdb53771727478d431e5a45

See more details on using hashes here.

File details

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

File metadata

  • Download URL: quantdl-0.2.0-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

Hashes for quantdl-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4bc93217f06b0384bda1409a83a7ed030941f53ebf16e8b1010a568f43d9c430
MD5 90565898b8fb357e0f9e4045ee9c9c8b
BLAKE2b-256 af232356eecff84f18d3b3933038d605c78731dab15e067e44d114b7bd802d5f

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