166
10 Quantum Finance and Path Integrals
Fig. 10.3 The histogram of random numbers generated by the acceptance-rejection method for
f (x) = 15(x 2 − x 4 )/15. Only about half of the initially N = 10 4 random numbers are accepted
for the histogram
thus need an algorithm that generates new random numbers, but has a preference to
stay near values where f (x) is large.
The Metropolis-Hastings algorithm is such an algorithm. It is based on generating
a new sample x j+1 from the previous sample x j by adding a random increment of
magnitude β ˆ
P, where ˆ
P is a sample drawn from any random number generator that
produces numbers symmetrically distributed around zero, for example, a generator
producing uniformly distributed random numbers between −1 and 1. The parameter
β determines the magnitude of the step. It should be large enough to avoid getting
stuck in local maxima and give the algorithm a chance to explore all possible values.
The algorithm then works as follows: first a new candidate is generated by y =
x k + β ˆ
P and we calculate α = f (y)/ f (x k ). If α > 1 the new value y gets us closer
to the maximum and is accepted as the new sample x k+1 = y. If, on the other hand
α ≤ 1, we give y a second chance by comparing α with a uniformly distributed
random number u between zero and unity and only select y if α > u. If the second
chance fails, we simply re-use x k . One can start the algorithm from any random
value, but it is recommended to iterate for a number (100s to 1000s) of burn-in
iterations before accepting values. This avoids getting stuck in a region due to an
unfortunate choice of initial value. A MATLAB rendition of the algorithm is shown
in Appendix B.5. It has the bonus that it does not waste a lot of effort creating random
numbers where they are not needed, but lingers around the maxima of the distribution
function.
Since the integrands of the path integrals are typically of the Gaussian type, we run
the acceptance-rejection algorithm 10000 times while sampling x− values between
±5 times the rms value of the Gaussian. About 8000 values are rejected and we can
use only 2000 values whose histogram we show in the upper plot of Fig. 10.4. We
then use the Metropolis algorithm and can use all generated 10000 random numbers
after an initial burn-in period of 100 iterations and show the resulting histogram in
the lower plot of Fig. 10.4. Obviously, the Metropolis algorithm is more efficient,
because it spends less time in regions where the function value is small.
In the following section we will use these methods to evaluate path integrals.
10 Quantum Finance and Path Integrals
Fig. 10.3 The histogram of random numbers generated by the acceptance-rejection method for
f (x) = 15(x 2 − x 4 )/15. Only about half of the initially N = 10 4 random numbers are accepted
for the histogram
thus need an algorithm that generates new random numbers, but has a preference to
stay near values where f (x) is large.
The Metropolis-Hastings algorithm is such an algorithm. It is based on generating
a new sample x j+1 from the previous sample x j by adding a random increment of
magnitude β ˆ
P, where ˆ
P is a sample drawn from any random number generator that
produces numbers symmetrically distributed around zero, for example, a generator
producing uniformly distributed random numbers between −1 and 1. The parameter
β determines the magnitude of the step. It should be large enough to avoid getting
stuck in local maxima and give the algorithm a chance to explore all possible values.
The algorithm then works as follows: first a new candidate is generated by y =
x k + β ˆ
P and we calculate α = f (y)/ f (x k ). If α > 1 the new value y gets us closer
to the maximum and is accepted as the new sample x k+1 = y. If, on the other hand
α ≤ 1, we give y a second chance by comparing α with a uniformly distributed
random number u between zero and unity and only select y if α > u. If the second
chance fails, we simply re-use x k . One can start the algorithm from any random
value, but it is recommended to iterate for a number (100s to 1000s) of burn-in
iterations before accepting values. This avoids getting stuck in a region due to an
unfortunate choice of initial value. A MATLAB rendition of the algorithm is shown
in Appendix B.5. It has the bonus that it does not waste a lot of effort creating random
numbers where they are not needed, but lingers around the maxima of the distribution
function.
Since the integrands of the path integrals are typically of the Gaussian type, we run
the acceptance-rejection algorithm 10000 times while sampling x− values between
±5 times the rms value of the Gaussian. About 8000 values are rejected and we can
use only 2000 values whose histogram we show in the upper plot of Fig. 10.4. We
then use the Metropolis algorithm and can use all generated 10000 random numbers
after an initial burn-in period of 100 iterations and show the resulting histogram in
the lower plot of Fig. 10.4. Obviously, the Metropolis algorithm is more efficient,
because it spends less time in regions where the function value is small.
In the following section we will use these methods to evaluate path integrals.
