Slide 1

Slide 1 text

BreakingDownRiskParity Portfolios: APracticalOpen SourceImplementation a talk by Zé Vinícius (in collab. with Daniel Palomar) Hong Kong Machine Learning Meetup @CreditSuisse Jan. nd,

Slide 2

Slide 2 text

whoami made in Brazil electrical engineer by training, computer scientist by passion/experience guest researcher at NIST so ware developer for Google summer of code with OpenAstronomy so ware engineer intern NASA since Sept. : phd student at HKUST National Institute of Standards and Technology, Washington DC, US National Aeronautics and Space Administration, Ames Research Center, Silicon Valley, US The Hong Kong University of Science and Technology

Slide 3

Slide 3 text

PortfolioOptimization

Slide 4

Slide 4 text

Stock Data /

Slide 5

Slide 5 text

Portfolio Optimization / problem: how to allocate B amount of money into N assets? Nobel Memorial Prize in Economic Sciences

Slide 6

Slide 6 text

Portfolio Optimization / problem: how to allocate B amount of money into N assets? assume the log-returns r are i.i.d. Gaussian, then for a portfolio w: expected return: E w r = w µ variance: V w r = w Σw Nobel Memorial Prize in Economic Sciences

Slide 7

Slide 7 text

Portfolio Optimization / problem: how to allocate B amount of money into N assets? assume the log-returns r are i.i.d. Gaussian, then for a portfolio w: expected return: E w r = w µ variance: V w r = w Σw Dr. Harry Markowitz ( ): maximize w w µ − λw Σw subject to w 0, 1 w = 1 Nobel Memorial Prize in Economic Sciences

Slide 8

Slide 8 text

Portfolio Optimization / problem: how to allocate B amount of money into N assets? assume the log-returns r are i.i.d. Gaussian, then for a portfolio w: expected return: E w r = w µ variance: V w r = w Σw Dr. Harry Markowitz ( ): maximize w w µ − λw Σw subject to w 0, 1 w = 1 criticisms: . sensitivity to estimation errors in µ and Σ . does not consider risk diversification Nobel Memorial Prize in Economic Sciences

Slide 9

Slide 9 text

RiskParity

Slide 10

Slide 10 text

From Capital to Risk Allocation / allocate risk rather than capital

Slide 11

Slide 11 text

From Capital to Risk Allocation / allocate risk rather than capital first risk parity fund ( ): Bridgewater’s All Weather

Slide 12

Slide 12 text

From Capital to Risk Allocation / allocate risk rather than capital first risk parity fund ( ): Bridgewater’s All Weather Bridgewater publishes "Engineering Targeted Returns and Risks" ( )

Slide 13

Slide 13 text

From Capital to Risk Allocation / allocate risk rather than capital first risk parity fund ( ): Bridgewater’s All Weather Bridgewater publishes "Engineering Targeted Returns and Risks" ( ) -onwards: risk parity gains broad adoption

Slide 14

Slide 14 text

From Capital to Risk Allocation / allocate risk rather than capital first risk parity fund ( ): Bridgewater’s All Weather Bridgewater publishes "Engineering Targeted Returns and Risks" ( ) -onwards: risk parity gains broad adoption basic idea: design a portfolio such that the risk is equally distributed among the asset classes (stocks, bonds, real state, etc.)

Slide 15

Slide 15 text

From Capital to Risk Allocation / Relative risk contribution Weight allocation AAPL AMD ADI ABBV AEZS A APD AA CF AAPL AMD ADI ABBV AEZS A APD AA CF 0.0 0.1 0.2 0.3 0.4 0.0 0.1 0.2 0.3 stocks risk parity Markowitz Portfolio capital and risk distribution

Slide 16

Slide 16 text

Risk Parity: Problem Formulation / risk parity portfolio: RCCi = bi , i = 1, 2, . . . , N feasibility problem: find w 0 w subject to wi (Σw) i w Σw = bi , i = 1, 2, . . . , N doesn’t look trivial approximation: Σ is diagonal wi ∝ √ bi √ Σii i.e. inverse volatility portfolio

Slide 17

Slide 17 text

Solution to Risk Parity / Spinu ( ): change of variables x = w √ w Σw , then w = x 1 x problem becomes: Σx = b x minimize x 0 f(x) = 1 2 x Σx − b log(x) optimality condition: ∇f(x) = Σx − b x = 0 then done? it’s not a QP, LP, etc.

Slide 18

Slide 18 text

Cyclical Coordinate Descent (CCD) / Griveau-Billion ( ): Algorithm : CCD to solve risk parity k ← 0, initial x(0) while not converged do for i = 1 to N do xk+1 i ← arg min xi f xk+1 1 , . . . , xk i , . . . , xk N end end closed-form update: xi = − x−i Σ:,i + x−i Σ:,i 2 + 4Σiibi 2Σii , where x−i = [x1, . . . , xi−1, 0, xi+1, . . . , xN ]

Slide 19

Slide 19 text

Non-convex Formulations / limitations of the previous formulation: w 0, 1 w = 1

Slide 20

Slide 20 text

Non-convex Formulations / limitations of the previous formulation: w 0, 1 w = 1 in practice we would like to include l w u, w µ

Slide 21

Slide 21 text

Non-convex Formulations / limitations of the previous formulation: w 0, 1 w = 1 in practice we would like to include l w u, w µ Bruder & Roncalli ( ): minimize w N i=1 wi (Σw)i w Σw − bi 2 subject to 1 w = 1, w ∈ W

Slide 22

Slide 22 text

Non-convex Formulations / limitations of the previous formulation: w 0, 1 w = 1 in practice we would like to include l w u, w µ Bruder & Roncalli ( ): minimize w N i=1 wi (Σw)i w Σw − bi 2 subject to 1 w = 1, w ∈ W how to "solve" the non-convex formulation?

Slide 23

Slide 23 text

Non-convex Formulations / limitations of the previous formulation: w 0, 1 w = 1 in practice we would like to include l w u, w µ Bruder & Roncalli ( ): minimize w N i=1 wi (Σw)i w Σw − bi 2 subject to 1 w = 1, w ∈ W how to "solve" the non-convex formulation? general purpose solvers: slow

Slide 24

Slide 24 text

Non-convex Formulations / Feng & Palomar ( ): minimize w N i=1 [gi (w)]2 + λF(w) subject to 1 w = 1, w ∈ W

Slide 25

Slide 25 text

Non-convex Formulations / Feng & Palomar ( ): minimize w N i=1 [gi (w)]2 + λF(w) subject to 1 w = 1, w ∈ W "convexify" the objective function: fast

Slide 26

Slide 26 text

Non-convex Formulations / Feng & Palomar ( ): minimize w N i=1 [gi (w)]2 + λF(w) subject to 1 w = 1, w ∈ W "convexify" the objective function: fast basic idea: find a "nice" approximation to the non-convex term, solve it, repeat (Scutari et al. )

Slide 27

Slide 27 text

Non-convex Formulations / Feng & Palomar ( ): minimize w N i=1 [gi (w)]2 + λF(w) subject to 1 w = 1, w ∈ W "convexify" the objective function: fast basic idea: find a "nice" approximation to the non-convex term, solve it, repeat (Scutari et al. ) "nice" approximation for gi (w): first order Taylor expansion (Feng & Palomar )

Slide 28

Slide 28 text

Open Source So ware Packages / dppalomar/riskParityPortfolio (R version) dppalomar/riskparity.py (Python version)

Slide 29

Slide 29 text

Basic Usage / R version:

Slide 30

Slide 30 text

Basic Usage / R version: > library(riskParityPortfolio) > my_portfolio <- riskParityPortfolio(Sigma = Sigma, b = b) > names(my_portfolio) [1] "w" "risk_contributions"

Slide 31

Slide 31 text

Basic Usage / R version: > library(riskParityPortfolio) > my_portfolio <- riskParityPortfolio(Sigma = Sigma, b = b) > names(my_portfolio) [1] "w" "risk_contributions" Python version: >>> import riskparityportfolio as rp >>> my_portfolio = rp.RiskParityPortfolio(covariance=Sigma, budget=b) >>> my_portfolio.design() >>> my_portfolio.weights.numpy() >>> my_portfolio.risk_contributions.numpy()

Slide 32

Slide 32 text

Practical Example / library(portfolioBacktest) library(riskParityPortfolio) # download price data faang_data <- stockDataDownload( c("GOOG", "NFLX", "AAPL", "AMZN", "FB"), from = "2014-01-01", to = "2019-06-25") risk_parity <- function(dataset) { prices <- dataset$adjusted log_returns <- diff(log(prices))[-1] return(riskParityPortfolio(cov(log_returns))$w) } bt <- portfolioBacktest( list("risk parity" = risk_parity, "tangency" = max_sharpe_ratio), list(faang_data), T_rolling_window = 12*20, optimize_every = 3*20, rebalance_every = 3*20)

Slide 33

Slide 33 text

Practical Example / backtestChartStackedBar(bt, portfolio = "tangency", legend = TRUE) 0.00 0.25 0.50 0.75 1.00 2015 2016 2017 2018 2019 weight Assets GOOG NFLX AAPL AMZN FB Weight allocation over time for tangency portfolio

Slide 34

Slide 34 text

Practical Example / backtestChartStackedBar(bt, portfolio = "risk parity", legend = TRUE) 0.00 0.25 0.50 0.75 1.00 2015 2016 2017 2018 2019 weight Assets GOOG NFLX AAPL AMZN FB Weight allocation over time for risk parity portfolio

Slide 35

Slide 35 text

Practical Example / backtestChartCumReturns(bt) + theme(legend.position="top") 1 2 3 2015 2016 2017 2018 2019 risk parity portfolio tangency portfolio Cumulative Return

Slide 36

Slide 36 text

Testimonials / "I can easily run optimizations across new covariance matrices in seconds, which has helped streamline portfolio allocation testing" Jonathan Dane, CFA. Director of Portfolio Strategy & Market Research, The Coury Firm. "riskParityPortfolio provides a state-of-the-art implementation of rpps, otherwise only available at the top quantitative hedge funds" Tharsis Souza, PhD. Director of Strategic Innovation, Axioma Inc. Founder, OpenQuants.com. Disclaimer: views, thoughts, and opinions expressed in the text belong solely to the author, and not necessarily to the author’s employer, organization, committee or other group or individual.

Slide 37

Slide 37 text

Takeaways / . risk parity represents a shi from capital allocation to risk allocation

Slide 38

Slide 38 text

Takeaways / . risk parity represents a shi from capital allocation to risk allocation . risk parity portfolios have been praised for their robustness in di erent market "weathers"

Slide 39

Slide 39 text

Takeaways / . risk parity represents a shi from capital allocation to risk allocation . risk parity portfolios have been praised for their robustness in di erent market "weathers" . non-convex? no problem!

Slide 40

Slide 40 text

Takeaways / . risk parity represents a shi from capital allocation to risk allocation . risk parity portfolios have been praised for their robustness in di erent market "weathers" . non-convex? no problem! . GitHub repositories to stay tuned: dppalomar/riskParityPortfolio dppalomar/riskparity.py dppalomar/portfolioBacktest

Slide 41

Slide 41 text

/ Thankyou! Questions?

Slide 42

Slide 42 text

References / H .M. Markowitz. "Portfolio selection". The Journal of Finance. ( ): – , . Y. Feng and D. Palomar, "SCRIP: Successive convex optimization methods for risk parity portfolios design," IEEE Trans. Signal Process., vol. , no. , pp. – , . Scutari et al. "Decomposition by partial linearization: Parallel optimization of multi-agent systems". IEEE Trans. Signal Processing, ( ), – , . B. Bruder and T. Roncalli, "Managing risk exposures using the risk budgeting approach". University Library of Münich, Germany, Tech. Rep., . F. Spinu, "An algorithm for computing risk parity weights". SSRN, . T. Griveau-Billion, "A fast algorithm for computing high-dimensional risk parity portfolios". https://www.thierry-roncalli.com/ download/CCD-Risk-Parity.pdf, . T. Souza, "DIY Ray Dalio ETF: How to build your own Hedge Fund strategy with risk parity portfolios". https://www.openquants.com