[R-SIG-Finance] Is there a general solution (package) for a portfolio optimization ?

Patrick Burns patrick at burns-stat.com
Sat Jul 5 12:45:28 CEST 2014


I'd say those calls are doing the
right thing for (sort of) the wrong
reason.

If the variance matrix input into a
portfolio optimization is singular,
then the optimizer will think that an
eigenvector associated with a zero
eigenvalue gives you a riskless portfolio.

If you were to get an answer out of this
problem, it would almost certainly be a
poor answer.

Pat

On 05/07/2014 11:20, u0055 at wolke7.net wrote:
> Dear R-SIGs,
>
> I am wondering,
> why it is that difficult for me,
> to find a general solution for a portfolio optimization in R.
>
> I would like to calculate the weights vector.
> For some return matrices it's working well,
> for other matrices I get error messages.
> I had a closer look to this 3 packages / functions / errors:
>
> 1) tseries / portfolio.optim /
> Fehler in solve.QP(Dmat, dvec, Amat, bvec = b0, meq = 2) :
>    matrix D in quadratic function is not positive definite!
>
> 2) ghyp / portfolio.optimize /
> Error in solve.default(sigma) :
>    System ist für den Rechner singulär: reziproke Konditionszahl =
> 1.04036e-17
> Warning: fitting procedure did not converge!
>
> 3) fPortfolio / efficientPortfolio /
> The result for the weights is a zero vector.
>
> Here my input matrix m of log. returns
> for 5 assets (columns) and 21 return values (rows).
> Please don't be confused by the strange initialization of m:
>
> x = c(
> 0.0004101995964433642, -0.00018580025947176148, 0.0001921211753136999,
> -0.0009374090928287272, 0.02179035825399216, -0.0008010181637519165,
> 0.02762103313486072, -0.02059593202791299, 0.009890131347811582,
> 0.008874502330834042, 0.03270962505025148, 0.0004709525370067878,
> -0.026172393520773156, -0.002070884888637307, -0.021394084189246338,
> 0.014663881480845464, 0.000007589055248672503, 0.03357767208442292,
> 0.007489994621009966, 0.0354779091735148, -0.004488890361817627,
> 0.0006037637415494107, -0.0001747374366735466, 0.0002776560800516695,
> -0.0010539757116864686, 0.007217907272059155, -0.0009999339576310352,
> 0.0018097094037338678, -0.0072761973581043134, 0.007274147797504215,
> 0.011722205826326859, 0.0284076103749228, 0.00020854896466472906,
> -0.027139287243448704, 0.0009288913408461102, -0.013985585851090089,
> 0.008355345607646895, 0.005703625000569552, 0.031154509412550213,
> 0.008409491754987508, 0.050116507149955865, -0.002471235927845941,
> 0.0004329670989004567, -0.00014108375322680291, 0.00024873249512844,
> -0.0007654340066147783, 0.018092403293930987, -0.0015557105255950537,
> 0.015910756127921546, -0.01736078352542159, 0.008348345947451275,
> 0.007744974101786212, 0.029968431702077265, 0.0016856756212381618,
> -0.0252969523459683, -0.0006213069455005302, -0.01923409835975207,
> 0.012209755091657625, 0.0007510294849596395, 0.03210686006944077,
> 0.006634533610756534, 0.04169475959584361, -0.0025908541571262045,
> 0.0005954295776526556, -0.00013175957287530423, 0.0002509094271978344,
> -0.0009448108075862921, 0.007528674135685146, -0.0014060182806468655,
> 0.0008597209029989182, -0.007178209888799298, 0.00689554753496824,
> 0.009766184066262252, 0.02818192946497762, -0.004207950567021389,
> -0.023491857691380978, 0.0005314474698686129, -0.015464139804048354,
> 0.008342940298155603, 0.005682816731364199, 0.03209078200750012,
> 0.00815688540306469, 0.04912648130491875, -0.004043194319244131,
> 0.0004677174973875975, -0.00007283224369502313, 0.0003351392464246223,
> -0.0005029457171303313, 0.012448156249627087, -0.002707609393671422,
> -0.001962824566880327, -0.012422925284776823, 0.005995094546901327,
> 0.006020957331134253, 0.025784505012758727, 0.0035397266445386837,
> -0.023960752658108264, 0.0015912067571819243, -0.015937277883155545,
> 0.008463983234476183, 0.001885754351360598, 0.029861936467625895,
> 0.005328829963527624, 0.05118363655624024, 0.0003061484710870088 )
> m = matrix( x, ncol=5 ) # nrow=21
>
> Here the corresponding mean return vector of my 5 assets:
> [ 0.005549026539862658, 0.00519471267813756, 0.005155380981994628,
> 0.004816276542524382, 0.004554553551564478 ].
> In my tests I chose 0.005 as the target return value,
> it should have a solution.
>
> Is there a package available,
> which would calculate solutions for the weights
> for a general input return matrix ?
>
> Do I have to do some pre-calculations
> before calling the optimization function ?
>
> Is there some mistake in my way of thinking about optimization ?
> Do other people have the same problem ?
> How do they calculate their weight vectors ?
>
> Thanks in advance,
> Uwe
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.

-- 
Patrick Burns
patrick at burns-stat.com
http://www.burns-stat.com
http://www.portfolioprobe.com/blog
twitter: @burnsstat @portfolioprobe



More information about the R-SIG-Finance mailing list