feat(PRICING-001): add GLD expense ratio decay correction
This commit is contained in:
@@ -1,11 +1,18 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from app.domain.portfolio_math import resolve_portfolio_spot_from_quote
|
||||
from app.models.portfolio import PortfolioConfig
|
||||
from app.services.alerts import build_portfolio_alert_context
|
||||
|
||||
|
||||
def test_overview_converts_gld_share_quote_to_ounce_equivalent_spot() -> None:
|
||||
"""Overview page converts GLD share quotes using expense-adjusted backing."""
|
||||
from datetime import date
|
||||
|
||||
from app.domain.instruments import gld_ounces_per_share
|
||||
|
||||
config = PortfolioConfig(entry_price=4400.0, gold_ounces=220.0, entry_basis_mode="weight", loan_amount=145000.0)
|
||||
|
||||
spot_price, source, updated_at = resolve_portfolio_spot_from_quote(
|
||||
@@ -25,11 +32,16 @@ def test_overview_converts_gld_share_quote_to_ounce_equivalent_spot() -> None:
|
||||
updated_at=updated_at,
|
||||
)
|
||||
|
||||
assert spot_price == 4041.9
|
||||
# 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 abs(spot_price - expected_spot) < 0.01
|
||||
assert source == "yfinance"
|
||||
assert updated_at == "2026-03-24T00:00:00+00:00"
|
||||
assert portfolio["gold_value"] == 889218.0
|
||||
assert portfolio["net_equity"] == 744218.0
|
||||
# Gold value = 220 oz * spot_price
|
||||
expected_gold_value = 220.0 * spot_price
|
||||
assert abs(portfolio["gold_value"] - expected_gold_value) < 0.01
|
||||
assert portfolio["net_equity"] == pytest.approx(expected_gold_value - 145000.0, abs=0.01)
|
||||
assert round(float(portfolio["margin_call_price"]), 2) == 878.79
|
||||
|
||||
|
||||
@@ -53,6 +65,11 @@ def test_overview_fails_closed_to_configured_entry_price_for_unsupported_quote_s
|
||||
|
||||
|
||||
def test_overview_uses_fallback_symbol_when_quote_payload_omits_symbol() -> None:
|
||||
"""GLD quote with fallback symbol uses expense-adjusted backing for conversion."""
|
||||
from datetime import date
|
||||
|
||||
from app.domain.instruments import gld_ounces_per_share
|
||||
|
||||
config = PortfolioConfig(entry_price=4400.0, gold_ounces=220.0, entry_basis_mode="weight", loan_amount=145000.0)
|
||||
|
||||
spot_price, source, updated_at = resolve_portfolio_spot_from_quote(
|
||||
@@ -61,7 +78,10 @@ def test_overview_uses_fallback_symbol_when_quote_payload_omits_symbol() -> None
|
||||
fallback_symbol="GLD",
|
||||
)
|
||||
|
||||
assert spot_price == 4041.9
|
||||
# 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 abs(spot_price - expected_spot) < 0.01
|
||||
assert source == "yfinance"
|
||||
assert updated_at == "2026-03-24T00:00:00+00:00"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user