Skip to content

Commit 8453074

Browse files
committed
feat: add CutWithdrawalsIfDrawdown (CWID) to cash flow strategies
1 parent 325639f commit 8453074

File tree

6 files changed

+1244
-412
lines changed

6 files changed

+1244
-412
lines changed

main.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# abs_deviation=0.10,
1818
# rel_deviation=0.40
1919
)
20-
weights = [0.12, 0.21, 0.42, 0.25]
20+
weights = [0, 0, 1, 0]
2121
pf = ok.Portfolio(
2222
['RGBITR.INDX', 'RUCBTRNS.INDX', 'MCFTR.INDX', 'GC.COMM'],
2323
weights=weights,
@@ -43,22 +43,35 @@
4343
# cf_strategy.amount = 10_000_000 * 0.05
4444
# cf_strategy.indexation = 0.09
4545

46+
# Cut Whithdrawals if Drawdown CWID strategy
47+
cf_strategy = ok.CutWithdrawalsIfDrawdown(pf)
48+
49+
cf_strategy.initial_investment = 10_000_000
50+
cf_strategy.frequency = "year"
51+
cf_strategy.amount = -10_000_000 * 0.05
52+
cf_strategy.indexation = 0.09
53+
cf_strategy.crash_threshold_reduction = [
54+
(.10, .20),
55+
(.20, .50),
56+
(.40, 1),
57+
]
58+
4659
# d = {
4760
# "2015-06": -35_000_000,
4861
# }
4962
#
5063
# cf_strategy.time_series_dic = d
5164
# cf_strategy.time_series_discounted_values = False
5265

53-
# VDS strategy
54-
cf_strategy = ok.VanguardDynamicSpending(pf)
55-
cf_strategy.initial_investment = 1_000_000
56-
cf_strategy.percentage = -0.08
57-
cf_strategy.indexation = 0.09
58-
# cf_strategy.min_max_annual_withdrawal = 10_000_000 / 5, 10_000_000 / 10 # 20%, 10%
59-
cf_strategy.floor_ceiling = -0.10, 0.20
60-
# cf_strategy.time_series_dic = d
61-
# cf_strategy.time_series_discounted_values = False
66+
# # VDS strategy
67+
# cf_strategy = ok.VanguardDynamicSpending(pf)
68+
# cf_strategy.initial_investment = 1_000_000
69+
# cf_strategy.percentage = -0.08
70+
# cf_strategy.indexation = 0.09
71+
# # cf_strategy.min_max_annual_withdrawal = 10_000_000 / 5, 10_000_000 / 10 # 20%, 10%
72+
# cf_strategy.floor_ceiling = -0.10, 0.20
73+
# # cf_strategy.time_series_dic = d
74+
# # cf_strategy.time_series_discounted_values = False
6275

6376
pf.dcf.cashflow_parameters = cf_strategy # assign the cash flow strategy to portfolio
6477

@@ -74,14 +87,14 @@
7487
# # period=15,
7588
# # number=100
7689
# # )
77-
# print(pf.dcf.cashflow_parameters.time_series_dic)
90+
# print(pf.dcf.cashflow_parameters._crash_threshold_reduction_series)
7891

7992
# wi = pf.dcf.wealth_index(discounting="pv", include_negative_values=False)
8093
cf = pf.dcf.cash_flow_ts(discounting="pv", remove_if_wealth_index_negative=True).resample("Y").sum()
8194
# wi = pf.dcf.monte_carlo_wealth(discounting="fv", include_negative_values=False)
8295
# cf = pf.dcf.monte_carlo_cash_flow(discounting="pv", remove_if_wealth_index_negative=True)
83-
print(cf)
84-
print(cf.pct_change())
96+
# print(cf)
97+
# print(cf.pct_change())
8598
# wi.plot(
8699
# # kind="bar",
87100
# legend=False
@@ -90,12 +103,12 @@
90103
# plt.show()
91104
#
92105
# df = cf[0]
93-
# df[df != 0].plot(
94-
# kind="bar",
95-
# legend=False
96-
# )
97-
# plt.yscale('linear') # linear or log
98-
# plt.show()
106+
cf.plot(
107+
kind="bar",
108+
legend=False
109+
)
110+
plt.yscale('linear') # linear or log
111+
plt.show()
99112

100113
# print(df[df != 0])
101114

0 commit comments

Comments
 (0)