Skip to content

scoring

optimizer.scoring

Performance scoring for model selection and hyperparameter tuning.

Wraps skfolio ratio measures and custom scoring functions into callables compatible with sklearn cross-validation.

ScorerConfig dataclass

Immutable configuration for building a scoring function.

When ratio_measure is set, the scorer evaluates portfolios using the corresponding built-in ratio measure (Sharpe, Sortino, Calmar, etc.). When ratio_measure is None, a custom callable must be passed to the factory function.

Parameters

ratio_measure : RatioMeasureType or None Built-in ratio measure. None indicates a custom scorer. greater_is_better : bool or None Whether higher scores are better. None auto-detects from the ratio measure.

for_sharpe() classmethod

Sharpe ratio scorer.

for_sortino() classmethod

Sortino ratio scorer.

for_calmar() classmethod

Calmar ratio scorer.

for_cvar_ratio() classmethod

CVaR ratio scorer.

for_information_ratio() classmethod

Information Ratio scorer (active return / tracking error).

Requires benchmark_returns to be passed to :func:~optimizer.scoring.build_scorer.

for_custom() classmethod

Custom scoring function (callable passed to factory).

build_scorer(config=None, *, score_func=None, benchmark_returns=None)

Build a scoring callable compatible with sklearn cross-validation.

Parameters

config : ScorerConfig or None Scorer configuration. Defaults to ScorerConfig() (Sharpe ratio). score_func : callable or None Custom scoring function that accepts a portfolio and returns a scalar. Required when config.ratio_measure is None. benchmark_returns : pd.Series or None Full benchmark return series indexed by date. Required when config.ratio_measure is RatioMeasureType.INFORMATION_RATIO; ignored otherwise.

Returns

callable A scorer callable compatible with GridSearchCV and RandomizedSearchCV.

Raises

ValueError If config.ratio_measure is None and no score_func is provided. ValueError If config.ratio_measure is RatioMeasureType.INFORMATION_RATIO and benchmark_returns is None.