File size: 1,112 Bytes
8f1601b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from __future__ import annotations

from dataclasses import asdict, dataclass
from typing import Any


@dataclass
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)


@dataclass
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