<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 03With the choice $A\left(S,t\right) = B\left(S,t\right) = S$ we obtain the geometric Brownian motion. Create random paths for the geometric Brownian motion by using It\^{o}'s lemma. Choose $\mu = \frac{0.08}{a}$, where a trading year $a$ consists of $250$ trading days $d$, $a = 250 d$. Determine at least five trajectories over $20$ years with $\sigma = \frac{0.02}{\sqrt{d}}$ and draw them with the computer. Determine at least five trajectories with the smaller volatility $\sigma = \frac{0.005}{\sqrt{d}}$ of an equity fund and present them in a separate figures.<jupyter_code>def geometric_brownian_motion(t0, t, s0, mu, sigma, N):
    
    delta_t = (t - t0) / N
    epsilon = np.random.normal(size=N) 
    mu_eff = mu - ((sigma ** 2) / 2)
    
    delta_f = mu_eff * delta_t * np.ones(N) + sigma * epsilon * delta_t ** .5
    
    t_vec = np.append(t0, t0 + np.cumsum(delta_t * np.ones(N)))
    f_vec = np.append(s0, s0 * np.exp(np.cumsum(delta_f)))
    
    return (t_vec , f_vec)
# Initial values

t0 = 0 # years
s0 = 1 # currency
days = 250 # days
t = 20 # years
mu = 0.08
sigma_1 = 0.02 * days ** .5
sigma_2 = 0.005 * days ** .5
N = 1000

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

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

plt.xlabel("$t$", fontsize=20)
plt.ylabel('$S$', fontsize=20)
plt.title(r"$\mu={:.2f}$, $\sigma={:.2f}$, $N={}$, $t - t_0 = {}$".format(mu, sigma_1, N, t - t0), fontsize=20)
plt.legend(loc='best', fontsize=20)
plt.xlim(min(t_vec), max(t_vec))
plt.grid(True)
# Figure
fig = plt.figure(figsize=(16,9))

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

plt.xlabel("$t$", fontsize=20)
plt.ylabel('$S$', fontsize=20)
plt.title(r"$\mu={:.2f}$, $\sigma={:.2f}$, $N={}$, $t - t_0 = {}$".format(mu, sigma_2, N, t-t0), fontsize=20)
plt.legend(loc='best', fontsize=20)
plt.xlim(min(t_vec), max(t_vec))
plt.grid(True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18155927376290495, 'fraction_numerical': 0.04556781772872909, 'mean_word_length': 4.194085027726432, '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': '174033', 'license': 'MIT', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1125, 'n_words': 291, 'path': 'week_4/Exercise04_H08_03.ipynb', 'repo_name': 'gravitas21/wp2020_programmierung', 'size': '2828'}