Error using fmincon (not enough input arguments)
显示 更早的评论
Dear community,
I'm having some issues in using fmincon for a function of two-variables. I have attached a mat file with the date I'm using (the variable "equity"), and the functions I call in the script. Here's my attempt
F = 50;
T = 1;
r = 0.05;
% sigma0 is realised equity volatility
% equity is daily time-series of equity price
N = size(equity, 1);
dt = 1./N;
retE = diff(log(equity));
mu0 = mean(retE).*N;
sigma0 = std(retE).*N.^.5;
x0 = [sigma0, mu0];
TTM = T*ones(N, 1);
for t = 1:N
TTM(t) = T - (t - 1)/N;
end
Asset = @(sigma) assetMerton1(equity, sigma, r, F, TTM);
retA = @(sigma) diff(log(Asset(sigma)));
ND1 = @(sigma) auxiliaryNd1(Asset(sigma), sigma, r, F, TTM);
S1 = @(sigma) arrayfun(@(x)(sum(log(Asset(x))) + N./2.*log(2.*pi.*x.^2.*dt)), sigma);
S2 = @(sigma, mu) arrayfun(@(x,y)((0.5)./(x.^2.*dt).*(sum(retA(x).^2) + (y - x.^2./2).^2.*dt ...
- 2.*(y - x.^2./2).*dt.*sum(retA(x)))), sigma, mu);
S3 = @(sigma) arrayfun(@(x)(sum(log(ND1(x)))), sigma);
S = @(sigma, mu) arrayfun(@(x,y)(S1(x) + S2(x, y) + S3(x)), sigma, mu);
D = fmincon(S, x0, [], [], [], [], [0 -Inf], [Inf Inf]);
In particular, I'm able to compute the function S, like
S(0.2, 0.1)
returning 438.9673. So the function S appears well defined. However, when I try to run the last line (fmincon) I get the following error
Not enough input arguments.
Error in @(sigma,mu)arrayfun(@(x,y)(S1(x)+S2(x,y)+S3(x)),sigma,mu)
Error in fmincon (line 573)
initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.
Do you know what is causing it? any suggestions? Thank you very much for your help!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Price and Analyze Financial Instruments 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!