High-frequency data and limit order books — Lecture 4 - March 18th, 2022 Ioane Muni Toke MICS Laboratory and Chair of Quantitative Finance CentraleSupélec – Université Paris-Saclay, France CentraleSupelec 3A Ingénieur Mathématiques et Data Science CentraleSupelec MS Mathématiques Appliquées à la Finance IP Paris M2 Statistics, Finance and Actuarial Science Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 1 Table of contents One dimensional Hawkes processes Multidimensional Hawkes processes Hawkes processes as branching processes Lab 4 Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 2 One dimensional Hawkes processes Table of contents One dimensional Hawkes processes Multidimensional Hawkes processes Hawkes processes as branching processes Lab 4 Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 3 One dimensional Hawkes processes One-dimensional Hawkes processes Definition (Linear self-exciting process) A counting process N is called a (linear, one-dimensional) Hawkes process if it is a counting process with (stochastic) intensity: Z t X λt = λ0 (t) + ν(t − s)dNs = λ0 (t) + ν(t − ti ), 0 0<ti <t where λ0 : R 7→ R+ and ν : R+ 7→ R+ are deterministic functions. I ν expresses the positive influence of the past events ti on the current value of the intensity process. I Hawkes processes are self-exciting processes. I λ0 is the baseline intensity (λ ≥ λ0 ). From now on, λ0 > 0 constant. I Original paper by [1]. Used in geology (earthquakes replicas), finance (see later in the course), biology (neuron excitation, multidimensional case, see below). Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 4 One dimensional Hawkes processes Sample path, kernels 5 Intensity maximum λ* Intensity λ Events I Exponential kernel commonly used: 4 ν(t) = 3 P X αj e −βj t 1R+ (t). j=1 2 1 0 0 2 4 6 8 10 Time Sample path of a 1D-Hawkes process with a single exponential kernel (P = 1) and parameters λ0 = 1.2, α1 = 0.6, β1 = 0.8. Ioane Muni Toke (CentraleSupélec) I Exponential kernels allow for efficient computations, especially for maximum-likelihood estimation (see later), but do not exhibit long-memory properties. HFD-LOB March 18th, 2022 February-April 2022 5 One dimensional Hawkes processes Stability of a Hawkes process If the process has reached a stationary regime, the average intensity value is: 1− λ R ∞0 . 0 ν(x)dx I The average number of points of a Hawkes process on a time interval of length T is thus λ0 T . in a stationary regime 1 − kνk1 I If kνk1 < 1, the Hawkes process is sub-critical / stationary. If kνk1 = 1 (resp. > 1), the process is called critical (resp. supercritical) (See discussion in finance later in the course). I In the case of exponential kernels, the stability condition is written P X αj j=1 Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 βj < 1. February-April 2022 6 One dimensional Hawkes processes Thinning for stochastic intensities I [4] extends the thinning method for non-homogeneous Poisson processes introduced by [2] to point processes with stochastic intensities. Theorem (Thinning) Consider point process N with intensity λt on an interval (0, T ]. Suppose we can find a process λ∗t such that λt ≤ λ∗t (P-a.s.). Let t1∗ , t2∗ , . . . tn∗ ∈ (0, T ] be the points of the process N ∗ with intensity λ∗ . For each of the points, attach a mark p = 1 with probability λ(tj∗ ) λ∗ (tj∗ ) , else p = 0. Then the points with marks p = 1 form a point process which is the same as N. I If λ∗t can be constructed pathwise as a piecewise constant process, we can thus simulate the point process N with simple exponential random variables. Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 7 One dimensional Hawkes processes Simulation algorithm for a one-dimensional Hawkes process 1. Initialization : Set t ← 0, λ∗ ← λ0 (0) and an empty list of events. 2. Main loop : While t < T : 1 (a) New event candidate : Generate U U[0,1] and set t ← t − ∗ log U. λ If t ≥ T , Then return the list of events. (b) Thinning : Generate D U[0,1] . λ(t) If D ≤ ∗ , λ Then New event: PP add t to the list of events and update the maximum intensity λ∗ ← λ(t) + j=1 αP ; Else No new event: update the maximum intensity λ∗ ← λ(t). 3. Output: return the list of events. It is crucial to observe that exponential kernels lead to easy update of the jump part of the intensity, without having to parse all previous events. Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 8 One dimensional Hawkes processes Path of a Hawkes process and its intensity I Simulation of a one-dimensional Hawkes process with parameters P = 1, λ0 = 1.2, α1 = 0.6, β1 = 0.8. 12 5 * * Intensity maximum λ Intensity λ Events Intensity maximum λ Intensity λ Events 10 4 8 3 6 2 4 1 2 0 0 0 10 20 30 40 50 Time Ioane Muni Toke (CentraleSupélec) 60 70 80 90 100 0 2 4 6 8 10 Time HFD-LOB March 18th, 2022 February-April 2022 9 One dimensional Hawkes processes Log-likelihood of a point process I Proposition (Log-likelihood of a point process) The log-likelihood of a counting process (Nt )t≥0 with conditional intensity (λt )t≥0 observed on [0, T ] is Z T Z T log LT = log λs dNs − λs ds. 0 0 I Example: In the case of a time-homogeneous Poisson process, we have for an observed sample 0 < t1 < . . . < tn < T : log LT = n log λ − λT . The maximum-likelihood estimator of the intensity is thus n λ̂MLE = , T as expected. Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 10 One dimensional Hawkes processes Log-likelihood of a Hawkes process I I In the case of a Hawkes process with P exponential kernels, the log-likelihood of an observation 0 < t1 < . . . < tn < T is: n P X i−1 X X log LT = log λ0 (ti ) + αj e −βj (ti −tk ) − Λ(0, T ). i=1 j=1 k=1 I The double sum can be bypassed by a recursive computation ([4]) n P X X log LT = ln λ0 (ti ) + αj Rj (i) − Λ(0, T ), i=1 j=1 where Rj (1) = 0 and Rj (i) = e −βj (ti −ti−1 ) (1 + Rj (i − 1)), for all j = 1, . . . , P. Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 11 One dimensional Hawkes processes Log-likelihood of a Hawkes process II Proposition (Log-likelihood of a Hawkes process, exponential kernels) The log-likelihood of a Hawkes process (Nt )t≥0 with P exponential kernels observed on [0, T ] is Z T n X P n P X X X αj log LT = − λ0 (s)ds − 1 − e −βj (T −ti ) + log λ0 (ti ) + αj Rj (i) . β j 0 i=1 j=1 i=1 j=1 I Maximum-likelihood estimator numerically available. I Analytical gradients available for better optimization. I In the case of non-exponential kernel, the absence of recursive evaluations may lead to prohibitive computational times. Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 12 One dimensional Hawkes processes Maximum-likelihood estimation I [3]: MLE estimator θ̂T = (λ̂0 , α̂j , β̂j )) is I consistent, i.e. converges in probability to the true values θ∗ = (λ0 , αj , βj )) as T → ∞ : ∀ > 0, lim P[|θ̂T − θ∗ | > ] = 0. T →∞ I asymptotically normal, i.e. √ T θ̂T − θ∗ → N (0, I −1 (θ∗ )) h ∂λ where I (θ) = E λ1 ∂θ i ∂λ ∂θj i . i,j I asymptotically efficient, i.e. asymptotically reaches the lower bound of the variance of an estimate. Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 13 One dimensional Hawkes processes Change of time I The “change of time” theorem proved for the non-homogeneous Poisson process can be extended in the general case. Theorem (Change of time of a point process) Let (Ñt )t≥0 be a point process with intensity (λt )t≥0 . Define for each t the stopping time τ (t) such that Z τ (t) λs ds = t 0 Then Nt = Ñτ (t) is a time-homogeneous Poisson process with intensity 1. I Consequence: If the t̃i ’s are the points of Ñ, then the quantities exponentially distributed with parameter 1. Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 R t̃i t̃i−1 λs ds are February-April 2022 14 One dimensional Hawkes processes Goodness-of-fit I For a one-dimensional Hawkes process with exponential kernels: Z ti Λ(ti−1 , ti ) = λ0 (s)ds 8 7 ti−1 Empirical quantiles 6 5 + 4 P X αj j=1 3 2 βj 1 − e −βj (ti −ti−1 ) Aj (i − 1), where Aj (1) = 1 and Aj (i − 1) = 1 + e −βj (ti−1 −ti−2 ) Aj (i − 2). 1 0 0 1 2 3 4 5 Theoretical quantiles Ioane Muni Toke (CentraleSupélec) 6 7 8 I Quantile plots available as a visual indication of goodness-of-fit HFD-LOB March 18th, 2022 February-April 2022 15 Multidimensional Hawkes processes Table of contents One dimensional Hawkes processes Multidimensional Hawkes processes Hawkes processes as branching processes Lab 4 Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 16 Multidimensional Hawkes processes Multidimensional Hawkes processes Definition (Multidimensional Hawkes processes) A M-dimensional Hawkes process is a point process Nt = (Nt1 , . . . , NtM ) with intensities (λm t )t≥0 , m = 1, . . . , M such that: m λ (t) = λm 0 (t) + M Z X n=1 t gmn (t − s)dNsn , 0 where λ0 : [0, ∞) → R+ and gmn : [0, ∞) → R+ , m, n = 1, . . . , M are deterministic functions. R I We may write using a vector notation: λ(t) = λ0 + 0t G(t − s) · dNs . mn I In the case of exponential kernels, G(t) = αmn e −β t . m,n=1,...,M Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 17 Multidimensional Hawkes processes Stability of multidimensional Hawkes processes I If the process is in a stationary state, the average intensities µt ∈ RM should satisfy: Z µ= I− −1 ∞ G(u)du λ0 0 R I If the spectral radius of the matrix Γ = 0∞ G(u)du is strictly smaller than 1, then the M-dimensional Hawkes process is stable. mn I In the exponential kernel case, Γ = βαmn . m,n=1,...,M Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 18 Multidimensional Hawkes processes Simulation of multidimensional Hawkes processes I The algorithm is formally identical to one in one dimension. P I Let Ik (t) = kn=1 λn (t), k = 1, . . . , M. ∗ , and the next candidate event I The total intensity is now IM (t), bounded above by IM ∗ must not be generated with IM . I The thinning step is now: Generate D U[0,1] . If D ≤ IM (s) ∗ , IM Then set s as a point of the process n0 , where n0 is such that go through the main loop again ; ∗ ← I (s) and generate a new candidate point. Else update IM M Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 In0 −1 (s) ∗ IM <D≤ In0 (s) ∗ , IM and February-April 2022 19 Multidimensional Hawkes processes Log-likelihood of multidimensional Hawkes processes I Log-likelihood of a multidimensional Hawkes process: log LT = M X log Lm T, m=1 with: log Lm T = RT 0 m log λm s dNs − Ioane Muni Toke (CentraleSupélec) RT 0 λm s ds.. HFD-LOB March 18th, 2022 February-April 2022 20 Hawkes processes as branching processes Table of contents One dimensional Hawkes processes Multidimensional Hawkes processes Hawkes processes as branching processes Lab 4 Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 21 Hawkes processes as branching processes Branching representation of a Hawkes process I Proposition (Branching representation of a Hawkes process) Let T > 0. Let λ0 > 0 and ν : [0, ∞) → R+ a deterministic function. Consider the following procedure: (0) 1. Generate a time-homogeneous Poisson process {ti } with intensity λ0 on [0, T ]. (0) (1) 2. For each ti , generate a non-homogeneous Poisson process {ti } with deterministic (0) (0) intensity t 7→ ν(t − ti ) on [ti , T ]. (1) 3. Repeat operation 2. for each point of all the sets {ti }, then for each point of all the (2) sets {ti }, etc. until there is no new point generated in [0, T ]. Then the ordered setR of all the points generated in [0, T ] is a Hawkes process N on [0, T ] with t intensity λt = λ0 + 0 ν(t − s) dNs . I Link with Galton-Watson processes Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 22 Hawkes processes as branching processes Branching representation of a Hawkes process II I The average number of points (offspring) generated by one point (parent) is kνk1 . We retrieve the three regimes (sub-critical, critical, supercritical) discussed above depending on the value of kνk1 compared to 1.. I Provides a new algorithm for the simulation of Hawkes processes I Immediate extension to the case of time-dependent baseline intensity and/or the case of a multidimensional Hawkes process. Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 23 Lab 4 Table of contents One dimensional Hawkes processes Multidimensional Hawkes processes Hawkes processes as branching processes Lab 4 Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 24 Lab 4 Lab 4 - Questions I 1. Implementation of fundamental routines. It is sufficient to write the following routines for a single exponential kernel (P = 1). 1.1 Write a function that simulates one path of a Hawkes process. Input: process parameters and horizon. Output: time series of events. 1.2 Write a function that computes the log-likelihood of a Hawkes process. Input: process parameters, horizon and time series of events. Output: value of the log-likelihood. 1.3 Write a function that computes the MLE estimates of the parameters of a Hawkes process. Input: optimization starting point, horizon and time series of events. Output: values of estimated parameters. 1.4 Write a function that computes the intensity integrated between consecutive events for a Hawkes process. Input: process parameters, horizon and time series of events. Output: series of integrated intensities (transformed durations). Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 25 Lab 4 Lab 4 - Questions II 2. Testing the implementation. 2.1 Choose some values to define a stationary Hawkes process with one exponential kernel. Simulate a realization of this Hawkes process with horizon T and compute the MLE estimates of the parameters. 2.2 Compute the QQ-plot of the integrated intensities of the fitted process versus the theoretical exponential distribution. Check visually the goodness-of-fit. 3. Convergence and performance. 3.1 For a given T , simulate multiple realizations of a Hawkes process (e.g., 100). Show that the MLE estimates converge towards the true values when T increases, and that the order of convergence in T is the one expected. 3.2 Plot the computational cost of your simulation and estimation in T is the one expected. 3.3 Add to your plots answering the two questions above the results obtained with an external library such as https://pypi.org/project/hawkes/. Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 26 Lab 4 References I [1] Alan G. Hawkes. “Spectra of some self-exciting and mutually exciting point processes”. In: Biometrika 58.1 (Apr. 1971), pp. 83 –90. [2] P. A. W Lewis and G. S. Shedler. “Simulation of nonhomogeneous poisson processes by thinning”. In: Naval Research Logistics Quarterly 26.3 (1979), pp. 403–413. [3] Yoshiko Ogata. “The asymptotic behaviour of maximum likelihood estimators for stationary point processes”. In: Annals of the Institute of Statistical Mathematics 30.1 (1978), pp. 243–261. [4] Yosihiko Ogata. “On Lewis’ simulation method for point processes”. In: IEEE Transactions on Information Theory 27.1 (Jan. 1981), pp. 23–31. Ioane Muni Toke (CentraleSupélec) HFD-LOB March 18th, 2022 February-April 2022 27