From 3b96d231f431622210126916ad47cbfbadf457ae Mon Sep 17 00:00:00 2001 From: gouravkr Date: Fri, 25 Mar 2022 08:43:28 +0530 Subject: [PATCH] fincal.expand now works by using .get and closest=previous --- fincal/fincal.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fincal/fincal.py b/fincal/fincal.py index b6d1387..f57dbc6 100644 --- a/fincal/fincal.py +++ b/fincal/fincal.py @@ -552,7 +552,10 @@ class TimeSeries(TimeSeriesCore): return max_drawdown def expand( - self, to_frequency: Literal["D", "W", "M", "Q", "H"], method: Literal["ffill", "bfill", "interpolate"] + self, + to_frequency: Literal["D", "W", "M", "Q", "H"], + method: Literal["ffill", "bfill", "interpolate"], + skip_weekends: bool = False, ) -> TimeSeries: try: to_frequency: Frequency = getattr(AllFrequencies, to_frequency) @@ -562,8 +565,10 @@ class TimeSeries(TimeSeriesCore): if to_frequency.days >= self.frequency.days: raise ValueError("TimeSeries can be only expanded to a higher frequency") - new_dates = create_date_series(self.start_date, self.end_date, frequency=to_frequency.symbol) - new_ts: dict = {dt: self.data.get(dt, None) for dt in new_dates} + new_dates = create_date_series( + self.start_date, self.end_date, frequency=to_frequency.symbol, skip_weekends=skip_weekends + ) + new_ts: dict = {dt: self.get(dt, closest="previous")[1] for dt in new_dates} output_ts: TimeSeries = TimeSeries(new_ts, frequency=to_frequency.symbol) if method == "ffill":