Created
November 16, 2018 16:22
-
-
Save slwu89/6d4cbaa3b2cad9a8d302c4852045e4f3 to your computer and use it in GitHub Desktop.
time changes for continuous time vs. Euler approximation of stochastic jump processes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# continuous time rate | |
R <- 1/5 | |
# mean time to next event in continuous time | |
mean(rexp(n = 1e6,rate = R)) | |
# get a discrete time rate to plug into Euler approximation of continuous time process | |
get_r <- function(R,dt){ | |
log(1 + R*dt) / dt | |
} | |
dt <- 0.5 | |
r <- get_r(R = R,dt = dt) | |
# check the Euler process gives the same expected waiting time as continuous process | |
mean(rgeom(n = 1e6,prob = 1-exp(-r*dt)) * dt) | |
# alternatively we can start with r and want R (discrete to continuous) | |
get_R <- function(r,dt){ | |
(exp(r*dt)-1) / dt | |
} | |
R <- get_R(r,dt) | |
mean(rexp(n = 1e6,rate = R)) | |
mean(rgeom(n = 1e6,prob = 1-exp(-r*dt)) * dt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment