Skip to content

Commit 8d66260

Browse files
committed
feat: add cashflow Time Series to IndexationStrategy & PercentageStrategy
1 parent f6549fc commit 8d66260

File tree

4 files changed

+782
-4206
lines changed

4 files changed

+782
-4206
lines changed

main.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import warnings
22

33
import pandas as pd
4+
from matplotlib import pyplot as plt
5+
46
import okama as ok
57

68
import os
@@ -21,22 +23,43 @@
2123
symbol="My_portfolio.PF",
2224
)
2325

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+
}
2544

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
2946

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
3148

3249
pf.dcf.set_mc_parameters(distribution="norm", period=30, number=400) # simulation period in years
3350

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+
4165

42-
print(result.withdrawal_rel)

0 commit comments

Comments
 (0)