Source code for kaxanuk.attribution_analysis.entities.market_data_daily_row
import dataclasses
import datetime
import decimal
from kaxanuk.attribution_analysis.exceptions import (
EntityTypeError,
EntityValueError
)
from kaxanuk.attribution_analysis.services import entity_helper
[docs]
@dataclasses.dataclass(frozen=True, slots=True)
class MarketDataDailyRow:
date: datetime.date
open: decimal.Decimal
high: decimal.Decimal
low: decimal.Decimal
close: decimal.Decimal
adjusted_close: decimal.Decimal | None
volume: int
vwap: decimal.Decimal | None
def __post_init__(self):
field_type_errors = entity_helper.detect_field_type_errors(self)
if len(field_type_errors):
msg = " ".join([
f"Field type errors found in {self.__class__.__name__} for date {self.date!s}:",
"\n\t".join(field_type_errors)
])
raise EntityTypeError(msg)
for field_name in (
'open',
'high',
'low',
'close',
'adjusted_close',
'volume',
'vwap'
):
field_value = getattr(self, field_name)
if (
field_value is not None
and field_value < decimal.Decimal(0)
):
msg = f"Negative MarketDataDailyRow.{field_name} for date {self.date!s}"
raise EntityValueError(msg)
if self.low > self.high:
msg = f"MarketDataDailyRow low > high for date {self.date!s}"
raise EntityValueError(msg)