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

u0055 at wolke7.net u0055 at wolke7.net
Sat Jul 5 14:20:05 CEST 2014


Thanks Pat,

I agree,
there can be return matrices,
which have weight vectors,
which result in riskless portfolios.
If this is the reason,
why multiple optimization packages stop working
(giving errors),
it would be a good idea to have a distinction of 2 cases:
a) If there is no riskless portfolio,
then give out the optimal weight vector.
b) If there is one or more riskless portfolio(s),
then give out one of the weight vectors.

How can I calculate one of the weight vectors
of a riskless portfolio ?

There are programs out there,
which calculate a weight vector for every input return matrix.
How do they work ?

Thanks in advance,
Uwe

PS:
> m
                [,1]          [,2]          [,3] [,4]          [,5]
  [1,]  4.101996e-04  0.0006037637  0.0004329671  0.0005954296 4.677175e-04
  [2,] -1.858003e-04 -0.0001747374 -0.0001410838 -0.0001317596 -7.283224e-05
  [3,]  1.921212e-04  0.0002776561  0.0002487325  0.0002509094 3.351392e-04
  [4,] -9.374091e-04 -0.0010539757 -0.0007654340 -0.0009448108 -5.029457e-04
  [5,]  2.179036e-02  0.0072179073  0.0180924033  0.0075286741 1.244816e-02
  [6,] -8.010182e-04 -0.0009999340 -0.0015557105 -0.0014060183 -2.707609e-03
  [7,]  2.762103e-02  0.0018097094  0.0159107561  0.0008597209 -1.962825e-03
  [8,] -2.059593e-02 -0.0072761974 -0.0173607835 -0.0071782099 -1.242293e-02
  [9,]  9.890131e-03  0.0072741478  0.0083483459  0.0068955475 5.995095e-03
[10,]  8.874502e-03  0.0117222058  0.0077449741  0.0097661841 6.020957e-03
[11,]  3.270963e-02  0.0284076104  0.0299684317  0.0281819295 2.578451e-02
[12,]  4.709525e-04  0.0002085490  0.0016856756 -0.0042079506 3.539727e-03
[13,] -2.617239e-02 -0.0271392872 -0.0252969523 -0.0234918577 -2.396075e-02
[14,] -2.070885e-03  0.0009288913 -0.0006213069  0.0005314475 1.591207e-03
[15,] -2.139408e-02 -0.0139855859 -0.0192340984 -0.0154641398 -1.593728e-02
[16,]  1.466388e-02  0.0083553456  0.0122097551  0.0083429403 8.463983e-03
[17,]  7.589055e-06  0.0057036250  0.0007510295  0.0056828167 1.885754e-03
[18,]  3.357767e-02  0.0311545094  0.0321068601  0.0320907820 2.986194e-02
[19,]  7.489995e-03  0.0084094918  0.0066345336  0.0081568854 5.328830e-03
[20,]  3.547791e-02  0.0501165071  0.0416947596  0.0491264813 5.118364e-02
[21,] -4.488890e-03 -0.0024712359 -0.0025908542 -0.0040431943 3.061485e-04


Am 05.07.2014 12:45, schrieb Patrick Burns:
> 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.



More information about the R-SIG-Finance mailing list