Not enough input arguments
2 次查看(过去 30 天)
显示 更早的评论
Hi all,
the following code yields me this error:
Not enough input arguments in line 1.
this is the code:
function [Re] = varmom(m,t,rf);
epsilon = zero(m,t,rf);
r = zeros(m,t);
for m=1:M;
epsilon(m,:,:) = mvnrnd(0, [0.006,-0.0051],t);
end
for m =1:M
r(m,1)=0.227+ epsilon(m,1,1)
for i = 1:T-1;
r(m,i+1) = 0.027 + epsilon(m,i+1,1);
end
end
%create excess return out of log excess return
Re = rf*exp(r)-rf;
Where m is #simulations, t is timehorizon and rf is a constant riskfree rate.
Something should be wrong in line one but I don't know how to fix it.
Any suggestions?
Cheers.
0 个评论
采纳的回答
John Doe
2013-5-11
编辑:John Doe
2013-5-11
How do you call this function?
You need input arguments when running it (you can't press F5 or something similar).
You could also define default arguments to be used if no input is provided:
if nargin < 3
rf = ..
if nargin < 2
t = ..
if nargin < 1
m = ..
end
end
end
Hope it helps =)
- Rob
0 个评论
更多回答(5 个)
Kevin van Berkel
2013-5-11
1 个评论
John Doe
2013-5-11
I just noticed zeros(M,T,rf). As rf is not an integer, this is not good. Which dimension do you want it to have?
John Doe
2013-5-11
编辑:John Doe
2013-5-11
Use lower case m, or some other letter that can't be mixed with upper case M, as indices in your for-loops, and you'll get there =)
if nargin < 3
rf = 1.06
if nargin < 2
T = 20
if nargin < 1
M = 1000
end
end
end
epsilon = zeros(M,T,rf);
r = zeros(M,T);
for ii=1:M;
epsilon(ii,:,:) = mvnrnd(0, [0.006],T);
end
for jj =1:M
r(jj,1)=0.227+ epsilon(jj,1,1)
for kk = 1:T-1;
r(jj,kk+1) = 0.027 + epsilon(jj,kk+1,1);
end
end
%create excess return out of log excess return
Re = rf*exp(r)-rf;
0 个评论
Kevin van Berkel
2013-5-11
1 个评论
John Doe
2013-5-11
I'm an electrical engineer and haven't got a clue what you're asking for, sorry about that... Glad I could help out with the programming part though =)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!