Skip to Content

lacuna.labels

Forward-return labels with explicit entry, exit and horizon semantics.

Generated from Lacuna 0.14.3. For what these do and when to use them, read the guide.

Classes

LabelResult

class LabelResult(evidence: AnalysisResult)

Typed forward-return frame plus compact construction evidence.

FieldTypeDefault
evidenceAnalysisResultrequired

LabelResult.frame

frame: pl.DataFrame

Return a shallow clone so callers cannot replace result-owned columns.

LabelResult.metadata

metadata: ResultMetadata

Expose construction provenance.

LabelResult.to_json

def to_json(*, indent: int | None = 2) -> str

Serialize compact evidence; the potentially large label frame stays columnar.

Functions

forward_returns

def forward_returns(
    prices: object,
    *,
    schema: Sequence[str] | None = None,
    horizons: Sequence[Horizon] | None = None,
    horizon: Horizon | None = None,
    time: str = 'time',
    instrument: str = 'instrument',
    price: str = 'close',
    signal_time: str | None = None,
    entry: str | None = None,
    exit: str = 'close',
    price_adjustment: PriceAdjustment = 'unknown',
    delisting_return: str | None = None,
    missing: Literal['drop', 'raise'] = 'drop',
    allow_same_close: bool = False,
) -> LabelResult

Construct simple forward returns over trading-observation horizons.

A horizon such as "5D" means five ordered observations per instrument, not five calendar days. The output is long-form and includes observation, earning-interval, instrument, horizon, and return columns.

Types and constants

Horizon

Horizon = str | int

PriceAdjustment

PriceAdjustment = Literal['raw', 'split_adjusted', 'total_return_adjusted', 'unknown']