Minimizing a scalar value using "fmincon" derived through many variables
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
susman
el 27 de Jul. de 2020
I have portfolio optimal allocation problem (two assets equity and bond) and I want to use "fmincon" to minimize "PCS", which is probability of consumption shortfall.
Using Matlab code I have derived the "PCS" which is a scalar. The code is below:
Return_portfolio = equity_share*Return_equity+(1-equity_share)*Return_bond
W = matrix of wealth in each period
B = matrix of withdrawal in each period
P = (B < b); % matrix showing the incidence of shortfall (realized benefit is less than target)
S = (cumsum(P, 2) == 1) .* P; % Finding the first incidence of shortfall
shortprob = sum(S)/sim; % vector of shortfall probability
PCS = sum(shortprob) ; % Probability of consumption shortfall
Now I want to minimize PCS by chooing right allocation (weight) of portfoilio. Initially I assumed it to be 0.5. This is my "fmincon" set up
fun = @(eq_share) PCS
x0 = [0.5; 0.5]; % initial weight of two assets
Aeq = [1, 1; ER_equity, ER_bonds];
beq = [1; CS];
lb = [0, 0];
ub = [1, 1];
[weights, PCS] = fmincon(fun, x0, Aeq, beq, lb, ub);
Can anyone tell me how is the set up correct because I am not even able to set it because my PCS is scalar and I do not how to define it in a function.
0 comentarios
Respuesta aceptada
Matt J
el 27 de Jul. de 2020
Editada: Matt J
el 27 de Jul. de 2020
Much is unclear from your post including what your unknowns are and how they determine shortprob. However, if S is a function of the unknowns, then it is clear that fmincon is not applicable to your problem. In particular, S is a binary-valued matrix and therefore sum(S) can only assume a finite number of values. That means PCS cannot be a continuous, differentiable function of whatever the unknowns are, and therefore it cannot be minimized by a derivative-based solver like fmincon.
8 comentarios
Matt J
el 28 de Jul. de 2020
Yes. I gather that you only have a single unknown variable, eq_share. If so, you can just use fminbnd. Unlike fmincon, the algorithm used by fminbnd does not require differentiability.
Más respuestas (1)
Walter Roberson
el 27 de Jul. de 2020
Editada: Walter Roberson
el 27 de Jul. de 2020
W = matrix of wealth in each period
B = matrix of withdrawal in each period
fun = @(eq_share) PCS(eq_share, W, B);
x0 = [0.5; 0.5]; % initial weight of two assets
Aeq = [1, 1; ER_equity, ER_bonds];
beq = [1; CS];
lb = [0, 0];
ub = [1, 1];
[weights, PCS] = fmincon(fun, x0, Aeq, beq, lb, ub);
function prob_comp_shortfall = PCS(equity_share, W, B)
Return_portfolio = equity_share*Return_equity+(1-equity_share)*Return_bond
P = (B < b); % matrix showing the incidence of shortfall (realized benefit is less than target)
S = (cumsum(P, 2) == 1) .* P; % Finding the first incidence of shortfall
shortprob = sum(S)/sim; % vector of shortfall probability
prob_comp_shortfall = sum(shortprob) ; % Probability of consumption shortfall
end
Except that you need to define Return_equity and Return_bond, and b, and sim, and you do not use Return_porfolio in calculating PCS.
Your equity_share is going to be received as a 1 x 2 vector, implying two things to be optimized independently. However when I see you use (1-equity_share) it looks to me more like you are trying to decide a single weight. Unless, that is, you have a whole series of equity and bonds that for some reason are paired? I am having difficulty figuring out why you would want to do that... but if there is a reason to define a whole series of equity / bond balances, then I would normally expect that you would have one variable for each of them rather than exactly two variables to optimize.
With you having two variables, Return_portfolio seems likely to become a vector... it is not clear how that would fit into the calculations below that point. Also not clear what W is doing for your PCS calculation.
Also, your constraints are confused. The top row of AEQ, [1 1], together with the [1] at top of beq, tells us that
1*eq_share(1) + 1*eq_share(2) == 1
but if you really only had two variables and you had that definition, then you would reduce down to a single variable and use 1-variable for the second variable, much like you did in your Return_portfolio calculation.
When you then look at the bottom Aeq beq in combination with that, you have
x(1) * ER_equity + (1-x(1)) * ER_bonds == CS
which has exactly one solution,
x(1) == (CS - ER_bonds)/(ER_equity - ER_bonds)
and since those are equality constraints, those define that there is exactly one valid value for x(1), in which case there is no point doing an optimization.
2 comentarios
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!