numerai-tools 0.5.1__tar.gz → 0.5.2.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {numerai_tools-0.5.1 → numerai_tools-0.5.2.dev1}/PKG-INFO +1 -1
- {numerai_tools-0.5.1 → numerai_tools-0.5.2.dev1}/numerai_tools/scoring.py +41 -20
- {numerai_tools-0.5.1 → numerai_tools-0.5.2.dev1}/pyproject.toml +1 -1
- {numerai_tools-0.5.1 → numerai_tools-0.5.2.dev1}/LICENSE +0 -0
- {numerai_tools-0.5.1 → numerai_tools-0.5.2.dev1}/README.md +0 -0
- {numerai_tools-0.5.1 → numerai_tools-0.5.2.dev1}/numerai_tools/__init__.py +0 -0
- {numerai_tools-0.5.1 → numerai_tools-0.5.2.dev1}/numerai_tools/py.typed +0 -0
- {numerai_tools-0.5.1 → numerai_tools-0.5.2.dev1}/numerai_tools/signals.py +0 -0
- {numerai_tools-0.5.1 → numerai_tools-0.5.2.dev1}/numerai_tools/submissions.py +0 -0
|
@@ -614,12 +614,14 @@ def meta_portfolio_contribution(
|
|
|
614
614
|
sample_weights: pd.Series,
|
|
615
615
|
targets: pd.Series,
|
|
616
616
|
) -> pd.Series:
|
|
617
|
-
"""Calculates the "meta portfolio"
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
617
|
+
"""Calculates the "meta portfolio" gradient w.r.t. stakes:
|
|
618
|
+
- rank, normalize, and power each signal
|
|
619
|
+
- convert each signal into neutralized weights
|
|
620
|
+
- center weights across samples (explicit W_c = C W)
|
|
621
|
+
- generate the stake-weighted portfolio
|
|
622
|
+
- calculate the gradient of the portfolio w.r.t. the stakes
|
|
623
|
+
- multiply by the (centered) targets
|
|
624
|
+
|
|
623
625
|
Arguments:
|
|
624
626
|
predictions: pd.DataFrame - the predictions to evaluate
|
|
625
627
|
stakes: pd.Series - the stakes to use as weights
|
|
@@ -627,22 +629,41 @@ def meta_portfolio_contribution(
|
|
|
627
629
|
sample_weights: pd.Series - the universe sampling weights
|
|
628
630
|
targets: pd.Series - the live targets to evaluate against
|
|
629
631
|
"""
|
|
630
|
-
targets
|
|
632
|
+
# Align predictions and targets on the same index / universe
|
|
631
633
|
predictions, targets = filter_sort_index(predictions, targets)
|
|
634
|
+
|
|
635
|
+
# Center targets in sample space: t_c = C t
|
|
636
|
+
targets = center(targets)
|
|
637
|
+
|
|
638
|
+
# Normalize stakes to sum to 1
|
|
632
639
|
stake_weights = weight_normalize(stakes.fillna(0))
|
|
633
640
|
assert np.isclose(stake_weights.sum(), 1), "Stakes must sum to 1"
|
|
641
|
+
|
|
642
|
+
# Generate neutralized weights W(predictions, neutralizers, sample_weights)
|
|
634
643
|
weights = generate_neutralized_weights(predictions, neutralizers, sample_weights)
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
644
|
+
|
|
645
|
+
# Extract aligned matrices/vectors
|
|
646
|
+
w = cast(np.ndarray, weights[stakes.index].values) # W ∈ R^{N×K}
|
|
647
|
+
s = cast(np.ndarray, stake_weights.values) # s ∈ R^K
|
|
648
|
+
t = cast(np.ndarray, targets.values) # t_c ∈ R^N (already centered)
|
|
649
|
+
|
|
650
|
+
# Explicit centering of weights across samples:
|
|
651
|
+
# W_c = C W = W - 1 μ^T, where μ is the column-wise mean of W
|
|
652
|
+
w_centered = w - w.mean(axis=0, keepdims=True) # W_c
|
|
653
|
+
|
|
654
|
+
# Centered prediction vector v = W_c s
|
|
655
|
+
v = w_centered @ s # v ∈ R^N, already mean ~ 0
|
|
656
|
+
# Optionally re-center to remove numerical drift
|
|
657
|
+
v = v - v.mean()
|
|
658
|
+
|
|
659
|
+
# Its L2 norm r = ||v||
|
|
660
|
+
l2_norm = np.sqrt(np.sum(v**2))
|
|
661
|
+
|
|
662
|
+
# Residualize W_c against v:
|
|
663
|
+
# residualized_w ≈ R_v W_c = (I - v v^T / ||v||^2) W_c
|
|
664
|
+
residualized_w = orthogonalize(w_centered, v)
|
|
665
|
+
|
|
666
|
+
# Gradient: ∇_s α = (1 / ||v||) (R_v W_c)^T t_c
|
|
667
|
+
mpc = (residualized_w.T @ t).squeeze() / l2_norm
|
|
668
|
+
|
|
648
669
|
return pd.Series(mpc, index=stakes.index)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "numerai-tools"
|
|
3
|
-
version = "0.5.
|
|
3
|
+
version = "0.5.2.dev1"
|
|
4
4
|
description = "A collection of open-source tools to help interact with Numerai, model data, and automate submissions."
|
|
5
5
|
authors = [
|
|
6
6
|
{name = "Numerai Engineering",email = "engineering@numer.ai"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|