From c1a91138273eb565f32ae81c7acde01e81dd2b3f Mon Sep 17 00:00:00 2001 From: shrektan Date: Sun, 29 Jan 2023 18:22:06 +0800 Subject: [PATCH] ensure PriceTS is an timeseries --- delta_hedge.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/delta_hedge.py b/delta_hedge.py index f5adb79..f6d7f38 100644 --- a/delta_hedge.py +++ b/delta_hedge.py @@ -77,6 +77,15 @@ class PriceTS(): points: np.ndarray prices: np.ndarray + def __post_init__(self) -> None: + if np.ndim(self.points) != 1 or np.ndim(self.prices) != 1: + raise ValueError("the dim of points and prices must be 1") + if np.shape(self.points) != np.shape(self.prices): + raise ValueError("points and prices must have the same length") + + def __len__(self) -> int: + return len(self.points) + def price_ts(p0: float, er: float, evol: float, days: int, times_per_day: int) -> PriceTS: