Function and Minimisation Problem
1 回表示 (過去 30 日間)
古いコメントを表示
Hi here is my problem :
Create a function that solves for the efficient portfolio, given a set of stocks, their expected value, their variance-covariance matrix, and a target expected value of the investment. The function should use either the MATLAB minimisation procedure fmincon or quadprog.
Inputs:
procedure a string containing the MATLAB procedure used to
perform the minimization ('quadprog' or 'fmincon')
Sigma Variance-covariance matrix (reminder: this is a
positive semi-definite matrix!)
mu vector of expected values for each stock
mu_p_0 expected return
initial_guess for fmincon, you need to give an initial guess,
can be left as [] if using quadprog
optimisation_options can be added, but otherwise set to default
by using [] as the value for this input
Outputs:
x optimal shares for each stock
fval value of the optimisation
expected_return as a check, needs to be equal to mu_p_0
The objective function for the optimisation will be a local function called effportobj. This function takes as inputs: the optimal shares x, and the variance-covariance matrix Sigma. In the main function, when calling this objective function in the optimisation procedure (either quadprog or fmincon), use the function handle (starting with @).
I have attached a file showing the theory behind this model
I am having trouble with my code:
function [x, fval, expected_return] = effportfolio(fmincon, Sigma, mu, mu_p_0, initial_guess, optimisation_options)
% EFFPORTFOLIO solves for the efficient portfolio.
A_eq = [2*Sigma, mu , 1; mu', 0, 0; 1', 0, 0];
B_eq = [0;mu_p_0;1];
optimisation_options = optimset('Display','iter');
[x, fval] = fmincon(@effportobj,initial_guess,[],[],A_eq,B_eq,[],[],[],optimisation_options,Sigma);
expected_return = mu_p_0 ;
end
function E = effportobj(x, Sigma)
E = x'* Sigma * x;
end
Thanks very much
0 件のコメント
回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Systems of Nonlinear Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!