Spaces:
Runtime error
Runtime error
File size: 1,766 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | from __future__ import annotations
from dataclasses import asdict, dataclass
from typing import Any
@dataclass
class UnderlyingQuote:
symbol: str
current_price: float | None
open: float | None
high: float | None
low: float | None
volume: int | None
timestamp: str
data_type: str
short_name: str = ""
def to_dict(self) -> dict[str, Any]:
return asdict(self)
@dataclass
class OptionContract:
contract_symbol: str
option_type: str
expiration: str
strike: float
bid: float | None
ask: float | None
mid: float | None
last_price: float | None
volume: int | None
open_interest: int | None
implied_volatility: float | None
in_the_money: bool
days_to_expiration: int
liquidity_warnings: list[str]
def to_dict(self) -> dict[str, Any]:
return asdict(self)
@dataclass
class OptionChain:
symbol: str
expiration: str
underlying_price: float | None
calls: list[OptionContract]
puts: list[OptionContract]
def to_dict(self) -> dict[str, Any]:
return {
"symbol": self.symbol,
"expiration": self.expiration,
"underlying_price": self.underlying_price,
"calls": [contract.to_dict() for contract in self.calls],
"puts": [contract.to_dict() for contract in self.puts],
}
@dataclass
class VolSnapshot:
symbol: str
current_price: float | None
realized_volatility: dict[str, float | None]
atm_iv_by_expiration: dict[str, float | None]
iv_rv_spread_by_expiration: dict[str, float | None]
term_structure_slope: float | None
skew_by_expiration: dict[str, float | None]
def to_dict(self) -> dict[str, Any]:
return asdict(self)
|