|
1 | 1 | import warnings |
2 | 2 |
|
3 | 3 | import pandas as pd |
| 4 | +from matplotlib import pyplot as plt |
| 5 | + |
4 | 6 | import okama as ok |
5 | 7 |
|
6 | 8 | import os |
|
21 | 23 | symbol="My_portfolio.PF", |
22 | 24 | ) |
23 | 25 |
|
24 | | -pc = ok.PercentageStrategy(pf) # create PercentageStrategy linked to the portfolio |
| 26 | +pf.dcf.use_discounted_values = True |
| 27 | +# # Percentage CF strategy |
| 28 | +# cf_strategy = ok.PercentageStrategy(pf) # create PercentageStrategy linked to the portfolio |
| 29 | +# |
| 30 | +# cf_strategy.initial_investment = 1_000 # initial investments size |
| 31 | +# cf_strategy.frequency = "year" # withdrawals frequency |
| 32 | +# cf_strategy.percentage = -0.12 |
| 33 | + |
| 34 | +# Indexation CF strategy |
| 35 | +cf_strategy = ok.IndexationStrategy(pf) |
| 36 | +cf_strategy.initial_investment = 10_000_000 |
| 37 | +cf_strategy.amount = -12_000 * 12 |
| 38 | +cf_strategy.frequency = "year" |
| 39 | + |
| 40 | +d = { |
| 41 | + "2026-02": 10_000_000, |
| 42 | + "2029-03": -20_000_000, |
| 43 | +} |
25 | 44 |
|
26 | | -pc.initial_investment = 10_000 # initial investments size |
27 | | -pc.frequency = "year" # withdrawals frequency |
28 | | -pc.percentage = -0.12 |
| 45 | +cf_strategy.time_series_dic = d |
29 | 46 |
|
30 | | -pf.dcf.cashflow_parameters = pc # assign the cash flow strategy to portfolio |
| 47 | +pf.dcf.cashflow_parameters = cf_strategy # assign the cash flow strategy to portfolio |
31 | 48 |
|
32 | 49 | pf.dcf.set_mc_parameters(distribution="norm", period=30, number=400) # simulation period in years |
33 | 50 |
|
34 | | -result = pf.dcf.find_the_largest_withdrawals_size( |
35 | | - goal="maintain_balance_pv", # The goal of the strategy in this case is to keep the portfolio's real balance (for the whole period) |
36 | | - percentile=25, # The percentile of Monte Carlo result distribution where the goal is to be achieved. The 25th percentile is a negative scenario. |
37 | | - threshold=0.10, # 10% - is the percentage of initial investments when the portfolio balance is considered voided. |
38 | | - iter_max=50, # The maximum number of iterations to find the solution. |
39 | | - tolerance_rel=0.15, # The allowed tolerance for the solution. The tolerance is the largest error for the achieved goal. |
40 | | -) |
| 51 | +df = pf.dcf.monte_carlo_wealth_fv |
| 52 | + |
| 53 | +df.plot(legend=False) |
| 54 | +plt.yscale('log') |
| 55 | +plt.show() |
| 56 | + |
| 57 | +sp = pf.dcf.monte_carlo_survival_period() |
| 58 | +print(sp.quantile(25 / 100), " years") |
| 59 | + |
| 60 | +wealth_pv = pf.dcf.monte_carlo_wealth_pv.iloc[-1].describe() |
| 61 | +wealth_fv = pf.dcf.monte_carlo_wealth_fv.iloc[-1].describe() |
| 62 | + |
| 63 | +print(f"{wealth_pv=}", f"{wealth_fv=}") |
| 64 | + |
41 | 65 |
|
42 | | -print(result.withdrawal_rel) |
|
0 commit comments