Created
March 13, 2016 11:23
-
-
Save delta2323/6bb572d9473f3b523e6e to your computer and use it in GitHub Desktop.
Brownian Bridge sample code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import numpy | |
import six | |
from matplotlib import pyplot | |
seed = 0 | |
N = 100 | |
M = 10 | |
numpy.random.seed(seed) | |
def sample_path_batch(M, N): | |
dt = 1.0 / N | |
dt_sqrt = numpy.sqrt(dt) | |
B = numpy.empty((M, N), dtype=numpy.float32) | |
B[:, 0] = 0 | |
for n in six.moves.range(N - 1): | |
t = n * dt | |
xi = numpy.random.randn(M) * dt_sqrt | |
B[:, n + 1] = B[:, n] * (1 - dt / (1 - t)) + xi | |
return B | |
B = sample_path_batch(M, N) | |
pyplot.plot(B.T) | |
pyplot.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You inspire me that a brownian bridges with arbitrary boundary condition may be an interesting problem.