Skip to content

Commit

Permalink
chore: set use_discounted_values to False in plot_forecast_monte_carlo
Browse files Browse the repository at this point in the history
  • Loading branch information
chilango74 committed Sep 19, 2024
1 parent 4a8aa50 commit 9540e95
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 42 deletions.
48 changes: 18 additions & 30 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
assets=["MCFTR.INDX", "RUCBTRNS.INDX"],
weights=[.3, .7],
inflation=True,
first_date="2014-01",
# first_date="2014-01",
ccy="RUB",
rebalancing_period="year",
)
Expand All @@ -32,45 +32,27 @@

# TimeSeries strategy
d = {
"2015-02": 1_000,
"2019-03": -2_000,
"2025-02": 1_000,
"2029-03": -2_000,
}

ts = ok.TimeSeriesStrategy(pf)
ts.initial_investment = 1_000
ts.time_series_dic = d

# Assign a strategy
pf.dcf.cashflow_parameters = ts
pf.dcf.cashflow_parameters = ind
pf.dcf.discount_rate = 0.10
pf.dcf.use_discounted_values = True

df = pf.dcf.wealth_index

plt.figure(figsize=(20, 12))
df.plot()
# plt.savefig('time_series.png')
plt.show()


# Set cashflow
# pf.dcf.set_cashflow_parameters(
# initial_investment=1000, # 10_300_000
# method="fixed_percentage",
# frequency="month",
# percentage=-0.15 / 12,
# # amount=-80_000,
# # indexation=pf.dcf.discount_rate
# )


# df = pf.dcf.wealth_index

# Set Monte Carlo
# pf.dcf.set_mc_parameters(
# distribution="t",
# period=50,
# number=500
# )
pf.dcf.set_mc_parameters(
distribution="t",
period=50,
number=100
)

# w = pf.dcf.find_the_largest_withdrawals_size(
# min_amount=-100_000,
Expand All @@ -86,8 +68,8 @@
# df = pf.dcf.monte_carlo_wealth
# print("portfolio balance \n", df.iloc[-1, :].describe())

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



# s = pf.dcf.monte_carlo_survival_period(threshold=.05)
Expand All @@ -99,3 +81,9 @@
# print(pf.dcf.mc_number)
# s = pf.dcf.monte_carlo_wealth
# print(s.iloc[-1].quantile(50/100))

# plt.figure(figsize=(20, 12))
plt.yscale("log") # log or linear
# df.plot()
# plt.savefig('time_series.png')
plt.show()
18 changes: 6 additions & 12 deletions okama/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2650,21 +2650,9 @@ def plot_forecast_monte_carlo(
Parameters
----------
distr : {'norm', 'lognorm', 't'}, default 'norm'
The type of a distribution to generate random portfolios.
'norm' - for normal distribution.
'lognorm' - for lognormal distribution.
't' - for Student's T distribution.
years : int, default 1
Investment period length for new wealth indexes
backtest : bool, default 'True'
Include historical wealth index if 'True'.
n : int, default 20
Number of random wealth indexes to generate with Monte Carlo simulation.
figsize : (float, float), optional
Width, height in inches.
If None default matplotlib figsize value is used.
Expand All @@ -2685,6 +2673,9 @@ def plot_forecast_monte_carlo(
>>> plt.show()
"""
if backtest:
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 @@ -2693,6 +2684,9 @@ 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)
Expand Down

0 comments on commit 9540e95

Please sign in to comment.