H2 = 0
H3 - H999 = =SQRT(EXP(0,05)*ABS($I2-50))*NORMINV(RAND();0;1)
I2 - I999 = =$E$2 $D$2*EXP($A$2*($G2-$B$2) $C$2)/(1 EXP($A$2*($G2-$B$2) $C$2)) H2
Hi guys,
i created the formula obove in excel. I want to implement this one to R. Can anyone help me with this?
I already tried to do it with formula and with data.frame.
The probelm is that sigma depends on t and X(t)-1.
Can anyone help me with it?
Thanks, Max
CodePudding user response:
This should get you started:
A <- 2
B <- 5
C <- 3
D <- 30
E <- 100
delta <- 0.05
t <- seq(0.05, by = 0.05, length.out = 998)
sigma <- c(0, sqrt(exp(0.05)*abs(t[-998] - 50))*rnorm(997))
Xt <- E D*exp(A*(t - B) C)/(1 exp(A*(t - B) C)) sigma
To get Xt
for multiple replications, it would be something like this
sigma <- c(0, sqrt(exp(0.05)*abs(t[-998] - 50)))
Xt <- E D*exp(A*(t - B) C)/(1 exp(A*(t - B) C))
Simulation <- replicate(100, Xt sigma*rnorm(998))
Or vectorize it like so (this will be faster than using replicate
)
Simulation <- E D*exp(A*(t - B) C)/(1 exp(A*(t - B) C)) c(0, sqrt(exp(0.05)*abs(t[-998] - 50)))*matrix(rnorm(998*100), 998, 100)