# First passage time distribution in mathematica

I'm trying to calculate first passage time distribution for some processes in Mathematica. First I tried to calculate this for Wiener process with zero drift and $\sigma = 1$ and the absorbing boundary at $a = 2%$. It's the well-known formula (Levy-Smirnov distribution) $${f_{FP}} = \frac{a}{{\sqrt {2\pi {\sigma ^2}{t^3}} }}{e^{ - \frac{{{a^2}}}{{2{\sigma ^2}t}}}}$$

I used this code

sample = Map[FirstCase[#, _?(Last[#] >= 2 &)] &,
RandomFunction[WienerProcess[0, 1], {0, 15, 0.001}, 10^4][
"Paths"]];
data0 = DeleteCases[sample, {}][[All, 1]];
data = Cases[data0, _?Positive];
Show[Histogram[data, 40, "PDF"],
Plot[2/Sqrt[2*\[Pi]*t^3]*Exp[-(2^2/(2*t))], {t, 0, 15},
PlotStyle -> Thick]]


but the result was strange

I haven't got any idea why the simplest case failed. Could someone help me with this? Thanks in advance

P.S. I'm sorry for terrible English

• FYI: InverseGammaDistribution[] is built-in, so you can do PDF[InverseGammaDistribution[1/2, a^2/(2 σ^2)], x]. – J. M. is away Oct 1 '17 at 18:19
• Yes, but I want to understand, why the numeric results don't agree with exact formula, because I'm going to calculate FPT for non-Markovian process (and there is no exact formula). – Msdos4 Oct 1 '17 at 18:24

Perhaps you were expecting this:

pdf = 2/Sqrt[2*π*t^3]*Exp[-(2^2/(2*t))];
normalization = NIntegrate[pdf, {t, 0, 15}];
Show[Histogram[data, 40, "PDF"],
Plot[pdf/normalization, {t, 0, 15}, PlotStyle -> Thick]]


• The function being plotted here is effectively PDF[TruncatedDistribution[{0, 15}, InverseGammaDistribution[1/2, 2]], t]; that is, the expected heavy tail distribution with a good amount of the tail cut off. – J. M. is away Oct 1 '17 at 19:58
• Thank you, I didn't think about normalization. But are there ways to normalize data (histogram), not function? – Msdos4 Oct 1 '17 at 20:31
• @Msdos4 Yes, the third argument of Histogram, where you have "PDF", can take an arbitrary function. See the documentation "Details" section of Histogram. – Michael E2 Oct 1 '17 at 21:13
• Thank you once again! Sorry for stupid questions, I'm not good in Mathematica but I want to learn. – Msdos4 Oct 1 '17 at 21:18
• @Msdos4 You're welcome. :) – Michael E2 Oct 1 '17 at 21:21