Skip to content

Instantly share code, notes, and snippets.

@lequant40
Last active October 18, 2021 18:20
Show Gist options
  • Save lequant40/59db177d0f20ea75ffa2e942b8a1d9ec to your computer and use it in GitHub Desktop.
Save lequant40/59db177d0f20ea75ffa2e942b8a1d9ec to your computer and use it in GitHub Desktop.
Hierarchical Risk Parity portfolio optimization algorithm
fetch('https://api.portfoliooptimizer.io/v1/portfolio/optimization/hierarchical-clustering-based-risk-parity',
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ assets: 10,
assetsCovarianceMatrix: [[1.000647799, -0.003050479, 0.010033224, -0.010759689, -0.005036503, 0.008762563, 0.998201625, -0.001393196, -0.001254522, -0.009365991],
[-0.003050479, 1.009021349, 0.008613817, 0.007334478, -0.009492688, 0.013031817, -0.009420720, -0.015346223, 1.010520047, 1.013334849],
[0.010033224, 0.008613817, 1.000739363, -0.000637885, 0.001783293, 1.001574768, 0.006385368, 0.001922316, 0.012902050, 0.007997935],
[-0.010759689, 0.007334478, -0.000637885, 1.011854725, 0.005759976, 0.000905812, -0.011912269, 0.000461894, 0.012572661, 0.009621670],
[-0.005036503, -0.009492688, 0.001783293, 0.005759976, 1.005835878, 0.005606343, -0.009643250, 1.008567427, -0.006183035, -0.007942770],
[0.008762563, 0.013031817, 1.001574768, 0.000905812, 0.005606343, 1.064309825, 0.004413960, 0.005780148, 0.017185396, 0.011601336],
[0.998201625, -0.009420720, 0.006385368, -0.011912269, -0.009643250, 0.004413960, 1.058172027, -0.006755374, -0.008099181, -0.016240271],
[-0.001393196, -0.015346223, 0.001922316, 0.000461894, 1.008567427, 0.005780148, -0.006755374, 1.074833155, -0.011903469, -0.013738378],
[-0.001254522, 1.010520047, 0.012902050, 0.012572661, -0.006183035, 0.017185396, -0.008099181, -0.011903469, 1.075346677, 1.015220126],
[-0.009365991, 1.013334849, 0.007997935, 0.009621670, -0.007942770, 0.011601336, -0.016240271, -0.013738378, 1.015220126, 1.078586686]]
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment