Spaces:
Runtime error
Runtime error
| from __future__ import annotations | |
| from dataclasses import asdict, dataclass | |
| from typing import Any | |
| class OptionLeg: | |
| action: str | |
| option_type: str | |
| strike: float | |
| expiration: str | |
| quantity: int | |
| premium: float | |
| implied_volatility: float | None = None | |
| delta: float | None = None | |
| liquidity_warnings: list[str] | None = None | |
| def signed_quantity(self) -> int: | |
| return self.quantity if self.action == "buy" else -self.quantity | |
| def cash_flow(self) -> float: | |
| return -self.premium * self.signed_quantity() * 100 | |
| def to_dict(self) -> dict[str, Any]: | |
| return asdict(self) | |
| class OptionStrategy: | |
| name: str | |
| volatility_view: str | |
| directional_view: str | |
| legs: list[OptionLeg] | |
| rationale: str | |
| risks: list[str] | |
| max_profit: float | str | None | |
| max_loss: float | str | None | |
| breakevens: list[float] | |
| net_debit_or_credit: float | |
| score: float | |
| def to_dict(self) -> dict[str, Any]: | |
| payload = asdict(self) | |
| payload["legs"] = [leg.to_dict() for leg in self.legs] | |
| return payload | |