Skip to content

Commit 8a060c1

Browse files
author
Thomas Schmelzer
committed
testing
1 parent bdc6d2f commit 8a060c1

File tree

6 files changed

+12
-87
lines changed

6 files changed

+12
-87
lines changed

cvx/cla/first.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def init_algo_lp(
7272
upper_bounds: MATRIX,
7373
A_eq: MATRIX | None = None,
7474
b_eq: MATRIX | None = None,
75-
solver=cp.ECOS,
75+
solver=cp.CLARABEL,
7676
**kwargs
7777
# A_ub: MATRIX | None = None,
7878
# b_ub: MATRIX | None = None,
@@ -140,10 +140,3 @@ def _free(w, lower_bounds, upper_bounds):
140140
free = np.full_like(w, False, dtype=np.bool_)
141141
free[index] = True
142142
return free
143-
144-
145-
if __name__ == "__main__":
146-
w = np.array([0.0, 0.0, 0.0])
147-
lower_bounds = np.array([0.0, 0.0, 0.0])
148-
upper_bounds = np.array([1.0, 1.0, 1.0])
149-
print(_free(w, lower_bounds, upper_bounds))

cvx/cla/types.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ class TurningPoint(FrontierPoint):
5959
free: BOOLEAN_VECTOR
6060
lamb: float = np.inf
6161

62-
@property
63-
def frontier_point(self):
64-
"""
65-
Returns the frontier point
66-
"""
67-
return FrontierPoint(weights=self.weights)
68-
6962
@property
7063
def free_indices(self):
7164
"""

tests/test_aux.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,6 @@ def test_append(cla):
6666
assert fig is not None
6767

6868

69-
def test_first_turning_point(cla):
70-
tp = cla._first_turning_point()
71-
np.testing.assert_almost_equal(
72-
tp.weights, np.array([0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
73-
)
74-
75-
7669
def test_raise():
7770
cla = Cla(
7871
covariance=np.eye(2),

tests/test_first.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
from cvx.cla.types import TurningPoint
66

77

8-
@pytest.mark.parametrize("n", [5, 20, 100, 1000, 10000, 100000])
8+
@pytest.mark.parametrize("n", [5, 20, 100, 1000, 10000])
99
def test_init_algo(n):
1010
"""Compute a first turning point"""
1111
mean = np.random.randn(n)
1212
lower_bounds = np.zeros(n)
1313
upper_bounds = np.random.rand(n)
1414

1515
first = init_algo_lp(
16-
mean=mean, lower_bounds=lower_bounds, upper_bounds=upper_bounds, solver="ECOS"
16+
mean=mean, lower_bounds=lower_bounds, upper_bounds=upper_bounds
1717
)
1818

1919
assert np.sum(first.free) == 1
@@ -34,9 +34,7 @@ def test_small():
3434
mean = np.array([1.0, 2.0, 3.0])
3535
lower_bound = np.array([0.0, 0.0, 0.0])
3636
upper_bound = np.array([0.4, 0.4, 0.4])
37-
tp = init_algo_lp(
38-
mean=mean, lower_bounds=lower_bound, upper_bounds=upper_bound, solver="ECOS"
39-
)
37+
tp = init_algo_lp(mean=mean, lower_bounds=lower_bound, upper_bounds=upper_bound)
4038

4139
assert np.allclose(tp.weights, [0.2, 0.4, 0.4])
4240
assert tp.lamb == np.inf
@@ -61,12 +59,7 @@ def test_no_fully_invested_portfolio():
6159
with pytest.raises(
6260
ValueError, match="Could not construct a fully invested portfolio"
6361
):
64-
init_algo_lp(
65-
mean=mean,
66-
lower_bounds=lower_bounds,
67-
upper_bounds=upper_bounds,
68-
solver="ECOS",
69-
)
62+
init_algo_lp(mean=mean, lower_bounds=lower_bounds, upper_bounds=upper_bounds)
7063

7164
with pytest.raises(
7265
ValueError, match="Could not construct a fully invested portfolio"
@@ -83,12 +76,7 @@ def test_lb_ub_mixed():
8376
mean = np.ones(3)
8477

8578
with pytest.raises(ValueError):
86-
init_algo_lp(
87-
mean=mean,
88-
lower_bounds=lower_bounds,
89-
upper_bounds=upper_bounds,
90-
solver="ECOS",
91-
)
79+
init_algo_lp(mean=mean, lower_bounds=lower_bounds, upper_bounds=upper_bounds)
9280

9381
with pytest.raises(ValueError):
9482
init_algo(mean=mean, lower_bounds=lower_bounds, upper_bounds=upper_bounds)

tests/test_frontier.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
@pytest.mark.parametrize("solver", [BAILEY, MARKOWITZ])
1313
def test_frontier(input_data, solver):
14+
"""
15+
Test the frontier both for Bailey and Markowitz
16+
"""
1417
f = solver(
1518
covariance=input_data.covariance,
1619
mean=input_data.mean,
@@ -34,6 +37,9 @@ def test_frontier(input_data, solver):
3437
"n", [2, 2, 2, 3, 3, 3, 5, 5, 5, 5, 10, 20, 20, 20, 20, 20, 20]
3538
)
3639
def test_frontiers(n, resource_dir):
40+
"""
41+
Compare the frontiers of BAILEY and MARKOWITZ for a variety of dimensions.
42+
"""
3743
mean = np.random.randn(n)
3844
lower_bounds = np.zeros(n)
3945
upper_bounds = np.ones(n)

tests/test_solver.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,6 @@
55
from tests.bailey.cla import CLA as BAILEY
66

77

8-
@pytest.mark.parametrize("solver", [BAILEY, MARKOWITZ])
9-
def test_solver(input_data, solver):
10-
x = solver(
11-
mean=input_data.mean,
12-
lower_bounds=input_data.lower_bounds,
13-
upper_bounds=input_data.upper_bounds,
14-
covariance=input_data.covariance,
15-
tol=1e-5,
16-
A=np.ones((1, len(input_data.mean))),
17-
b=np.ones(1),
18-
)
19-
20-
assert x
21-
for a in x.turning_points:
22-
assert a
23-
24-
258
@pytest.mark.parametrize("solver", [BAILEY, MARKOWITZ])
269
def test_example(example, example_solution, solver):
2710
# example from section 3.1 in the Markowitz 2019 paper
@@ -57,37 +40,6 @@ def test_example(example, example_solution, solver):
5740
)
5841

5942

60-
@pytest.mark.parametrize("n", [2, 3, 5, 10, 20, 50])
61-
def test_init_dimension(n):
62-
mean = np.random.randn(n)
63-
64-
# solver = Solver.BAILEY
65-
tp_bailey = BAILEY(
66-
mean=mean,
67-
lower_bounds=np.zeros(n),
68-
upper_bounds=np.ones(n),
69-
covariance=np.eye(n),
70-
A=np.ones((1, n)),
71-
b=np.ones(1),
72-
)
73-
74-
# solver = Solver.MARKOWITZ
75-
tp_markowitz = MARKOWITZ(
76-
mean=mean,
77-
lower_bounds=np.zeros(n),
78-
upper_bounds=np.ones(n),
79-
covariance=np.eye(n),
80-
A=np.ones((1, n)),
81-
b=np.ones(1),
82-
)
83-
84-
np.testing.assert_almost_equal(
85-
tp_bailey.turning_points[0].weights, tp_markowitz.turning_points[0].weights
86-
)
87-
88-
assert len(tp_bailey) == len(tp_markowitz)
89-
90-
9143
@pytest.mark.parametrize("solver", [MARKOWITZ, BAILEY])
9244
@pytest.mark.parametrize("n", [2, 4, 8, 16, 32, 64, 128]) # , 256, 512])
9345
def test_init_solver(solver, n):

0 commit comments

Comments
 (0)