Critical line algorithm for the efficient frontier
Project description
cvxcla
Critical line algorithm
The critical line algorithm is a method to compute the efficient frontier of a portfolio optimization problem.
The algorithm has been introduced by Markowitz in The Optimization of Quadratic Functions Subject to Linear Constraints and subsequently described in his book Portfolio Selection.
The algorithm is based on the observation that the efficient frontier is a piecewise linear function if expected return is plotted over expected variance. The critical line algorithm computes the turning points, e.g. the corners of the efficient frontier.
Literature
We are using the following sources
Niedermayer and Niedermayer
They suggested a method to avoid the expensive inversion of the covariance matrix.
Applying Markowitz's critical line algorithm
It turns out that implementing their method in Python is not significantly faster
than the explicit inversion of the covariance matrix relying on LAPACK via numpy.linalg.inv
.
Bailey and Lopez de Prado
We have initially started with their code published in An Open-Source Implementation of the Critical-Line Algorithm for Portfolio Optimization. We have updated their original code and covered it in tests. We have made a few noteworthy changes:
- Use a boolean numpy array to indicate whether a weight is free or blocked.
- Rewrote the computation of the first turning point.
- Isolated the computation of $\lambda$ and the update of weights to make them testable.
- Use modern and immutable dataclasses throughout.
The code is not part of the published package though. It is only used for testing purposes. We recommend it for educational purposes only.
Markowitz et al
In Avoiding the Downside: A Practical Review of the Critical Line Algorithm for Mean-Semivariance Portfolio Optimizatio Markowitz and a team of researchers from Hudson Bay Capital Management and Constantia Capital provide a step-by-step tutorial on how to implement the critical line algorithm.
We address a problem they oversaw: After finding the first starting point all variables might be blocked. We need to enforce that one variable is labeled as free even it sits on a boundary otherwise the matrix needed is singular.
Rather than using their involved construction of the sparse matrix to estimate the weights we bisect the weights into a free and a blocked part. We then use a linear solver to compute the weights only for the free part.
We alter some of their Python code. Our experiments to combine it with Niedermayer's ideas to accelerate the computation of the matrix inverses did not yet justify the additional complexity.
Poetry
We assume you share already the love for Poetry. Once you have installed poetry you can perform
make install
to replicate the virtual environment we have defined in pyproject.toml and locked in poetry.lock.
Jupyter
We install JupyterLab on fly within the aforementioned virtual environment. Executing
make jupyter
will install and start the jupyter lab.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cvxcla-1.1.0.tar.gz
.
File metadata
- Download URL: cvxcla-1.1.0.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13cc3ad89179483c1500c591bfd6141c86d7f1cdb2671a5afb131caf3970364a |
|
MD5 | 0184a5ad9b415286d50f82c8d5feb6ef |
|
BLAKE2b-256 | 79919d7d75785ab339d5e6db62a581f41ae5d2d017d8ed785ab4bcd58c8fd81a |
File details
Details for the file cvxcla-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: cvxcla-1.1.0-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53a5c0d86ccfcdeb110ba150d3c035d7b63e450f49c6fa0c3db5a3bc610cee85 |
|
MD5 | 59cea2091400d0349d3c85a3d162cb44 |
|
BLAKE2b-256 | dded98fa47c40e45a48512ea98e85340a725cc1f1777aba7afed5024d70d358e |