<jupyter_start><jupyter_text>Econophysics I Exercise 04 - H08 <NAME> Universität Duisburg-Essen12.05.2020<jupyter_code># Modules

import numpy as np
from matplotlib import pyplot as plt<jupyter_output><empty_output><jupyter_text>Exercise 04. Homework 08. Point 01The choice $A\left(S,t\right) = B\left(S,t\right) = 1$ for the coefficient functions defines the Brownian motion with drift$$dS=\mu\,dt+\sigma\varepsilon\,\sqrt{dt}$$Choose an appropriate time discretization of $t_{0}$ to $t_{1}$ in $N$ steps and generate different runs of the simulation with unchanged parameters.<jupyter_code>def brownian_motion(t0, t, s0, mu, sigma, N):
    
    delta_t = (t - t0) / N
    
    epsilon = np.random.normal(size=N) 
    
    delta_s = mu * delta_t * np.ones(N) + sigma * epsilon * delta_t ** .5
    
    t_vec = np.append(t0, t0 + np.cumsum(delta_t * np.ones(N)))
    s_vec = np.append(s0, s0 + np.cumsum(delta_s))
    
    return (t_vec , s_vec)
# Initial values

t0 = 0
s0 = 1
mu = 1
sigma = 1
t = 1
N = 1000

simulations = 6
# Brownian motion

# Figure
fig = plt.figure(figsize=(16,9))

for sim in range(simulations):
    
    (t_vec, s_vec) = brownian_motion(t0, t, s0, mu, sigma, N)
    plt.plot(t_vec, s_vec, label=f'Simulation {sim}')
    
# Clean drift (sigma = 0)
(t_vec, s_vec) = brownian_motion(t0, t, s0, mu, 0 * sigma, N)
plt.plot(t_vec, s_vec, '--k', linewidth = 3, label=r'Clean drift ($\sigma = {}$)'.format(0 * sigma))

plt.xlabel("$t$", fontsize=20)
plt.ylabel('$S$', fontsize=20)
plt.title(r"$\mu={}$, $\sigma={}$, $N={}$, $t_0 = {}$, $s(t_0)= {}$".format(mu, sigma, N, t0, s0), fontsize=20)
plt.legend(loc='best')
plt.xlim(min(t_vec), max(t_vec))
plt.grid(True)
# Different number of increments
N_vec = [10, 100, 1000, 10000]

# Figure
fig = plt.figure(figsize=(16,9))

for N in N_vec:
    
    (t_vec, s_vec) = brownian_motion(t0, t, s0, mu, sigma, N)
    plt.plot(t_vec, s_vec, label=f'Increment {N}')

# clean drift (sigma = 0)
(t_vec, s_vec) = brownian_motion(t0, t, s0, mu, 0 * sigma, N)
plt.plot(t_vec, s_vec, '--k', linewidth = 3, label=r'Clean drift ($\sigma = {}$)'.format(0 * sigma))

plt.xlabel("$t$", fontsize=20)
plt.ylabel('$S$', fontsize=20)
plt.title(r"$\mu={}$, $\sigma={}$, $t_0 = {}$, $s(t_0)= {}$".format(mu, sigma, t0, s0), fontsize=20)
plt.legend(loc='best')
plt.xlim(min(t_vec), max(t_vec))
plt.grid(True)
# Translation

# Initial values
s0 = 101
t0 = 2
t = 3
N = 1000

# Figure
fig = plt.figure(figsize=(16,9))

for sim in range(simulations):
    
    (t_vec, s_vec) = brownian_motion(t0, t, s0, mu, sigma, N)
    plt.plot(t_vec, s_vec, label=f'Simulation {sim}')
    
# clean drift (sigma = 0)
(t_vec, s_vec) = brownian_motion(t0, t, s0, mu, 0 * sigma, N)
plt.plot(t_vec, s_vec, '--k', linewidth = 3, label='Clean drift ($\sigma = {}$)'.format(0 * sigma))

plt.xlabel("$t$", fontsize=20)
plt.ylabel('$S$', fontsize=20)
plt.title(r"$\mu={}$, $\sigma={}$, $N={}$, $t_0 = {}$, $s(t_0)= {}$".format(mu, sigma, N, t0, s0), fontsize=20)
plt.legend(loc='best')
plt.xlim(min(t_vec), max(t_vec))
plt.grid(True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19869918699186992, 'fraction_numerical': 0.041951219512195125, 'mean_word_length': 4.3776223776223775, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '381812', 'license': 'MIT', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1303, 'n_words': 310, 'path': 'week_4/Exercise04_H08_01.ipynb', 'repo_name': 'gravitas21/wp2020_programmierung', 'size': '3094'}