[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
ARG?
From: |
Bazman76 |
Subject: |
ARG? |
Date: |
Tue, 21 Jun 2011 03:02:27 -0700 (PDT) |
Hi there,
The code below was posted at the following address:
http://www.quantcode.com/modules/mydownloads/singlefile.php?lid=495
Just wondered what significance the "1;" has (I am compltetly new to octave)
Also what does the following section do?
badidx=find(abs(arg(S))>0);
nBad_values=size(badidx,1) %should ideally be zero
goodidx=find(abs(arg(S))==0);
S=S(goodidx);
Also what does the arg function do? (more generally is there a resource
where I can type in an octave function name and find out what it does?)
Thanks
Baz
1;
clear all;
global alpha;
global beta;
global rho;
global nu;
global T;
global S;
global r;
%----------Input parameters ----------------
S0=100; %Spot price
r=0.05; %risk free rate
K=98; %strike
alpha = 0.852; %alpha parameter
beta=.5; %beta parameter set from backbone or aesthetics
rho = 0.5; %rho parameter
nu = .42; %variance of volatility paramater
T=1; %maturity price
nsimulations=100000; %no of MC simulations (will get doubled for anithetic)
nT=50; %no. of time step points
%------------------------
function ret=GetSABRsigma(F,X)
global alpha;
global beta;
global rho;
global nu;
global T;
z=(nu/alpha)*((F.*X).^(0.5*(1-beta))).*log(F./X);
zhi=log( ( ((1-2*rho*z+z.*z).^0.5) + z - rho)/(1-rho) );
numer1= ( ((1-beta)^2)/24 )*((alpha*alpha)./((F.*X).^(1-beta)));
numer2=.25*rho*beta*nu*alpha./((F*X).^((1-beta)/2));
numer3=((2-3*rho*rho)/24)*nu*nu;
numer=alpha*(1+(numer1+numer2+numer3)*T).*z;
denom1=((1-beta)^2/24)*(log(F./X)).^2;
denom2=(((1-beta)^4)/1920)*((log(F./X)).^4);
denom=((F.*X).^((1-beta)/2)).*(1+denom1+denom2).*zhi;
ret=numer./denom;
idx=find(X==F);
if idx>0,
%use eqn(20) to avoid NaN problem
numer1=(((1-beta)^2)/24)*alpha*alpha/(F^(2-2*beta));
numer2=.25*rho*beta*nu*alpha/(F^(1-beta));
numer3=((2-3*rho*rho)/24)*nu*nu;
VolAtm=alpha*(1+(numer1+numer2+numer3)*T)/(F^(1-beta))
ret(idx)=VolAtm;
end
endfunction
%form a correlated pair of random variables for the 2 factors
rndmat1=randn(nsimulations,nT);
rndmat1=[rndmat1; -rndmat1];
rndmat2=randn(nsimulations,nT);
rndmat2=[rndmat2; -rndmat2];
rndmat2=rho*rndmat1+(1-rho*rho)^0.5*rndmat2;
nsimulations=nsimulations*2;
dt=T/(nT-1);
F0=S0*exp(r*T);
rdt=dt^0.5;
F=ones(nsimulations,1)*F0;
S=ones(nsimulations,1)*S0;
alphavec=ones(nsimulations,1)*alpha;
for i=1:nT-1,
%dF=(r-0.5*sig*sig)*dt + sig*rdt*rndmat(:,i);
%dS=(r-0.5*sig*sig)*dt + sig*rdt*rndmat(:,i);
%F=F.*exp(dF);
%S=S.*exp(dS);
S = S + r*S*dt + alphavec.*
exp(r*(beta-1)*T).*S.^beta*rdt.*rndmat1(:,i);
%alphavec = alphavec + nu*alphavec*rdt.*rndmat2(:,i);
alphavec = alphavec.*exp(nu*rdt.*rndmat2(:,i));
end
badidx=find(abs(arg(S))>0);
nBad_values=size(badidx,1) %should ideally be zero
goodidx=find(abs(arg(S))==0);
S=S(goodidx);
payoff=max(S-K,0);
mccallprice=exp(-r*T)*mean(payoff)
% Calculate implied volatility using Hagan's analytical formula
sig=GetSABRsigma(F0,K)
Dest=exp(-r*T);
d1=(log(F0/K) + 0.5*sig*sig*T)/(sig*T^0.5);
d2=(log(F0/K) - 0.5*sig*sig*T)/(sig*T^0.5);
V_BScall=Dest*(F0*normcdf(d1)-K*normcdf(d2)) %analytical price
--
View this message in context:
http://octave.1599824.n4.nabble.com/ARG-tp3613617p3613617.html
Sent from the Octave - General mailing list archive at Nabble.com.