06.09.2021 Views

First Semester in Numerical Analysis with Julia, 2020a

First Semester in Numerical Analysis with Julia, 2020a

First Semester in Numerical Analysis with Julia, 2020a

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 2. SOLUTIONS OF EQUATIONS: ROOT-FINDING 68<br />

F<strong>in</strong>ally, we have the derivative we need:<br />

dC<br />

d 2<br />

dσ = Se− 1<br />

2<br />

√<br />

2π<br />

(<br />

√T log( S σ2<br />

)+(r + )T<br />

−<br />

K 2<br />

σ 2√ T<br />

) ( d 2<br />

+ K e−(rT+ 2<br />

2 ) log(<br />

S<br />

σ2<br />

)+(r +<br />

K<br />

√ )T<br />

)<br />

2<br />

2π<br />

σ 2√ T<br />

(2.10)<br />

We are ready to apply Newton’s method to solve the equation C(σ) − Ĉ =0. Now let’s<br />

f<strong>in</strong>d some data.<br />

The General Electric Company (GE) stock is $7.01 on Dec 8, 2018, and a European call<br />

option on this stock, expir<strong>in</strong>g on Dec 14, 2018, is priced at $0.10. The option has strike price<br />

K =$7.5. The risk-free <strong>in</strong>terest rate is 2.25%. The expiry T is measured <strong>in</strong> years, and s<strong>in</strong>ce<br />

there are 252 trad<strong>in</strong>g days <strong>in</strong> a year, T =6/252. We put this <strong>in</strong>formation <strong>in</strong> <strong>Julia</strong>:<br />

In [1]: S=7.01<br />

K=7.5<br />

r=0.0225<br />

T=6/252;<br />

We have not discussed how to compute the distribution function of the standard<br />

∫<br />

normal random variable φ(x) = √ 1 x /2<br />

2π −∞ e−t2 dt. In Chapter 4, we will discuss how to<br />

compute <strong>in</strong>tegrals numerically, but for this example, we will use the built-<strong>in</strong> function<br />

<strong>Julia</strong> has for φ(x). It is <strong>in</strong> a package called Distributions:<br />

In [2]: us<strong>in</strong>g Distributions<br />

The follow<strong>in</strong>g def<strong>in</strong>es stdnormal as the standard normal random variable.<br />

In [3]: stdnormal=Normal(0,1)<br />

Out[3]: Normal{Float64}(μ=0.0, σ=1.0)<br />

The built-<strong>in</strong> function cdf(stdnormal,x) computes the standard normal distribution<br />

function at x. We write a function phi(x) based on this built-<strong>in</strong> function, match<strong>in</strong>g<br />

our notation φ(x) for the distribution function.<br />

In [4]: phi(x)=cdf(stdnormal,x)<br />

Out[4]: phi (generic function <strong>with</strong> 1 method)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!