Skip to content

Commit efd9401

Browse files
committed
test: add tests for PortfolioDCF
1 parent 4350c4f commit efd9401

File tree

5 files changed

+146
-109
lines changed

5 files changed

+146
-109
lines changed

main.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@
1111
warnings.simplefilter(action="ignore", category=FutureWarning)
1212

1313
pd.set_option("display.float_format", lambda x: "%.2f" % x)
14-
ef = ok.EfficientFrontierReb(
15-
['SPY.US', 'AGG.US', 'GLD.US'],
16-
rebalancing_strategy=ok.Rebalance(period='year'),
17-
ccy='USD',
18-
first_date='2020-01', last_date='2025-03', full_frontier=True, verbose=True)
19-
glob = ef.global_max_return_portfolio
20-
cagr = glob['CAGR']
21-
print(cagr)
22-
23-
pf = ef.minimize_risk(cagr)
24-
print(pf)
14+
15+
16+
# ef = ok.EfficientFrontierReb(
17+
# ['SPY.US', 'AGG.US', 'GLD.US'],
18+
# rebalancing_strategy=ok.Rebalance(period='year'),
19+
# ccy='USD',
20+
# first_date='2020-01', last_date='2025-03', full_frontier=True, verbose=True)
21+
# glob = ef.global_max_return_portfolio
22+
# cagr = glob['CAGR']
23+
# print(cagr)
24+
#
25+
# pf = ef.minimize_risk(cagr)
26+
# print(pf)
2527

2628
# w = ef.minimize_risk(0.184914755913651)
2729
# print(w)
@@ -58,16 +60,21 @@
5860
#
5961
# print(pf.dividend_yield_annual)
6062

61-
62-
# assets = ['RGBITR.INDX', 'MCFTR.INDX', 'GC.COMM']
63-
# weights = [0.60, 0.35, 0.05]
64-
# assets = ['RGBITR.INDX', 'MCFTR.INDX']
65-
# weights = [0.50, 0.50]
66-
# pf = ok.Portfolio(assets, weights=weights,
67-
# first_date="2015-01",
68-
# last_date="2020-01",
69-
# ccy='RUB',
70-
# inflation=True)
63+
pf2 = ok.Portfolio(first_date="2015-01", last_date="2024-10")
64+
d = {
65+
"2018-02": 2_000, # contribution
66+
"2024-03": -4_000 # withdrawal
67+
}
68+
ts = ok.TimeSeriesStrategy(pf2)
69+
ts.time_series_dic = d # use the dictionary to set cash flow
70+
ts.initial_investment = 1_000 # add initial investments size (optional)
71+
pf2.dcf.cashflow_parameters = ts
72+
print(pf2.dcf.wealth_index)
73+
# assets = ['RGBITR.INDX', 'RUCBTRNS.INDX', 'MCFTR.INDX', 'GC.COMM']
74+
# weights = [0.16, 0.40, 0.25, 0.19]
75+
# # assets = ['RGBITR.INDX', 'MCFTR.INDX']
76+
# # weights = [0.50, 0.50]
77+
# pf = ok.Portfolio(assets, weights=weights, ccy='RUB', inflation=False)
7178
# pf.rebalancing_strategy = ok.Rebalance(
7279
# period="none",
7380
# abs_deviation=0.10,
@@ -103,7 +110,7 @@
103110
# pc = ok.PercentageStrategy(pf)
104111
# pc.initial_investment = 10_000
105112
# pc.frequency = "year"
106-
# pc.percentage = -0.55
113+
# pc.percentage = -0.12
107114
#
108115
# pf.dcf.cashflow_parameters = pc
109116
#
@@ -116,7 +123,7 @@
116123
# solution = pf.dcf.find_the_largest_withdrawals_size(
117124
# goal="maintain_balance_pv",
118125
# percentile=20,
119-
# tolerance_rel=0.05,
126+
# tolerance_rel=0.10,
120127
# threshold=0.05,
121128
# iter_max=20
122129
# )

0 commit comments

Comments
 (0)