-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtry2.html
281 lines (251 loc) · 19.2 KB
/
try2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title> AJ </title>
<link href="res/css/prism.css" rel="stylesheet" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:400,700&display=swap">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="res/css/styles.css">
</head>
<!-- --------------------nav end------------------------------------ -->
<nav id="navbar_top" class="navbar navbar-expand-md navbar-dark pr-0" style="background-color: #000000EE;">
<a href="#" class="navbar-brand navbar-logo"> AJ </a>
<div class="navbar-nav" id="navbar-collapsed">
<a href="index.html#home" class="nav-item nav-link navbar-brand">
<img src="res/img/home-24px.svg" alt="H">
</a>
<a href="index.html#stuff" class="nav-item nav-link navbar-brand">
<img src="res/img/work-24px.svg" style="filter: invert(0);" alt="S">
</a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse">
<div id="navbarFull" class="navbar-nav ml-auto pr-2">
<a href="index.html#home" class="nav-item nav-link">HOME</a>
<a href="index.html#stuff" class="nav-item nav-link">WORK</a>
</div>
</div>
</nav>
<!-- ------------------------------------------ -->
<body>
<div id="home" class="tsys main3 container-fluid">
<div class="snap-pad"></div>
<button type="button" id="top_button" onclick="goToTop()">
<img class="top_caret" src="res/img/keyboard_arrow_up-24px.svg" alt="^">
</button>
<br><br>
<h2 class="ourproject_title title_padding" style="color:black"> Black Scholes </h2>
<h4 class="ourproject_title title_padding" style="color:#A569BD">
<b>Stochastic Differential Equations</b>
</h4>
<p style="color: black; font-size: 19px">Now that we have defined Brownian motion, we can utilise it as a building block to start constructing stochastic differential equations (SDE). We need SDE in order to discuss how functions <i>f=f(s)</i> and their derivatives with respect to <i>S</i> behave, where <i>S</i> is a stock price determined by a Brownian motion.
<br> <br>Some of the rules of ordinary calculus do not work as expected in a stochastic world. We need to modify them to take into account both the random behaviour of Brownian motion as well as its non-differentiable nature. We will begin by discussing stochastic integrals, which will lead us naturally to the concept of an SDE.
</p>
<h4 class="ourproject_title title_padding" style="color:#A569BD">
<b>Definition (Stochastic Integral)</b>
</h4>
<p style="color: black; font-size: 19px">
A stochastic integral of the function <i>f=f(t)</i> is a function
<br><br><i>W=W(t),t</i> ∈ [0,T] given by:
<br> <br> <img src="res/img/img11.png" alt="ok" class="responsive">
<br><br> where <i>t<sub>k</sub>=kt/N.</i>
<br>Note that the function <i>f</i> is non-anticipatory, in the sense that it is evaluated within the summation sign at time <i>t<sub>k</sub>-1.</i> This means that it has no information as to what the random variable at <i>X(t<sub>k</sub>)</i> is. Supposing that <i>f</i> represented some portfolio allocation based on B, then if it were not evaluated at <i>t<sub>k</sub>−1</i>, but rather at <i>t<sub>k</sub></i>, we would be able to anticipate the future and modify the portfolio accordingly.
<br> <br> The previous expression provided for <i>W(t)</i> is an integral expression and thus is well-defined for a non-differentiable variable, <i>B(t)</i>, due the property of finiteness as well as the chosen mean and variance. However, we wish to be able to write it in differential form:
<br> <br> <img src="res/img/img12.png" alt="ok" class="responsive">
<br><br>One can consider the term dB as being a normally distributed random variable with zero mean and variance dt. The formal definition is provided:
</p>
<h4 class="ourproject_title title_padding" style="color:#A569BD">
<b>Definition (Stochastic Differential Equation)</b>
</h4>
<p style="color: black; font-size: 19px">Let <i>B(t)</i> be a Brownian motion. If <i>W(t)</i> is a sequence of random variables, such that for all <i>t</i>,
<br> <br> <img src="res/img/img13.png" alt="ok" class="responsive">
<br><br> is a random variable with mean and variance that rae o(δt), then:
<br> <br> <img src="res/img/img14.png" alt="ok" class="responsive">
<br><br>is a stochastic differential equation for <i>W(t)</i>.
<br> <br>A sequence of random variables given by the above is termed an Ito drift-diffusion process, or simply an Ito process or a stochastic process.
<br> <br> It can be seen that <i>μ</i> and <i>σ</i> are both functions of <i>t</i> and <i>W</i>. <i>μ</i> has the interpretation of a non-stochastic drift coefficient, while σ represents the coefficient of volatility - it is multiplied by the stochastic dB term. Hence, stochastic differential equations have both a non-stochastic and stochastic component.
<br> <br> In the following section on geometric Brownian motion, a stochastic differential equation will be utilised to model asset price movements.
</p>
<h4 class="ourproject_title title_padding" style="color:#A569BD">
<b>Geometric Brownian Motion</b>
</h4>
<p style="color: black; font-size: 19px">
The usual model for the time-evolution of an asset price <i>S(t)</i> is given by the geometric Brownian motion, represented by the following stochastic differential equation:
<br> <br> <img src="res/img/img15.png" alt="ok" class="responsive">
<br><br>Note that the coefficients <i>μ</i> and <i>σ</i>, representing the drift and volatility of the asset, respectively, are both constant in this model. In more sophisticated models they can be made to be functions of <i>t,S(t)</i> and other stochastic processes.
<br><br> <img src="res/img/img16.png" alt="ok" class="responsive">
<br><br>The solution <i>S(t)</i> can be found by the application of Ito's Lemma to the stochastic differential equation.
<br> Dividing through by <i>S(t)</i> in the above equation leads to:
<br> <br> <img src="res/img/img17.png" alt="ok" class="responsive">
<br><br>Notice that the left hand side of this equation looks similar to the derivative of <i>logS(t)</i>. Applying Ito's Lemma to <i>logS(t)</i> gives:
<br> <br> <img src="res/img/img41.png" alt="ok" class="responsive">
<br><br> This becomes:
<br> <br> <img src="res/img/img18.png" alt="ok" class="responsive">
<br><br>This is an Ito drift-diffusion process. It is a standard Brownian motion with a drift term. Since the above formula is simply shorthand for an integral formula, we can write this as:
<br> <br> <img src="res/img/img19.jpeg" alt="ok" class="responsive">
<br><br> Finally,taking the exponential of this equation gives:
<br> <br> <img src="res/img/img20.png" alt="ok" class="responsive">
<br><br>This is the solution the stochastic differential equation. In fact it is one of the only analytical solutions that can be obtained from stochastic differential equations.
</p>
<h4 class="ourproject_title title_padding" style="color:#A569BD">
<b>Ito’s Lemma</b>
</h4>
<p style="color: black; font-size: 19px">Ito's Lemma is a key component in the Ito Calculus, used to determine the derivative of a time-dependent function of a stochastic process. It performs the role of the chain rule in a stochastic setting, analogous to the chain rule in ordinary differential calculus. Ito's Lemma is a cornerstone of quantitative finance and it is intrinsic to the derivation of the Black-Scholes equation for contingent claims (options) pricing.
<br><br>It is necessary to understand the concepts of Brownian motion, stochastic differential equations and geometric Brownian motion before proceeding.
</p>
<h4 class="ourproject_title title_padding" style="color:#A569BD">
<b>The Chain Rule</b>
</h4>
<p style="color: black; font-size: 19px">One of the most fundamental tools from ordinary calculus is the chain rule. It allows the calculation of the derivative of chained functional composition. Formally, if W(t) is a continuous function, and:
<br> <br> <img src="res/img/img21.png" alt="ok" class="responsive">
<br><br> Then the chain rule states:
<br> <br> <img src="res/img/img22.png" alt="ok" class="responsive">
<br><br>When f has t as a direct dependent parameter also, we require additional terms and partial derivatives. In this instance, the chain rule is given by:
<br><br> <img src="res/img/img23.png" alt="ok" class="responsive">
<br>In order to model an asset price distribution correctly in a log-normal fashion, a stochastic version of the chain rule will be used to solve a stochastic differential equation representing geometric Brownian motion.
<br><br>
The primary task is now to correctly extend the ordinary calculus version of the chain rule to be able to cope with random variables.
</p>
<h4 class="ourproject_title title_padding" style="color:#A569BD">
<b>Theorem(Ito's Lemma)</b>
</h4>
<p style="color: black; font-size: 19px">
Let B(t) be a Brownian motion and W(t) be an Ito drift-diffusion process which satisfies the stochastic differential equation:
<br><br><br> <br> <img src="res/img/img24.png" alt="ok" class="responsive">
<br><br> If f(w,t)∈C<sup>2</sup>(R<sup>2</sup>,R) then f(W(t),t) is also and Ito drift-diffusion with its differential given by:
<br><br> <!--<img src="res/img/image076.png" alt="ok"> <br><br>-->
<br> <br> <img src="res/img/img25.png" alt="ok" class="responsive">
<br><br>With dW(t)<sup>2</sup> given by: dt<sup>2</sup>=0, dtdB(t)=0∧dB(t)<sup>2</sup>=dt.
</p>
<h4 class="ourproject_title title_padding" style="color:#A569BD">
<b>Deriving the Black-Scholes</b>
</h4>
<p style="color: black; font-size: 19px">Now that we have derived Ito's Lemma, we are in a position to derive the Black-Scholes equation.
<br><br>Suppose we wish to price a vanilla European contingent claim C, on a time-varying asset S, which is set to mature at T. We shall assume that S follows a geometric Brownian motion with mean growth rate of μ and volatility σ. r will represent the continuously compounding risk free interest rate.r , μ and σ are not functions of time, t, or the asset price S and so are fixed for the duration of the option's lifetime.
<br><br>Since our option price,C , is a function of time t and the price of the asset S, we will use the notation C=C(S,t) to represent the price of the option. Note that we are assuming at this stage that C exists and is well-defined. We will later show this to be a justified claim.
<br>The first step is to utilise Ito's Lemma on the function C(S,t) to give us a SDE:
<br><br> <!--<img src="res/img/image087.png" alt="ok">-->
<br> <br> <img src="res/img/img26.png" alt="ok" class="responsive">
<br><br>
Our asset price is modelled by a geometric Brownian motion, the expression for which is recalled here. Note that μ and σ are constant - i.e. not functions of S or t:
<br> <br> <img src="res/img/img27.png" alt="ok" class="responsive">
<br><br>We can substitute this expression into Ito's Lemma to obtain:
<br><!--<img src="res/img/image089.png" alt="ok"> <br><br>-->
<br> <br> <img src="res/img/img28.png" alt="ok" class="responsive">
<br><br>
The thrust of our derivation argument will essentially be to say that a fully hedged portfolio, with all risk eliminated, will grow at the risk free rate. Thus, we need to determine how our portfolio changes in time. Specifically, we are interested in the infinitesimal change of a mixture of a call option and a quantity of assets. The quantity will be denoted by Δ. Hence:
<br><!--<img src="res/img/image090.png" alt="ok"> <br><br>-->
<br> <br> <img src="res/img/img29.png" alt="ok" class="responsive">
This leads us to a choice for Δ which will eliminate the term associated with the randomness. If we set<!-- <img src="res/img/image091.png" alt="ok">--> δ = -∂C/∂S(S,t), we receive:
<br><br><!--<img src="res/img/image092.png" alt="ok">-->
<img src="res/img/img30.png" alt="ok" class="responsive">
<br><br>
Note that we have glossed over the issue of what the derivative of Δ is. We will return to this later.
<br>This technique is known as Delta-Hedging and provides us with a portfolio that is free of randomness. This is how we can apply the argument that it should grow at the risk free rate, otherwise, as with our previous arguments, we would have an arbitrage opportunity. Hence the growth rate of our delta-hedged portfolio must be equal the continuously compounding risk free rate, r.<br> Thus we are able to state that:
<br><!--<img src="res/img/image093.png" alt="ok"> <br><br>-->
<br> <br> <img src="res/img/img31.png" alt="ok" class="responsive">
<br><br>
If we rearrange this equation, and using shorthand notation to drop the dependence on (S,T) we arrive at the famous Black-Scholes equation for the value of our contingent claim:
<br><!--<img src="res/img/image095.png" alt="ok"> <br><br>-->
<br> <br> <img src="res/img/img32.png" alt="ok" class="responsive">
<br><br>
Although we have derived the equation, we do not yet possess enough conditions in order to provide a unique solution. The equation is a second-order linear partial differential equation (PDE) and without boundary conditions (such as a payoff function for our contingent claim), we will not be able to solve it.
<br><br>
One payoff function we can use is that of a European call option struck at K. This has a payoff function at expiry, T, of:
<br> <br> <img src="res/img/img33.png" alt="ok" class="responsive"><br>
<br>We are now in a position to solve the Black-Scholes equation.
</p>
<h4 class="ourproject_title title_padding" style="color:#A569BD">
<b>Black Scholes Pricing formula</b>
</h4>
<p style="color: black; font-size: 19px">
It has already been outlined that the reader is to be familiar with the Black-Scholes formula for the pricing of European Vanilla Calls and Puts. For completeness, the price of a European Vanilla Call, <i>C(S,t)</i> is given below, where <i>S</i> is the underlying asset, <i>K</i> is the strike price, <i>r</i> is the risk-free rate, <i>T</i> is the time to maturity and σ is the (constant) volatility of the underlying S(N is described below):
<br> <br> <img src="res/img/img34.png" alt="ok" class="responsive">
<br><br>With d<sub>1</sub> and d<sub>2</sub> defined as follows:
<br><!--<img src="res/img/image104.png" alt="ok">-->
<br> <br> <img src="res/img/img35.png" alt="ok" class="responsive"><br><br>
<br><br>Thanks to Put-Call Parity, we are also able to price a European Vanilla Put P(S,t) with the following formula:
<br> <br> <img src="res/img/img36.png" alt="ok" class="responsive">
<br> <br> <img src="res/img/img37.png" alt="ok" class="responsive"> <br><br>
The remaining function we have yet to describe is N. This is the cumulative distribution function of the standard normal distribution. The formula for N is given by:
<br> <br> <img src="res/img/img38.png" alt="ok" class="responsive">
<br> <br> <img src="res/img/img39.png" alt="ok" class="responsive"><br><br>
In addition, we would like to have closed form solutions for the "Greeks", which are the option price sensitivities to the underlying variables and parameters. For this reason we also need the formula for the probability density function of the standard normal distribution which is given below:
<br> <br> <img src="res/img/img40.png" alt="ok" class="responsive">
<br><br>
</p>
<h4 class="ourproject_title title_padding" style="color:#A569BD">
<b>Code Snippets To Calculate the Black-Scholes Pricing Value:</b>
</h4>
<p>
With our ticker symbols saved in a list, we can iterate through the list and query the Alpha Vantage API for daily price data.<br><br>
<pre class="line-numbers">
<code class="language-python" style="text-align:left">
from math import exp, log, sqrt, pi
from statistics import norm_pdf, norm_cfd
def norm_pdf(x):
"""
Standard normal probability density function
"""
return (1.0/((2*pi)**0.5))*exp(-0.5*x*x)
def norm_cdf(x):
"""
An approximation to the cumulative distribution
function for the standard normal distribution:
N(x) = \frac{1}{sqrt(2*\pi)} \int^x_{-\infty} e^{-\frac{1}{2}s^2} ds
"""
k = 1.0/(1.0+0.2316419*x)
k_sum = k * (0.319381530 + k * (-0.356563782 + \
k * (1.781477937 + k * (-1.821255978 + 1.330274429 * k))))
if x >= 0.0:
return (1.0 - (1.0 / ((2 * pi)**0.5)) * exp(-0.5 * x * x) * k_sum)
else:
return 1.0 - norm_cdf(-x)
def d_j(j, S, K, r, v, T):
"""
d_j = \frac{log(\frac{S}{K})+(r+(-1)^{j-1} \frac{1}{2}v^2)T}{v sqrt(T)}
"""
return (log(S/K) + (r + ((-1)**(j-1))*0.5*v*v)*T)/(v*(T**0.5))
def vanilla_call_price(S, K, r, v, T):
"""
Price of a European call option struck at K, with
spot S, constant rate r, constant vol v (over the
life of the option) and time to maturity T
"""
return S * norm_cdf(d_j(1, S, K, r, v, T)) - \
K*exp(-r*T) * norm_cdf(d_j(2, S, K, r, v, T))
def vanilla_put_price(S, K, r, v, T):
"""
Price of a European put option struck at K, with
spot S, constant rate r, constant vol v (over the
life of the option) and time to maturity T
"""
return -S * norm_cdf(-d_j(1, S, K, r, v, T)) + \
K*exp(-r*T) * norm_cdf(-d_j(2, S, K, r, v, T))
</code>
</pre><br>
</p>
</p>
<p align="center">
<a class="button" href="index.html"> << Back Home</a>
<a class="button" href="try.html"> << Back </a>
<!-- <a class="button" href="tsys2.html">Next</a> -->
</p>
<!-- </div> -->
<!-- <div id="home" class="section main container-fluid"> -->
</div>
<script src="res/js/prism.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<!-- Popper.JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
<!-- Bootstrap JS -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
<script src="res/js/typing_text.js" type="text/javascript"></script>
<script src="res/js/work_carousel.js" type="text/javascript"></script>
<script src="res/js/scroll_top.js" type="text/javascript"></script>
<script src="res/js/sticky_navbar.js" type="text/javascript"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>