Skip to content

Translate the parma package portfolio objectives and constraints to CVXR compatible code to be used in a new tsport package

keunwoolim edited this page Mar 31, 2023 · 2 revisions

Background

The parma package solves a set of portfolio optimization problems using LP, QP, SOCP and NLP based approaches, with the latter using analytic derivatives for objectives and Jacobians for constraints. Some non-smooth problems are approximated with smooth counterparts to avoid discontinuities, but almost all problems are convex. Uniquely at its release time, the package offered fractional programming solutions for directly solving the reward-risk ratio as described in Charnes and Cooper (1973) and summarized in Stoyanov et al. (2007), as well as benchmark relative optimization. The set of portfolio optimization problems in parma are all mathematically described in the June 13, 2022 parma vignette, available on CRAN.

The primary goal of this project is to incorporate the CVXR functionality into a new tsport package in the existing tsmodels family of packages. The first step of the project is to implement all of the optimization problems currently in parma in the CVXR optimization modeling language, i.e., convert the currently implemented portfolio objective functions and constraints into CVXR-compatible problems. Then implement these in the tsport package. CVXR is an R package that provides an object-oriented modeling language for convex optimization, which interfaces to a wide variety of commercial and open-source solvers. See the table of Supported Solvers at CVXR. The underlying CVX modeling system is described (here)[https://www.cse.iitb.ac.in/~cs709/notes/code/cvx/doc/intro.html].

An additional goal is to extend the list of objective functions in parma to include the expected quadratic shortfall (EQS), known as the second moment coherent risk measure (SMCR) in Krokhmal (2007), to be directly estimated using CVXR, and included in tsport.

A third goal, if time and feasibility, permits is to include reward-EQS risk optimization in the set of fractional programming solutions in tsport.

References

Krokhmal, P. "Higher moment coherent risk measures." Quantitative Finance 7.4 (2007): 373-387.

Charnes, A., and W. W. Cooper. "An explicit general solution in linear fractional programming." Naval Research Logistics Quarterly 20.3 (1973): 449-467.

Stoyanov, Stoyan V., Svetlozar T. Rachev, and Frank J. Fabozzi. "Optimal financial portfolios." Applied Mathematical Finance 14.5 (2007): 401-436.

Related Work

The parma package solves a fixed set of problems (including minimum risk, optimal risk-reward, and benchmark relative optimization) given a fixed subset of constraints (e.g., box, budget, turnover etc.), but with hardcoded analytical derivatives for NLP. On the other hand, the PortfolioAnalytics (PA) package solves a more open set of problems using ROI, CVXR and DEoptim. The parma and PA packages also differ in their interfaces with PortfolioAnalytics aiming for optimal flexibility using a multi-stage recipe type system for building a problem, while parma uses a single stage recipe. There are tradeoffs to both approaches, and the anticipated side result of this tsport project will set the stage to analyze these trade-offs later.

Details of Coding Project

The first deliverable is to translate the currently implemented parma objective functions and constraints into compatible problems which can be solved by CVXR. This will then be incorporated into the tsport package with the help of the tsmodels package author and maintainer.

The second deliverable is to implement the expected quadratic shortfall (EQS) problem using CVXR, and then evaluate the relative performance of minimum variance (minVar), minimum expected shortfall (minES), and minimum expected quadratic shortfall (minEQS) portfolios, using the monthly, weekly and daily CRSP stocks data that is available in the PCRA package on CRAN.

Expected Impact

Incorporating CVXR into tsport will enable faster implementation of new portfolio optimization capabilities (since there will be no need to hardcode the analytic derivatives for each problem), a more robust and unified solution interface (CVXR problem formulation) and eventually the ability to make the interface more flexible (from the current single stage step recipe approach).

Mentors

EVALUATING MENTOR: Alexios Galanos (alexios@4dscape.com) PhD is the author and maintainer of the parma, rmgarch, Rsolnp, rugarch and spd packages on CRAN, and an integrated Time Series Framework tsmodels on github.

Doug Martin (martinrd3d@gmail.com) has been a GSOC Mentor for many years. Some details concerning Doug are available at https://www.risk.net/author/r-douglas-martin.

Steve Murray (sm.murray@comcast.net) is Director of Asset Allocation and Investment Solutions, Russell Investments, Seattle, WA, an Affiliate Instructor in the University of Washington MS-CFRM Program, and a GSOC 2022 Mentor.

Tests

Given the following portfolio problems and their solutions from parma, generate the equivalent formulation using CVXR and compare the results. The parma codes are provided below, please post equivalent solutions using CVXR.

common setup code

library(parma)
library(xts)
data("etfdata")
Data <- etfdata/lag(etfdata) - 1
Data <- na.omit(Data)

Test 1

spec <- parmaspec(S = cov(Data), forecast = colMeans(Data), risk = "EV", target = mean(colMeans(Data)), targetType = "equality", riskType =  "minrisk", LB = rep(0, 15), UB = rep(1, 15), budget = 1)
solution <- parmasolve(spec, type = "QP")

Test 2

spec <- parmaspec(scenario = Data, forecast = colMeans(Data), risk = "MAD", target = mean(colMeans(Data)), targetType = "equality", riskType = "minrisk", LB = rep(0, 15), UB = rep(1, 15), budget = 1)
solution <- parmasolve(spec, type = "LP")

Solutions for Tests

Contributor Name GitHub Profile Test Results
Arepalli Yashwanth Reddy https://github.com/bugslayer-332 https://github.com/bugslayer-332/testSolutions
Keunwoo Lim https://github.com/keunwoolim https://github.com/keunwoolim/gsoc_test
Contributors, please post a link to your test results here:
Clone this wiki locally