Quantile transform features and ret in each cross-section
Cross-validate on one year (2019) just for illustration
Custom Scorer
For picking stocks based on return predictions, the important issue is whether stocks predicted to have higher returns actually do have higher returns.
The numerical values of the predictions and the numerical errors matter less.
To calculate the extent to which higher predictions correspond to higher returns, Spearman’s rank correlation is useful.
from scipy.stats import spearmanrfrom sklearn.metrics import make_scorerscorer = make_scorer( lambda a, b: spearmanr(a, b).statistic, greater_is_better=True)