Skip to content

Commit c1df18d

Browse files
committed
fix: use self.use_discounted_values = False in plot_forecast_monte_carlo for any value of backtest parameter
1 parent 60d3d75 commit c1df18d

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

okama/common/helpers/helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def get_wealth_indexes_with_cashflow(
203203
204204
Values of the wealth index correspond to the beginning of the month.
205205
"""
206+
# TODO: add use_discounted_values parameters to setup initial conditions without modifying cashflow_parameters
206207
pf_object = cashflow_parameters.parent
207208
dcf_object = cashflow_parameters.parent.dcf
208209
amount = getattr(cashflow_parameters, "amount", None)

okama/portfolio.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,12 +2876,12 @@ def plot_forecast_monte_carlo(
28762876
>>> plt.yscale("log") # Y-axis has logarithmic scale
28772877
>>> plt.show()
28782878
"""
2879+
backup_obj = self.cashflow_parameters
2880+
backup = self.use_discounted_values
2881+
self.use_discounted_values = False # we need to start with not discounted values
28792882
if backtest:
28802883
if self.cashflow_parameters is None:
28812884
raise AttributeError("'cashflow_parameters' is not defined.")
2882-
backup_obj = self.cashflow_parameters
2883-
backup = self.use_discounted_values
2884-
self.use_discounted_values = False
28852885
s1 = self.wealth_index[self.parent.symbol]
28862886
s1.plot(legend=None, figsize=figsize)
28872887
last_backtest_value = s1.iloc[-1]
@@ -2895,12 +2895,12 @@ def plot_forecast_monte_carlo(
28952895
s2 = self.monte_carlo_wealth
28962896
for s in s2:
28972897
s2[s].plot(legend=None)
2898-
self.cashflow_parameters = backup_obj
2899-
self.cashflow_parameters._clear_cf_cache()
2900-
self.use_discounted_values = backup
29012898
else:
29022899
s2 = self.monte_carlo_wealth
29032900
s2.plot(legend=None)
2901+
self.cashflow_parameters = backup_obj
2902+
self.cashflow_parameters._clear_cf_cache()
2903+
self.use_discounted_values = backup
29042904

29052905
def monte_carlo_survival_period(self, threshold: float = 0) -> pd.Series:
29062906
"""
@@ -3219,6 +3219,8 @@ def initial_investment(self):
32193219
"""
32203220
Portfolio initial investment FV size (at last_date).
32213221
3222+
Initial investment must be positive.
3223+
32223224
Returns
32233225
-------
32243226
float
@@ -3230,6 +3232,8 @@ def initial_investment(self):
32303232
def initial_investment(self, initial_investment):
32313233
if initial_investment is not None:
32323234
validators.validate_real("initial_investment", initial_investment)
3235+
if initial_investment <= 0:
3236+
raise ValueError("Initial investment must be positive.")
32333237
self._clear_cf_cache()
32343238
self._initial_investment = initial_investment
32353239

0 commit comments

Comments
 (0)