Skip to content

Commit 62324d5

Browse files
committed
test: fixed test and added initialization test for bounds
1 parent fa042d4 commit 62324d5

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

tests/conftest.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,28 @@ def init_efficient_frontier_three_assets(init_efficient_frontier_values2):
277277
# Efficient Frontier Multi-Period
278278
@pytest.fixture(scope="module")
279279
def init_efficient_frontier_reb():
280-
ls = ["SPY.US", "GLD.US"]
281280
return ok.EfficientFrontierReb(
282-
assets=ls,
281+
assets=["SPY.US", "GLD.US"],
283282
ccy="USD",
284283
first_date="2019-01",
285284
last_date="2020-02",
285+
rebalancing_period="year",
286+
bounds=((0, 1), (0, 1)),
287+
inflation=True,
286288
n_points=2,
287-
verbose=False,
288289
full_frontier=False,
290+
)
291+
292+
293+
@pytest.fixture(scope="module")
294+
def bounds_frontier_params():
295+
return dict(
296+
assets=["SPY.US", "GLD.US", "PGJ.US", "RGBITR.INDX", "MCFTR.INDX"],
297+
ccy="USD",
298+
first_date="2019-01",
299+
last_date="2020-02",
300+
rebalancing_period="year",
301+
bounds=((0, 0.2), (0.2, 0.4), (0.4, 0.6), (0, 1), (0, 1)),
289302
inflation=True,
290303
)
291304

@@ -316,6 +329,11 @@ def nonconvex_frontier_params():
316329
)
317330

318331

332+
@pytest.fixture(scope="module")
333+
def init_bounds_frontier(bounds_frontier_params):
334+
return ok.EfficientFrontierReb(**bounds_frontier_params)
335+
336+
319337
@pytest.fixture(scope="module")
320338
def init_convex_frontier(convex_frontier_params):
321339
return ok.EfficientFrontierReb(**convex_frontier_params)

tests/test_frontier_reb.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,25 @@ def test_init_efficient_frontier_reb():
2020
def test_repr(init_efficient_frontier_reb):
2121
value = pd.Series(
2222
dict(
23-
symbols="[SPY.US, GLD.US]",
23+
symbols=["SPY.US", "GLD.US"],
2424
currency="USD",
2525
first_date="2019-01",
2626
last_date="2020-02",
2727
period_length="1 years, 2 months",
2828
rebalancing_period="year",
29-
inflation="USD.INFL",
29+
bounds=((0, 1), (0, 1)),
30+
inflation="USD.INFL"
3031
)
3132
)
3233
assert repr(init_efficient_frontier_reb) == repr(value)
3334

3435

36+
@mark.rebalance
37+
@mark.frontier
38+
def test_bounds_frontier(init_bounds_frontier):
39+
assert init_bounds_frontier.bounds == ((0, 0.2), (0.2, 0.4), (0.4, 0.6), (0, 1), (0, 1))
40+
41+
3542
@mark.rebalance
3643
@mark.frontier
3744
def test_gmv_annual_weights(init_efficient_frontier_reb):
@@ -75,6 +82,7 @@ def test_convex_right_frontier(init_convex_frontier):
7582

7683
assert result == expected_result
7784

85+
7886
@mark.rebalance
7987
@mark.frontier
8088
def test_nonconvex_right_frontier(init_nonconvex_frontier):
@@ -89,6 +97,7 @@ def test_nonconvex_right_frontier(init_nonconvex_frontier):
8997

9098
assert result == expected_result
9199

100+
92101
@mark.rebalance
93102
@mark.frontier
94103
def test_maximize_risk_with_convex_right_frontier(init_convex_frontier):
@@ -100,6 +109,7 @@ def test_maximize_risk_with_convex_right_frontier(init_convex_frontier):
100109

101110
assert result_risk == expected_risk
102111

112+
103113
@mark.rebalance
104114
@mark.frontier
105115
def test_maximize_risk_with_nonconvex_right_frontier(init_nonconvex_frontier):
@@ -109,4 +119,4 @@ def test_maximize_risk_with_nonconvex_right_frontier(init_nonconvex_frontier):
109119
result_risk = result['Risk']
110120
expected_risk = approx(0.28761107914313766, abs=1e-2)
111121

112-
assert result_risk == expected_risk
122+
assert result_risk == expected_risk

0 commit comments

Comments
 (0)