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 withPortfolio
objects.This factory function wraps scoring functions for use in
sklearn.model_selection.GridSearchCV
andsklearn.model_selection.cross_val_score
.- Parameters:
- score_funcMeasure | callable
If
score_func
is a measure, we return the measure of the predictedPortfolio
times1
or-1
depending on thegreater_is_better
parameter.Otherwise,
score_func
must be a score function (or loss function) with signaturescore_func(pred, **kwargs)
. The argumentpred
is 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_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 thescore_func
. The default (None
) is to use:If
score_func
is a measure:True for
PerfMeasure
andRationMeasure
False for
RiskMeasure
andExtraRiskMeasure
.
Otherwise, True.
- **kwargsadditional arguments
Additional parameters to be passed to score_func.
- Returns:
- scorercallable
Callable object that returns a scalar score.