Skip to main content

Python for Hierarchical Risk Parity

Project description

pyhrp

A recursive implementation of the Hierarchical Risk Parity (hrp) approach by Marcos Lopez de Prado. We take heavily advantage of the scipy.cluster.hierarchy package.

Here's a simple example

import numpy as np

from pyhrp.cluster import root
from pyhrp.graph import dendrogram
from pyhrp.hrp import dist, hrp_feed

# use a small covariance matrix
cov = np.array([[1, 0.2, 0], [0.2, 2, 0.0], [0, 0, 3]])

# we compute the rootnode of a graph here
# The rootnode points to left and right and has an id attribute.
rootnode, link = root(dist(cov), 'ward')

# plot the dendrogram
ax = dendrogram(link, orientation="left")
ax.get_figure().savefig("dendrogram.png")

v, weights = hrp_feed(rootnode, cov=cov)

print(v)
print(np.linalg.multi_dot([weights, cov, weights]))
print(weights)
print(weights.sum())

Installation:

pip install pyhpr

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhrp-0.0.5.tar.gz (4.0 kB view details)

Uploaded Source

File details

Details for the file pyhrp-0.0.5.tar.gz.

File metadata

  • Download URL: pyhrp-0.0.5.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/2.7.17

File hashes

Hashes for pyhrp-0.0.5.tar.gz
Algorithm Hash digest
SHA256 b7ba542d4f0a62208c987774ae5533a5e34855a56972ac948434fedc441545c9
MD5 c7f46b88431c3c3883ddd029a3e7d25f
BLAKE2b-256 72808a1d140df29e92e098ec1872b591e400adf843c7d4ab76855fa237443f09

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page