Skip to content

Commit

Permalink
33 add markowitz paper (#38)
Browse files Browse the repository at this point in the history
* solver from Markowitz paper

* correct solver interface

* correct solver interface

* remove hist code (#35) (#36)

* Markowitz implementation

* fix experiments

* testing starting point

* moving bailey

* adjusting names

* adjusting names

* adjusting names

* adding cvxpy

* example data from Section 3.1 in Markowitz paper

* example data supported by conftest

* bring in cvxbson

* bring bson test files

* introducing the claux motherclass

* introducing the claux motherclass

* introducing the claux motherclass

* introducing the claux motherclass

* introducing the claux motherclass
  • Loading branch information
tschm authored Aug 6, 2023
1 parent 0b7eb47 commit 3aa9f9b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 0 additions & 10 deletions cvx/cla/markowitz/cla.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def __post_init__(self):
logger = loguru

ns = self.mean.shape[0]
logger.info(f"Number of assets {ns}")

A = np.ones((1, ns))
b = np.array([1.0])
Expand All @@ -50,9 +49,6 @@ def __post_init__(self):
# --A08-- Initialize the portfolio.
x = init_algo(self.mean, self.lower_bounds, self.upper_bounds)

#x = initport(self.mean, self.lower_bounds, self.upper_bounds)
logger.info(f"First vector of weights {x}")

# --A10-- Set the P matrix.
P = np.concatenate((C, A.T), axis=1)

Expand Down Expand Up @@ -108,7 +104,6 @@ def __post_init__(self):
r_alpha = alpha[range(ns)]

# --A18-- IN security possibly going UP.
#i = np.where(IN & (r_beta < -self.tol))[0]
i = IN & (r_beta < -self.tol)
L[i, 0] = (self.upper_bounds[i] - r_alpha[i]) / r_beta[i]

Expand All @@ -119,25 +114,20 @@ def __post_init__(self):
# --A20--UP security possibly going IN.
i = UP & (delta < -self.tol)
L[i, 2] = -gamma[i] / delta[i]
logger.info(f"UP going IN: {i}")

# --A21-- DN security possibly going IN.
i = DN & (delta > +self.tol)
L[i, 3] = -gamma[i] / delta[i]
logger.info(f"DN going IN: {i}")

logger.info(f"L matrix: \n{L}")
# --A22--If all elements of ratio are negative,
# we have reached the end of the efficient frontier.
if np.max(L) < 0:
break

secchg, dirchg = np.unravel_index(np.argmax(L, axis=None), L.shape)
logger.info(f"Asset changing state: {secchg}")

# --A25-- Set the new value of lambda_E.
lam = L[secchg, dirchg]
logger.info(f"Lambda: {lam}")

free = np.copy(last.free)
if dirchg == 0 or dirchg == 1:
Expand Down
14 changes: 13 additions & 1 deletion tests/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,16 @@ def test_init(n):
np.testing.assert_almost_equal(tp_bailey.turning_points[0].weights,
tp_markowitz.turning_points[0].weights)

#assert tp_bailey.num_points == tp_markowitz.num_points
assert tp_bailey.num_points == tp_markowitz.num_points


@pytest.mark.parametrize("solver", [Solver.BAILEY, Solver.MARKOWITZ])
@pytest.mark.parametrize("n", [50,100])
def test_init(solver, n):
mean = np.random.randn(n)


solver = solver.build(mean=mean,
lower_bounds=np.zeros(n),
upper_bounds=np.ones(n),
covariance=np.eye(n))

0 comments on commit 3aa9f9b

Please sign in to comment.