<jupyter_start><jupyter_text>MIT License (c) 2019 by <NAME>  Jupyter notebook written in Python 3. It illustrates the derivation of the Black-Scholes-Merton formula for the price of an European style call option by using SymPy. In particular, it illustrates the inversion of a function by using 'solve.' The formula is derived with non-zero dividends.<jupyter_code>from sympy import *
t=Symbol('t',positive=True)
r=Symbol('r',positive=True)
S=Symbol('S',positive=True)
K=Symbol('K',positive=True)
a=Symbol('a',positive=True)
x=Symbol('x',real=True)
sigma=Symbol('sigma',positive=True)
delta=Symbol('delta',positive=True)
init_printing()
ibound=solve(S*exp(x+(r-delta-Rational(1,2)*sigma**2)*t)-K,x,dict=True)[0]
ibound
ibound[x]
integrate(exp(-x**2/(2*t*sigma**2))/(sigma*sqrt(2*pi*t)),(x,-oo,+oo))
A=exp(-r*t)*integrate(exp(-x**2/(2*t*sigma**2))*(S*exp(x+(r-delta-(1/2)*sigma**2)*t)-K)/(sigma*sqrt(2*pi*t)),(x,a,+oo))
A
A.subs(a,ibound[x]).simplify()
(-K*exp(delta*t)*erfc(sqrt(2)*(2*delta*t - 2*r*t + sigma**2*t + log(K**2/S**2))/(4*sigma*sqrt(t))) + S*exp(r*t)*erf(sqrt(2)*(-2*delta*t + 2*r*t + sigma**2*t + log(S**2/K**2))/(4*sigma*sqrt(t))) + S*exp(r*t))*exp(-t*(delta + r))/2<jupyter_output><empty_output><jupyter_text>Note: ${\rm erfc}(x)=1-{\rm erf}(x)=1+{\rm erf}(-x)$.<jupyter_code>A.subs(a,ibound[x]).subs(delta,0).simplify()
(K*erfc(sqrt(2)*(2*r*t - sigma**2*t + log(S**2/K**2))/(4*sigma*sqrt(t))) - 2*K + S*exp(r*t)*erf(sqrt(2)*(2*r*t + sigma**2*t + log(S**2/K**2))/(4*sigma*sqrt(t))) + S*exp(r*t))*exp(-r*t)/2
A.subs(a,ibound[x]).subs(delta,0).simplify().expand()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.26757934038581205, 'fraction_numerical': 0.03298070939639079, 'mean_word_length': 8.804878048780488, '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': '657109', 'license': 'MIT', 'n_tokens_mistral': 752, 'n_tokens_neox': 705, 'n_words': 92, 'path': 'Black_Scholes_Merton_Formula_Derived_by_SymPy_Python.ipynb', 'repo_name': 'AndrewLyasoff/SMAP', 'size': '1615'}