Asset Allocation Models

class RiskParity(sigma=None, cor=None, cov=None, ret=None, budget=None, longshort=1)[source]

Risk parity (equal risk contribution) asset allocation.

References

Examples

>>> import numpy as np
>>> import pyfeng as pf
>>> cov = np.array([
        [ 94.868, 33.750, 12.325, -1.178, 8.778 ],
        [ 33.750, 445.642, 98.955, -7.901, 84.954 ],
        [ 12.325, 98.955, 117.265, 0.503, 45.184 ],
        [ -1.178, -7.901, 0.503, 5.460, 1.057 ],
        [ 8.778, 84.954, 45.184, 1.057, 34.126 ]
    ])/10000
>>> m = pf.RiskParity(cov=cov)
>>> m.weight()
array([0.125, 0.047, 0.083, 0.613, 0.132])
>>> m._result
{'err': 2.2697290741335863e-07, 'n_iter': 6}
>>> m = pf.RiskParity(cov=cov, budget=[0.1, 0.1, 0.2, 0.3, 0.3])
>>> m.weight()
array([0.077, 0.025, 0.074, 0.648, 0.176])
>>> m = pf.RiskParity(cov=cov, longshort=[-1, -1, 1, 1, 1])
>>> m.weight()
array([-0.216, -0.162,  0.182,  0.726,  0.47 ])
classmethod init_random(n_asset=10, zero_ev=0, budget=False)[source]

Randomly initialize the correlation matrix

Parameters
  • n_asset – number of assets

  • zero_ev – number of zero eivenvalues. 0 by default

  • budget – randomize budget if True. False by default.

Returns

RiskParity model object

weight(tol=1e-06)[source]

Risk parity weight using the improved CCD method of Choi and Chen (2022)

Parameters

tol – error tolerance

Returns

risk parity weight

References

weight_ccd_original(tol=1e-06)[source]

Risk parity weight using original CCD method of Griveau-Billion et al (2013). This is implemented for performance comparison. Use weight() for better performance.

Parameters

tol – error tolerance

Returns

risk parity weight

References

  • Griveau-Billion T, Richard J-C, Roncalli T (2013) A Fast Algorithm for Computing High-dimensional Risk Parity Portfolios. arXiv:13114057 [q-fin]

weight_newton(tol=1e-06)[source]

Risk parity weight using the ‘improved’ Newton method by Choi & Chen (2022). This is implemented for performance comparison. Use weight() for better performance.

Parameters

tol – error tolerance

Returns

risk parity weight

References