Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "alpha-engine-lib"
version = "0.50.0"
version = "0.51.0"
description = "Shared utilities for the Alpha Engine modules: preflight, logging, ArcticDB, dates, decision capture, cost telemetry, Anthropic payload chokepoint, artifact freshness, RAG, agent schemas, SSM secrets, Telegram + SNS alerts, EC2 spot resilience, SSM log-capture, SSM dispatcher, Step-Functions execution-state projection, S3-conditional-PUT writer locks, and bounded-backoff HTTP retry. Full surface documented in README."
readme = "README.md"
# EC2 still runs Python 3.9 on the always-on micro instance (boto3 drops
Expand Down
2 changes: 1 addition & 1 deletion src/alpha_engine_lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""alpha-engine-lib — shared utilities for Alpha Engine modules."""

__version__ = "0.50.0"
__version__ = "0.51.0"
11 changes: 9 additions & 2 deletions src/alpha_engine_lib/quant/factor_risk_xs.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,15 @@ def estimate_factor_covariance(
return pd.DataFrame(np.full((K, K), np.nan), index=cols, columns=cols)

if shrinkage == "ledoit_wolf":
from sklearn.covariance import LedoitWolf
F = LedoitWolf().fit(clean.to_numpy()).covariance_
# Single shared Ledoit-Wolf estimator (LV1-AE.a, 2026-06-03). The numpy
# ``quant.factor_risk.ledoit_wolf_cov`` is numerically identical to
# sklearn's ``LedoitWolf`` (max abs diff ~1e-21, validated across
# n∈[35,1000]) — both center the data and estimate the same shrinkage
# intensity toward a scaled-identity target. Consolidating onto the numpy
# impl kills the duplicate reimplementation; sklearn stays a lazy import
# for OAS only.
from .factor_risk import ledoit_wolf_cov
F = ledoit_wolf_cov(clean.to_numpy(), shrinkage="ledoit_wolf")
elif shrinkage == "oas":
from sklearn.covariance import OAS
F = OAS().fit(clean.to_numpy()).covariance_
Expand Down
12 changes: 12 additions & 0 deletions tests/test_quant_factor_risk_xs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
)


def test_ledoit_wolf_branch_uses_shared_numpy_impl():
"""LV1-AE.a consolidation contract: estimate_factor_covariance's ledoit_wolf
path is the shared numpy quant.factor_risk.ledoit_wolf_cov (one LW impl)."""
from alpha_engine_lib.quant.factor_risk import ledoit_wolf_cov

rng = np.random.RandomState(0)
panel = pd.DataFrame(rng.normal(0, 0.01, (200, 4)), columns=["market", "MOM", "VAL", "QUAL"])
F = estimate_factor_covariance(panel, shrinkage="ledoit_wolf", min_obs=30)
expected = ledoit_wolf_cov(panel.to_numpy(), shrinkage="ledoit_wolf")
assert np.allclose(F.to_numpy(), expected, atol=1e-15)


# ─── Helpers ────────────────────────────────────────────────────────────────


Expand Down