26 lines
948 B
Python
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))
|