Skip to content

Commit

Permalink
feat: add dividends_annual property in Portfolio like dividends_annua…
Browse files Browse the repository at this point in the history
…l property in AssetList.
  • Loading branch information
vkhomyakov committed Dec 19, 2023
1 parent 3e33670 commit 5a93f15
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
12 changes: 9 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
19 changes: 19 additions & 0 deletions okama/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down

0 comments on commit 5a93f15

Please sign in to comment.