feat(CORE-002B): roll out hedge quote unit conversion
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.domain.portfolio_math import resolve_portfolio_spot_from_quote
|
||||
from app.models.portfolio import PortfolioConfig
|
||||
from app.pages.common import strategy_metrics
|
||||
from app.pages.hedge import _waterfall_options
|
||||
|
||||
@@ -29,3 +31,52 @@ def test_hedge_waterfall_uses_zero_based_contribution_bars() -> None:
|
||||
values = options["series"][0]["data"]
|
||||
assert values[2]["value"] == 38_000.0
|
||||
assert values[2]["itemStyle"]["color"] == "#22c55e"
|
||||
|
||||
|
||||
def test_hedge_quote_resolution_converts_gld_share_price_to_ozt_spot() -> None:
|
||||
"""Hedge page should convert GLD share quotes to USD/ozt for display."""
|
||||
config = PortfolioConfig(entry_price=4400.0, gold_ounces=220.0, entry_basis_mode="weight", loan_amount=145000.0)
|
||||
share_quote = {
|
||||
"symbol": "GLD",
|
||||
"price": 404.19,
|
||||
"quote_unit": "share",
|
||||
"source": "yfinance",
|
||||
"updated_at": "2026-03-25T00:00:00+00:00",
|
||||
}
|
||||
|
||||
spot, source, updated_at = resolve_portfolio_spot_from_quote(config, share_quote)
|
||||
|
||||
assert spot == 4041.9
|
||||
assert source == "yfinance"
|
||||
|
||||
|
||||
def test_hedge_quote_resolution_fails_closed_when_quote_unit_missing() -> None:
|
||||
"""Hedge page should fall back to configured price when quote_unit is missing."""
|
||||
config = PortfolioConfig(entry_price=4400.0, gold_ounces=220.0, entry_basis_mode="weight", loan_amount=145000.0)
|
||||
legacy_quote = {
|
||||
"symbol": "GLD",
|
||||
"price": 404.19,
|
||||
"source": "cache",
|
||||
}
|
||||
|
||||
spot, source, _ = resolve_portfolio_spot_from_quote(config, legacy_quote)
|
||||
|
||||
assert spot == 4400.0
|
||||
assert source == "configured_entry_price"
|
||||
|
||||
|
||||
def test_hedge_quote_resolution_fails_closed_for_unsupported_instrument() -> None:
|
||||
"""Hedge page should fall back when instrument metadata is unavailable."""
|
||||
config = PortfolioConfig(entry_price=4400.0, gold_ounces=220.0, entry_basis_mode="weight", loan_amount=145000.0)
|
||||
slv_quote = {
|
||||
"symbol": "SLV",
|
||||
"price": 28.50,
|
||||
"quote_unit": "share",
|
||||
"source": "yfinance",
|
||||
"updated_at": "2026-03-25T00:00:00+00:00",
|
||||
}
|
||||
|
||||
spot, source, _ = resolve_portfolio_spot_from_quote(config, slv_quote)
|
||||
|
||||
assert spot == 4400.0
|
||||
assert source == "configured_entry_price"
|
||||
|
||||
Reference in New Issue
Block a user