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-learnmake_scorerfor enhanced functionalities withPortfolioobjects.This factory function wraps scoring functions for use in
sklearn.model_selection.GridSearchCVandsklearn.model_selection.cross_val_score.- Parameters:
- score_funcMeasure | callable
If
score_funcis a measure, we return the measure of the predictedPortfoliotimes1or-1depending on thegreater_is_betterparameter.Otherwise,
score_funcmust be a score function (or loss function) with signaturescore_func(pred, **kwargs). The argumentpredis the predictedPortfolio.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_funcis 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 thescore_func. The default (None) is to use:If
score_funcis a measure:True for
PerfMeasureandRationMeasureFalse for
RiskMeasureandExtraRiskMeasure.
Otherwise, True.
- **kwargsadditional arguments
Additional parameters to be passed to score_func.
- Returns:
- scorercallable
Callable object that returns a scalar score.