Fit Hawkes on finance data

This example fit hawkes kernels on finance data provided by tick-datasets. repository.

Kernels norms of a Hawkes process fit on finance data of Bund market place. This reproduces experiments run in

Bacry, E., Jaisson, T. and Muzy, J.F., 2016. Estimation of slowly decreasing Hawkes kernels: application to high-frequency order book dynamics. Quantitative Finance, 16(8), pp.1179-1201.

with \(P_u\) (resp. \(P_d\)) counts the number of upward (resp. downward) mid-price moves and \(T_A\) (resp. \(T_b\)) counts the number of market orders at the ask (resp. bid) that do not move the price. We observe expected behavior with for example mid-price moving downward triggering (resp. preventing) market orders at the ask (resp. at the bid).

../_images/plot_hawkes_finance_data_001.png

Script output:

(5.88 MB) [                                        ]  0%

(5.88 MB) [= ] 2% (5.88 MB) [== ] 5% (5.88 MB) [=== ] 7% (5.88 MB) [==== ] 10% (5.88 MB) [===== ] 12% (5.88 MB) [====== ] 15% (5.88 MB) [======= ] 17% (5.88 MB) [======== ] 20% (5.88 MB) [========= ] 22% (5.88 MB) [========== ] 25% (5.88 MB) [=========== ] 27% (5.88 MB) [============ ] 30% (5.88 MB) [============= ] 32% (5.88 MB) [============== ] 35% (5.88 MB) [=============== ] 37% (5.88 MB) [================ ] 40% (5.88 MB) [================= ] 42% (5.88 MB) [================== ] 45% (5.88 MB) [=================== ] 47% (5.88 MB) [==================== ] 50% (5.88 MB) [===================== ] 52% (5.88 MB) [====================== ] 55% (5.88 MB) [======================= ] 57% (5.88 MB) [======================== ] 60% (5.88 MB) [========================= ] 62% (5.88 MB) [========================== ] 65% (5.88 MB) [=========================== ] 67% (5.88 MB) [============================ ] 70% (5.88 MB) [============================= ] 72% (5.88 MB) [============================== ] 75% (5.88 MB) [=============================== ] 77% (5.88 MB) [================================ ] 80% (5.88 MB) [================================= ] 82% (5.88 MB) [================================== ] 85% (5.88 MB) [=================================== ] 87% (5.88 MB) [==================================== ] 90% (5.88 MB) [===================================== ] 92% (5.88 MB) [====================================== ] 95% (5.88 MB) [======================================= ] 97% (5.88 MB) [========================================] 100%

Python source code: plot_hawkes_finance_data.py

import numpy as np

from tick.dataset import fetch_hawkes_bund_data
from tick.hawkes import HawkesConditionalLaw
from tick.plot import plot_hawkes_kernel_norms

timestamps_list = fetch_hawkes_bund_data()

kernel_discretization = np.hstack((0, np.logspace(-5, 0, 50)))
hawkes_learner = HawkesConditionalLaw(
    claw_method="log", delta_lag=0.1, min_lag=5e-4, max_lag=500,
    quad_method="log", n_quad=10, min_support=1e-4, max_support=1, n_threads=4)

hawkes_learner.fit(timestamps_list)

plot_hawkes_kernel_norms(hawkes_learner,
                         node_names=["P_u", "P_d", "T_a", "T_b"])

Total running time of the example: 1.92 seconds ( 0 minutes 1.92 seconds)

Mentioned tick classes: