riskparity.py
riskparity.py copied to clipboard
Example of how to use equality_constraints and inequality_constraints parameters
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=?)
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.
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 :)
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 :)