riskparity.py icon indicating copy to clipboard operation
riskparity.py copied to clipboard

Example of how to use equality_constraints and inequality_constraints parameters

Open turmeric-blend opened this issue 3 years ago • 3 comments

Problem description

How to use equality_constraints and inequality_constraints parameters?

Example

import riskparityportfolio as rp

my_portfolio = rp.RiskParityPortfolio(covariance=sigma, budget=b, equality_constraints=?, inequality_constraints=?)

turmeric-blend avatar Mar 02 '21 06:03 turmeric-blend

Hi @turmeric-blend, this interface to define inequality/equality constraints via strings is not yet available, however, you can pass directly the quantities Cmat, cvec, Dmat, and dvec to the design method of a RiskParityPortfolio object as illustrated in this tutorial: https://mirca.github.io/riskparity.py/tutorials/comparison-with-pyrb.html#Constrained-Risk-Parity. FYI see https://mirca.github.io/riskparity.py/index.html for the optimization formulation.

mirca avatar Mar 02 '21 12:03 mirca

From the example, Dmat has shape (2, 8) and dvec has shape (2,). What does the 2 dimension represent?

Also, its not immediately clear to me how to write out the constraint w <= 0.1 (any asset can only have a maximum weight of 10%) in Dmat and dvec format. Could you help with this? Thanks :)

turmeric-blend avatar Mar 03 '21 02:03 turmeric-blend

Hi @turmeric-blend, if you want to have a max weight at 10%, you can create and identity matrix and a vector. Dmat=np.eye(50,50)% example 50 is the number of stocks. dvec = np.empty((50)); dvec.fill(0.1) # weight 10% my_rpp.design(Dmat=Dmat, dvec=dvec)

and you are done :)

davdigioia avatar Jul 02 '21 15:07 davdigioia