reduced the use of self.dates
This commit is contained in:
parent
56af7c33aa
commit
b9366541f3
@ -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):
|
||||
|
@ -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__":
|
||||
|
Loading…
Reference in New Issue
Block a user