Skip to content

Commit babbc12

Browse files
committed
fix: replace possible nan and inf in AssetList.get_dividend_mean_growth_rate
1 parent 55e0a6c commit babbc12

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

main.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
import numpy as np
12
import okama as ok
23

3-
asset_list = ok.AssetList(assets=['RUB.FX', 'MCFTR.INDX'], ccy='RUB', first_date='2019-01', last_date='2020-01', inflation=True)
4-
print(asset_list.get_cumulative_return(period='ytd', real=True))
4+
asset_list = ok.AssetList(assets=['MSFT.US'], ccy='USD')
5+
6+
print(asset_list.dividends_annual)
7+
8+
9+
x = asset_list.get_dividend_mean_growth_rate(period=20)
10+
# x.replace([np.inf, -np.inf], 0, inplace=True)
11+
12+
print(f'Growth rate:', x)

okama/asset_list.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,9 @@ def dividend_paying_years(self) -> pd.DataFrame:
901901

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

0 commit comments

Comments
 (0)