numerai-tools 0.4.2.dev0__tar.gz → 0.4.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: numerai_tools
3
- Version: 0.4.2.dev0
3
+ Version: 0.4.3
4
4
  Summary: A collection of open-source tools to help interact with Numerai, model data, and automate submissions.
5
5
  Home-page: https://github.com/numerai/numerai-tools
6
6
  Maintainer: Numerai
@@ -1,6 +1,5 @@
1
1
  from typing import List, Tuple, Union, Optional, TypeVar
2
2
 
3
- import torch
4
3
  import numpy as np
5
4
  import pandas as pd # type: ignore
6
5
  from scipy import stats # type: ignore
@@ -462,7 +461,7 @@ def numerai_corr(
462
461
  Returns:
463
462
  pd.Series - the resulting correlation scores for each column in predictions
464
463
  """
465
- targets = targets - targets.mean()
464
+ targets = center(targets)
466
465
  targets, predictions = filter_sort_index(
467
466
  targets, predictions, max_filtered_index_ratio
468
467
  )
@@ -558,14 +557,15 @@ def alpha(
558
557
  sample_weights: pd.Series - the universe sampling weights
559
558
  targets: pd.Series - the live targets to evaluate against
560
559
  """
560
+ targets = center(targets)
561
561
  assert not predictions.isna().any().any(), "Predictions contain NaNs"
562
562
  assert not neutralizers.isna().any().any(), "Normalization factors contain NaNs"
563
563
  assert not sample_weights.isna().any(), "Weights contain NaNs"
564
564
  predictions, neutralizers, sample_weights, targets = filter_sort_index_many(
565
565
  [predictions, neutralizers, sample_weights, targets]
566
566
  )
567
-
568
- weights = tie_kept_rank__gaussianize__pow_1_5(predictions).apply(
567
+ ranked_preds = tie_kept_rank__gaussianize__pow_1_5(predictions)
568
+ weights = ranked_preds.apply(
569
569
  lambda s_prime: generate_neutralized_weights(
570
570
  s_prime, neutralizers, sample_weights
571
571
  )
@@ -594,6 +594,7 @@ def meta_portfolio_contribution(
594
594
  sample_weights: pd.Series - the universe sampling weights
595
595
  targets: pd.Series - the live targets to evaluate against
596
596
  """
597
+ targets = center(targets)
597
598
  assert not predictions.isna().any().any(), "Predictions contain NaNs"
598
599
  assert not neutralizers.isna().any().any(), "Normalization factors contain NaNs"
599
600
  assert not sample_weights.isna().any(), "Weights contain NaNs"
@@ -612,15 +613,12 @@ def meta_portfolio_contribution(
612
613
  t = targets.values
613
614
  swp = w @ s
614
615
  swp = swp - swp.mean()
615
- swp_abs_sum = np.sum(np.abs(swp))
616
+ l1_norm = np.sum(np.abs(swp))
617
+ l1_norm_squared = np.power(l1_norm, 2)
616
618
  swp_sign = np.sign(swp)
617
- alpha_unnormalized_swp_grad = (
618
- 1
619
- / np.power(swp_abs_sum, 2)
620
- * (swp_abs_sum * t - swp_sign * np.dot(swp, t)).reshape(-1, 1)
621
- )
622
- zero_mean_jac_vec_prod = (
623
- alpha_unnormalized_swp_grad - alpha_unnormalized_swp_grad.mean()
624
- )
625
- mpc = (w.T @ zero_mean_jac_vec_prod).squeeze()
619
+ swp_alpha = np.dot(swp, t)
620
+ directional_gradient = l1_norm * t - swp_sign * swp_alpha
621
+ jacobian_vector_product = directional_gradient.reshape(-1, 1) / l1_norm_squared
622
+ centered_jacobian = jacobian_vector_product - jacobian_vector_product.mean()
623
+ mpc = (w.T @ centered_jacobian).squeeze()
626
624
  return pd.Series(mpc, index=stakes.index)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: numerai-tools
3
- Version: 0.4.2.dev0
3
+ Version: 0.4.3
4
4
  Summary: A collection of open-source tools to help interact with Numerai, model data, and automate submissions.
5
5
  Home-page: https://github.com/numerai/numerai-tools
6
6
  Maintainer: Numerai
@@ -1,7 +1,7 @@
1
1
  from setuptools import setup
2
2
  from setuptools import find_packages
3
3
 
4
- VERSION = "0.4.2.dev0"
4
+ VERSION = "0.4.3"
5
5
 
6
6
 
7
7
  def load(path):