Files
fxhnt/tests/unit/test_marginal.py
jgrusewski e48c0c2094 feat(factory): marginal Sharpe contribution (selection objective)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 19:54:08 +02:00

26 lines
948 B
Python

"""Marginal contribution = the change in book Sharpe from adding a sleeve at a small weight."""
from __future__ import annotations
import numpy as np
from fxhnt.domain.diversification.marginal import marginal_sharpe
def test_uncorrelated_positive_sleeve_adds_sharpe() -> None:
rng = np.random.default_rng(0)
book = rng.normal(0.0005, 0.01, 1000)
sleeve = rng.normal(0.0005, 0.01, 1000) # independent, positive drift
assert marginal_sharpe(book, sleeve, weight=0.2) > 0.0
def test_duplicate_book_adds_little() -> None:
rng = np.random.default_rng(1)
book = rng.normal(0.0005, 0.01, 1000)
add = marginal_sharpe(book, book.copy(), weight=0.2) # same stream -> no diversification
indep = marginal_sharpe(book, rng.normal(0.0005, 0.01, 1000), weight=0.2)
assert indep > add
def test_too_short_returns_nan() -> None:
assert np.isnan(marginal_sharpe(np.array([0.01]), np.array([0.01]), weight=0.2))