Skip to content

Target

Targets define how forward returns are turned into labels, and samplers select which observations to keep for training.

Labelers

signalflow.Target

Bases: ABC

Derives labels from raw data for a model to learn.

horizon abstractmethod property

horizon: int

Forward bars consumed - used for purge/embargo in the walk-forward CV.

horizon_bars

horizon_bars(data: Dataset) -> int

Forward bars for purge/embargo, resolving a duration-string horizon against the data.

Source code in src/signalflow/target/base.py
def horizon_bars(self, data: Dataset) -> int:
    """Forward bars for purge/embargo, resolving a duration-string horizon against the data."""
    return resolve_bars(self._effective_horizon(), data)

labels abstractmethod

labels(data: Dataset, at: DataFrame | None = None) -> pl.DataFrame

Return (pair, ts, label); if at (pair, ts) given, restrict to it.

Source code in src/signalflow/target/base.py
@abstractmethod
def labels(self, data: Dataset, at: pl.DataFrame | None = None) -> pl.DataFrame:
    """Return ``(pair, ts, label)``; if ``at`` (pair, ts) given, restrict to it."""

signalflow.FixedHorizon dataclass

FixedHorizon(bars: int | str = 120, threshold: float = 0.0)

Bases: Target

Label 1 if close rises by more than threshold after bars bars.

bars accepts a bar count (int, assuming 1-minute data for the default) or a duration string ("1h") resolved against the dataset interval.

signalflow.TripleBarrier dataclass

TripleBarrier(tp: float = 0.03, sl: float = 0.015, max_bars: int = 100)

Bases: Target

Meta-labeling target: success = tp hit before sl within the horizon.

Samplers

signalflow.Sampler

Bases: ABC

Selects training points from a Dataset.

sample abstractmethod

sample(data: Dataset) -> SampleSet

Select training rows from data, returning their index, optional weights, and a provenance stamp.

Source code in src/signalflow/sampler/base.py
@abstractmethod
def sample(self, data: Dataset) -> SampleSet:
    """Select training rows from ``data``, returning their index, optional weights,
    and a provenance stamp."""
    ...

signalflow.SampleSet dataclass

SampleSet(index: DataFrame, weights: Series | None = None, provenance: Provenance = Provenance.FULL)

Result of a sampler: training points + weights + provenance.

signalflow.UniformSampler

Bases: Sampler

Train on every row.

signalflow.MetaLabelingSampler

MetaLabelingSampler(signals: Dataset)

Bases: Sampler

Select rows where signal != NONE.

Source code in src/signalflow/sampler/meta_labeling.py
def __init__(self, signals: Dataset):
    self.signals = signals

signalflow.CUSUMSampler dataclass

CUSUMSampler(column: str = 'close', threshold: float = 0.05)

Bases: Sampler

Sample at structural shifts where cumulative log-return exceeds a threshold.

signalflow.UniquenessSampler

UniquenessSampler(target, base: Sampler | None = None)

Bases: Sampler

Add average-uniqueness weights to base's selection for a horizon target.

Source code in src/signalflow/sampler/uniqueness.py
def __init__(self, target, base: Sampler | None = None):
    self.target = target
    self.base = base or UniformSampler()