feat: add Portfolio Value, Option Value, and Contracts columns to daily results

- Add option_contracts field to BacktestDailyPoint (number of contracts held)
- Update engine to calculate total option contracts from positions
- Update job serialization to include underlying_value, option_market_value, net_portfolio_value, option_contracts
- Update both render_result and render_job_result tables to show:
  - Low, High, Close (from previous commit)
  - Portfolio value (net_portfolio_value)
  - Option value (option_market_value)
  - Contracts (option_contracts)
  - LTV hedged
  - Margin call status
This commit is contained in:
Bu5hm4nn
2026-04-05 08:54:38 +02:00
parent 7a7b191a6d
commit 6b8336ab7e
4 changed files with 69 additions and 1 deletions

View File

@@ -97,10 +97,12 @@ class BacktestDailyPoint:
ltv_hedged: float
margin_call_unhedged: bool
margin_call_hedged: bool
active_position_ids: tuple[str, ...] = field(default_factory=tuple)
# Optional OHLC fields for worst-case margin call evaluation
spot_low: float | None = None # Day's low for margin call evaluation
spot_high: float | None = None # Day's high
active_position_ids: tuple[str, ...] = field(default_factory=tuple)
# Option position info
option_contracts: float = 0.0 # Number of option contracts held
@dataclass(frozen=True)
@@ -154,3 +156,22 @@ class EventComparisonReport:
scenario: BacktestScenario
rankings: tuple[EventComparisonRanking, ...]
run_result: BacktestRunResult
@dataclass(frozen=True)
class BacktestPortfolioPreset:
"""User-facing preset for quick scenario configuration."""
preset_id: str
name: str
description: str
underlying_symbol: str
start_date: date
end_date: date
entry_spot: float | None = None # If None, derive from historical data
underlying_units: float = 1000.0
loan_amount: float = 50000.0
margin_call_ltv: float = 0.80
template_slug: str = "protective-put-atm-12m"
# Event-specific overrides
scenario_overrides: dict[str, object] | None = None