Repository navigation
Train IC objectives on complete dates without NaN gradients - #82
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
IC/RankIC training previously shuffled stock-days from different dates into the same correlation batch. Between-date level shifts can make the pooled correlation positive even when every daily cross-section has reversed stock ordering. The time split could also put stocks from the same date on both sides, and a training set smaller than
batch_sizesilently performed no optimizer steps.The trainer now defaults to one complete observed date per batch for
ICLoss/RankICLoss, shuffles dates, and averages daily losses equally. Time validation holds out complete latest dates;val_splitis a date fraction in this mode. Random daily splits also keep dates intact. Ordinary regression retains sample batching and includes the final partial batch.batch_mode="date"supports custom daily objectives; explicit sample batching is rejected for the built-in IC losses. Validation runs without autograd.The PR also guards zero-variance operands before Pearson square roots: constant/singleton batches contribute zero loss and zero gradients instead of poisoning optimizer state with NaNs. Ordinary finite nonconstant batches retain the previous correlation formula/gradients. Correlation inputs must be aligned, nonempty and finite;
gamma/temperaturemust be finite positive values.Behavior and limits:
batch_size; memory depends on the largest cross-section. Soft RankIC still uses quadratic pairwise rank memory.Local verification for head
c955c1a8b937cdf78a33b1ed7cedb3ddf16e0a33, Python 3.12.14 / PyTorch 2.14.1, macOS 26.6.2, Apple M5 CPU, deterministic unit/synthetic fixtures only (no external market data, no trading-cost assumption applicable):/tmp/projects-push-20261028-venv/bin/python -m pytest tests/test_cross_section_training.py tests/test_trainer_split.py tests/test_losses.py— 69 passed./tmp/projects-push-20261028-venv/bin/python -m pytest— 209 passed./tmp/projects-push-20261028-venv/bin/python -m ruff check src tests— passed.git diff --check— passed before commit.Regression tests cover the pooled-correlation counterexample, ragged and singleton dates, date-disjoint time/random splits, equal-date validation weighting, actual updates on undersized regression datasets, four-dtype degenerate gradients, normal gradient parity and Adam recovery.
GitHub CI passed on the exact head above: Python 3.9/3.10/3.11 lint, full tests and CLI smoke checks. The maintainer explicitly requested direct merge on 2026-10-28 after these checks passed. Merged using the repository's permitted administrator override; no independent review is claimed and branch protection settings were not changed.