Brownian Bridge
A brownian bridge can be defined as
Overview
The Brownian Bridge is an extension of the notion of a Brownian Motion where both the beginning and end point is specified. In the simple definition, a brownian bridge is a random process {% X_t %} such that {% X_0 = 0 %} and {% X_1 = 0 %}.A brownian bridge can be defined as
{% X_t = Z_t - t \times Z_1 %}
where {% Z_t %} is a
brownian motion
and t runs from 0 to 1.
Implementation
import random
def generate(iterations, time=0, vol=0.1, init=0, generator=None):
def gen(): return random.normalvariate(0,1)
if generator == None:generator = gen
if not callable(time):
_time = time
def func(ans): return _time
time = func
if not callable(vol):
_vol = vol
def func2(ans):return _vol
vol = func2
ans = [init]
for i in range(iterations):
dt = time(ans)
cvol = vol(ans)
ans.append(ans[len(ans)-1]+dt + generator()*cvol)
pass
return ans
def brownian_bridge(iterations):
series = generate(iterations)
for i in range(len(series)):
series[i] = series[i]-(i/iterations)*series[i]
return series