Skip to content

Commit dcd2244

Browse files
committed
test: add parametric tests for default and configurable bounds
1 parent f4235bf commit dcd2244

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

tests/conftest.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,31 @@ def bounds_frontier_params():
303303
)
304304

305305

306+
@pytest.fixture(scope="module")
307+
def without_bounds_params():
308+
return dict(
309+
assets=["GLD.US", "PGJ.US", "GC.COMM", "VB.US"],
310+
ccy="RUB",
311+
first_date="2004-12",
312+
last_date="2020-12",
313+
rebalancing_period="year",
314+
inflation=True,
315+
)
316+
317+
318+
@pytest.fixture(scope="module")
319+
def with_bounds_params():
320+
return dict(
321+
assets=["GLD.US", "PGJ.US", "GC.COMM", "VB.US"],
322+
ccy="RUB",
323+
first_date="2004-12",
324+
last_date="2020-12",
325+
rebalancing_period="year",
326+
bounds=((0, 1), (0, 1), (0, 1), (0, 0.4)),
327+
inflation=True,
328+
)
329+
330+
306331
@pytest.fixture(scope="module")
307332
def convex_frontier_params():
308333
return dict(
@@ -334,6 +359,16 @@ def init_bounds_frontier(bounds_frontier_params):
334359
return ok.EfficientFrontierReb(**bounds_frontier_params)
335360

336361

362+
@pytest.fixture(scope="module")
363+
def init_frontier_without_bounds(without_bounds_params):
364+
return ok.EfficientFrontierReb(**without_bounds_params)
365+
366+
367+
@pytest.fixture(scope="module")
368+
def init_frontier_with_bounds(with_bounds_params):
369+
return ok.EfficientFrontierReb(**with_bounds_params)
370+
371+
337372
@pytest.fixture(scope="module")
338373
def init_convex_frontier(convex_frontier_params):
339374
return ok.EfficientFrontierReb(**convex_frontier_params)

tests/test_frontier_reb.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,53 @@ def test_ef_points_reb(init_efficient_frontier_reb):
6868
assert init_efficient_frontier_reb.ef_points["CAGR"].iloc[1] == approx(0.1889, abs=1e-2)
6969

7070

71+
test_params = [
72+
(
73+
{
74+
'GLD.US': 0.0,
75+
'PGJ.US': 0.084373066707716,
76+
'GC.COMM': 0.3657553971903911,
77+
'VB.US': 0.549871536101893,
78+
'CAGR': 0.17674807724452934,
79+
'Risk': 0.1942250533311337
80+
},
81+
{
82+
'GLD.US': 0.4824328877342874,
83+
'PGJ.US': 0.1175671122657124,
84+
'GC.COMM': 1.759024851233533e-16,
85+
'VB.US': 0.4,
86+
'CAGR': 0.17674807724452934,
87+
'Risk': 0.19857284519244595
88+
}
89+
)
90+
]
91+
92+
93+
@mark.rebalance
94+
@mark.frontier
95+
@pytest.mark.parametrize("dict_1, dict_2", test_params)
96+
def test_minimize_risk_without_bounds(init_frontier_without_bounds, dict_1, dict_2):
97+
98+
target_cagr = 0.17674807724452934
99+
100+
result = init_frontier_without_bounds.minimize_risk(target_cagr)
101+
102+
for key in dict_1:
103+
assert np.isclose(result[key], dict_1[key], rtol=1e-2)
104+
105+
@mark.rebalance
106+
@mark.frontier
107+
@pytest.mark.parametrize("dict_1, dict_2", test_params)
108+
def test_minimize_risk_with_bounds(init_frontier_with_bounds, dict_1, dict_2):
109+
110+
target_cagr = 0.17674807724452934
111+
112+
result = init_frontier_with_bounds.minimize_risk(target_cagr)
113+
114+
for key in dict_2:
115+
assert np.isclose(result[key], dict_2[key], rtol=1e-2)
116+
117+
71118
@mark.rebalance
72119
@mark.frontier
73120
def test_convex_right_frontier(init_convex_frontier):

0 commit comments

Comments
 (0)