Design of Risk Parity Portfolios
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
R
R_buildignore
docs add logo Feb 16, 2019
inst Version updated to 0.1.1 Jan 8, 2019
man Fixing links... Jan 7, 2019
papers To implement in the future... Jan 24, 2019
python
src
tests
vignettes Trying pagedown but the output doesn't look as good as our pdf... Jan 29, 2019
.Rbuildignore update .Rbuildignore Jan 11, 2019
.compileAttributes.R
.gitattributes
.gitignore
.roxygenize.R
.travis.yml
DESCRIPTION After CRAN submission Jan 8, 2019
Dockerfile
LICENSE
Makefile
NAMESPACE
NEWS.md
README.Rmd Merge branch 'master' of https://github.com/dppalomar/riskParityPortf… Feb 16, 2019
README.html
README.md
appveyor.yml
cran-comments.md Fixed some links. Dec 15, 2018
riskParityPortfolio.Rproj Adding source material in the vignette. Aug 22, 2018

README.md

CRAN_Status_Badge CRAN Downloads CRAN Downloads Total

PyPI version Downloads

codecov Travis-CI-Badge Build status CircleCI Docker Build Status


The package riskParityPortfolio provides tools to design risk parity portfolios. In its simplest form, we consider the convex formulation with a unique solution proposed by Spinu (2013) and use a cyclical method inspired by Griveau-Billion (2013). For more general formulations, which are usually nonconvex, we implement the successive convex approximation method proposed by Feng & Palomar (2015).

The latest stable version of riskParityPortfolio is available at https://CRAN.R-project.org/package=riskParityPortfolio.

The latest development version of riskParityPortfolio is available at https://github.com/dppalomar/riskParityPortfolio.

Installation

To install the latest stable version of riskParityPortfolio, run the following commands in R:

install.packages("riskParityPortfolio")

To install the development version of riskParityPortfolio, run the following commands in R:

install.packages("devtools")
devtools::install_github("dppalomar/riskParityPortfolio")

To get help:

library(riskParityPortfolio)
help(package = "riskParityPortfolio")
package?riskParityPortfolio
?riskParityPortfolio

Please cite riskParityPortfolio in publications:

citation("riskParityPortfolio")

You can also get riskParityPortfolio from Docker as follows:

docker pull mirca/riskparityportfolio

Microsoft Windows

On MS Windows environments, make sure to install the most recent version of Rtools.

Python

A Python3 implementation of the vanilla method is available in PYPI and can be installed as follows:

pip install riskparityportfolio

Usage of riskParityPortfolio

R

library(riskParityPortfolio)

set.seed(42)
# create covariance matrix
N <- 5
V <- matrix(rnorm(N^2), ncol = N)
Sigma <- cov(V)

# risk parity portfolio
res <- riskParityPortfolio(Sigma)
names(res)
#> [1] "w"                 "risk_contribution"
res$w
#> [1] 0.32715962 0.27110678 0.14480081 0.09766356 0.15926922
res$risk_contribution
#> [1] 0.03857039 0.03857039 0.03857039 0.03857039 0.03857039
c(res$w * (Sigma %*% res$w))
#> [1] 0.03857039 0.03857039 0.03857039 0.03857039 0.03857039

# risk budggeting portfolio
res <- riskParityPortfolio(Sigma, b = c(0.4, 0.4, 0.1, 0.05, 0.05))
res$risk_contribution/sum(res$risk_contribution)
#> [1] 0.40 0.40 0.10 0.05 0.05

Python

import numpy as np
import riskparityportfolio as rpp
np.random.seed(42)
# creates a correlation matrix from time-series of five assets
x = np.random.normal(size=1000).reshape((5, -1))
corr = x @ x.T
# create the desired risk budgeting vector
b = np.ones(len(corr)) / len(corr)
# design the portfolio
w = rpp.design(corr, b)
print(w)
# compute the risk budgeting
#> [ 0.21075375  0.21402865  0.20205399  0.16994639  0.20321721]
rc = w @ (corr * w)
print(rc / np.sum(rc))
# let's try a different budget
#> [ 0.2  0.2  0.2  0.2  0.2]
b = np.array([0.01, 0.09, .1, .1, .7])
w = rpp.design(corr, b)
print(w)
#> [ 0.06178354  0.19655744  0.16217134  0.12808275  0.45140493]
rc = w @ (corr * w)
print(rc / np.sum(rc))
#> [ 0.01  0.09  0.1   0.1   0.7 ]

Documentation

For more detailed information, please check the CRAN vignette, GitHub vignette, or the package webpage.

Citation

If you find this package useful in your research, please consider citing the following works:

Contributing

We welcome all sorts of contributions. Please feel free to open an issue to report a bug or discuss a feature request.

Links

Package: CRAN and GitHub.

README file: CRAN-readme and GitHub-readme.

Vignette: CRAN-html-vignette, CRAN-pdf-vignette, GitHub-html-vignette, and GitHub-pdf-vignette.