Skip to content

Commit

Permalink
added pandas .ffill() as precursor to pct_change() in .value_to_ret()…
Browse files Browse the repository at this point in the history
… method.
  • Loading branch information
karrmagadgeteer2 committed Sep 26, 2024
1 parent 661adc1 commit 89c3d0a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions openseries/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,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
new_labels = [ValueType.RTRN] * self.item_count
arrays = [self.tsdf.columns.get_level_values(0), new_labels]
self.tsdf.columns = MultiIndex.from_arrays(arrays)
returns.columns = MultiIndex.from_arrays(arrays)
self.tsdf = returns.copy()
return self

def value_to_diff(self: Self, periods: int = 1) -> Self:
Expand Down

0 comments on commit 89c3d0a

Please sign in to comment.