diff --git a/openseries/frame.py b/openseries/frame.py index f0e560f9..612b5627 100644 --- a/openseries/frame.py +++ b/openseries/frame.py @@ -340,7 +340,7 @@ def value_to_ret(self: Self) -> Self: returns.iloc[0] = 0 new_labels = [ValueType.RTRN] * self.item_count arrays = [self.tsdf.columns.get_level_values(0), new_labels] - returns.columns = MultiIndex.from_arrays(arrays) + returns.columns = MultiIndex.from_arrays(arrays=arrays) self.tsdf = returns.copy() return self diff --git a/openseries/series.py b/openseries/series.py index 60f2948c..f8e86ef9 100644 --- a/openseries/series.py +++ b/openseries/series.py @@ -346,6 +346,7 @@ def from_fixed_rate( - cast(DatetimeIndex, d_range)[:-1] ], ) + # noinspection PyTypeChecker arr = list(cumprod(insert(1 + deltas * rate / 365, 0, 1.0))) dates = [d.strftime("%Y-%m-%d") for d in cast(DatetimeIndex, d_range)] @@ -434,15 +435,12 @@ def value_to_ret(self: Self) -> Self: The returns of the values in the series """ - self.tsdf = self.tsdf.pct_change() - self.tsdf.iloc[0] = 0 + returns = self.tsdf.ffill().pct_change() + returns.iloc[0] = 0 self.valuetype = ValueType.RTRN - self.tsdf.columns = MultiIndex.from_arrays( - [ - [self.label], - [self.valuetype], - ], - ) + arrays = [[self.label], [self.valuetype]] + returns.columns = MultiIndex.from_arrays(arrays=arrays) + self.tsdf = returns.copy() return self def value_to_diff(self: Self, periods: int = 1) -> Self: @@ -520,6 +518,7 @@ def from_1d_rate_to_cumret( arr = array(self.values) / divider deltas = array([i.days for i in self.tsdf.index[1:] - self.tsdf.index[:-1]]) + # noinspection PyTypeChecker arr = cumprod(insert(1.0 + deltas * arr[:-1] / days_in_year, 0, 1.0)) self.dates = [d.strftime("%Y-%m-%d") for d in self.tsdf.index] @@ -818,6 +817,7 @@ def timeseries_chain( dates.extend([x.strftime("%Y-%m-%d") for x in new.tsdf.index]) + # noinspection PyUnresolvedReferences if back.__class__.__subclasscheck__( OpenTimeSeries, ):