SERVING THE QUANTITATIVE FINANCE COMMUNITY

 
User avatar
Bazman2
Topic Author
Posts: 239
Joined: January 28th, 2004, 2:22 pm

Varargin

November 19th, 2008, 7:59 pm

Hi,I have the following function:function val = MyFalsePosition(f,a,b,prec,varargin)if nargin==4 sfa=sign(f(a)); sfb=sign(f(b));else sfa = sign(f(a,varargin{:})); sfb = sign(f(b,varargin{:}));enditer=0;if sfa == 0 val= a; elseif sfb == 0 val= b; elseif (sfa*sfb)>0 disp ('wrong starting values'); else m=b; mlast=a; d=abs((f(m,varargin{:})/(f(m,varargin{:})-f(mlast,varargin{:})))*(m-mlast)); while (d>prec) iter=iter+1; mlast=m; m=(a*f(b,varargin{:})- b*f(a,varargin{:}))/(f(b,varargin{:})-f(a,varargin{:})); if f(m,varargin{:})==0 d=0; else d=abs(f(m,varargin{:})/f(m,varargin{:})-f(mlast,varargin{:}))*(m-mlast); if sign(f(m,varargin{:})) ==sfa a=m; else b=m; end end disp(sprintf('iteration %5.0f',iter)); disp(sprintf('a %5.0f',a)); disp(sprintf('b) %5.0f',b)); disp(sprintf('error %5.0f',d)); end val= m;endendfunction val =BS_European_Call(S, K, sigma, r, T);%useage BS_European_Call(S,K,sigma,r,T)%European call option value in the Black-Scholes modeld1 = (log(S./K)+(r+sigma^2/2)*T)/(sigma*sqrt(T));d2 = (log(S./K)+(r-sigma^2/2)*T)/(sigma*sqrt(T));val=S.*mynormcdf(d1)-K*exp(-r*T)*mynormcdf(d2);I am confident that both function work individually.I want to call BS_European_call into MyFalsePosition to find the value it equals zero for by varying the input sigma in BS_european_Call.How should I type this in to the command window?I tried:MyFalsePosition(BS_European_Call,0,1,0.01,40,40,x,0.1,0.5)but that did not work?
 
User avatar
aiQUANT
Posts: 91
Joined: June 4th, 2008, 6:20 pm

Varargin

November 22nd, 2008, 12:26 pm

I dont understand what the hell you want to do. Do you want MyFalsePosition to process the output from BS_European_Call? And also in the call MyFalsePosition(BS_European_Call,0,1,0.01,40,40,x,0.1,0.5) matlab will think BS_European_Call is a workspace variable and not a function pointer. Use '@' sign to denote function pointer. But still i'm confused.
ABOUT WILMOTT

PW by JB

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...


Twitter LinkedIn Instagram

JOBS BOARD

JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...


GZIP: On