Constraints in Riskfolio does not work
HongyuanZhang-uzh opened this issue · 1 comments
Hi Cajasn,
I've set constraints as below, the class FI should have an weight below 45%, but got the result with a FI weight of 75.88103257%. I am confused why the constraints of the class was not working, and would appreciate your reply. Thank you very much in advance!
asset_classes = {'Assets': ['USSLM Index', 'EUSI Index', 'M9CXJESR Index', 'MXEFESR Index', 'GBEUTRUU Index', 'GBUSTRUU Index', 'I35570EU Index','I36690EU Index','MFLEHYET Index','MFLEHYUT Index','I36233US Index','DJBGIT Index','S5REAL Index'], 'Class': ['EQ', 'EQ', 'EQ', 'EQ', 'FI', 'FI', 'FI','FI','FI','FI','FI','AL','AL']}
asset_classes = pd.DataFrame(asset_classes) asset_classes = asset_classes.sort_values(by=['Assets']) display(asset_classes)
constraints = { 'Disabled': [True, False, False, False], 'Type': ['All Assets','Classes', 'Classes', 'Classes'], 'Set': ['','Class', 'Class', 'Class', ], 'Position': ['','EQ', 'FI', 'AL'], 'Sign': ['<=','<=', '<=', '<='], 'Weight': [0.10, 0.45, 0.45, 0.1], 'Type relative': ['','', '', ''], 'Relative set': ['','', '', ''], 'Relative': ['','', '', ''], 'Factor': ['','', '', ''] }
constraints = pd.DataFrame(constraints) display(constraints)
A, B = rp.assets_constraints(constraints, asset_classes)
port.ainequality = A port.binequality = B
w_rp = port.rp_optimization(model=model, rm=rm, rf=rf, b=b, hist=hist)
I don't know the person that made that tutorial so I don't recommend to follow videos from youtube, only rely in the official documentation and examples.
The riskparity model mathematically is not designed to enforce constraints, if you add linear constraints the model will try to incorporate it but the solution is not exact or approximate, but it is closer to what you want compared to the solution if you don't include these linear constraints.
Best regards,
Dany Cajas