From 5a93f150c5d801ff911c7fe1b98f2a3da04d671d Mon Sep 17 00:00:00 2001 From: Vladimir Khomyakov Date: Tue, 19 Dec 2023 16:55:05 +0300 Subject: [PATCH] feat: add dividends_annual property in Portfolio like dividends_annual property in AssetList. --- main.py | 12 +++++++++--- okama/portfolio.py | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 76ec158..81f7c34 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,12 @@ # ef.plot_cml(rf_return=0.15, y_axe="cagr") # plt.show() -pf = ok.Portfolio(["SPY.US", "BND.US"], weights=[.5, .5], rebalancing_period="monthly") -pf.wealth_index_with_assets.plot() -plt.show() +#pf = ok.Portfolio(["SPY.US", "BND.US"], weights=[.5, .5], rebalancing_period="monthly") +#pf.wealth_index_with_assets.plot() +#plt.show() + + +import matplotlib.pyplot as plt +pf = ok.Portfolio(['SPY.US', 'BND.US'], ccy='USD', last_date='07-2021', rebalancing_period="monthly") +pf.dividends_annual.plot(kind='bar') +plt.show() \ No newline at end of file diff --git a/okama/portfolio.py b/okama/portfolio.py index 04baf31..3be7725 100644 --- a/okama/portfolio.py +++ b/okama/portfolio.py @@ -822,6 +822,25 @@ def dividend_yield(self) -> pd.Series: div_yield_series.rename(self.symbol, inplace=True) return div_yield_series + @property + def dividends_annual(self) -> pd.DataFrame: + """ + Return calendar year dividends sum time series for each asset. + + Returns + ------- + DataFrame + Annual dividends time series for each asset. + + Examples + -------- + >>> import matplotlib.pyplot as plt + >>> pf = ok.Portfolio(['SPY.US', 'BND.US'], ccy='USD', last_date='07-2021') + >>> pf.dividends_annual.plot(kind='bar') + >>> plt.show() + """ + return self._get_assets_dividends().resample("Y").sum() + @property def real_mean_return(self) -> float: """