Hello everybody. I am really desperate because I do not succeed in simulating asset paths by monte carlo simulation. Somehow, everytime I am typing in the one of the following commands:
function SPaths=AssetPaths(S0,mu,sigma,T,NSteps,NRepl)
or
function SPaths=AssetPaths(S0,mu,sigma,T,NSteps,NRepl) or
paths=AssetPaths(...)
I get the following message:
??? function SPaths=AssetPaths(S0,mu,sigma,T,NSteps,NRepl) | Error: Function definitions are not permitted in this context.
Can someone please help me? Maybe I am missing the AssetPaths.m file?
Thanks for every answer
Kind regards dominic

回答 (4 件)

Oleg Komarov
Oleg Komarov 2011 年 6 月 22 日

1 投票

You can declare a function only in a separate m. file and only as the very first line. So for example the following script will give the same error:
a = 10
function out = hi(a)
end

2 件のコメント

Walter Roberson
Walter Roberson 2011 年 6 月 22 日
Minor variation: function must be the first non-blank non-comment line.
知有
知有 2023 年 8 月 2 日
请问你可以提供一下定义该函数的内容吗 十分感谢

サインインしてコメントする。

lavistacrunchy
lavistacrunchy 2011 年 6 月 22 日

0 投票

Thanks for the quick response. Unfortunately I still don't get, how I can make it work. Does your answer mean, that I cannot enter the function in the command window or in a script file?
I am currently using version 7.12.0 (R2011a).

3 件のコメント

lavistacrunchy
lavistacrunchy 2011 年 6 月 22 日
This is what I typed in at first:
>> function [SPaths]=AssetPaths(S0;mu;sigma;T;NSteps;NRepl)
??? function [SPaths]=AssetPaths(S0;mu;sigma;T;NSteps;NRepl)
|
Error: Function definitions are not permitted in this context.
>> S0=50;
>> mu=0.04;
>> sigma=0.3;
>> T=1;
>> Nsteps=365;
>> NRepl=3;
>> function [SPaths]=AssetPaths(S0;mu;sigma;T;NSteps;NRepl)
??? function [SPaths]=AssetPaths(S0;mu;sigma;T;NSteps;NRepl)
|
Error: Function definitions are not permitted in this context.
So, when it didn't work, I tried this:
>> S0=50;
>> mu=0.04;
>> sigma=0.3;
>> T=1;
>> Nsteps=365;
>> NRepl=3;
But both ways didn't work.
Does anybody know, what might be the problem. If not in the command window, where do I have to type in the command?
Walter Roberson
Walter Roberson 2011 年 6 月 22 日
Correct, you cannot enter function definitions at the command window or script file. You must put them in to a function .m file.
Walter Roberson
Walter Roberson 2011 年 6 月 22 日
At the command window,
edit AssetPaths
and paste in the code and save the file as AssetPaths.m

サインインしてコメントする。

Angus
Angus 2011 年 6 月 22 日

0 投票

You need to put the function AssetPath in a separate m-file that is named the same as the function.
eg: file 1: AssetPaths.m
function results = AssetPaths( ... )
statements
end
now you can invoke a call to AssetPaths on the command line like
>> paths = AssetPaths( ... input variables)
Anirban Naskar
Anirban Naskar 2014 年 5 月 25 日

0 投票

Is there any in-built function called "assetpaths"?

カテゴリ

ヘルプ センター および File ExchangeScope Variables and Generate Names についてさらに検索

質問済み:

2011 年 6 月 22 日

コメント済み:

2023 年 8 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by