Skip to content

loaders

Loader protocol and ZipLoader for decoupled simulation data loading.

Classes:

  • Loader

    Protocol for loading simulation data from any source.

  • SimulationData

    Container for all data loaded by a loader.

  • ZipLoader

    Loads simulation data from a zip archive (file path or in-memory buffer).

  • ZipLoaderConfig

    Configuration for file names within a zip archive.

Loader

Bases: Protocol

Protocol for loading simulation data from any source.

Methods:

  • load

    Load and return simulation data.

load

load() -> SimulationData

Load and return simulation data.

SimulationData dataclass

SimulationData(
    name: str,
    start_date: date,
    end_date: date,
    instruments: list[Instrument],
    positions: list[Position],
    market_frames: dict[str, DataFrame],
    balances: dict[str, float] = dict(),
    valuations: dict[str, dict[str, float]] = dict(),
)

Container for all data loaded by a loader.

ZipLoader

ZipLoader(
    *,
    path: Path | str | None = None,
    buffer: BytesIO | None = None,
    instrument_registry: InstrumentRegistry,
    config: ZipLoaderConfig | None = None,
)

Loads simulation data from a zip archive (file path or in-memory buffer).

Parameters:

  • path

    (Path | str | None, default: None ) –

    Path to a zip file on disk. Mutually exclusive with buffer.

  • buffer

    (BytesIO | None, default: None ) –

    In-memory zip data. Mutually exclusive with path.

  • instrument_registry

    (InstrumentRegistry) –

    Registry used to construct instrument instances.

  • config

    (ZipLoaderConfig | None, default: None ) –

    Optional file-name configuration for the archive layout.

Methods:

  • load

    Read the zip archive and return a populated SimulationData.

load

load() -> SimulationData

Read the zip archive and return a populated SimulationData.

ZipLoaderConfig dataclass

ZipLoaderConfig(
    config_file: str = "config.json",
    instruments_file: str = "instruments.json",
    positions_file: str = "positions.json",
    market_data_mapping: dict[str, str] = lambda: {
        "yields": "yields.csv",
        "benchmarks": "benchmarks.csv",
    }(),
)

Configuration for file names within a zip archive.