skfolio.metrics.make_scorer#

skfolio.metrics.make_scorer(score_func, greater_is_better=None, **kwargs)[source]#

Make a scorer from a measure or from a custom score function.

This is a modified version from scikit-learn make_scorer for enhanced functionalities with Portfolio objects.

This factory function wraps scoring functions for use in sklearn.model_selection.GridSearchCV and sklearn.model_selection.cross_val_score.

Parameters:
score_funcMeasure | callable

If score_func is a measure, we return the measure of the predicted Portfolio times 1 or -1 depending on the greater_is_better parameter.

Otherwise, score_func must be a score function (or loss function) with signature score_func(pred, **kwargs). The argument pred is the predicted Portfolio.

Note that you can convert this portfolio object into a numpy array of price returns with np.asarray(pred).

greater_is_betterbool, optional

If this is set to True, score_func is a score function (default) meaning high is good, otherwise it is a loss function, meaning low is good. In the latter case, the scorer object will sign-flip the outcome of the score_func. The default (None) is to use:

  • If score_func is a measure:

    • True for PerfMeasure and RationMeasure

    • False for RiskMeasure and ExtraRiskMeasure.

  • Otherwise, True.

**kwargsadditional arguments

Additional parameters to be passed to score_func.

Returns:
scorercallable

Callable object that returns a scalar score.