Skip to content

Commit

Permalink
fix: replace possible nan and inf in AssetList.get_dividend_mean_grow…
Browse files Browse the repository at this point in the history
…th_rate
  • Loading branch information
chilango74 committed Sep 25, 2021
1 parent 55e0a6c commit babbc12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 10 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import numpy as np
import okama as ok

asset_list = ok.AssetList(assets=['RUB.FX', 'MCFTR.INDX'], ccy='RUB', first_date='2019-01', last_date='2020-01', inflation=True)
print(asset_list.get_cumulative_return(period='ytd', real=True))
asset_list = ok.AssetList(assets=['MSFT.US'], ccy='USD')

print(asset_list.dividends_annual)


x = asset_list.get_dividend_mean_growth_rate(period=20)
# x.replace([np.inf, -np.inf], 0, inplace=True)

print(f'Growth rate:', x)
5 changes: 4 additions & 1 deletion okama/asset_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,9 @@ def dividend_paying_years(self) -> pd.DataFrame:

def get_dividend_mean_growth_rate(self, period=5) -> pd.Series:
"""
Calculate geometric mean of dividends growth rate time series for a given trailing period.
Calculate geometric mean of annual dividends growth rate time series for a given trailing period.
Growth rate is taken for full calendar annual dividends.
Parameters
----------
Expand All @@ -926,6 +928,7 @@ def get_dividend_mean_growth_rate(self, period=5) -> pd.Series:
growth_ts = self.dividends_annual.pct_change().iloc[
1:-1
] # Slice the last year for full dividends
growth_ts.replace([np.inf, -np.inf, np.nan], 0, inplace=True) # replace possible nan and inf
dt0 = self.last_date
dt = Date.subtract_years(dt0, period)
return ((growth_ts[dt:] + 1.0).prod()) ** (1 / period) - 1.0
Expand Down

0 comments on commit babbc12

Please sign in to comment.