convexfi / riskparity.py

Fast and scalable construction of risk parity portfolios
https://mirca.github.io/riskparity.py/
MIT License
284 stars 64 forks source link

add simple example showcasing the need for the SCRIP algorithm #6

Open mirca opened 4 years ago

mirca commented 4 years ago

like we did in the R package, we should show examples where general solvers (from e.g., scipy.optimize) are not able to or are too slow to solve the non-convex risk parity formulation.

mtsokol commented 3 years ago

Hi @mirca!

I'm a master program CS student and I was searching in jax dependency graph for projects using it to learn it's usage. I came across this repository and after inspecting it I would like to learn more and try contributing.

Is this issue free to take?


As I understand the goal here is to show performance comparison between SCRIP and scipy.optimize solvers, similarly to the example in riskParityPortfolio documentation for risk concentration only example. Is that correct?

Following the derivation from presentation I used SLSQP solver from scipy.optimize because it's the only one that supports both equality and inequality constraints.

I made a PoC notebook, where for trick case used in tests I ran scipy solver.

Colab: https://colab.research.google.com/drive/1KluLJd7xXD9vSeLO1ULOXF2Cwa7_PvRO?usp=sharing

nbviewer: https://nbviewer.jupyter.org/gist/mtsokol/4743d73c086940795ba428abf0b73c1a

Although for initial points that are close to the solution it does converge, it fails for others. I used initial guess from newton_nesterov.cc from riskParityPortfolio project:

Eigen::VectorXd xk = Eigen::VectorXd::Constant(N, 1);
// initial guess
xk = std::sqrt(b.sum() / Sigma.sum()) * xk;

and I also tried b as initial guess. Unfortunately it failed for both.

Is approach in the notebook correct? Is SLSQP the right solver to use? What should be used as initial guess for that case?

After solving it I think I can try preparing speed comparison plot like from riskParityPortfolio.

Thank you for any guidance or help!