Package: jumpdiff
JumpDiffjumpdiffis apythonlibrary with non-parametric Nadaraya─Watson estimators to extract the parameters of jump-diffusion processes.
Withjumpdiffone can extract the parameters of a jump-diffusion process from one-dimensional timeseries, employing both a kernel-density estimation method combined with a set on second-order corrections for a precise retrieval of the parameters for short timeseries.InstallationTo installjumpdiff, runpip install jumpdiffThen on your favourite editor just useimportjumpdiffasjdDependenciesThe library parameter estimation depends onnumpyandscipysolely. The mathematical formulae depend onsympy. It stems fromkramersmoyalproject, but functions independently from it3.DocumentationYou can find the documentationhere.Jump-diffusion processesThe theoryJump-diffusion processes1, as the name suggest, are a mixed type of stochastic processes with a diffusive and a jump term.
One form of these processes which is mathematically traceable is given by theStochastic Differential Equationwhich has 4 main elements: a drift term, a diffusion term, and jump amplitude term, which is given by a Gaussian distribution, and finally a jump rate.
You can find a good review on this topic in Ref. 2.Integrating a jump-diffusion processLet us use the functions injumpdiffto generate a jump-difussion process, and subsequently retrieve the parameters. This is a good way to understand the usage of the integrator and the non-parametric retrieval of the parameters.First we need to load our library. We will call itjdimportjumpdiffasjdLet us thus define a jump-diffusion process and usejd_processto integrate it. Do notice here that we need the driftand diffusionas functions.# integration time and time samplingt_final=10000delta_t=0.001# A drift functiondefa(x):return-0.5*x# and a (constant) diffusion termdefb(x):return0.75# Now define a jump amplitude and ratexi=2.5lamb=1.75# and simply call the integration functionX=jd.jd_process(t_final,delta_t,a=a,b=b,xi=xi,lamb=lamb)This will generate a jump diffusion processXof lengthint(10000/0.001)with the given parameters.Usingjumpdiffto retrieve the parametersMoments and Kramers─Moyal coefficientsTake the timeseriesXand use the functionmomentsto retrieve the conditional moments of the process.
For now let us focus on the shortest time lag, so we can best approximate the Kramers─Moyal coefficients.
For this case we can simply employedges,moments=jd.moments(timeseries=X)In the arrayedgesare the limits of our space, and in our arraymomentsare recorded all 6 powers/order of our conditional moments.
Let us take a look at these before we proceed, to get acquainted with them.We can plot the first moment with any conventional plotter, so lets use hereplotlyfrommatplotlibimportmatplotlib.plotlyasplt# we want the first power, so we need 'moments[1,...]'plt.plot(edges,moments[1,...])The first moment here (i.e., the first Kramers─Moyal coefficient) is given solely by the drift term that we have selected-0.5*xAnd the second moment (i.e., the second Kramers─Moyal coefficient) is a mixture of both the contributions of the diffusive termand the jump termsand.You have this stored inmoments[2,...].Retrieving the jump-related termsNaturally one of the most pertinent questions when addressing jump-diffusion processes is the possibility of recovering these same parameters from data. For the given jump-diffusion process we can use thejump_amplitudeandjump_ratefunctions to non-parametrically estimate the jump amplitudeand jump rateterms.After having themomentsin hand, all we need is# first estimate the jump amplitudexi_est=jd.jump_amplitude(moments=moments)# and now estimated the jump ratelamb_est=jd.jump_rate(moments=moments)which resulted in our case in(xi_est) ξ = 2.43 ± 0.17and(lamb_est) λ = 1.744 * delta_t(don't forget to dividelamb_estbydelta_t)!Other functions and optionsInclude in this package is also theMilstein schemeof integration, particularly important when the diffusion term has some spacialxdependence.momentscan actually calculate the conditional moments for different lags, using the parameterlag.Informulaethe set of formulas needed to calculate the second order corrections are given (insympy).ContributionsWe welcome reviews and ideas from everyone. If you want to share your ideas, upgrades, doubts, or simply report a bug, open anissuehere on GitHub, or contact us directly.
If you need help with the code, the theory, or the implementation, drop us an email.
We abide to aConduct of Fairness.ChangelogVersion 0.4 - Designing a set of self-consistency checks, the documentation, examples, and a trial code. Code at PyPi.Version 0.3 - Designing a straightforward procedure to retrieve the jump amplitude and jump rate functions, alongside with a easysympydisplaying the correction.Version 0.2 - Introducing the second-order corrections to the momentsVersion 0.1 - Design an implementation of themomentsfunctions, generalisingkramersmoyalkm.Literature and SupportHistoryThis project was started in 2017 at theneurophysikby Leonardo Rydin Gorjão, Jan Heysel, Klaus Lehnertz, and M. Reza Rahimi Tabar, and separately by Pedro G. Lind, at the Department of Computer Science, Oslo Metropolitan University. From 2019 to 2021, Pedro G. Lind, Leonardo Rydin Gorjão, and Dirk Witthaut developed a set of corrections and an implementation for python, presented here.FundingHelmholtz Association InitiativeEnergy System 2050 - A Contribution of the Research Field Energyand the grant No. VH-NG-1025 andSTORM - Stochastics for Time-Space Risk Modelsproject of the Research Council of Norway (RCN) No. 274410.Bibliography1Tabar, M. R. R.Analysis and Data-Based Reconstruction of Complex Nonlinear Dynamical Systems.Springer, International Publishing (2019), ChapterStochastic Processes with Jumps and Non-vanishing Higher-Order Kramers–Moyal Coefficients.2Friedrich, R., Peinke, J., Sahimi, M., Tabar, M. R. R.Approaching complexity by stochastic methods: From biological systems to turbulence,Physics Reports 506, 87–162 (2011).3Rydin Gorjão, L., Meirinhos, F.kramersmoyal: Kramers–Moyal coefficients for stochastic processes.Journal of Open Source Software,4(44) (2019).Extended LiteratureYou can find further reading on SDE, non-parametric estimatons, and the general principles of the Fokker–Planck equation, Kramers–Moyal expansion, and related topics in the classic (physics) booksRisken, H.The Fokker–Planck equation.Springer, Berlin, Heidelberg (1989).Gardiner, C.W.Handbook of Stochastic Methods.Springer, Berlin (1985).And an extensive review on the subjecthere