feat(PORT-001A): add collateral entry basis settings
This commit is contained in:
@@ -9,7 +9,6 @@ from app.models.portfolio import PortfolioConfig, get_portfolio_repository
|
||||
from app.pages.common import dashboard_page, quick_recommendations, recommendation_style, strategy_catalog
|
||||
from app.services.runtime import get_data_service
|
||||
|
||||
_REFERENCE_SPOT_PRICE = 215.0
|
||||
_DEFAULT_CASH_BUFFER = 18_500.0
|
||||
|
||||
|
||||
@@ -24,23 +23,24 @@ def _format_timestamp(value: str | None) -> str:
|
||||
|
||||
|
||||
def _build_live_portfolio(config: PortfolioConfig, quote: dict[str, object]) -> dict[str, float | str]:
|
||||
spot_price = float(quote.get("price", _REFERENCE_SPOT_PRICE))
|
||||
configured_gold_value = float(config.gold_value)
|
||||
estimated_units = configured_gold_value / _REFERENCE_SPOT_PRICE if _REFERENCE_SPOT_PRICE > 0 else 0.0
|
||||
live_gold_value = estimated_units * spot_price
|
||||
fallback_spot_price = float(config.entry_price or 0.0)
|
||||
spot_price = float(quote.get("price", fallback_spot_price))
|
||||
configured_gold_value = float(config.gold_value or 0.0)
|
||||
gold_units = float(config.gold_ounces or 0.0)
|
||||
live_gold_value = gold_units * spot_price
|
||||
loan_amount = float(config.loan_amount)
|
||||
margin_call_ltv = float(config.margin_threshold)
|
||||
ltv_ratio = loan_amount / live_gold_value if live_gold_value > 0 else 0.0
|
||||
|
||||
return {
|
||||
"spot_price": spot_price,
|
||||
"gold_units": estimated_units,
|
||||
"gold_units": gold_units,
|
||||
"gold_value": live_gold_value,
|
||||
"loan_amount": loan_amount,
|
||||
"ltv_ratio": ltv_ratio,
|
||||
"net_equity": live_gold_value - loan_amount,
|
||||
"margin_call_ltv": margin_call_ltv,
|
||||
"margin_call_price": loan_amount / (margin_call_ltv * estimated_units) if estimated_units > 0 else 0.0,
|
||||
"margin_call_price": loan_amount / (margin_call_ltv * gold_units) if gold_units > 0 else 0.0,
|
||||
"cash_buffer": max(live_gold_value - configured_gold_value, 0.0) + _DEFAULT_CASH_BUFFER,
|
||||
"hedge_budget": float(config.monthly_budget),
|
||||
"quote_source": str(quote.get("source", "unknown")),
|
||||
|
||||
Reference in New Issue
Block a user