[R-SIG-Finance] FPortfolio / MAxReturnPortfolio

alexios ghalanos alexios at 4dscape.com
Tue Jul 8 10:21:23 CEST 2014


I believe Pat has already addressed this issue in his previous email to
you and the list.

If on the other hand you want to "jiggle" your matrix a little to make
it PD, then use the 'make.positive.definite' function from the corpcor
package.

Regards,

Alexios

On 08/07/2014 09:02, u0055 at wolke7.net wrote:
> Hello Alexios,
> 
> I read the parma docu and the parma package seems to be great stuff.
> 
> "S" needs to be a
> "m-by-m positive definite covariance matrix",
> but in general a covariance matrix can also be not PD.
> 
> Do you know any R snippet or package,
> which works for any covariance matrix
> (including not PD ones, like the attached one) ?
> 
> Thanks in Advance
> Uwe
> 
> 
>> I'm not too familiar with how fPortfolio works, but since you asked for
>> "alternative code" here is how you can do this with parma:
>>
>> ###############
>> library(parma)
>> spec = parmaspec(S = cov(datamatrix), riskB=0.1,
>> risk="EV",riskType="maxreward", LB = rep(0,8), UB = rep(1,8), budget=1,
>> forecast=colMeans(datamatrix))
>> weights(parmasolve(spec, solver="SOCP"))
>> #############
>>
>> Note the following:
>> 1. The risk (riskB) is an upper bound since this is an inequality
>> constraint (less than or equal to), and is available to solve for
>> covariance inputs using an SOCP solver (you can also solve QCQP problems
>> as well).
>> 2. The solution can be completely dominated by one asset (as in the
>> case above) unless you change risk bound or constraints (UB, LB or some
>> other linear combinations ... see documentation)
>> 3. You MUST provide a forecast vector (which is not all zeros).
>>
>> Regards,
>>
>> Alexios
> 
> 
> ############
> library(parma)
> 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
> spec = parmaspec(S = cov(m), riskB=0.1,
> risk="EV",riskType="maxreward", LB = rep(0,8), UB = rep(1,8), budget=1,
> forecast=colMeans(m))
> parmasolve(spec, solver="SOCP")
> ############
> 
>



More information about the R-SIG-Finance mailing list