Exact simulation of first exit times for one-dimensional diffusion processes

The simulation of exit times for diffusion processes is a challenging task since it concerns many applications in different fields like mathematical finance, neuroscience, reliability... The usual procedure is to use discretiza-tion schemes which unfortunately introduce some error in the target distribution. Our aim is to present a new algorithm which simulates exactly the exit time for one-dimensional diffusions. This acceptance-rejection algorithm requires to simulate exactly the exit time of the Brownian motion on one side and the Brownian position at a given time, constrained not to have exit before, on the other side. Crucial tools in this study are the Girsanov transformation, the convergent series method for the simulation of random variables and the classical rejection sampling. The efficiency of the method is described through theoretical results and numerical examples.


Introduction
First exit time distributions for general stochastic processes are of prime importance in many contexts.In mathematical finance, they permit to appreciate the risk of default for a given path-dependent option; in neuroscience, they characterize for instance the interspike time distribution... Since diffusion processes (solutions of stochastic differential equations) form an important family of stochastic processes, we aim to describe quite precisely their exit times.Unfortunately a simple and explicit expression of their distribution is not generally available which leads us to consider numerical approximations.Our task is to point out an algorithm which permits to simulate the exit time of the diffusion.This objective was already concerned by several studies introducing a discretization scheme for the corresponding stochastic differential equation.Most of them are based on improvements of the classical Euler scheme (see for instance [7], [12], [11]) which essentially consist in reducing the error stem from the approximation procedure.Let us also note another point of view which consists in approximating the probability density function of the exit time and therefore to approximate the solution of an integral equation [19].
Our approach is completely different since we emphasize an exact simulation procedure: the distribution of the random outcome of the algorithm is identical to the distribution of the first exit time of the diffusion process.For such simulation methods based on an acceptance-rejection sampling, the challenge is to describe and reduce if possible the time consumption of the simulation.Beskos & Roberts, in their founding work [5], already introduced the exact simulation for diffusion paths on some fixed time interval.Meanwhile several modifications of this algorithm have been proposed [3,4,15].The basic idea of the rejection sampling is to sequentially observe independent random objects generated according to a proposal distribution until a condition is satisfied.That means that each object is accepted or rejected according to a certain probability weight.
For diffusion processes on a fixed interval [0, T ], the proposed object pointed out by Beskos & Roberts is the Brownian paths (easy to simulate) and the rejection weight can be computed using the Girsanov transformation which essentially requires the simulation of Brownian bridges.In a previous work [13], the authors proposed a similar procedure in order to exactly simulate the first passage time of a one-dimensional diffusion through a given threshold: the proposal object is then the Brownian first passage time (inverse gaussian random variable) and the rejection weight requires the simulation of Brownian bridges conditioned to stay under a given threshold (Bessel processes).In order to adapt such a procedure to exit times, it suffices to generate Brownian exit times and to use the rejection weight suggested by the Girsanov transformation.Unfortunately this random weight requires the simulation of a Brownian bridge conditioned to stay in a given interval, which corresponds to a SDE with singular coefficients: there is no way to exactly simulate such a stochastic paths.Such an intuitive generalization leads therefore to a deadlock.
That's why we aim to present a quite different rejection sampling based on a similar concept (Girsanov's transformation) and avoiding the simulation of the whole conditioned Brownian paths.Let us consider the stochastic process (X t , t ≥ 0), solution of the SDE: where (B t , t ≥ 0) stands for the standard one-dimensional Brownian motion.We denote by τ a,b the first time the diffusion exits from the interval [a, b]: τ a,b (X) := inf{t > 0 : The aim of the study is to propose an efficient algorithm in order to simulate the first exit time τ a,b (X).Under suitable conditions, the Lamperti transform permits to reduce the area of investigation to the constant diffusion case: σ(x) ≡ 1 providing to change the interval [a, b].That's why we shall only focus our attention on the diffusion process: for t ≤ τ a,b (X) with a < 0 < b.The exact algorithm presented here (Section 3) is essentially based on the Girsanov transformation which permits to relate the diffusion (0.2) to a standard one-dimensional Brownian motion.Let us roughly describe the crucial tools needed to execute such an algorithm.The proposal random variable is the Brownian exit time of the interval [a, b], denoted T prop .
The weight used in order to accept or reject this proposal depends both on the conditional distribution of the Brownian paths (B t ) given that τ a,b (B) = T prop and on a Poisson process defined on the time axis R + which is independent of the Brownian motion (B t ) and whose events occur at time T 1 , . . ., T n , . . .Then conditionally to τ a,b (B) = T prop , only the values of B T k , for any T k ≤ T prop , and B Tprop (dots in Figure 1) are involved in the specific conditions associated to the acceptance of T prop .The exact simulation of τ a,b (X) therefore requires to describe: 1.The conditional distribution of B t for a given t > 0, given that the first exit of the interval τ a,b (B) is larger than t (Section 1).Using the classical convergent series method, we propose an algorithm denoted by CON-DITIONAL_DISTR (x,[a,b],t) for the simulation of the constrained Brownian motion B t with initial condition x.

The distribution of the
where x = 2y−a−b b−a .So if we denote B x the Brownian motion starting in x, we deduce easily the following distribution identity In other words, it suffices to study precisely the first Brownian exit problem from the normalized interval [−1, 1] with the initial condition For notational convenience, we denote by Let us first emphasize a classical result on the exit position: since (B t , t ≥ 0) is a martingale, the identity function s(x) = x corresponds to the scale function of the Brownian motion.The optimal stopping theorem permits therefore to describe the probability to exit from the interval on one particular side:

Distribution of B t given τ > t
Let us now focus our attention to the distribution of the constrained Brownian motion.We introduce the killed Brownian motion: as soon as the process hits the boundary of the interval, it jumps to a cemetery point x * / ∈ [−1, 1].Indeed let us denote by p(t, x, dy) := P(B x t ∈ dy, τ > t) the transition probability of the Brownian motion joint with τ > t.It can be written as p(t, x, y) = q(t, x, y)P(τ x > t) where q(t, x, y) is the transition probability of the Brownian motion conditioned to stay in the interval [−1, 1] till time t.For any non negative or bounded measurable function ψ, we get It is well known (see, for instance [14] Section 4.11 or [8] Section 5.7) that (t, y) → p(t, x, y) satisfies an Initial-Boundary value problem associated to the heat equation: (1.4) Milstein and Tretyakov [18] recall that the solution of (1.4) takes two different expressions.The first one is obtained by the method of images and the second one is based on a spectral decomposition of the heat equation.We introduce the standard gaussian pdf and cdf : φ which is a convenient formula for small values of t.For large times t, we would prefer the second formula: Let us fix (t, x): since we get an explicit expression of p(t, x, y), we can point out exact simulation algorithms based on the acceptance/rejection method even if p(t, x, y) is not a probability density function.Indeed it suffices to divide by P(τ x > t) in order to obtain such a density (cf.Section 2.1).The method applied here is a particular acceptance/rejection method presented in [10] as the convergent series method.

Inequalities related to the series expansion
Let us consider f a non negative function satisfying a series expansion: We assume that I(f ) := R f (y) dy < ∞.The convergent series method permits to simulate a random variable with the corresponding probability distribution function f /I(f ).It requires two important features: • the existence of both a pdf h and a constant κ > 0 such that f (y) ≤ κh(y), y ∈ R. (1.7) • the existence of a positive sequence (r n ) n≥0 which converges toward 0 and satisfies the following reminder upper-bound CONVERGENT SERIES METHOD Step 1. Generate a random variable Y with density h.
Step 4. While (Test = 0) do: Step 5.If W ≤ S then X = Y otherwise go to Step 1.
Outcome: the random variable X with density f /I(f ) and the global number of terms of the series expansions N c used.
In order to simulate q(t, x, y), i.e. the conditional distribution of B t given t < τ , we need to choose the density h, to point out some constant κ and the sequence (r n ) n≥0 for each explicit expression of f given by (1.5) and (1.6).Let us just note that it is challenging to find the smallest constant κ as possible since the number of iterations of Step 1 in order to get an outcome is geometrically distributed with average κ/I(f ).

Some comments on the series expansion (1.5)
We note that (1.5) is not an alternating series and can be rewritten as p(t, x, y) = a 0 (t, x, y) + ∞ n=1 (a n (t, x, y) + a −n (t, x, y)), where a n (t, x, y) We first observe that a −n (t, x, y) < 0 and a n (t, x, y) > 0, ∀n ≥ 1, ∀(x, y) ∈ [−1, 1] 2 . (1.9) Moreover both increments of the function φ are computed on intervals whose length does not depend on the variables x and n: For n large enough, the increments are decreasing and therefore a n (t, x, y) + a −n (t, x, y) becomes negative.Indeed by considering the four terms: it is straightforward to see that the smallest one in absolute value is |x + y − 2 + 4n|.Since the change of convexity of the curve x → φ(x) appears for x = 1, the sum a n (t, x, y) + a −n (t, x, y) is negative as soon as (1.10) Since the terms of the series are negative for n ≥ n 0 , the series (1.5) is obviously not an alternating series.
In order to apply the convergent series method, we need to bound this reminder.Since φ is a decreasing function, we obtain the following bound: as soon as α + 4n ≥ 0.Moreover, by symmetry, as soon as α − 4n ≤ 0. If α = x − y or α = x + y − 2, then the inequalities are satisfied for any n ≥ 1.Finally, for n ≥ 1, we get Let us now observe that we can obtain a bound which is uniform with respect to both the variable x and y.
Let us note that this upper-bound is efficient for small values of t.
Proposal distribution for the rejection method using (1.5) The aim is to use the acceptance/rejection algorithm in order to simulate a random variable with the target density q(t, x, y) = p(t, x, y)/P(τ x > t) where p(t, x, y) is given by (1.5).That's why we are looking for a proposal pdf h and a constant κ(t, x) independent of y satisfying as explained in (1.7).We suggest here the following choice of the proposal distribution: that means that we choose a gaussian distribution centered in x with variance t: it corresponds to the distribution of B t without any conditioning.The rejection method shall permit to go from this initial distribution to the conditional distribution with respect to the event {τ > t}.Let us note that this bound is uniform with respect to the variable x (starting value of the Brownian paths).
Some comments on the series expansion (1.6) Since q(t, x, y) can be characterized by two different series expansions, it is useful to understand which kind of acceptance/rejection algorithm each series produces.Let us now focus on the second series (1.6): where β n (t) = e −n 2 π 2 t/8 and a n (x, y) = sin nπ 2 (x+1) sin nπ 2 (y +1) .Let us first notice that, for fixed t > 0, (β n (t)) n≥1 is a decreasing sequence of positive real numbers which converges towards 0. Since a n is defined as the product of two sine functions, one idea to bound the reminder of the series is to use the Abel transform and to prove that N n=1 a n (x, y) is bounded as N tends to infinity.It is quite easy to obtain some bound when x = y but for the particular case x = y, the sequence of partial sums is increasing (sum of squares) and tends to infinity.In conclusion, we cannot apply technics based on the Abel transform for the series (1.6).We shall therefore present an other approach.
Bound of the series reminder in (1.6)Let us define the reminder of the series (1.6): Let us find a bound of this reminder.Since Moreover, u → e −u 2 π 2 t/8 is a decreasing function on R + , and therefore we get the following bound Note that this bound is sharp for large value of t.
Proposal distribution for the rejection method using (1.6) The aim is to use an acceptance /rejection method in order to simulate a random variable with the target density p(t, x, y)/P(τ > t) based on the equation (1.6), as already done for (1.5).We are looking for a probability distribution function h(y) and a constant κ(t, x) > 0 independent of y such that: as explained in (1.7).Our particular choice for the function h is which corresponds to the invariant probability measure of the Brownian motion conditioned to stay in the interval [−1, 1].Let us now determine a constant κ(t, x).We have where Moreover the function x → x 2 e −x 2 π 2 t/8 is decreasing as soon as x ≥ 2 √ 2 π √ t , we obtain the following upper bound: where The integration by parts formula and a change of variables lead to Finally we can choose the constant κ(t, x) ))e −π 2 t/8 as t tends to infinity.Since the averaged number of iterations in the acceptance/rejection method corresponds to κ(t, x)/P x (τ > t) and since both κ(t, x) and P x (τ > t) are of the same order in the large time limit, the efficiency of the algorithm using (1.6) still remains strong when the time variable enlarges.Indeed let us decompose the following probability: Using the definition (1.14), we obtain The inequality |s n (x)| ≤ n for any x ∈ [−1, 1] and n ≥ 1 leads to We observe that each term of the series converges in a monotonous way towards 0 as t tends to ∞ which implies that the ratio tends towards 1 by the Lebesgue theorem.We therefore deduce that for any θ > 1, there exists t θ > 0 such that the average number of iterations in the acceptance/rejection algorithm is smaller than θ as soon as t ≥ t θ .

Algorithm and numerics
Let us now describe the algorithms used in the following in order to simulate q(t, x, dy), the conditional distribution of the Brownian motion at time t given τ > t.We know that p(t, x, dy) admits two different series expansion presented in (1.5) and (1.6).As introduced in Section 1.2, the classical convergent series method requires both a proposal distribution h, satisfying the inequality (1.7) that is p(t, x, y) ≤ κ(t, x)h t,x (y) (also necessary for classical acceptance/rejection methods), and a precise description of the series reminder characterized by the sequence (r n (t)) n and (r n (t)) n , see (1.8).
We just recall the results obtained in the previous section: Proposal distribution: h t,x (y) Reminder bounds: r n (t) It is straightforward that the convergent series method using (1.5) is convenient for small values of t while (1.6) is rather convenient for large t.That's why we choose a threshold t c > 0 (threshold for the conditional distribution) such that (1.5) is used for t ≤ t c and (1.6) otherwise.For practical purposes, we fix t c = 0.7, this choice is motivated by the curves in Fig. 2 and will be held for all numerical illustrations presented in this study.Applying the convergence series algorithm either for small times or large times permits to obtain the simulations presented in Fig. 3.We observe that, even if x = 0, the condition t < τ leads to a distribution which looks like symmetric as t becomes large and which converges towards h t,x (y) the invariant measure of the diffusion conditioned to stay in the interval [−1, 1].

Efficiency of the algorithms
Let us just recall classical results concerning the efficiency of the convergent series method introduced in Section 1.2.We introduce N c the random number of computations of terms f n used in order to simulate just one random variable X.In fact N c also corresponds to the number of random variable S generated before the algorithm halts.We also define N l the local counter depending on Y which represents the number of terms f n used till the decision of acceptance or rejection of the variable Y can be taken.Theorem IV.5.2 in Devroye [10] emphasizes the following upper-bound: where R n (y) is the reminder of the series expansion defined in the general framework (1.8).Let us also notice that the starting idea behind this bound is quite classical: it suffices to use the classical expansion: In the study developed in the previous section, we obtained precise bounds for the reminder terms only for n ≥ 1.So we shall modify the bound isolating the term n = 0 -instead of (1.17) -which plays a crucial role for the description of the algorithm efficiency: Since the uniform bound |R n (y)| ≤ r n holds for n ≥ 1, and since the average number of iterations is κ/I(f ), Wald's inequality immediately implies that the total number N c satisfies for general positive integrable functions f : Let us describe the consequences of this general statement to our particular algorithms.
For small values of the time variable t.
For small t, it is useful to use the series expansion (1.5) and the associated reminder bounds presented in Table 1.
Proposition 1.1.For t > 0 and x ∈ [−1, 1], we observe the following bound for the number of computations in the convergent series algorithm associated to the expansion (1.5): where ϑ 2 stands for the Jacobi theta function given by see [20] for instance.In particular the r.h.s of the previous inequality tends to 3 as t tends to 0.
Proof.The arguments are based on the upper-bound (1.18).Let us recall that Using the bound we obtain In order to conclude, it suffices to replace κ by (1.12) and to notice that I(f For large values of the time variable t. For large values of t it is more convenient to use the series expansion (1.6).A similar approach to Proposition 1.1 easily leads to the upper bound: The number of computations N c for the convergent series algorithm associated to the expansion (1.6) satisfies where the constant κ(t, x) associated to (1.6) is described in Section 1.3 and ϑ 3 stands for the Jacobi theta function given by Since the proofs of Proposition 1.2 and Proposition 1.1 are similar, we let the details of the proof to the reader.

Distribution of the Brownian first exit time
In this section, we focus our attention to the distribution of the first Brownian exit (τ, B x τ ), where B x stands for the one-dimensional Brownian motion starting in x and τ the exit time of the interval [−1, 1] as defined in (1.2).

Distribution of the first exit time τ
Since p(t, x, y) satisfies two different series expansions (1.5) and (1.6), we can also obtain two series for the cumulative distribution of the exit time τ : Therefore (1.5) becomes We deduce easily the expression of the pdf : Of course the particular case x = 0 ensures simplifications: the symmetry of the function φ implies φ(−(2n Such an expression for the pdf of τ is of prime interest for simulation purposes.Let us note that the reminder of the series is small for small values of t.Indeed the sequence (R 1 (2n + 1, t)) n≥1 is a decreasing sequence under the assumption t ≤ 9.For large values t, it is more convenient to consider (1.6) which leads to (see also (3.3) in Milstein and Tretyakov [18]).We deduce the expression Here also the case x = 0 plays a crucial role due to its simple expression: This expression is of prime interest as soon as the variable t is large.Indeed the series becomes alternating with a decreasing sequence (R 2 (2n + 1)) n≥1 as soon as t ≥ 4/(9π 2 ).

Algorithms and numerics
The aim is to describe an algorithm which permits to simulate both the Brownian exit time τ and the exit position B x τ of the interval [−1, 1].In the previous section, we have pointed out two different series (2.1) and (2.3) corresponding to the pdf of τ .We could therefore apply the classical convergent series method for simulation purposes.But here, we prefer to introduce another method based on an iterative procedure, the advantage of our approach is to deal with alternative series rather than general convergent series and therefore the reminder of the series is easier to bound.
First of all, we shall focus our attention to the case x = 0.In this case the interval is symmetric and the expression of the pdf of τ is simplified, see (2.2) and (2.4).Moreover these series are alternating for suitable conditions on the time variable t.So we can apply the alternating series method for the simulation of the exit time τ , the exit location being just uniformly distributed in {−1, 1}.The alternating series method is an acceptance/rejection method.We need therefore a proposal distribution and an acceptance procedure.For the proposal distribution, let us first fix t e > 0 (threshold for the exit distribution).Let us consider a standard gaussian random variable G.We define a new variable Y as follows: if 1/G 2 ≤ t e then Y = 1/G 2 otherwise Y = t e − 8 π 2 log(U ) where U is uniformly distributed on [0, 1] and independent of G.The density function of Y which corresponds to the proposal distribution of the algorithm satisfies: where κ −1 = π erf( 1/(2t e )) e π 2 te/8 /2.Using (2.2) and (2.4), we deduce the following link between the proposal distribution and the target distribution: Let us present now the acceptance/rejection method applied to this particular situation which permits to simulate the exit time τ in the symmetric case.

BROWNIAN EXIT TIME FOR SYMM. INTERVALS (with parameter t e )
BROWNIAN_EXIT_SYMMETRIC First initialization: N s = 0.
Step 1. Generate a random variable Y with pdf ĥ given by (2.5).If Y ≤ t e then set i = 1 and C = 1 else set i = 2 and C = κ.
Outcome: the random variable Z with density p τ and the number of incrementations needed N s .
The outcome variable distribution p τ corresponds to the target one as soon as the sequences (R i (2n + 1, t)/R i (1, t)) n≥1 appearing in (2.6) are decreasing.This is an easy adaptation of the classical alternating series method (proof left to the reader).Such a property leads to the condition: Let us just note that the probability of acceptance A = {Accept Y } in the acceptance/rejection algorithm satisfies: We deduce that the number of random variables Y simulated in order to obtain Z is geometrically distributed with average 2 and does not depend on the choice of t e .Nevertheless the parameter t e has an influence on the efficiency of the algorithm as illustrated in Fig. 5.This figure represents the averaged value of the number of iterations of Step 3 needed by the algorithm in order to simulate one r.v. with the p.d.f.p τ .This figure suggest to choose a parameter t e of the order of 1/2.For this parameter, we obtain: 1 − e −5π 2 te , (2.9) where x → erfc(x) is the complementary error function and t e is the parameter appearing in the algorithm and satisfying (2.7).In particular, for t e = 1/2, the value of the upper bound is approximatively 1.027 which emphasizes that the inequality is quite sharp in comparison with the estimated number of iterations in Figure 5 (solid line/stars).Moreover the bound is reasonably small which permits to confirm the efficiency of the proposed algorithm.
Proof.The arguments are quite similar to those developed in Theorem 5.1 in Devroye [10] for the efficiency of the alternating series method.Let us denote by N loop s the number of steps of type 3 used in order to go from Step 1 to Step 4, in other words: the number of increments n ← n + 1 during one loop.By Wald's equation and since the number of Steps 0 in this algorithm is geometrically distributed with parameter 1/2 (see (2.8)), we get Let us first compute the probability of the following event {N loop s > 0}.This event corresponds to {V < C}.In the following, we shall just recall that the constant C so as L 1 , U 1 ... depend on Y , that's why we use from now on the notation C = C Y .We obtain: Let us now consider the event {N loop s > 1}.This event corresponds to {CL 1 < V < CU 1 } and therefore The definition of L 1 and U 1 leads to where i = 1 for Y ≤ t e and i = 2 otherwise.The same arguments lead to We deduce Using the distribution of the random variable Y with density ĥ in (2.5), we obtain (2.11) Moreover, using the change of variable w = r −2 /2, we have Let us now come to the exit simulation in the asymmetric case.Since we know how to handle with symmetric intervals, we shall use this first algorithm BROWNIAN_EXIT_SYMMETRIC in an iteration procedure in order to solve the asymmetric case.The main idea consists in the following : • starting in x, we consider the largest interval centered in x of the type • We simulate the exit time of this interval denoted by T 1 and the exit position will be uniformly distributed in {x − δ, x + δ}.Step 0: Initialization.X = x, T = 0, test = 0, L = a, U = b and N as = 0.
While (test=0) do: Step 1. Set D = min(X−L, U −X). Generate a random variable τ (and the number of iterations N s ) using the algorithm BROWNIAN_EXIT_SYMMETRIC and define S = D 2 τ .Set T ← T + S and N as ← N as + N s .
Step 2. Generate a random variable V uniformly distributed on {−D, D}.Set X ← X + V Figure 6: Histogram of the algorithm counter corresponding to the Brownian exit from the interval [−1.5, 2] (left), p.d.f. and histograms of the exit time when exiting at the top or at the bottom of this interval (right).A sample of 100 000 simulations has been used for these figures and te = 0.5.
Step 3. If X ∈ {a, b} then test = 1 else set L ← X − L and U ← U − X.

End While
Outcome: the exit time T and the exit location X of the interval [a, b] and the total number of iterations N as .
The number of iterations is stochastically upper-bounded by a geometrically distribution with parameter 1/2 since we only deal with symmetric intervals.Moreover this random number is independent of the generation cost of any Brownian symmetric exit time and position.Let us finally note that (T, X) and (τ, B x τ ) are obviously identically distributed.This algorithm can be illustrated by Fig. 6  Corollary 2.2.The algorithm BROWNIAN_EXIT_ASYMM involves a random number of calls to BROWNIAN_EXIT_SYMMETRIC whose efficiency is characterized by the number of iterations N s .That's why the total number of iterations N as is directly linked to the efficiency of BROWNIAN_EXIT_ASYMM.We have where x → erfc(x) is the complementary error function and t e is the parameter appearing in BROWNIAN_EXIT_SYMMETRIC.
The statement is a direct consequence of the geometrical distributed upperbound of the number of calls to the symmetric case algorithm on one hand (Wald's identity therefore leads to E[N as ] ≤ 2E[N s ]) and of Proposition 2.1 on the other hand.

First exit time for one-dimensional diffusion
This section is concerned with the exit problem for a one-dimensional diffusion.Let us first consider (X t , t ≥ 0) the solution of the following stochastic differential equation: where (B t , t ≥ 0) stands for the standard one-dimensional Brownian motion.
As already introduced in (0.1), we denote by τ a,b (X) the first exit time of the interval [a, b].It suffices to assume the existence of a unique weak solution to the equation, see for instance [16] for the corresponding conditions.In order to simplify the presentation of all algorithms, we restrict our study to the constant diffusion case: σ(x) ≡ 1.Using the classical Lamperti transform, we observe that this restriction is not sharp at all.That is why, from now on, X stands for the unique solution of Let us note that, for the particular Brownian case: µ(x) ≡ 0, the first exit time has already been presented in Section 2. The aim is to use the results developed in the previous sections when considering the general diffusion case and the important tool for such a strategy is Girsanov's formula.

First Exit Time Algorithm (DET)
Let us now consider the exact simulation algorithm which permits to handle with the diffusion exit problem.
Step 0: Initialization.Z = x, T = 0, test = 0.Here x stands for the initial value of the diffusion.
While (test=0) do: Step 1. Generate an expon.distr.random variable E with parameter γ 0 and U and V two random variables uniformly distributed on [0, 1], the variables E, U and V being independent.
Step 2. Simulate the Brownian exit time and location and set N tot ← N tot + N as .
Step 3. If S < E then where X stands for the diffusion defined by (3.2).In particular, if µ + µ 2 is a non-negative function on the interval [a, b] (we set ρ = 0), then the outcome (Z, T ) has the same distribution as (X τ a,b (X) , τ a,b (X)).
Proof.The proof of Theorem 3.1 is organized as follows: first we introduce a stochastic theoretical model which is based on the one-dimensional Brownian motion and on an independent Poisson process.This model is closely related to the exact simulation introduced by Beskos and Roberts in [5].Secondly we consider in details the outcome of Algorithm (DET) and point out the strong link between the outcome and random variables derived from the theoretical model of the first step.Finally we shall use the Girsanov transformation in order to conclude the proof.
Step 1.A theoretical model.Let us consider for any non-negative functions f and g: where λ(•) is the Lebesgue measure.In particular, if A is defined as follows: the independence of both the Brownian motion and the Poisson process implies where For n ≥ 1, due to the Markov property of the Brownian path and since the Poisson process is independent of the Brownian motion, we have Since ξ 1 is exponentially distributed and independent of the Brownian motion, we get where Γ(y) := P(U 1 > γ(y)) and p(t, x) = P x (τ B > t).The probability measure M(x, dt, dy) represents the distribution of the couple (T, Y ) where T is an exponentially distributed r.v. with parameter γ + and Y represents the distribution of B T the value of the Brownian motion at time T starting in x and given {τ B > T }, T and (B t ) being independent.The recurrence relations (3.7) and (3.8) are satisfied for any n ≥ 1.
Step 2. Relation between Algorithm (DET) and the Brownian-Poisson theoretical model presented in Step 1.
If we denote by N 0 the number of Step 0 used during the procedure which leads to the computation of the outcome (Z, T ) and N 1 the number of exponentially distributed random variables generated (Step 1 ), then we obviously obtain Let us now consider that N 1 > 1.On the event {N 0 = 1} ∩ {N 1 > 1}, we observe that • the first exponentially distr.r.v.E satisfies E < S where S is given by Step 2 and corresponds to the Brownian exit time of the interval [a, b].
• Y c given that E < S satisfies V > γ(Y c ), where V is uniformly distributed and Y c becomes the new starting point for the next use of the exit problem.
In other words, if we denote by . Moreover by (3.7) and using the same arguments, we prove easily that I n satisfies the recurrence relations (3.7) and (3.8).We deduce that (3.10) Since the Algorithm (DET) is an acceptance/rejection algorithm, (3.10) leads to .
Step 3. The Girsanov transformation.In this last part of the proof, the aim is to link the distribution of (T, Z) described in (3.11) to the distribution of where X is the diffusion defined by (3.2).Using the definition of the function β and Itô's formula, we obtain that is an exponential martingale.Moreover the stopped martingale (M t∧τ B ) t≥0 is bounded.The stopping theorem therefore implies E x [M τ B ] = 1 which means that The expression (3.11) and Girsanov's transformation permits to obtain , where X stands for the diffusion defined by (3.2).In particular, if ρ = 0 that is µ 2 + µ is a non-negative function, we get

Efficiency of the algorithm
Let us now focus our attention to the analysis of Algorithm (DET).Of course since the algorithm permits to simulate exactly the random variables desired, there is no error terms to deal with, it suffices therefore to describe the time needed by the algorithm.We introduced in Algorithm (DET) the random variable N tot which permits to have a precise idea of the efficiency.Let us just add the information concerning the starting position of the Brownian motion B 0 = x with the following notation N tot = N x tot .Let us also note that the efficiency of Algorithm (DET) in particular depends on two different parameters: t e which appears in the use of the algorithm BROWNIAN_EXIT_SYM and therefore also in BROWNIAN_EXIT_ASYMM and t c ∈ R + which appears in CONDITIONAL_DISTR (if t ≤ t c we consider the algorithm associated to the small values of t and for t > t c the algorithm associated to the large values).
Using informations concerning the cost of each part of the algorithm, namely Proposition 1.1, Proposition 1.2 and Proposition 2.1, we obtain a bound for Theorem 3.2.The random variable N x tot which is one of the outcomes of Algorithm (DET) and represents its cost satisfies the following bound: there exists a constant C(t c , t e ) > 0 independent of both the interval [a, b] and the starting position x, such that Each term appearing in the denominator, that is E x [e −ρτ a,b (X) ] on one hand and E (a+b)/2 [e −γ+τ a,b (B) ] on the other hand, tends to 0 when the interval size b − a tends to infinity.It is therefore important to choose ρ and γ + as small as possible in order to obtain a sharper bound.The exit problem of the Brownian motion can be precisely described using classical results on Laplace transforms and differential equations, see for instance [9] or [6].We obtain Let us also note that E x [e −ρτ a,b (X) ] can be linked to the two linearly independent solutions of the differential equation (see, for instance [9]) which permits to describe the asymptotic behaviour as b−a tends to infinity.For the link between the Laplace transform and the speed measure, see for instance [2].
Proof.The counter N tot introduced in the algorithm can be decomposed as follows: where N x,k tot represents the number of counter increases observed in-between the k-th and (k+1)-th passage through the item Step 0. We recall that we defined N 0 in the proof of Theorem 3.1: it corresponds to the number of Step 0 necessary to obtain the desired outcome.Since Algorithm (DET) is an acceptance-rejection algorithm, the random variable N 0 is geometrically distributed.Let us also note that N x,k tot = 0 a.s. on the event {N 0 < k} and conditionally to {N 0 ≥ k}, N x,k tot has the same distribution as N x,1 tot .Hence . (3.13) The last equality is related to the third step in the proof of Theorem 3. • if S < E then N x,1 tot = N as .
• if S > E then N x,1 tot = N as + N c + N Yc,1 tot 1 {γ0V >γ(Yc)} where N x,1 tot is an independent copy of N x,1 tot .Such a property is essentially based on the Markov property of the Brownian paths.
We deduce 1 − e −5π 2 te , where x → erfc(x) is the complementary error function and t e is the parameter appearing in BROWNIAN_EXIT_SYMMETRIC.This parameter t e satisfying (2.7) can be chosen in order to minimize this average.
• Moreover we need some information on E x Using these three items and (3.14), we obtain .
The identity (3.13) permits to conclude the proof.

Modifications of Algorithm (DET)
Under the drift condition µ + µ 2 ≥ 0, Algorithm (DET) permits to simulate in an exact way the exit time of the interval [a, b] for diffusion processes.Let us now improve this algorithm in order to deal with any one dimensional diffusion.This generalization first requires a modified algorithm with outcome Step 0: Initialization.K = κ, Z = x, T = 0, test = 0.Here x stands for the initial value of the diffusion and κ the time upper-bound.

While (test=0) do:
Step 1 Generate an expon.distr.random variable E with parameter γ 0 and U , V and W three random variables uniformly distributed on [0, 1], the variables E, U , V and W being independent.
Step 2. Simulate the Brownian exit time and location and set N tot ← N tot + N as .
Step 3. If S = min(K, E, S) then • simulate the conditional Brownian location at time K: Let us introduce the following series expansion: the definition of I n (x, f, g, κ) is similar to the definition appearing in the proof of Theorem 3.1, it suffices to replace in the definition τ B by τ B ∧ κ.Therefore where (ξ 1 , U 1 ) stands for the coordinates of the Poisson process point with the smallest abscissa.Moreover we obtain the following step by step property: Step 2. Relation between Algorithm (κ-DET) and the Brownian-Poisson theoretical model presented in Step 1.
If we denote by N 0 the number of Step 0 used during the procedure which leads to the computation of the outcome (Z, T ) and N 1 the number of exponentially distributed random variables generated (Step 1 ), then we obviously obtain for Using similar arguments, we can prove that I n satisfies the same step by step relation as (3.16).So by identification, we get I n (x, f, g, κ) = I n (x, f ×e −ρ(κ−•) , g× β m , κ) for all n ≥ 0 and therefore Since Algorithm (κ-DET) is an acceptance rejection algorithm, we have The link between β m and β leads to , where M t is the exponential martingale defined in (3.12).It is actually important to note that since the time interval is bounded (upper-bounded by κ) we can use the time reversal expression e −ρ(κ−•) and the ratio in the previous equation verifies a cancellation of the terms e −ρκ .Finally it suffices therefore to use the Girsanov transformation in order to obtain the announced result: Let us now focus our attention on the exact simulation of (X τ a,b , τ a,b ) for any diffusion process with regular drift term and constant diffusion coefficient.We have already seen that Algorithm (DET) permits to reach such objective however it is restricted to drift terms satisfying µ + µ 2 ≥ 0 on the interval [a, b].If such a condition is not verified, we propose the following procedure: first we choose some time parameter κ > 0, then we apply: GENERAL DIFFUSION EXIT TIME (GDET) parameters: κ, a and b.

End While
Outcome: the couple of random variables (Z, T ) and the number of iterations N it .
Due to the Markov property, it is obvious that the outcome of such an algorithm and (X τ a,b (X) , τ a,b (X)) are identically distributed.Moreover the number of iterations of GDET has the same distribution as It is evident that the number of iterations decreases as κ becomes large but we should be careful for a clever choice of κ since the number of rejections in Algorithm (κ-DET) grows exponentially fast when κ enlarges, see Proposition 3.4.A reasonable choice is therefore κ ≈ ρ −1 .

Examples and numerics
The aim of this section is to emphasize the efficiency of Algorithm (DET) and Algorithm (κ-DET) through the analysis of two examples.The first situation concerns a diffusion whose drift term b satisfies the condition µ + µ 2 ≥ 0 and consequently only requires the basic Algorithm (DET).The second situation concerns the Ornstein-Uhlenbeck process which plays an essential role in several applications namely in neuroscience.For both examples, we set the parameters appearing in the algorithms: t c = 0.7 and t e = 0.5.

Example with the Algorithm (DET)
We first consider a stochastic differential equation which was already presented in [13] for the simulation of the first passage time.Here the objective is clearly different since we focus our attention to the exit time and exit position of the diffusion and the algorithm is different too.Let us also note that a similar diffusion process was also introduced in [5].
We consider the following stochastic differential equation: dX t = (2 + sin(X t )) dt + dB t , t ≥ 0, X 0 = 0. (3.17) We first observe that γ(x) = (µ 2 (x) + µ (x))/2 = ((2 + sin(x)) 2 + cos(x))/2 satisfies 0 ≤ γ ≤ 5. We deduce that we can apply Theorem 3.1 with the particular choice ρ = 0: the outcome (Z, T ) of Algorithm (DET) has therefore the same distribution as (X τ a,b (X) , τ a,b (X)).The algorithm permits to obtain the histograms of respectively the exit time (Fig. 7       Let us now consider the Ornstein-Uhlenbeck process given by the following SDE dX t = −µ 0 X t dt + dB t , X 0 = 0. Since the coefficient ρ is strictly positive (for positive µ 0 > 0), we cannot use the (DET)-algorithm in order to simulate the exit time.We shall therefore use the (κ-DET) algorithm in order to simulate exactly the couple (X τ−a,a(X)∧κ , τ −a,a (X)∧ κ) for any given constant time κ > 0. Fig. 10 represents the distribution of X τ−a,a(X)∧κ and Fig. 11 illustrates the time distribution and describes the counter values N tot .In order to simulate exactly the exit time for the Ornstein-  Uhlenbeck process, we use the (GDET)-algorithm.The histogram in Figure 12 emphasizes the distribution of the exit time for the particular case: µ 0 = 2 and a = 1 and the efficiency of the algorithm for such a simulation.We can easily observe that the exit time increases as the parameter µ 0 increases, see Fig. 13.This result can be generalized for any K ≤ κ and therefore we obtain .

Figure 1 :
Figure 1: Decomposition of the Brownian paths

4 1
Brownian exit time of the interval [a, b] as the Brownian trajectory starts in x.The corresponding algorithm, presented in Section 2, is denoted BROWNIAN_EXIT_ASYMM (x,[a,b]) .The two main algorithms (DET) and (GDET) presented in Section 3 use these two previous algorithms as basic components.They permit the exact simulation of diffusion exit times under weak conditions on the coefficient µ.Efficiency results are pointed out (Theorem 3.2 and Proposition 3.4) and numerical illustrations complete the study in Section 3.Brownian motion constrained to stay in an interval [a, b] Let us first consider the Brownian motion in the space interval [a, b].We need to describe the distribution of B t for a given t > 0, given that the first exit of the interval τ a,b (B) is larger than t.We fix the starting position of the Brownian motion B 0 = y ∈ (a, b).Due to both the translation invariance and the scaling property of the Brownian motion, we get

Figure 4 :
Figure 4: Average value of the algorithm counter Nc versus the time variable, for the starting position x = 0.5 (solid line) and x = 0.2 (dashed line) with tc = 0.7 and 100 000 simulations.

Figure 5 :
Figure 5: The estimated average value of the counter Ns versus the barrier te with 100 000 simulations for the estimation (stars) and the upper-bound function given by (2.9) (solid line).

. 10 )
Combining the definition of R 1 in (2.2) and the change of variable w = 1} then we set T = T 1 and X = B x T1 else we start a new simulation for the exit time and position of a Brownian motion Bx starting in x = B T1 from the largest symmetric interval centered in x and included in [−1, 1].This exit time is denoted by T 2 .• As above, if Bx T2 ∈ {−1, 1} then we set X = Bx T2 and T = T 1 + T 2 else we start again with a new initial position in the interval [−1, 1].BROWNIAN EXIT TIME FOR ASYMMETRIC INTERVALS [a, b] BROWNIAN_EXIT_ASYMM Input: x (initial value of the Brownian paths) and [a, b].
for the standard Brownian exit time of the asymmetric interval [−1.5, 2].Of course the algorithm is not restricted to the standard Brownian case, it takes into account any initial position x belonging to the interval [a, b].

2 + 1 . 3 . 1 .
and T ← T + S else go to Step 0 end if, else • simulate the Brownian location at time E given that the exit time is larger than E: (Y c , N c ) = CONDITIONAL_DISTR (Z,[a,b],E), and set N tot ← N tot + N c .• if γ 0 V ≤ γ(Y c ) then go to Step 0 else set Z ← Y c and T ← T + E. end if.End While Outcome: the exit location Z, the exit time T of the interval [a, b] and the efficiency index N tot .Let ρ ≥ 0 such that γ(x) := µ 2 (x)+µ (x) ρ is a non negative function on the interval [a, b].We introduce γ + = sup x∈[a,b] γ(x) and define ∆ = b a µ(y)dy and β(x) = min 1, e −∆ exp x a µ(y) dy.(3.3)Let us just notice that 0 ≤ β(a) ≤ 1 and 0 ≤ β(b) ≤ Theorem The outcome (Z, T ) of the Algorithm (DET) with parameter γ 0 = γ + and input functions γ(•) and β(•) satisfies: for any non-negative measurable functions f and g, τ B means τ a,b (B) for notational simplicity and B represents a Brownian motion starting in x ∈ [a, b] and γ a non negative continuous function.Let us now introduce a Poisson point process N on the space R + × [0, γ + ] with Lebesgue intensity measure and independent of the Brownian paths.If we reorganize the points of the Poisson process with respect to the abscissa, we obtain a sequence of points defined by (ξ n , U n ) n≥1 where (U n ) are independent uniformly distributed r.v. on [0, γ + ] and ξ n := n j=1 e j with (e j ) j≥1 a sequence of independent exponentially distributed r.v. with parameter γ + .Both sequences (U n ) n and (e n ) n are independent.Therefore, for any subset A of R + × [0, γ + ], we get N (A) = n≥1 1 {(ξn,Un)∈A} and P(N (A) = 0) = e −λ(A) , ρτ a,b (X) ]E (a+b)/2 [e −γ+τ a,b (B) ] , ∀x ∈]a, b[.We recall that τ a,b stands for the first exit time of the interval [a, b].The parameters ρ and γ + are defined in the introduction of Theorem 3.1.

1 .
Let us now describe E[N x,1 tot ].Let (S, Y, N as ) stands for the result of the first use of the function BROWNIAN_EXIT_ASYMM and (Y c , N c ) of the first use of CONDITIONAL_DISTR , we can therefore distinguish two different cases.

. 14 )•e −25 π 2 te 8
Let us note that P(S > E) = P x (τ a,b (B) > ξ) where τ a,b (B) is the exit time of the Brownian motion from the interval [a, b] and ξ is exponentially distributed with parameter γ + .Using the scaling property (1.1), we have P x (τ a,b (B) > ξ) = P y (τ > 4ξ(b − a) −2 ), where τ is the first Brownian exit time of the normalized interval [−1, 1] and y = 2x−a−b b−a .Since y → P y (τ > 4ξ(b − a) −2) is a concave function whose derivative vanishes for y = 0 (see the expression (2.3)), we getP x (τ a,b (B) > ξ) ≤ P 0 (τ > 4ξ(b − a) −2 ).•Since N as is the cost of the function BROWNIAN_EXIT_ASYMM (x, [a, b]) and using the scaling property (1.1), we obtain that it is equal to the cost of BROWNIAN_EXIT_ASYMM (y, [−1, +1]) which satisfies due to Corollary 2.2: E[N as ] ≤ C 0 (t e ) with C 0 (t e ) [N c |E = t] where N c is the cost of the function CONDITIONAL_DISTR (x, [a, b], t).Due to the scaling property (1.1), we know that the cost of this function is identical as the cost of CONDITIONAL_DISTR (y, [−1, 1], 4t(b−a) −2 ).We choose a parameter t c > 0 such that 4t(b − a) −2 ≤ t c corresponds to the algorithm for small time values and 4t(b − a) −2 > t c corresponds to large times.Combining Proposition 1.1 and Proposition 1.2 permits to have the following bound: for any x ∈ [a, b], X) ∧ κ) for any κ > 0. The simulation of (X τ a,b (X) , τ a,b (X)) can then be obtained by iteration due to the diffusion Markov property.Let us present Algorithm (κ-DET).MODIFIED DIFFUSION EXIT TIME (κ-DET) Parameters: ρ and γ 0 , input functions γ(•) and β m (•) First initialization: N tot = 0.
left) and the counter N tot illustrating the efficiency of the algorithm DET (right).These histograms use a sample of size 100 000 and concerns the interval [a, b] = [−0.5,0.5].The average value of the counter is 8.5 and its estimated standard deviation is 8.88.Let us just compare the approximated results obtained by Algorithm (DET) for the interval [a, b] = [−0.5,0.5] with a classical Euler method with step size 0.0001 and 100 000 samples.Algo.E[τ a,b ] σ(τ a,b ) E[τ a,b 1 {Xτ a,b =a} ] P(X τ a,b = a) intervals like for instance [−1, 2] (Fig. 8), the counter becomes large (average: 1205) and the algorithm DET is rather time consuming (C++ progaming: CPU 1,77 sec for 100 000 samples of the exit from the interval [−0.5, 0.5] and CPU 230,8 sec for the interval [−1, 2]).
Figure 9   is an illustration of the high level of rejection for the algorithm (DET) as the interval size increases.

Figure 8 :
Figure 8: Simulation of the first exit time from the interval [a, b] = [−1, 2] for the diffusion (3.17) (100 000 samples).Histograms of the exit time variable (left) and of the counter Ntot (right).

Figure 9 :
Figure 9: FET from the interval [a, b] = [−1, 2] for the diffusion (3.17) (100 000 samples).Empirical c.d.f. of the exit times when the exit occurs at the top -lower curve -or at the bottom of the interval -upper curve -(left).Simulation of the FET from the interval [−a, a] for the diffusion (3.17) (10 000 samples).Average counter E[Ntot] in logarithmic scale versus a (right).

Figure 10 :
Figure 10: Distribution of X τ −a,a (X)∧κ with a sample of size 10 000, for the drift parameter µ0 = 2, the interval size a = 1 and the constant time upper-bound κ = 0.5: histogram (left) and cumulative distribution (right).

Figure 11 :
Figure 11: Cumulative distribution of τ−a,a(X) ∧ κ with a sample of size 10 000, for the drift parameter µ0 = 2, the interval size a = 1 and the constant time upper-bound κ = 0.5 (left, blue curve) or κ = 1 (left, black curve) and the corresponding histogram of the counter Ntot for κ = 0.5 (right).

4529458
Proposition 2.1.Let us note that N s is the random number of iterations of Step 3 used in the previous algorithm called BROWNIAN_EXIT_SYMMETRIC in order to simulate just one random variable Z with density p τ .Then Let us note that A 1 (t e ) becomes small as t e becomes small.Let us now focus our attention to A 2 defined in (2.10).