crflynn / stochastic

Generate realizations of stochastic processes in python.
http://stochastic.readthedocs.io/en/stable/
MIT License
456 stars 82 forks source link

Fixed issue #15 BrownianMotion #23

Closed MichaelHogervorst closed 4 years ago

MichaelHogervorst commented 4 years ago

Fixed issue #15 by adding drift and scale to BrownianMotion._sample_brownian_motion_at.

The _sample_gaussian_noise_at(times) return a vector of gaussian noise for the time t's in times. This means that every element in the output vector is scaled by the increments in times. Multiplying the output vector with the scale parameter gives the correct scaling.

The drift can simply be added to the output vector by adding the product of the drift and times vector, as drift is proportional to time.

The operations are now something like this. mu_tt + sig_tdiff sig_scale * X, for X~N(0,1)

It could have been possible to add the drift part before the np.cumsum by adding the t_diff * drift to each element in the vector, but this is mathematically the same.

I'm not really experienced with contributing to other libraries, so I hope this all will go well.

crflynn commented 4 years ago

Hi @MichaelHogervorst. If you can push the changes to this branch I can take another look