Last active
October 20, 2022 08:04
-
-
Save IlievskiV/23a8a06dd1365684c47b60a6010e27c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| def geometric_brownian_motion(G0, mu, sigma, N, T): | |
| """Simulates a Geometric Brownian Motion. | |
| :param float G0: initial value | |
| :param float mu: drift coefficient | |
| :param float sigma: diffusion coefficient | |
| :param int N: number of discrete steps | |
| :param int T: number of continuous time steps | |
| :return list: the geometric Brownian Motion | |
| """ | |
| # the normalizing constant | |
| dt = 1. * T/N | |
| # standard brownian motion | |
| W, _ = brownian_motion(N, T ,1.0) | |
| # generate the time steps | |
| time_steps = np.linspace(0.0, N*dt, N+1) | |
| # calculate the geometric brownian motion | |
| G = G0 * np.exp(mu * time_steps + sigma * W) | |
| # replace the initial value | |
| G[0] = G0 | |
| return G |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment