diff --git a/fincal/core.py b/fincal/core.py index 0064814..f762c7f 100644 --- a/fincal/core.py +++ b/fincal/core.py @@ -124,11 +124,11 @@ class TimeSeriesCore: data = _preprocess_timeseries(data, date_format=date_format) self.time_series = dict(data) - self.dates = set(list(self.time_series)) - if len(self.dates) != len(data): + self.dates = list(self.time_series) + if len(self.time_series) != len(data): print("Warning: The input data contains duplicate dates which have been ignored.") - self.start_date = list(self.time_series)[0] - self.end_date = list(self.time_series)[-1] + self.start_date = self.dates[0] + self.end_date = self.dates[-1] self.frequency = getattr(AllFrequencies, frequency) def __repr__(self): diff --git a/fincal/fincal.py b/fincal/fincal.py index b11b0cf..f313b0e 100644 --- a/fincal/fincal.py +++ b/fincal/fincal.py @@ -177,10 +177,14 @@ class TimeSeries(TimeSeriesCore): ) -> List[tuple]: """Calculates the rolling return""" - all_dates = create_date_series(from_date, to_date, getattr(AllFrequencies, frequency)) - dates = set(all_dates) + try: + frequency = getattr(AllFrequencies, frequency) + except AttributeError: + raise ValueError(f"Invalid argument for frequency {frequency}") + + dates = create_date_series(from_date, to_date, frequency) if frequency == AllFrequencies.D: - dates = all_dates.intersection(self.dates) + dates = [i for i in dates if i in self.time_series] rolling_returns = [] for i in dates: @@ -193,8 +197,8 @@ class TimeSeries(TimeSeriesCore): closest=closest, ) rolling_returns.append((i, returns)) - self.rolling_returns = rolling_returns - return self.rolling_returns + rolling_returns.sort() + return rolling_returns if __name__ == "__main__":