Skip to content

Commit

Permalink
fix: use self.use_discounted_values = False in plot_forecast_monte_ca…
Browse files Browse the repository at this point in the history
…rlo for any value of backtest parameter
  • Loading branch information
chilango74 committed Oct 10, 2024
1 parent 60d3d75 commit c1df18d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions okama/common/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def get_wealth_indexes_with_cashflow(
Values of the wealth index correspond to the beginning of the month.
"""
# TODO: add use_discounted_values parameters to setup initial conditions without modifying cashflow_parameters
pf_object = cashflow_parameters.parent
dcf_object = cashflow_parameters.parent.dcf
amount = getattr(cashflow_parameters, "amount", None)
Expand Down
16 changes: 10 additions & 6 deletions okama/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2876,12 +2876,12 @@ def plot_forecast_monte_carlo(
>>> plt.yscale("log") # Y-axis has logarithmic scale
>>> plt.show()
"""
backup_obj = self.cashflow_parameters
backup = self.use_discounted_values
self.use_discounted_values = False # we need to start with not discounted values
if backtest:
if self.cashflow_parameters is None:
raise AttributeError("'cashflow_parameters' is not defined.")
backup_obj = self.cashflow_parameters
backup = self.use_discounted_values
self.use_discounted_values = False
s1 = self.wealth_index[self.parent.symbol]
s1.plot(legend=None, figsize=figsize)
last_backtest_value = s1.iloc[-1]
Expand All @@ -2895,12 +2895,12 @@ def plot_forecast_monte_carlo(
s2 = self.monte_carlo_wealth
for s in s2:
s2[s].plot(legend=None)
self.cashflow_parameters = backup_obj
self.cashflow_parameters._clear_cf_cache()
self.use_discounted_values = backup
else:
s2 = self.monte_carlo_wealth
s2.plot(legend=None)
self.cashflow_parameters = backup_obj
self.cashflow_parameters._clear_cf_cache()
self.use_discounted_values = backup

def monte_carlo_survival_period(self, threshold: float = 0) -> pd.Series:
"""
Expand Down Expand Up @@ -3219,6 +3219,8 @@ def initial_investment(self):
"""
Portfolio initial investment FV size (at last_date).
Initial investment must be positive.
Returns
-------
float
Expand All @@ -3230,6 +3232,8 @@ def initial_investment(self):
def initial_investment(self, initial_investment):
if initial_investment is not None:
validators.validate_real("initial_investment", initial_investment)
if initial_investment <= 0:
raise ValueError("Initial investment must be positive.")
self._clear_cf_cache()
self._initial_investment = initial_investment

Expand Down

0 comments on commit c1df18d

Please sign in to comment.