Skip to content

Commit

Permalink
fix: cashflow amount must be indexed in plot_forecast_monte_carlo
Browse files Browse the repository at this point in the history
  • Loading branch information
chilango74 committed Sep 24, 2024
1 parent 733dca3 commit e10347d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@
# print(w)


df = pf.dcf.wealth_with_assets
df.plot()
# df = pf.dcf.wealth_with_assets
# df.plot()
# print("portfolio balance \n", df.iloc[-1, :].describe())

# pf.dcf.plot_forecast_monte_carlo(backtest=True)
pf.dcf.plot_forecast_monte_carlo(backtest=True)



Expand Down
2 changes: 1 addition & 1 deletion okama/common/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ def subtract_years(dt: pd.Timestamp, years: int) -> pd.Timestamp:
)

@staticmethod
def get_difference_in_months(last_day: pd.Timestamp, first_day: pd.Timestamp):
def get_difference_in_months(last_day: pd.Timestamp, first_day: pd.Timestamp) -> pd.DateOffset:
return last_day.to_period("M") - first_day.to_period("M")

@staticmethod
Expand Down
5 changes: 5 additions & 0 deletions okama/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2760,6 +2760,11 @@ def plot_forecast_monte_carlo(
last_backtest_value = s1.iloc[-1]
if last_backtest_value > 0:
self.cashflow_parameters.initial_investment = last_backtest_value
if self.cashflow_parameters.name == "fixed_amount":
months = helpers.Date.get_difference_in_months(self.parent.last_date, self.parent.first_date).n
years = months / settings._MONTHS_PER_YEAR
periods = years / settings.frequency_periods_per_year[self.cashflow_parameters.frequency]
self.cashflow_parameters.amount *= (1.0 + self.cashflow_parameters.indexation) ** periods
s2 = self.monte_carlo_wealth
for s in s2:
s2[s].plot(legend=None)
Expand Down

0 comments on commit e10347d

Please sign in to comment.