Using fminsearch for solving a problem with constraints

12 views (last 30 days)
I have an optimization problem that is suitable for fmincon but fmincon fails to converge. I have to increase the tolerances to absurd levels (22%) to make it work.
I am trying to find an optimum portfolio from a set of 8 assets. The program will determine optimal percentage weight (W) of each asset in the portfolio.
I would like to try fminsearch and therefore have to come up with ways to make sure that:
the weights (variable) don't go negative
and that the weights of all assets add up to 1.
Is there a trick to put either or both of these constraints somewhere (either in the functions or in the optimization tool)?
I have put these constraints in the function and the function by itself works but fminsearch does not work on this function. It stops at zero iteration and gives the following error mesasge:
Output argument "RARV" (and maybe others) not assigned during call to "C:\Users\ ....
The code I am using is the following:
function RARV=RARvariance2(A,B,C,D,E,F,G,H,W)
T=length(A); %Time period, the same for all assets
SW=sum(W);
if abs(SW-1)<.00000001
if W(1,:)>0
DD=[A-mean(A), B-mean(B), C-mean(C), D-mean(D), E-mean(E), F-mean(F), G-mean(G), H-mean(H)]; %Temporal, needed for covariances
Cov=DD'*DD/T;
V=W(1,:)*Cov*W(1,:)';
%Portfolio expected returns
ER=[mean(A), mean(B), mean(C), mean(D), mean(E), mean(F), mean(G), mean(H)]*W(1,:)';
%(Negative) risk adjusted return
RARV=-(ER)/sqrt(V); %Change V to sqrt(V) for semi-standard deviation
else
end
end
Please help. Thanks.

Answers (0)

Categories

Find more on Portfolio Optimization and Asset Allocation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!