2 views (last 30 days)

I want to determine the optimal allocation of two assets (here "x") such that shortfall probability is minimized.

Shofrtfall probability is derived by applying condition that (if B<b) then sum all incidences and divide by total trials for each "t" and then finally sum the probability of all "t". The value of shortfall probability is 50.55.

When I run fmincon, I get fval=50.55 and the same initial guess of the two weights of two assets.

Following is my code.

%Defined constants inlcude m_e,v_e, m_b,v_b,rho, L,trials,b

x1 = 0.5; %weights of assets

x2 =0.5;

t =1:35; % columns

T = 35; % Total time

x = [eq_share, bd_share]; % total

%simulations

RNx1=normrnd(); % n x m normalized random numbers for first asset

RNx2=normrnd(); % n x m normalized random numbers for second asset

Returnx1= exp(m_e + v_e*(RNx1)); % return on first asset

Returnx2 = exp(m_b+(rho*v_b*RNx1+((1-rho^2)^0.5)*v_b*RNx2)); % return on second asset

Returnportfolio = x1*Returnx1+(x2)*Returnx2; % portfolio returns

W = max(L*Returnportfolio,0); % Matrix of wealth

B = min(b,L*Returnportfolio); % Realized Benefit

p= B<b

S=(cumsum(B<b, 2) == 1) .* (B<b)

shortfallprobability =sum(S)./trials

%% Optimal allocation

options = optimoptions('fmincon','Display','iter','Algorithm','sqp');

opts.Algorithm = 'sqp';

f = @(x) shortfallprobability

[n,fval] = fmincon(f,[0.5 0.5],[],[],[],[],[],[],[],options)

When I run the program, I get

function_handle with value:

@(x) sum((sum((cumsum(B<b,2)==1).*(B<b))./sim))

Iter Func-count Fval Feasibility Step Length Norm of First-order

step optimality

0 3 5.055392e-01 0.000e+00 1.000e+00 0.000e+00 0.000e+00

Initial point is a local minimum that satisfies the constraints.

Optimization completed because at the initial point, the objective function is non-decreasing

in feasible directions to within the value of the optimality tolerance, and

constraints are satisfied to within the value of the constraint tolerance.

<stopping criteria details>

n =

0.5 0.5

fval =

0.505539191954337

Can you please check the code and my mistake. I am sorry to bother as I have already spent much time on it but could not figure out.

Is my fmincon setup ok?

can I use fmincon for this problem?

Am I definining objective function wrongly?

Alan Weiss
on 31 Jul 2020

Edited: Alan Weiss
on 31 Jul 2020

The problem is the you have not defined your objective function as a separate file that the optimization calls. You need to write a file something like this:

function f = shortfallprobability(x,RNx1,RNx2,m_e,m_b)

Returnx1= exp(m_e + v_e*(RNx1)); % return on first asset

Returnx2 = exp(m_b+(rho*v_b*RNx1+((1-rho^2)^0.5)*v_b*RNx2)); % return on second asset

Returnportfolio = x1*Returnx1+(x2)*Returnx2; % portfolio returns

W = max(L*Returnportfolio,0); % Matrix of wealth

B = min(b,L*Returnportfolio); % Realized Benefit

p = B<b

S = (cumsum(B<b, 2) == 1) .* (B<b)

f = sum(S)./trials

end

Take the corresponding lines out of your code. Then call the solver like this:

f = @(x)shortfallprobability(x,RNx1,RNx2,m_e,m_b);

[n,fval] = fmincon(f,[0.5 0.5],[],[],[],[],[],[],[],options)

Alan Weiss

MATLAB mathematical toolbox documentation

Opportunities for recent engineering grads.

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

Start Hunting!
## 0 Comments

Sign in to comment.