feat(PRICING-001): add GLD expense ratio decay correction

This commit is contained in:
Bu5hm4nn
2026-03-28 09:04:35 +01:00
parent ff251b5ace
commit 894d88f72f
7 changed files with 208 additions and 26 deletions

View File

@@ -4,6 +4,7 @@ import json
import re
from uuid import uuid4
import pytest
from fastapi.testclient import TestClient
from app.main import app
@@ -109,9 +110,17 @@ def test_bootstrap_endpoint_requires_turnstile_and_creates_workspace_cookie_and_
assert response.cookies.get("workspace_id") == workspace_id
created = repo.load_portfolio_config(workspace_id)
assert created.entry_price == 4041.9
# GLD quote at $404.19/share converts to spot using expense-adjusted backing
from datetime import date
from app.domain.instruments import gld_ounces_per_share
current_backing = float(gld_ounces_per_share(date.today()))
expected_entry_price = 404.19 / current_backing # ~4413.71 with 2026 backing
expected_gold_value = expected_entry_price * 100.0
assert created.entry_price == pytest.approx(expected_entry_price, rel=1e-4)
assert created.gold_ounces == 100.0
assert created.gold_value == 404190.0
assert created.gold_value == pytest.approx(expected_gold_value, rel=1e-4)
def test_root_with_valid_workspace_cookie_redirects_to_workspace(tmp_path, monkeypatch) -> None:
@@ -238,9 +247,11 @@ def test_workspace_routes_seed_page_defaults_from_workspace_portfolio_config(tmp
def test_hedge_page_upgrades_cached_gld_quote_and_uses_converted_spot(tmp_path, monkeypatch) -> None:
"""Hedge page should reuse DataService cache normalization for legacy GLD quotes."""
"""Hedge page should reuse DataService cache normalization for legacy GLD quotes with expense-adjusted backing."""
import asyncio
from datetime import date
from app.domain.instruments import gld_ounces_per_share
from app.pages import hedge as hedge_module
from app.services import runtime as runtime_module
@@ -269,10 +280,13 @@ def test_hedge_page_upgrades_cached_gld_quote_and_uses_converted_spot(tmp_path,
portfolio, source, _ = asyncio.run(hedge_module._resolve_hedge_spot(workspace_id))
# With expense-adjusted backing (~0.0916 oz/share), spot = 404.19 / 0.091576... ≈ 4413.71
current_backing = float(gld_ounces_per_share(date.today()))
expected_spot = 404.19 / current_backing
assert source == "cache"
assert portfolio["spot_price"] == 4041.9
assert portfolio["gold_value"] == 889218.0
assert portfolio["net_equity"] == 667218.0
assert portfolio["spot_price"] == pytest.approx(expected_spot, abs=0.01)
assert portfolio["gold_value"] == pytest.approx(220.0 * expected_spot, abs=0.01)
assert portfolio["net_equity"] == pytest.approx(220.0 * expected_spot - 222_000.0, abs=0.01)
def test_hedge_page_upgrades_legacy_default_workspace_footprint(tmp_path, monkeypatch) -> None:
@@ -323,8 +337,16 @@ def test_hedge_page_upgrades_legacy_default_workspace_footprint(tmp_path, monkey
portfolio, source, _ = asyncio.run(hedge_module._resolve_hedge_spot(workspace_id))
# With expense-adjusted backing (~0.0916 oz/share), spot = 404.19 / 0.091576... ≈ 4413.71
from datetime import date
from app.domain.instruments import gld_ounces_per_share
current_backing = float(gld_ounces_per_share(date.today()))
expected_spot = 404.19 / current_backing
assert source == "cache"
assert portfolio["gold_units"] == 100.0
assert portfolio["margin_call_price"] == 1933.3333333333333
assert portfolio["gold_value"] == 404190.0
assert portfolio["net_equity"] == 259190.0
assert portfolio["margin_call_price"] == pytest.approx(1933.3333333333333, abs=0.01)
assert portfolio["gold_value"] == pytest.approx(100.0 * expected_spot, abs=0.01)
assert portfolio["net_equity"] == pytest.approx(100.0 * expected_spot - 145000.0, abs=0.01)