<jupyter_start><jupyter_text>Stock price evolution equation  (Geometric Brownian Motion)$S_t = S_0 e^{\mu t+\sigma \sqrt{t} \epsilon}$<jupyter_code>from derivatives_pricing.sim.wiener import *
import matplotlib.pyplot as plt
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
def f(vol,mu):
    S0 = 100
    T = 1
    N = 255
    n = 100
    mean,time,results = get_path(S0,vol,mu,T,N,n)
    plt.figure(figsize=(11,5));
    plt.ylim(S0*0.5,S0*1.8);
    plt.title("Brownian motion - Paths for stock S");
    plt.plot(time,results);
    pass
interact(f,vol=(0.05,0.5,0.05),mu=(-0.2,0.2,0.05));<jupyter_output><empty_output><jupyter_text>OBS: We will be pricing derivative, so from this point on instead of the expected return of the stock, we will use the risk free rate to simulate the brownian motion.$S_t = S_0 e^{r_f t+\sigma \sqrt{t} \epsilon}$<jupyter_code>from derivatives_pricing.securities.derivatives import *
ticker = 'IBM'
strike = 155
maturity = '2019-4-2'
type_ = 'european'
c = call(ticker,strike,maturity,type_='european',check_BS=1)
print('Annualized volatility: {}'.format(c.std))
price = c.price()
c.n=10000
c.N=10000
print('Price {}'.format(c.price()))<jupyter_output>iteration: 1 : 9.614349176372706
iteration: 2 : 9.643812525405421
iteration: 3 : 9.46753910560587
iteration: 4 : 9.93637099120166
iteration: 5 : 9.528109181044973
iteration: 6 : 9.755621482412327
call_BS: 9.608285007278937
MC result: 9.755621482412327
BS minus MC = 0.14733647513338965
Price (9.755621482412327, 0.14733647513338965)<jupyter_text>Show brownian path:<jupyter_code>c.n= 500
c.N = 500
c.build_path()
plt.title('Average simulaated stock price')
plt.ylabel('price')
plt.plot(c.results[:,-100:].T);<jupyter_output>9.38549779748872<jupyter_text>American put Option<jupyter_code>ticker = 'AAPL'
strike = 170
maturity = '2019-4-2'
type_ = 'american'
p = put(ticker,strike,maturity,type_='american',check_BS=1)
p.std_horiz=3
print('Annualized volatility: {}'.format(p.std))
p.build_path();
price = p.price();
p.n=10000
p.N=10000
print('Price {}'.format(p.price()))
p.n= 10000
p.N = 500
p.build_path()
plt.title('Average simulated stock price')
plt.ylabel('price')
plt.plot(p.results[:,-100:].T);<jupyter_output>12.538955809546978
{'fraction_non_alphanumeric': 0.1487424111014744, 'fraction_numerical': 0.13660017346053774, 'mean_word_length': 5.866071428571429, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '19997', 'license': 'MIT', 'n_tokens_mistral': 1136, 'n_tokens_neox': 922, 'n_words': 186, 'path': 'derivatives_pricing/jupyter-notebook/PricingNotebook.ipynb', 'repo_name': 'RobinsoGarcia/derivatives-pricing', 'size': '2306'}