fix: correct hedge equity math at downside scenarios
This commit is contained in:
@@ -114,7 +114,11 @@ def strategy_metrics(strategy_name: str, scenario_pct: int) -> dict[str, Any]:
|
||||
(item for item in strategy_catalog() if item["name"] == strategy_name),
|
||||
strategy_catalog()[0],
|
||||
)
|
||||
spot = demo_spot_price()
|
||||
portfolio = portfolio_snapshot()
|
||||
spot = float(portfolio["spot_price"])
|
||||
underlying_units = portfolio["gold_value"] / spot
|
||||
loan_amount = float(portfolio["loan_amount"])
|
||||
base_equity = float(portfolio["net_equity"])
|
||||
floor = float(strategy.get("max_drawdown_floor", spot * 0.95))
|
||||
cap = strategy.get("upside_cap")
|
||||
cost = float(strategy["estimated_cost"])
|
||||
@@ -128,19 +132,23 @@ def strategy_metrics(strategy_name: str, scenario_pct: int) -> dict[str, Any]:
|
||||
benefits.append(round(payoff - cost, 2))
|
||||
|
||||
scenario_price = round(spot * (1 + scenario_pct / 100), 2)
|
||||
unhedged_equity = scenario_price * 1_000 - 145_000.0
|
||||
scenario_payoff = max(floor - scenario_price, 0.0)
|
||||
capped_upside = 0.0
|
||||
unhedged_equity = scenario_price * underlying_units - loan_amount
|
||||
scenario_payoff_per_unit = max(floor - scenario_price, 0.0)
|
||||
capped_upside_per_unit = 0.0
|
||||
if isinstance(cap, (int, float)) and scenario_price > float(cap):
|
||||
capped_upside = -(scenario_price - float(cap))
|
||||
hedged_equity = unhedged_equity + scenario_payoff + capped_upside - cost * 1_000
|
||||
capped_upside_per_unit = -(scenario_price - float(cap))
|
||||
|
||||
option_payoff_cash = scenario_payoff_per_unit * underlying_units
|
||||
capped_upside_cash = capped_upside_per_unit * underlying_units
|
||||
hedge_cost_cash = cost * underlying_units
|
||||
hedged_equity = unhedged_equity + option_payoff_cash + capped_upside_cash - hedge_cost_cash
|
||||
|
||||
waterfall_steps = [
|
||||
("Base equity", round(70_000.0, 2)),
|
||||
("Spot move", round((scenario_price - spot) * 1_000, 2)),
|
||||
("Option payoff", round(scenario_payoff * 1_000, 2)),
|
||||
("Call cap", round(capped_upside * 1_000, 2)),
|
||||
("Hedge cost", round(-cost * 1_000, 2)),
|
||||
("Base equity", round(base_equity, 2)),
|
||||
("Spot move", round((scenario_price - spot) * underlying_units, 2)),
|
||||
("Option payoff", round(option_payoff_cash, 2)),
|
||||
("Call cap", round(capped_upside_cash, 2)),
|
||||
("Hedge cost", round(-hedge_cost_cash, 2)),
|
||||
("Net equity", round(hedged_equity, 2)),
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user