Skip to content
Prev 11939 / 15274 Next

Parma Package QP optimization Failing and Ignoring Leverage Constraint

Nothing (almost) prevents you from doing what the blog post has done in
parma:
##################################################
library(parma)
# get it from r-forge which includes a fix for the eq.mat
# constraint in the QP case (works for Rev. 7)
library(quadprog)
data(etfdata)
library(timeSeries)
R = returns(etfdata)
RB = cbind(R, -R)
V = cov(R)
VV <- rbind( cbind(V,-V), cbind(-V,V) )
VV <- kronecker( matrix(c(1,-1,-1,1), 2), V )
# Make PD by truncation...
e <- eigen(VV)
VV <- e$vectors %*% diag(pmax(1e-12,e$values)) %*% t(e$vectors)
A = matrix(c(rep(1,15),rep(-1,15)), ncol=30)
# budget constraint
b <- 0
# budget constraint in the parmaspec then becomes leverage constraint
spec<-parmaspec(S=VV,forecast=as.numeric(c(100*abs(colMeans(R)),
-100*abs(colMeans(R)))), LB=rep(0,30),UB=rep(0.05,30), eq.mat=A, eqB=b,
budget=0.2,risk='EV',riskType='minrisk',target=0.0030346)

# or don't include the 'budget' constraint
# spec<-parmaspec(S=VV,forecast=as.numeric(c(100*abs(colMeans(R)),
#-100*abs(colMeans(R)))), LB=rep(0,30),UB=rep(0.05,30),
# budget=0.2,risk='EV',riskType='minrisk',target=0.0030346)

mysol <- parmasolve(spec, type='QP')
w = weights(mysol)[1:15] - weights(mysol)[16:30]
# round(w, 5)
0.00000 -0.01722  0.00000  0.00000  0.02495  0.01118  0.00567  0.01648
-0.02124  0.00953  0.00955 -0.04315 -0.01838  0.00413  0.01851
# sum(abs(w))
0.2
# sum(w)
-4.722557e-14
################################################
The solution or not will of course depend on the consistency of the
constraints placed (so no solution likely means inconsistent constraints).

Finally, this particular method of imposing the leverage constraint is
already partially alluded to in the vignette at the bottom of page 18
and a related paper. I am still unsure how stable the approach is (cases
of non PD matrix) and how important the assumptions are.


-Alexios
On 01/10/2013 07:23, Preston Li wrote: