🐻❄️
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
| # import libraries | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import matplotlib.animation as animation | |
| # ignore warnings | |
| import warnings | |
| warnings.filterwarnings("ignore") | |
| def brownian_motion(N, T, h, seed=42): |
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
| import numpy as np | |
| def drifted_brownian_motion(mu, sigma, N, T, seed=42): | |
| """Simulates a Brownian Motion with drift. | |
| :param float mu: drift coefficient | |
| :param float sigma: volatility coefficient | |
| :param int N : number of discrete steps | |
| :param int T: number of continuous time steps | |
| :param int seed: initial seed of the random generator |
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 | |
| """ |
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
| import numpy as np | |
| def gbm_mean(G0, mu, sigma, N, T): | |
| """Simulates the mean of the Geometric Brownian Motion, which is: | |
| E(t) = G0*e^{(mu + sigma^{2}/2)*t} | |
| :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 |
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 calculate_integral(f, a, b, n): | |
| '''Calculates the integral based on the composite trapezoidal rule | |
| relying on the Riemann Sums. | |
| :param function f: the integrand function | |
| :param int a: lower bound of the integral | |
| :param int b: upper bound of theintergal | |
| :param int n: number of trapezoids of equal width | |
| :return float: the integral of the function f between a and b | |
| ''' |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 mandelbrot(x, y, threshold): | |
| """Calculates whether the number c = x + i*y belongs to the | |
| Mandelbrot set. In order to belong, the sequence z[i + 1] = z[i]**2 + c | |
| must not diverge after 'threshold' number of steps. The sequence diverges | |
| if the absolute value of z[i+1] is greater than 4. | |
| :param float x: the x component of the initial complex number | |
| :param float y: the y component of the initial complex number | |
| :param int threshold: the number of iterations to considered it converged | |
| """ |
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
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import matplotlib.animation as animation | |
| x_start, y_start = -2, -1.5 # an interesting region starts here | |
| width, height = 3, 3 # for 3 units up and right | |
| density_per_unit = 250 # how many pixles per unit | |
| # real and imaginary axis | |
| re = np.linspace(x_start, x_start + width, width * density_per_unit ) |