Asked by Kevin van Berkel
on 11 May 2013

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.

*No products are associated with this question.*

Answer by John Doe
on 11 May 2013

Edited by John Doe
on 11 May 2013

Accepted answer

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

Answer by Kevin van Berkel
on 11 May 2013

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!

Answer by Kevin van Berkel
on 11 May 2013

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

John Doe
on 11 May 2013

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?

Answer by John Doe
on 11 May 2013

Edited by John Doe
on 11 May 2013

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;

Answer by Kevin van Berkel
on 11 May 2013

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,

John Doe
on 11 May 2013

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 =)

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments