COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Mean Variance optimization with FMINCON

• Email
• Follow

```Hi All,
I have just started with Matlab, and struggle with the following problem -
optimization of 3-assets portfolio:

ExpRet = [0.1  0.2  0.15];
ExpCov = [0.005  -0.010  0.004;  -0.010  0.040  -0.002;  0.004  -0.002  0.023];

%My goal is to minimize the function for portfolio variance (saved in Weights.m):
function [Weights] = f(w,ExpCov)
Weights = w'*ExpCov*w
%I believe my problem lies in the objective function

%Given:
ExpRet = [0.1  0.2  0.15];
ExpCov = [0.005  -0.010  0.004;  -0.010  0.040  -0.002;  0.004  -0.002  0.023];
TargetReturn=0.15;
X0=zeros(3,1);
Aeq = [ExpRet;ones(1,3)];
Beq = [TargetReturn;1];
LB = zeros(3,1);
UB = ones(3,1);

[OptimalWeights, OptimalVariance] = fmincon(@Weights,X0,[],[],Aeq,Beq,LB,UB);

I would be extremely grateful for your insight.
```
 0

See related articles to this posting

```ADam Skoczynski wrote:
> Hi All, I have just started with Matlab, and struggle with the following
> problem -
> optimization of 3-assets portfolio:
>
> ExpRet = [0.1  0.2  0.15];
> ExpCov = [0.005  -0.010  0.004;  -0.010  0.040  -0.002;  0.004  -0.002
> 0.023];
>
> %My goal is to minimize the function for portfolio variance (saved in
> Weights.m):
> function [Weights] = f(w,ExpCov)
> Weights = w'*ExpCov*w
> %I believe my problem lies in the objective function
>
> %Given:
> ExpRet = [0.1  0.2  0.15];
> ExpCov = [0.005  -0.010  0.004;  -0.010  0.040  -0.002;  0.004  -0.002
> 0.023];
> TargetReturn=0.15;
> X0=zeros(3,1);
> Aeq = [ExpRet;ones(1,3)];
> Beq = [TargetReturn;1];
> LB = zeros(3,1); UB = ones(3,1);
> [OptimalWeights, OptimalVariance] =
> fmincon(@Weights,X0,[],[],Aeq,Beq,LB,UB);
>
> I would be extremely grateful for your insight.
1. You are correct in believing you did not write the objective function
correctly. Take a look at the documentation, or at least an example
where it is done correctly.
http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brhkghv-3.html
http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brn4nh7.html
To pass the ExpCov parameters, see
http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brhkghv-7.html
Weights = @(w)w'*ExpCov*w;
Pass this form of the function without an @ sign (I mean the syntax is
fmincon(Weights,X0,...))
http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brhkghv-18.html#brhkghv-19

Good luck,

Alan Weiss
MATLAB mathematical toolbox documentation
```
 0

1 Replies
1671 Views

Similar Articles

12/7/2013 8:40:11 AM
page loaded in 39330 ms. (0)

Similar Artilces:

What Does Optimization Mean?
I understand that MASM32 and HLA do not use optimization when they use user32 functions from user32 library such as WinMain, CreateWindow, ShowWindow, UpdateWindow, DestroyWindow, DispatchMessage, and TranslateMessage including WindowProc. It looks like total 8 functions that we need to use. It is why MASM32 only show 2-3K size rather than 38K on pure C runtime. MASM32 and HLA do not use optimization, but it always improve performance because it has the shorest 8 routines as functions that we need. Optimization is used to take out some x86 instructions that they are not needed. Is it correct that optimization is defined to reduce the byte size by removing some unneeded instructions or extra instructions? Do you think that I am satisifed with MASM32 and HLA that it can run much faster with only 8 functions. I prefer to use MASM32 as my programmer. Why do I have to move to HLA? Is it because HLA is much easier for reading than MASM32? It does not mean that it is good to use HLA for the beginning, but it is useful for both beginners and advanced users. Please advise. -- Bryan Parkoff "Bryan Parkoff" <nospam@nospam.com> wrote in message news

Optimization and memory-mapped I/O
entitled to optimize this to > : PULSE ( addr -- ) > 0 SWAP ! ; > > ? If so, that would defeat the whole purpose of this word. I'd be plenty mad if that happened! I remember many years ago trying to round a number in a Fortran program by going: N = X X = N ....and that was optimized out of existence! But, practically speaking, most optimizing compilers have ways to turn off optimization temporarily, which would be useful in such a case. > I notice that section A.3.1.3.3 of the standard says "A Standard > Program may never assume a particular... notices that the end result of executing PULSE is always > > to leave 0 in the addressed location. > > It doesn't know that writing 1 to that address has a side effect. > > > Is the compiler entitled to optimize this to > > : PULSE ( addr -- ) > > =A0 =A00 SWAP ! ; > > > ? =A0 If so, that would defeat the whole purpose of this word. > > I'd be plenty mad if that happened! =A0 >=A0But, practically speaking, > most optimizing compilers have ways to turn off optimization > temporarily, which would be useful in such a case. How about

output function of optimization toolbox, realtime update?
Hei there, i have a small problem with my fitting program, i want to have a real time output of the current iteration and optimization values in a text box, but the program only updates the text of the textbox at the end of the fitting... the used code: set(handles.out_txt, 'String', ''); function stop = outfun(x,optimValues,state) stop = false; guidata(hObject, handles); switch state case 'init' hold on case 'iter' str=cellstr(get(handles.out_txt, 'String')); str=[str; cellstr(sprintf('%s \t %s', int2str(optimValues.iteration), int2str(optimValues.firstorderopt)))]; if length(str)>6 new_str=str(2:7); str=new_str; end set(handles.out_txt, 'String',str); guidata(hObject, handles); case 'done' hold off otherwise end end %%fitting procedure with the optimization toolbox options=optimset('OutputFcn', @outfun); [param,resnorm,residual,exitflag,output,lambda

[CFP] Natural-Computing Algorithms and Optimization of Bioprocesses (NAMOB
TITLE: Natural-computing Algorithms to Modeling and Optimization of Bioprocesses (NAMOB-2005) This special session will be presented at ICANNGA05 (http://icannga05.dei.uc.pt/), Coimbra, Portugal, 21-23 March 2005. The conference proceedings will be published by Springer-Verlag. TOPICS OF INTEREST (not limited to): Techniques: Artificial Neural Networks; Genetic and Evolutionary Computation; Ant colonies; Swarm intelligence; Simulated Annealing; Tabu Search; Hybrid systems. Applications: Modelling of biological and ecological processes; Adaptive control of biotechnological processes; Optimization of bioprocesses; Real-time applications; Applications in system's biology; Bioinformatics applications. ORGANIZERS: Prof. Miguel Rocha, Dept. of Informatics, University of Minho, Portugal, mrocha@di.uminho.pt Prof. Eug�nio C. Ferreira, Dept. Biological Eng., Univ. Minho, Portugal, ecferreira@deb.uminho.pt Prof. Paulo Cortez, Dept. Information Systems, Univ. Minho, Portugal, pcortez@dsi.uminho.pt Prof. Isabel Rocha, Dept. Biological Eng., Univ. Minho, Portugal, irocha@deb.uminho.pt Please proceed according to the instructions at the Conference Web Page http