跳转至

Data Reference

OHLCV data providers, caching, and resampling utilities.

Back to API Reference

Market data contracts, adapters, and cache helpers.

BarsCache

Simple parquet cache for Bars DataFrames.

__init__

__init__(
    root: Path | str,
    *,
    ttl: timedelta | int | float | None = None,
    offline: bool = False,
) -> None

Create a cache rooted at root.

write

write(
    engine: str,
    symbol: str,
    freq: str,
    bars: DataFrame,
    *,
    now: Timestamp | datetime | str | None = None,
) -> CacheEntry

Write Bars data and sidecar metadata.

read

read(
    engine: str,
    symbol: str,
    freq: str,
    *,
    ttl: timedelta | int | float | None = None,
    offline: bool | None = None,
    now: Timestamp | datetime | str | None = None,
    symbols: str | list[str] | None = None,
    start: str | Timestamp | None = None,
    end: str | Timestamp | None = None,
    columns: list[str] | None = None,
) -> pd.DataFrame

Read cached Bars data and restore attrs.

fingerprint

fingerprint(engine: str, symbol: str, freq: str) -> str

Return the cached fingerprint for one engine/symbol/frequency key.

exists

exists(engine: str, symbol: str, freq: str) -> bool

Return whether both parquet data and metadata exist for a cache key.

is_fresh

is_fresh(
    engine: str,
    symbol: str,
    freq: str,
    *,
    ttl: timedelta | int | float | None = None,
    now: Timestamp | datetime | str | None = None,
) -> bool

Return whether a cache entry exists and has not exceeded its TTL.

CacheEntry dataclass

Paths written for one cached Bars object.

CacheExpiredError

Raised when a requested Bars cache entry is stale in online mode.

CacheMissError

Raised when a requested Bars cache entry is missing.

Dataset

A local file set queried by DuckDB with explicit UTC timestamps.

CSVs must include timestamp (with timezone), symbol and OHLCV columns. Parquet uses the same columns. Files are never rewritten or repaired.

read

read(
    *,
    symbols: Any = None,
    start: Any = None,
    end: Any = None,
    columns: Sequence[str] | None = None,
) -> pd.DataFrame

Read inclusive UTC boundaries and requested fields with SQL pushdown.

Full OHLCV is validated before projection. Filtering executes at source; no cache is silently reused after a file changes.

iter_batches

iter_batches(
    *,
    batch_size: int = 65536,
    symbols: Any = None,
    start: Any = None,
    end: Any = None,
    columns: Sequence[str] | None = None,
)

Stream ordered validated frames; reject duplicates across batches.

Consume/close the iterator before another query on this connection.

profile

profile(**query: Any) -> DataExplorer

Return the existing explorer over the explicitly selected data.

close

close() -> None

Release this dataset instance's DuckDB connection.

DuckDBBarsBackend

Columnar Bars storage backed by DuckDB.

DuckDB is optional. Tests and custom integrations may inject a connection object with execute/register/unregister methods to avoid importing the package.

ensure_schema

ensure_schema() -> None

Create the Bars table if it does not exist.

write

write(bars: DataFrame, *, mode: str = 'append') -> None

Write contract-valid Bars rows into DuckDB.

read

read(
    *,
    symbols: str
    | list[str]
    | tuple[str, ...]
    | None = None,
    start: str | Timestamp | None = None,
    end: str | Timestamp | None = None,
    columns: list[str] | tuple[str, ...] | None = None,
    market: str | None = None,
    freq: str | None = None,
) -> pd.DataFrame

Read Bars rows with optional symbol, date, and column filters.

read_cross_section

read_cross_section(
    timestamp: str | Timestamp,
    *,
    symbols: str
    | list[str]
    | tuple[str, ...]
    | None = None,
    columns: list[str] | tuple[str, ...] | None = None,
    market: str | None = None,
    freq: str | None = None,
) -> pd.DataFrame

Read one timestamp as a symbol-indexed cross section.

read_panel

read_panel(
    *,
    symbols: str
    | list[str]
    | tuple[str, ...]
    | None = None,
    start: str | Timestamp | None = None,
    end: str | Timestamp | None = None,
    columns: list[str] | tuple[str, ...] | None = None,
    market: str | None = None,
    freq: str | None = None,
) -> pd.DataFrame

Read a timestamp/symbol indexed Bars panel.

DataExplorer

Explore raw Bars-like market data before research or backtesting.

__init__

__init__(data: DataFrame) -> None

Create an explorer from a Bars contract frame or raw DataFrame.

summary

summary() -> dict[str, Any]

Return compact dataset-level diagnostics.

schema

schema() -> pd.DataFrame

Return dtype, missingness, and cardinality by column.

missing

missing() -> pd.DataFrame

Return columns sorted by missing value count.

describe

describe() -> pd.DataFrame

Return numeric descriptive statistics including skew and kurtosis.

ohlcv_quality

ohlcv_quality() -> pd.DataFrame

Return market-data-specific quality checks.

gaps

gaps() -> pd.DataFrame

Return observed timestamp gaps by symbol.

returns

returns(column: str = 'close') -> pd.Series

Return per-symbol percentage returns.

outliers

outliers(
    *, column: str = "close", zscore: float = 4.0
) -> pd.DataFrame

Return return outliers by absolute z-score.

correlation

correlation(column: str = 'close') -> pd.DataFrame

Return multi-symbol return correlation.

to_analysis

to_analysis() -> dict[str, Any]

Compute domain tables once for the shared Reporter.

report

report(path: str | Path) -> Path

Render computed exploration tables through the shared Reporter.

DataProvider

Protocol for OHLCV market data providers.

history_ohlc

history_ohlc(
    symbol: str | list[str] | tuple[str, ...],
    *,
    start: str | None = None,
    end: str | None = None,
    freq: Frequency = "1d",
) -> pd.DataFrame

Fetch historical OHLCV bars.

TdxProvider

TDX-backed A-share OHLCV provider.

__init__

__init__(
    *,
    host: str | None = None,
    port: int = 7709,
    timeout: float = 5.0,
    count: int = 800,
    client_factory: Callable[[], object] | None = None,
) -> None

Create a provider with optional TDX client injection.

history_ohlc

history_ohlc(
    symbol: str | list[str] | tuple[str, ...],
    *,
    start: str | None = None,
    end: str | None = None,
    freq: Frequency = "1d",
) -> pd.DataFrame

Fetch A-share OHLCV data and return contract-valid Bars.

TradingViewProvider

TradeLearn TradingView transport with legacy tvDatafeed client injection.

history_ohlc

history_ohlc(
    symbol: str | list[str] | tuple[str, ...],
    *,
    start: str | None = None,
    end: str | None = None,
    freq: Frequency = "1d",
    exchange: str | None = None,
) -> pd.DataFrame

Fetch TradingView OHLCV data and return contract-valid Bars.

history_window

history_window(
    symbol,
    resolution,
    count=300,
    to=None,
    forward=False,
    *,
    adjustment="splits",
)

Fetch chart bars with a server-side cutoff or forward replay anchor.

resolve_symbol

resolve_symbol(symbol, *, adjustment='splits')

Return TradingView chart symbol metadata.

search_symbols

search_symbols(query)

Search TradingView markets through TradeLearn.

TushareProvider

Daily A-share prices, with weekly/monthly aggregation of adjusted daily data.

Requests cover at most 25 years and return at most 5,000 daily observations. The latest observations are retained when the cap is reached; the result then has possibly_truncated=True. Period bars include partial periods and use the first observed session date. Pre-adjustment uses the last factor on/before the fixed anchor (default: requested end). Post-adjustment follows Tushare's absolute factor convention: raw price * adj_factor. Volume and amount are never price-adjusted.

search

search(query)

Search the cached listed-stock directory by code or name.

resolve

resolve(symbol)

Resolve a validated code against the cached listed-stock directory.

history_ohlc

history_ohlc(
    symbol,
    start=None,
    end=None,
    freq="1d",
    adjust="none",
    anchor=None,
)

Fetch finite daily Bars and explicitly apply the requested anchored adjustment/aggregation.

open_dataset

open_dataset(
    paths: str | Path | Sequence[str | Path],
) -> Dataset

Open explicit local CSV/Parquet paths or glob patterns.