feat(DATA-002): add live GLD options chain data via yfinance
This commit is contained in:
@@ -1,14 +1,66 @@
|
||||
"""Portfolio configuration models with validation and persistence."""
|
||||
"""Portfolio configuration and domain portfolio models."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
from dataclasses import dataclass, field
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class LombardPortfolio:
|
||||
"""Lombard loan portfolio backed by physical gold."""
|
||||
|
||||
gold_ounces: float
|
||||
gold_price_per_ounce: float
|
||||
loan_amount: float
|
||||
initial_ltv: float
|
||||
margin_call_ltv: float
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
if self.gold_ounces <= 0:
|
||||
raise ValueError("gold_ounces must be positive")
|
||||
if self.gold_price_per_ounce <= 0:
|
||||
raise ValueError("gold_price_per_ounce must be positive")
|
||||
if self.loan_amount < 0:
|
||||
raise ValueError("loan_amount must be non-negative")
|
||||
if not 0 < self.initial_ltv < 1:
|
||||
raise ValueError("initial_ltv must be between 0 and 1")
|
||||
if not 0 < self.margin_call_ltv < 1:
|
||||
raise ValueError("margin_call_ltv must be between 0 and 1")
|
||||
if self.initial_ltv > self.margin_call_ltv:
|
||||
raise ValueError("initial_ltv cannot exceed margin_call_ltv")
|
||||
if self.loan_amount > self.gold_value:
|
||||
raise ValueError("loan_amount cannot exceed current gold value")
|
||||
|
||||
@property
|
||||
def gold_value(self) -> float:
|
||||
return self.gold_ounces * self.gold_price_per_ounce
|
||||
|
||||
@property
|
||||
def current_ltv(self) -> float:
|
||||
return self.loan_amount / self.gold_value
|
||||
|
||||
@property
|
||||
def net_equity(self) -> float:
|
||||
return self.gold_value - self.loan_amount
|
||||
|
||||
def gold_value_at_price(self, gold_price_per_ounce: float) -> float:
|
||||
if gold_price_per_ounce <= 0:
|
||||
raise ValueError("gold_price_per_ounce must be positive")
|
||||
return self.gold_ounces * gold_price_per_ounce
|
||||
|
||||
def ltv_at_price(self, gold_price_per_ounce: float) -> float:
|
||||
return self.loan_amount / self.gold_value_at_price(gold_price_per_ounce)
|
||||
|
||||
def net_equity_at_price(self, gold_price_per_ounce: float) -> float:
|
||||
return self.gold_value_at_price(gold_price_per_ounce) - self.loan_amount
|
||||
|
||||
def margin_call_price(self) -> float:
|
||||
return self.loan_amount / (self.margin_call_ltv * self.gold_ounces)
|
||||
|
||||
|
||||
@dataclass
|
||||
class PortfolioConfig:
|
||||
"""User portfolio configuration with validation.
|
||||
|
||||
Reference in New Issue
Block a user