monte_carlo_wealth
- PortfolioDCF.monte_carlo_wealth(discounting='fv', include_negative_values=True)
Calculate portfolio random wealth indexes with cash flows (withdrawals/contributions) using Monte Carlo simulation.
Monte Carlo simulation generates n random monthly time series. Each wealth index is calculated with rate of return time series of a given distribution.
First date of forecasted returns is portfolio last_date. First value for the forecasted wealth indexes is the last historical portfolio index value. It is useful for a chart with historical wealth index and forecasted values.
- Parameters:
- discounting{‘fv’, ‘pv’}, default ‘fv’
‘fv’ - calculate Future Value (not discounted) wealth indexes. ‘pv’ - calculate Present Value (discounted) wealth indexes.
- include_negative_valuesbool, default True
If True, negative values in the wealth index are preserved. If False, negative values are replaced with 0.
- Returns:
- DataFrame
Table with n random wealth indexes monthly time series.
Examples
>>> import matplotlib.pyplot as plt
>>> pf = ok.Portfolio( ... ["SPY.US", "AGG.US", "GLD.US"], ... weights=[0.60, 0.35, 0.05], ... rebalancing_strategy=ok.Rebalance(period="month"), ... ) >>> pf.dcf.set_mc_parameters(distribution="t", period=10, mc_number=100) # Set Monte Carlo parameters >>> # set cash flow parameters >>> ind = ok.IndexationStrategy(pf) # create cash flow strategy linked to the portfolio >>> ind.initial_investment = 10_000 # add initial investment to cash flow strategy >>> ind.amount = -500 # set withdrawal size >>> ind.frequency = "year" # set withdrawal frequency >>> pf.dcf.cashflow_parameters = ind # assign cash flow strategy to portfolio >>> pf.dcf.monte_carlo_wealth(discounting="fv").plot() >>> plt.legend("") # don't show legend for each line >>> plt.show()