Skip to content

Commit

Permalink
feat: add __repr__ to PortfolioDCF
Browse files Browse the repository at this point in the history
  • Loading branch information
chilango74 committed Oct 4, 2024
1 parent af49ced commit 3fa9648
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 2 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
pf.dcf.discount_rate = 0.10
pf.dcf.use_discounted_values = False

print(pf.dcf)

# df = pf.dcf.wealth_index

# Set Monte Carlo
Expand Down
21 changes: 12 additions & 9 deletions okama/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2373,8 +2373,14 @@ def __init__(

def __repr__(self):
pf_repr = repr(self.parent)
# TODO: add MC, CashFlow, discount_rate, use_discounted_values
return pf_repr
dic = {
"Portfolio symbol": self.parent.symbol,
"Monte carlo distribution": self.mc.distribution,
"Monte carlo period": self.mc.period,
"Cash flow strategy": self.cashflow_parameters.NAME if hasattr(self.cashflow_parameters, "NAME") else None,
"use_discounted_values": self.use_discounted_values,
}
return repr(pd.Series(dic))

@property
def discount_rate(self) -> float:
Expand Down Expand Up @@ -2696,8 +2702,8 @@ def monte_carlo_wealth(self) -> pd.DataFrame:
2021-11 4179.544897 4156.839698 ... 3899.249696 4097.003962
2021-12 4237.030690 4351.305114 ... 3916.639721 4042.011774
"""
if not hasattr(self, "cash_flow_parameters"):
raise AttributeError("'cash_flow_parameters' are not defined.")
if self.cashflow_parameters == None:
raise AttributeError("'cash_flow_parameters' is not defined.")
if self._monte_carlo_wealth.empty:
return_ts = self.parent.monte_carlo_returns_ts(distr=self.mc.distribution,
years=self.mc.period,
Expand Down Expand Up @@ -2802,8 +2808,8 @@ def plot_forecast_monte_carlo(
>>> plt.show()
"""
if backtest:
if not hasattr(self, "cash_flow_parameters"):
raise AttributeError("'cash_flow_parameters' are not defined.")
if self.cash_flow_parameters == None:
raise AttributeError("'cash_flow_parameters' is not defined.")
backup_obj = self.cashflow_parameters
backup = self.use_discounted_values
self.use_discounted_values = False
Expand Down Expand Up @@ -3265,7 +3271,6 @@ def percentage(self) -> float:
The percentage of withdrawals or contributions.
The size of withdrawals or contribution is defined as a percentage of portfolio balance.
The value of percentage is form 0 to 1 (0 is 0%, 1 is 100%).
Returns
-------
Expand All @@ -3278,8 +3283,6 @@ def percentage(self) -> float:
def percentage(self, percentage):
self._clear_cf_cache()
validators.validate_real("percentage", percentage)
if percentage < 0 or percentage > 1:
raise ValueError("percentage must be between 0 and 1")
self._percentage = percentage


Expand Down

0 comments on commit 3fa9648

Please sign in to comment.