Hi, my problem is that an optimization with fmincon (see below) is not stable, i.e. various runs deliver various results. The optimization problem is described as below:
Many thanks in advance for your help!
Best Wishes, Alex
The function to be optimized:
fun=@(x)x*meanOrRegressed
The non-linear constraint (Sum of all positive weights not above 1.3 and sum of all negative weights not below -0.3:
function [c,ceq,gradc,gradceq]=nonlcon_g(x,1.3,0.3) nrAssets=size(x,1); weightSumMax = sum(max(0,x(1:nrAssets-1))); c(1) = weightSumMax-1.3; weightSumMin = sum(min(0, x(1:nrAssets-1))); c(2) = -weightSumMin-0.3; gradc1=1/2*(sign(x(1:nrAssets-1))+ones(nrAssets-1,1)); gradc1=vertcat(gradc1,0); gradc2=1/2*(sign(x(1:nrAssets-1))-ones(nrAssets-1,1)); gradc2=vertcat(gradc2,0); gradc=horzcat(gradc1,gradc2); ceq =[]; gradceq=[];end[weights,optimizedValue,exitflag] = fmincon(@fun,initialWeights',A,b,Aeq,beq,lowerBound,upperBound,@nonlcon_g,options)A = -1 -1 -1 -1 -1 0 1 1 1 1 1 0 0 0 0 0 0 -1 0 0 0 0 0 1b = 0.3 1.3 0.3 1.3Aeq = 1 1 1 1 1 1beq = 1lowerBound = -0.3 -0.3 -0.3 -0.3 -0.3 -0.3upperBound = 1.3 1.3 1.3 1.3 1.3 1.3 1 3meanOrRegressed = 2.349096891796729e-004 -7.582259013820250e-005 1.190461785891006e-003 2.529756213317396e-003 1.066862350689632e-003 5.133561643835617e-005options = Display: []MaxFunEvals: 60000MaxIter: 40000TolFun: 1.000000000000000e-010TolX: []FunValCheck: []OutputFcn: []PlotFcns: []ActiveConstrTol: []Algorithm: 'active-set'AlwaysHonorConstraints: []BranchStrategy: []DerivativeCheck: []Diagnostics: []DiffMaxChange: []DiffMinChange: []FinDiffRelStep: []FinDiffType: 'forward'GoalsExactAchieve: []GradConstr: 'on'GradObj: []HessFcn: []Hessian: []HessMult: []HessPattern: []HessUpdate: []InitialHessType: []InitialHessMatrix: []InitBarrierParam: []InitTrustRegionRadius: []Jacobian: []JacobMult: []JacobPattern: []LargeScale: []LineSearchType: []MaxNodes: []MaxPCGIter: []MaxProjCGIter: []MaxRLPIter: []MaxSQPIter: 200000MaxTime: []MeritFunction: []MinAbsMax: []NodeDisplayInterval: []NodeSearchStrategy: []NoStopIfFlatInfeas: []ObjectiveLimit: []PhaseOneTotalScaling: []Preconditioner: []PrecondBandWidth: []RelLineSrchBnd: []RelLineSrchBndDuration: []ScaleProblem: []Simplex: []SubproblemAlgorithm: []TolCon: 1.000000000000000e-008TolConSQP: []TolGradCon: []TolPCG: []TolProjCG: []TolProjCGAbs: []TolRLPFun: []TolXInteger: []TypicalX: []UseParallel: 'always'
Best Answer