<jupyter_start><jupyter_text>Naive Monte Carlo in a Black-Scholes Economy$$S_{T} = S_{0} \exp{\left((r - \delta  + \frac{1}{2} \sigma^{2}) T + \sigma \sqrt{T} Z \right)}$$<jupyter_code>import numpy as np
z = np.random.normal(size = 100)
z[:10]<jupyter_output><empty_output><jupyter_text>Set Up Parameters<jupyter_code>S = 41.0
K = 40.0
r = 0.08
v = 0.30
T = 1.0
q = 0.0
M = 1000000
spot_t = np.empty((M,))

nudt = (r - q - 0.5 * v * v) * T
sigdt = v * np.sqrt(T)
z = np.random.normal(size=(M,))
#for i in range(M):
#    spot_t[i] = S * np.exp(nudt + sigdt * z[i])
spot_t = S * np.exp(nudt + sigdt * z)
spot_t[:10]
def CallPayoff(spot, strike):
    return np.maximum(spot - strike, 0.0)


def PutPayoff(spot, strike):
    return np.maximum(strike - spot, 0.0)
call_t = CallPayoff(spot_t, K)
call_t[:10]
bob = call_t.mean()
bob
callPrc = np.exp(-r * T) * bob
callPrc
put_t = PutPayoff(spot_t, K)
put_t[:10]
putPrc = np.exp(-r * T) * put_t.mean()
putPrc<jupyter_output><empty_output><jupyter_text>Simulating Paths<jupyter_code>reps = 3000000
steps = 4
path = np.zeros((reps,steps))
path
path[:,0] = S
path
dt = T / steps
nudt = (r - q - 0.5 * v * v) * dt
sigdt = v * np.sqrt(dt)

for i in range(reps):
    z = np.random.normal(size=steps)
    for j in range(1, steps):
        path[i,j] = path[i,j-1] * np.exp(nudt + sigdt * z[j])
        
path
def ArithmeticAsianCallPayoff(path, strike):
    spot_t = path.mean(axis = 1)
    return np.maximum(spot_t - strike, 0.0)
call_t = ArithmeticAsianCallPayoff(path, K).mean()
call_t *= np.exp(-r * T)
call_t<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17956852791878172, 'fraction_numerical': 0.03807106598984772, 'mean_word_length': 3.735735735735736, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '336404', 'license': 'CC0-1.0', 'n_tokens_mistral': 757, 'n_tokens_neox': 708, 'n_words': 160, 'path': 'Notes/Frequentist/Monte-Carlo-Basics.ipynb', 'repo_name': 'CAIJedi/DATA-5600-FL21', 'size': '1576'}