Lazy Python Brownian Generator

nerdblog » Lazy Python Brownian Generator

Posted on 14 Nov 2015 23:46

I needed a source stochastic data to act as a mock for some time series IoT work I have been doing lately. After some google searching I was unable to find something right off the bat so decided to write one. I needed a source of random looking walk data that was endless as they would need to produce data for long periods of time and have a low memory footprint. It's possible to just use numpy just to generate a long list of walk data but this was more fun.

def geometric_brownian_sequence(s0=0, upper=0, lower=0, dt=.1, mu=0.0, sigma=0.01):
    current = s0
    while True:
        w = np.random.standard_normal() * np.sqrt(dt)
        x = (mu - 0.5 * sigma ** 2) * dt + sigma * w
        current = max(lower, min(upper, current * np.exp(x)))
        yield current

Like this entry?

rating: 0+x

Leave a comment

Add a New Comment
Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.