#### MIT License (c) 2019 by Andrew Lyasoff

#### 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.


```python
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()
```


```python
ibound=solve(S*exp(x+(r-delta-Rational(1,2)*sigma**2)*t)-K,x,dict=True)[0]
ibound
```


```python
ibound[x]
```


```python
integrate(exp(-x**2/(2*t*sigma**2))/(sigma*sqrt(2*pi*t)),(x,-oo,+oo))
```


```python
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
```


```python
A.subs(a,ibound[x]).simplify()
```


```python
(-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
```

##### Note: ${\rm erfc}(x)=1-{\rm erf}(x)=1+{\rm erf}(-x)$.


```python

```


```python
A.subs(a,ibound[x]).subs(delta,0).simplify()
```


```python
(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
```


```python
A.subs(a,ibound[x]).subs(delta,0).simplify().expand()
```


```python

```

cf913461fd03698d4d020a368914a9752dd64367
ipynb
Jupyter Notebook
Black_Scholes_Merton_Formula_Derived_by_SymPy_Python.ipynb
AndrewLyasoff/SMAP
6eeea8953a26a05b1e23387067109d23b2011824
MIT
2018-09-04T19:12:32.000Z
2022-03-20T02:05:44.000Z
Black_Scholes_Merton_Formula_Derived_by_SymPy_Python.ipynb
lhyzh/SMAP
f6687291769d4c16a0d51a06a941384f646bb432
MIT
2019-02-13T14:24:38.000Z
2019-02-13T14:24:38.000Z
Black_Scholes_Merton_Formula_Derived_by_SymPy_Python.ipynb
lhyzh/SMAP
f6687291769d4c16a0d51a06a941384f646bb432
MIT
2019-02-10T03:43:40.000Z
2021-03-28T03:53:22.000Z
Qwen/Qwen-72B
1. YES
2. YES