<jupyter_start><jupyter_text>Ex 3.1 By using the following parameters: - asset price at $t=0$: $S(0)=100$- delivery time: $T=1$- strike price: $K=100$- risk-free interest rate: $r=0.1$- volatility: $\sigma=0.25$compute at time $t=0$ **via Monte Carlo** the European call-option price, $C[S(0),0]$, and put-option price, $P[S(0),0]$:1.  By sampling **directly** the final asset price $S(T)$ for a $GBM(r,\sigma^2)$2.  By sampling the discretized $GBM(r,\sigma^2)$ path of the asset price dividing $[0,T]$ in $10^2$ time intervals: $S(0)$, $S(t_1)$, $S(t_2)$, ... up to $S(t_{100}=T=1)$Make four pictures for the estimation of the European call-option prices, $C[S(0),0]$ (direct and discretized), and put-option prices, $P[S(0),0]$ (direct and discretized), with their uncertainties  with a large number of asset prices at time $t=T$, say $M\ge 10^4$, as a function of the number of blocks, $N$.  As usual, in computing statistical uncertainties, use data blocking.<jupyter_code>import matplotlib 
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.pyplot import figure
from time import time
from os import system
start = time()
# execute the c++ programm
system("./main.exe")
f1 = np.loadtxt('part2.txt', skiprows=2)
f2 = np.loadtxt('part1.txt', skiprows=2)
figure(figsize=(7,5), dpi=100)

plt.errorbar(f1[:,0],f1[:,1], yerr=f1[:,2], color='blue')
plt.axhline(14.975790778311286, color='red', label='Black-Scholes')
plt.title('Direct Call')
plt.xlabel("Block")
plt.ylabel("$<call>$")
plt.legend(loc='best')
plt.grid(True)
plt.show()
figure(figsize=(7,5), dpi=100)

plt.errorbar(f1[:,0],f1[:,3], yerr=f1[:,4], color='green')
#plt.errorbar(x,f[:,1],yerr=0)
plt.axhline(5.4595325819072364, color='red', label='Black-Scholes')
plt.title('Direct Put')
plt.xlabel("Block")
plt.ylabel("$<put>$")
plt.legend(loc='best')
plt.grid(True)
plt.show()
figure(figsize=(7,5), dpi=100)

plt.errorbar(f2[:,0],f2[:,1], yerr=f2[:,2], color='blue')
#plt.errorbar(x,f[:,1],yerr=0)
plt.axhline(14.975790778311286, color='red', label='Black-Scholes')
plt.title('Descrete Call')
plt.xlabel("Block")
plt.ylabel("$<call>$")
plt.legend(loc='best')
plt.grid(True)

plt.show()
figure(figsize=(7,5), dpi=100)

plt.errorbar(f2[:,0],f2[:,3], yerr=f2[:,4], color='green')
#plt.errorbar(x,f[:,1],yerr=0)
plt.axhline(5.4595325819072364, color='red', label='Black-Scholes')
plt.title('Descrete Put')
plt.xlabel("Block")
plt.ylabel("$<put>$")
plt.legend(loc='best')
plt.grid(True)
plt.show()
end = time()

print("Total computing time:", int((end-start)*100.)/100., 'sec.')<jupyter_output>Total computing time: 1.39 sec.
{'fraction_non_alphanumeric': 0.2144782441278398, 'fraction_numerical': 0.06777050442818637, 'mean_word_length': 6.732142857142857, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '437663', 'license': 'MIT', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1026, 'n_words': 235, 'path': 'LSN_exercise_03/Ex_3.1/Ex_3.1.ipynb', 'repo_name': 'LeonardoAlchieri/LSN_exercises', 'size': '2597'}