[R] help for code in jump diffusion
cruz
cruadam at gmail.com
Sat Nov 22 09:04:02 CET 2008
i tried to run your code, this is how/why you got NaN:
> mu<-0.2
> sig<-0.2
> S0<-100
> j<-0.2
> dt<-1/252
> int<-0.1
> i<-0
> is.nan
function (x) .Primitive("is.nan")
> k<-rnorm(1,0,1)
> k
[1] 0.3214954
> theta<-ifelse((k<(int*dt)),1,0)
> theta
[1] 0
> m<-rnorm(1)
> m
[1] -0.4525731
> gam<-qnorm(m,0,1)
Warning message:
In qnorm(p, mean, sd, lower.tail, log.p) : NaNs produced
> gam
[1] NaN
> S0<-abs(S0*((1+mu*dt+sig*sqrt(dt)+ gam)- j*theta))
> S0
[1] NaN
> if(!is.nan (S0 <= 0))
+ warning("S0 must be positive")
Warning message:
S0 must be positive
> cat("NaN","\n")
NaN
> cat(S0,"\n")
NaN
>
On Sat, Nov 22, 2008 at 2:37 PM, subbudas <subratdas0407sssu at gmail.com> wrote:
>
> hello everyone ,
> i have written some code in R for jump diffusion model.
> the code generates answer as
> " NaN
> There were 50 or more warnings (use warnings() to see the first 50)"
> my code is
>
> mu<-0.2
> sig<-0.2
> S0<-100
> j<-0.2
> dt<-1/252
> int<-0.1
> i<-0
> while(i<=1)
> {
> is.nan
> k<-rnorm(1,0,1)
> theta<-ifelse((k<(int*dt)),1,0)
> m<-rnorm(1)
> gam<-qnorm(m,0,1)
> S0<-abs(S0*((1+mu*dt+sig*sqrt(dt)+ gam)- j*theta))
> if(!is.nan (S0 <= 0))
> warning("S0 must be positive")
> cat("NaN","\n")
> cat(S0,"\n")
> i<-i+(1/252)
> }
>
> the problem i am facing is i am not able to find out the reason for this NaN
> output.
> please help
>
> thanks in advance.
>
>
>
More information about the R-help
mailing list