Hi , R is a new language for me so sorry in advance if this error is to basic
for posting. I have tried the R manual and search online for quite a few, if
anyone could help i would be very thankful.
Here is my code.
kappa = 1.1
theta = 0.1
sigma = 0.4
rho = -0.6
v0 = 0.2
r = 0.05
T = 0.5
s0 = 1
K = 0.5
type = 1
Hestoncall = function(kappa,theta,sigma,rho,v0,r,T,s0,K,type)
{
u = 0.5
b = kappa-rho*sigma
a = kappa*theta
x = log(s0)
Hestf = function(phi)
{
d = sqrt((b-rho*sigma*phi*complex(1,0,1)-b )^2-sigma^2*(2*u*phi^2))
g (b-rho*sigma*phi*complex(1,0,1)+d)/(b-rho*sigma*phi*complex(1,0,1)-d)
C = r*phi*complex(1,0,1)*T +
a/sigma^2*((b-rho*sigma*phi*complex(1,0,1)+d)*T-2*log((1-g.*exp(d*T))/(1-g)))
D (b-rho*sigma*phi*complex(1,0,1)+d)/sigma^2*((1-exp(d*T))/(1-g*exp(d*T)))
f = exp(C+D*v0 +complex(1,0,1)*phi*x);
HestonPintegrand = real (exp(-1i*phi*log(K))*f/(1i*phi))
HestonPintegrand
}
#int.fn = function(t){sapply(t,FUN=Hestf)}
IH = integrate(Hestf,lower=0,upper=Inf,rel.tol=1e-10,subdivisions=1000000)
ret = 0.5 + 1/pi*IH
call = s0*ret - K*exp(r-T)*ret
call
}
thanks in advance
--
View this message in context:
http://r.789695.n4.nabble.com/ErrError-in-f-x-object-g-not-found-tp4590465p4590465.html
Sent from the R help mailing list archive at Nabble.com.
Just what it says: You define g but refer to a variable g. in the next line. Just get rid of the typo. Sarah On Thu, Apr 26, 2012 at 1:43 PM, Guaramy <Guaramy at hotmail.com> wrote:> Hi , R is a new language for me so sorry in advance if this error is to basic > for posting. I have tried the R manual and search online for quite a few, if > anyone could help i would be very thankful. > Here is ?my code. > > kappa = 1.1 > theta = 0.1 > sigma = 0.4 > rho = -0.6 > v0 = 0.2 > r = 0.05 > T = 0.5 > s0 = 1 > K = 0.5 > type = 1 > Hestoncall = function(kappa,theta,sigma,rho,v0,r,T,s0,K,type) > { > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? u = 0.5 > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? b = kappa-rho*sigma > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? a = kappa*theta > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? x = log(s0) > > ? ? ? ? ? ? ? ?Hestf = function(phi) > ? ? ? ? ? ? ? ?{ > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? d = sqrt((b-rho*sigma*phi*complex(1,0,1)-b )^2-sigma^2*(2*u*phi^2)) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? g > (b-rho*sigma*phi*complex(1,0,1)+d)/(b-rho*sigma*phi*complex(1,0,1)-d) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? C = r*phi*complex(1,0,1)*T + > a/sigma^2*((b-rho*sigma*phi*complex(1,0,1)+d)*T-2*log((1-g.*exp(d*T))/(1-g))) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? D > (b-rho*sigma*phi*complex(1,0,1)+d)/sigma^2*((1-exp(d*T))/(1-g*exp(d*T))) > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? f = exp(C+D*v0 +complex(1,0,1)*phi*x); > > > ? ? ? ? ? ? ? ? ? ? ? ? ?HestonPintegrand ?= real (exp(-1i*phi*log(K))*f/(1i*phi)) > > ? ? ? ? ? ? ? ? ? ? ? ? ?HestonPintegrand > > ? ? ? ? ? ? ? ? ? ? ? ?} > > ? ? ? ? #int.fn = function(t){sapply(t,FUN=Hestf)} > ? ? ? ? IH = integrate(Hestf,lower=0,upper=Inf,rel.tol=1e-10,subdivisions=1000000) > ? ? ? ? ret = 0.5 + 1/pi*IH > > > > ? ? ? ?call = s0*ret - K*exp(r-T)*ret > ? ? ? ?call > > } > > thanks in advance >-- Sarah Goslee http://www.functionaldiversity.org
On Thu, Apr 26, 2012 at 5:34 PM, Guaramy _ <guaramy at hotmail.com> wrote:> Thanks for your answer, but how can i correct that, the mathematical > expression is correct that way with that g. Do you know how can i program it > ?Then you need to define g. and how it differs from g alone. g. and g are two separate objects in R. Sarah PS You also need to convert your email program to plain text, or whatever caused the horrid formatting below.> >> Date: Thu, 26 Apr 2012 13:57:36 -0400 >> Subject: Re: [R] ErrError in f(x, ...) : object 'g.' not found >> From: sarah.goslee at gmail.com >> To: Guaramy at hotmail.com >> CC: r-help at r-project.org >> >> Just what it says: >> >> You define g but refer to a variable g. in the next line. >> >> Just get rid of the typo. >> >> Sarah >> >> On Thu, Apr 26, 2012 at 1:43 PM, Guaramy <Guaramy at hotmail.com> wrote: >> > Hi , R is a new language for me so sorry in advance if this error is to >> > basic >> > for posting. I have tried the R manual and search online for quite a >> > few, if >> > anyone could help i would be very thankful. >> > Here is ?my code. >> > >> > kappa = 1.1 >> > theta = 0.1 >> > sigma = 0.4 >> > rho = -0.6 >> > v0 = 0.2 >> > r = 0.05 >> > T = 0.5 >> > s0 = 1 >> > K = 0.5 >> > type = 1 >> > Hestoncall = function(kappa,theta,sigma,rho,v0,r,T,s0,K,type) >> > { >> > >> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? u = 0.5 >> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? b = kappa-rho*sigma >> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? a = kappa*theta >> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? x = log(s0) >> > >> > ? ? ? ? ? ? ? ?Hestf = function(phi) >> > ? ? ? ? ? ? ? ?{ >> > >> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? d >> > sqrt((b-rho*sigma*phi*complex(1,0,1)-b )^2-sigma^2*(2*u*phi^2)) >> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? g >> > (b-rho*sigma*phi*complex(1,0,1)+d)/(b-rho*sigma*phi*complex(1,0,1)-d) >> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? C = r*phi*complex(1,0,1)*T + >> > >> > a/sigma^2*((b-rho*sigma*phi*complex(1,0,1)+d)*T-2*log((1-g.*exp(d*T))/(1-g))) >> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? D >> > (b-rho*sigma*phi*complex(1,0,1)+d)/sigma^2*((1-exp(d*T))/(1-g*exp(d*T))) >> > >> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? f = exp(C+D*v0 +complex(1,0,1)*phi*x); >> > >> > >> > ? ? ? ? ? ? ? ? ? ? ? ? ?HestonPintegrand ?= real >> > (exp(-1i*phi*log(K))*f/(1i*phi)) >> > >> > ? ? ? ? ? ? ? ? ? ? ? ? ?HestonPintegrand >> > >> > ? ? ? ? ? ? ? ? ? ? ? ?} >> > >> > ? ? ? ? #int.fn = function(t){sapply(t,FUN=Hestf)} >> > ? ? ? ? IH >> > integrate(Hestf,lower=0,upper=Inf,rel.tol=1e-10,subdivisions=1000000) >> > ? ? ? ? ret = 0.5 + 1/pi*IH >> > >> > >> > >> > ? ? ? ?call = s0*ret - K*exp(r-T)*ret >> > ? ? ? ?call >> > >> > } >> > >> > thanks in advance >> >-- Sarah Goslee http://www.functionaldiversity.org