@@ -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