Not enough input arguments

조회 수: 1 (최근 30일)
Kevin van Berkel
Kevin van Berkel 2013년 5월 11일
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.

채택된 답변

John Doe
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

추가 답변 (5개)

Kevin van Berkel
Kevin van Berkel 2013년 5월 11일
Hi guys,
thanks for your quick replies!
To Robert:
My purpose is to simulate stock returns according to a VectorAutoRegressive (VAR)model. So the vector [Re] should give me the desired simulated returns. So what parameters would you suggest to fill in your code?
To Per:
Sorry, it should indeed be line 2! And zero should be zeros. Pretty sloppy!
>> which zero gives:
C:\Program Files\MATLAB\R2012b\toolbox\shared\controllib\engine\@DynamicSystem\zero.m % DynamicSystem method >> which zeros built-in (C:\Program Files\MATLAB\R2012b\toolbox\matlab\elmat\zeros)
Thanks guys!

Kevin van Berkel
Kevin van Berkel 2013년 5월 11일
Hi,
I adjusted the code in this way, according to Robert:
It looks like this now and it is actually running:
function [Re] = varmom(M,T,rf);
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 m=1:M;
epsilon(M,:,:) = mvnrnd(0, [0.006],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;
However, it gives me a 1000*20 matrix with the same numbers: 0.2701 for the 1x1000 and 0.029 for the elements thereafter. This obviously does not give me the simulated excess returns.. But we're getting there since the code is running :)
Any suggestions?
Cheers,
Kevin
  댓글 수: 1
John Doe
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
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;

Kevin van Berkel
Kevin van Berkel 2013년 5월 11일
Thanks Robert you really helped me out, got a nice 1000*20 matrix which contains numbers!
Still got some questions though:
in the final line of my script I wrote %create excess return out of log excess return Re = rf*exp(r)-rf;
So I thought this would give me a scalar with the simulated excess returns of 20 periods ahead. However, I do not get this 'Re' scalar.
Next to that, I would like to verify if the numbers I plugged in your suggestion
(so: rf = 1.0147
if nargin < 2
T = 20
if nargin < 1
m = 1000)
are the correct ones?
And the last one, do you think I should use a VAR model to make this simulation for just a single risky asset (next to a risk-free one) in a portfolio? Or should I use an AR model.. Hope you have any suggestions.
Anyway,
Thanks again for your effort! It drove me crazy for the last 48 hours ;)
Cheers,
  댓글 수: 1
John Doe
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 =)

댓글을 달려면 로그인하십시오.


Kevin van Berkel
Kevin van Berkel 2013년 5월 11일
No worries!

카테고리

Help CenterFile Exchange에서 Time Series Collections에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by