[R-SIG-Finance] parma - How to optimize a long/short portfolio with sum( abs( weights )) = 1

u0055 at wolke7.net u0055 at wolke7.net
Thu Aug 21 23:49:01 CEST 2014


Dear R-SIGs,

I'm very happy of finding the package
http://cran.r-project.org/web/packages/DEoptim
for portfolio optimization.
A very cool document is this:
http://cran.r-project.org/web/packages/DEoptim/vignettes/DEoptimPortfolioOptimization.pdf

For all my difficult input matrices of return values
I got solutions with "DEoptim":
- long/short portfolios
- easy adding constraints, e.g:
   sum( abs( weights )) = 1 and/or
   sum( weights ) = 0
- no problems with "positive definite"

The only disadvantage is maybe,
that the solutions are only approximations.
This is because of the different approach,
as pointed out in the vignette documents ...

Best,
Uwe


> Hi Uwe,
>
> Can you let me know if you find an answer? I tried the same thing not
> too long ago and failed… It does not seem that there is a stable
> convergence here… I even tried using continuous approximation for
> abs() function, lima→ϵa2+x2‾‾‾‾‾‾‾√=|x| with different methods for
> solving this…
>
>
>> Dear R-SIGs,
>>
>> I would like to optimize a long/short portfolio and apply the
>> constraint: sum( abs( weights )) = 1. The parma package is very
>> close to that, but I still didn't find a general way, which works
>> for every input matrix of return values.
>>
>> Thanks Alexios, I found the 'parma.tests' with lots of great
>> examples. I think "parma.test11" "Example 6" "riskType='optimal'"
>> is the best choice for what I'm looking for. I'm using that and
>> very often I get warnings: "In Socp(f, A1, b1, NULL, NULL, N1, x,
>> z1, NULL, control) : Dual is not in the feasible hyperplane,
>> solution may be wrong.".
>>
>> 1) Why do I get the warnings ? Is there a work around ?
>>
>> 2) Does anybody have a general solution (R snippet), which works
>> for every input matrix of return values ?
>>
>> Thanks in advance, Uwe
>>
>>
>> ### R snippet begin ###
>>
>> require( corpcor ) require( parma )
>>
>> # returns x=c() x=c(x,0)#0-0 x=c(x,0.00029801026024799343)#1
>> x=c(x,0.01923480801352125)#2 x=c(x,0.0046403921153714825)#3
>> x=c(x,0.03869859235256766)#4 x=c(x,-0.019476139659286133)#5
>> x=c(x,-0.009050645351487118)#6 x=c(x,0.02984309624005349)#7
>> x=c(x,0)#0-1 x=c(x,-0.012975945313424369)#1
>> x=c(x,-0.02407901001552061)#2 x=c(x,0.021245616535913895)#3
>> x=c(x,0.056956457439674014)#4 x=c(x,-0.06073619413646872)#5
>> x=c(x,0.0348564722762156)#6 x=c(x,-0.07581515130311306)#7
>> x=c(x,0)#0-2 x=c(x,0.00029801026024799343)#1
>> x=c(x,0.01923480801352125)#2 x=c(x,0.0046403921153714825)#3
>> x=c(x,0.0386985923399131)#4 x=c(x,-0.019476139659286133)#5
>> x=c(x,-0.009050645351487118)#6 x=c(x,0.029831537955057316)#7
>> x=c(x,0)#0-3 x=c(x,-0.012975945313424369)#1
>> x=c(x,-0.02407901001552061)#2 x=c(x,0.021245616535913895)#3
>> x=c(x,0.05695645745232857)#4 x=c(x,-0.06073619413646872)#5
>> x=c(x,0.0348564722762156)#6 x=c(x,-0.07580359301811687)#7
>> x=c(x,0)#0-4 x=c(x,0.00029801026024799343)#1
>> x=c(x,0.019234808013345154)#2 x=c(x,0.0046403921153714825)#3
>> x=c(x,0.038698591002771045)#4 x=c(x,-0.019476139659286133)#5
>> x=c(x,-0.009050645351487118)#6 x=c(x,0.029814537533275967)#7
>> x=c(x,0)#0-5 x=c(x,-0.012975945313424369)#1
>> x=c(x,-0.024079010015344522)#2 x=c(x,0.021245616535913895)#3
>> x=c(x,0.056956458789470615)#4 x=c(x,-0.06073619413646872)#5
>> x=c(x,0.0348564722762156)#6 x=c(x,-0.07578659259633552)#7
>> x=c(x,0)#0-6 x=c(x,0.00029801026024799343)#1
>> x=c(x,0.019234806760933323)#2 x=c(x,0.0046403921153714825)#3
>> x=c(x,0.03869855234509703)#4 x=c(x,-0.019476139659287156)#5
>> x=c(x,-0.009050645351487125)#6 x=c(x,0.029790636978526824)#7
>> x=c(x,0)#0-7 x=c(x,-0.012975945313424369)#1
>> x=c(x,-0.024079008762932695)#2 x=c(x,0.021245616535913895)#3
>> x=c(x,0.05695649744714464)#4 x=c(x,-0.0607361941364677)#5
>> x=c(x,0.0348564722762156)#6 x=c(x,-0.07576269204158638)#7
>> x=c(x,0)#0-8 x=c(x,0.00029801026025892376)#1
>> x=c(x,0.01923453220069893)#2 x=c(x,0.004640392115430811)#3
>> x=c(x,0.03869828542503245)#4 x=c(x,-0.019476139815127035)#5
>> x=c(x,-0.009050645351487118)#6 x=c(x,0.029768353535081143)#7
>> x=c(x,0)#0-9 x=c(x,-0.0129759453134353)#1
>> x=c(x,-0.024078734202698304)#2 x=c(x,0.021245616535854574)#3
>> x=c(x,0.05695676436720922)#4 x=c(x,-0.060736193980627816)#5
>> x=c(x,0.0348564722762156)#6 x=c(x,-0.07574040859814071)#7
>> x=c(x,0)#0-10 x=c(x,0.0002980103179347729)#1
>> x=c(x,0.01923043617762049)#2 x=c(x,0.004640392486997125)#3
>> x=c(x,0.03869776965250973)#4 x=c(x,-0.01947619048004869)#5
>> x=c(x,-0.009050645351487118)#6 x=c(x,0.02975459006868922)#7
>> x=c(x,0)#0-11 x=c(x,-0.012975945371111148)#1
>> x=c(x,-0.024074638179619856)#2 x=c(x,0.021245616164288255)#3
>> x=c(x,0.056957280139731954)#4 x=c(x,-0.06073614331570616)#5
>> x=c(x,0.0348564722762156)#6 x=c(x,-0.07572664513174876)#7
>> x=c(x,0)#0-12 x=c(x,0.00029803649043954857)#1
>> x=c(x,0.019192162723869248)#2 x=c(x,0.004640656340453675)#3
>> x=c(x,0.0386968409321401)#4 x=c(x,-0.019480064142972733)#5
>> x=c(x,-0.009050645351488088)#6 x=c(x,0.029743057109602365)#7
>> x=c(x,0)#0-13 x=c(x,-0.012975971543615924)#1
>> x=c(x,-0.024036364725868627)#2 x=c(x,0.0212453523108317)#3
>> x=c(x,0.05695820886010157)#4 x=c(x,-0.06073226965278212)#5
>> x=c(x,0.03485647227621657)#6 x=c(x,-0.07571511217266193)#7
>> x=c(x,0)#0-14 x=c(x,0.0002984370859375864)#1
>> x=c(x,0.019062660408625483)#2 x=c(x,0.00465122630987321)#3
>> x=c(x,0.038693166438592115)#4 x=c(x,-0.019521858395814863)#5
>> x=c(x,-0.009050645366251428)#6 x=c(x,0.029737617239541797)#7
>> x=c(x,0)#0-15 x=c(x,-0.012976372139113963)#1
>> x=c(x,-0.023906862410624858)#2 x=c(x,0.021234782341412173)#3
>> x=c(x,0.056961883353649566)#4 x=c(x,-0.06069047539993999)#5
>> x=c(x,0.03485647229097991)#6 x=c(x,-0.07570967230260134)#7
>> x=c(x,0)#0-16 x=c(x,0.0002971799298054011)#1
>> x=c(x,0.018802174294039967)#2 x=c(x,0.0047563932799025285)#3
>> x=c(x,0.038646702644233005)#4 x=c(x,-0.01969350191625727)#5
>> x=c(x,-0.00905064913872669)#6 x=c(x,0.02972290172590976)#7
>> x=c(x,0)#0-17 x=c(x,-0.012975114982981777)#1
>> x=c(x,-0.023646376296039332)#2 x=c(x,0.021129615371382856)#3
>> x=c(x,0.057008347148008676)#4 x=c(x,-0.06051883187949758)#5
>> x=c(x,0.034856476063455176)#6 x=c(x,-0.07569495678896931)#7
>> x=c(x,0)#0-18 x=c(x,0.0002696431479482309)#1
>> x=c(x,0.01844955210532226)#2 x=c(x,0.005163748103738864)#3
>> x=c(x,0.038392434478673985)#4 x=c(x,-0.02006062694298151)#5
>> x=c(x,-0.009050600101314333)#6 x=c(x,0.02961349117308415)#7
>> x=c(x,0)#0-19 x=c(x,-0.012947578201124608)#1
>> x=c(x,-0.023293754107321638)#2 x=c(x,0.02072226054754651)#3
>> x=c(x,0.057262615313567675)#4 x=c(x,-0.060151706852773344)#5
>> x=c(x,0.034856427026042816)#6 x=c(x,-0.0755855462361437)#7
>> x=c(x,0)#0-20 x=c(x,0.00015235255196601426)#1
>> x=c(x,0.018090134670099473)#2 x=c(x,0.005826010999584576)#3
>> x=c(x,0.03781096377417702)#4 x=c(x,-0.02051387732871736)#5
>> x=c(x,-0.009041385295032383)#6 x=c(x,0.029326041084552244)#7
>> x=c(x,0)#0-21 x=c(x,-0.01283028760514239)#1
>> x=c(x,-0.02293433667209884)#2 x=c(x,0.02005999765170081)#3
>> x=c(x,0.057844086018064664)#4 x=c(x,-0.059698456467037496)#5
>> x=c(x,0.03484721221976086)#6 x=c(x,-0.07529809614761179)#7
>> x=c(x,0)#0-22 x=c(x,-0.00010016815499999405)#1
>> x=c(x,0.017581183485064163)#2 x=c(x,0.006409181081122117)#3
>> x=c(x,0.03703441151715984)#4 x=c(x,-0.020933288820437643)#5
>> x=c(x,-0.008896102672098314)#6 x=c(x,0.0289138560987212)#7
>> x=c(x,0)#0-23 x=c(x,-0.012577766898176383)#1
>> x=c(x,-0.022425385487063534)#2 x=c(x,0.01947682757016327)#3
>> x=c(x,0.058620638275081835)#4 x=c(x,-0.05927904497531721)#5
>> x=c(x,0.034701929596826796)#6 x=c(x,-0.07488591116178075)#7
>> x=c(x,0)#0-24 x=c(x,-0.00045768754116740166)#1
>> x=c(x,0.016933958174540985)#2 x=c(x,0.006845027226092256)#3
>> x=c(x,0.036293597180222126)#4 x=c(x,-0.021260198083024463)#5
>> x=c(x,-0.008159185047229593)#6 x=c(x,0.028743274667077524)#7
>> x=c(x,0)#0-25 x=c(x,-0.012220247512008975)#1
>> x=c(x,-0.021778160176540357)#2 x=c(x,0.019040981425193122)#3
>> x=c(x,0.05936145261201955)#4 x=c(x,-0.05895213571273039)#5
>> x=c(x,0.033965011971958066)#6 x=c(x,-0.07471532973013709)#7
>> x=c(x,0)#0-26 x=c(x,-0.0008873151489962878)#1
>> x=c(x,0.016085311475881815)#2 x=c(x,0.007162773178278581)#3
>> x=c(x,0.03563186295203474)#4 x=c(x,-0.02153358198952339)#5
>> x=c(x,-0.006465431369639936)#6 x=c(x,0.028971621313637043)#7
>> x=c(x,0)#0-27 x=c(x,-0.011790619904180089)#1
>> x=c(x,-0.02092951347788118)#2 x=c(x,0.0187232354730068)#3
>> x=c(x,0.06002318684020693)#4 x=c(x,-0.058678751806231465)#5
>> x=c(x,0.03227125829436841)#6 x=c(x,-0.07494367637669659)#7
>> x=c(x,0)#0-28 x=c(x,-0.001352039495111673)#1
>> x=c(x,0.015580897283599052)#2 x=c(x,0.007338821832786869)#3
>> x=c(x,0.034689872867353914)#4 x=c(x,-0.021986525503168198)#5
>> x=c(x,-0.004304639325606844)#6 x=c(x,0.02942721457973837)#7
>> x=c(x,0)#0-29 x=c(x,-0.011325895558064705)#1
>> x=c(x,-0.020425099285598422)#2 x=c(x,0.018547186818498516)#3
>> x=c(x,0.06096517692488776)#4 x=c(x,-0.05822580829258665)#5
>> x=c(x,0.030110466250335324)#6 x=c(x,-0.07539926964279792)#7
>> x=c(x,0)#0-30 x=c(x,-0.0018626750989563113)#1
>> x=c(x,0.015036699574173586)#2 x=c(x,0.007650233219604404)#3
>> x=c(x,0.03305445135619395)#4 x=c(x,-0.022873781833506156)#5
>> x=c(x,-0.00222238149546775)#6 x=c(x,0.029919947705238273)#7
>> x=c(x,0)#0-31 x=c(x,-0.010815259954220066)#1
>> x=c(x,-0.019880901576172963)#2 x=c(x,0.018235775431680975)#3
>> x=c(x,0.06260059843604772)#4 x=c(x,-0.05733855196224869)#5
>> x=c(x,0.02802820842019623)#6 x=c(x,-0.07589200276829783)#7 returns
>> = matrix( x, ncol=32 ) # nrow=8
>>
>> # performs performs = colMeans( returns )
>>
>> # C C = cov( returns ) if( ! is.positive.definite( C )) C =
>> make.positive.definite( C, tol=1e-6 ) ## Alexios: tol=1e-2
>>
>> # spec spec = parmaspec( S = C, risk = 'EV', # EV LPM MiniMax
>> riskType = 'optimal', # minrisk optimal maxreward targetType =
>> 'equality', # equality inequality LB = rep( -1, length( performs
>> )), UB = rep( +1, length( performs )), leverage = 1, budget =
>> NULL, forecast = performs, asset.names = colnames( returns, do.NULL
>> = FALSE ) )
>>
>> # control control = list( abs.tol = 1e-12, rel.tol = 1e-12, Nu =
>> 4, max.iter = 1250, BigM.K = 4, BigM.iter = 15 )
>>
>> # portfolio portfolio = parmasolve( spec, solver.control =
>> control, type = 'SOCP' )
>>
>> ### R snippet end ###



More information about the R-SIG-Finance mailing list