STK4510 - Mandatory Assignment

advertisement
STK4510 - Mandatory Assignment
Sindre Froyn
Exercise 1
(a)
Matlab code for calculating the expectation and volatility for the Dow Jones
index (using closing prices from 1. October 2005 to 2. October 2010).
1
2
3
% Input from the file 'data.txt'
[Date,Open,High,Low,Close,Volume,Adj] = ...
textread('data.txt', '%s %f %f %f %f %d %f');
4
5
6
% Storing the closing prices in the vector s
s = Close(end:−1:1); %(flipping the vector)
7
8
9
10
% Defining vectors
y = zeros(length(s),1);
x = zeros(length(s),1);
11
12
13
14
15
16
% Calculating the return y and logreturn x
for i=2:length(s)
y(i) = (s(i) − s(i−1))/s(i−1);
x(i) = log(s(i)) − log(s(i−1));
end
17
18
19
20
% Finding the expectations (mean) and volatility (std)
my = mean(y);
voly = std(y);
mx = mean(x);
volx = std(x);
After running this code, we get the results:
Matlab
>> my
my =
1.2440e-04
>> mx
mx =
2.1876e-05
>> voly
voly =
0.0143
>> volx
volx =
0.0143
1
(b)
1
2
3
4
5
[Date,Open,High,Low,Close,Volume,Adj] = ...
textread('data.txt', '%s %f %f %f %f %d %f');
s = Close(end:−1:1);
N =length(s);
i=1;
6
7
8
% Temporary storage vector
x = zeros(100,1);
9
10
11
12
% Mean and std for rolling average vector
meanravg = zeros((N−99),1);
stdravg = zeros((N−99),1);
13
14
15
16
17
18
% Running through 's' and retrieving subvectors of length 100
% For each subvector we calculate mean and std
while (i+99) ≤ N
sub = s(i:(i+99));
19
% Logarithmic return for each subvector
for j=2:length(sub)
x(j) = log(sub(j)) − log(sub(j−1));
end
20
21
22
23
24
%Caculating the rolling average mean and std
meanravg(i) = mean(x);
stdravg(i) = std(x);
i=i+1;
25
26
27
28
29
end
30
31
32
33
% Finding the expectation and std for the series of estimates
meanseries = mean(meanravg);
stdseries = std(stdravg);
>> meanseries
Matlab
meanseries =
-3.1656e-05
>> stdseries
stdseries =
0.0077
2
Closing Prices dji
4
1.5
x 10
Rolling Volatility
0.035
1.4
0.03
1.3
0.025
1.2
1.1
0.02
1
0.015
0.9
0.01
0.8
0.005
0.7
0.6
0
200
400
600
800
1000
1200
0
1400
0
200
400
600
800
1000
1200
In the left plot we have the vector s, which are the closing prices for the dji
index, and in the right plot we have the rolling 100 day volatilities, stdravg.
On the left plot we can clearly see the effects of the 2009 financial crisis as the
index fell down beneath the 7000-mark. In our 100 day volatility estimations,
we can see how the the volatility peaks at the financial crisis.
Exercise 2
(a)
We are working with the Vasicek model,
drt = (µ − αrt )dt + σdBt .
Given rt , we are going to use Ito’s formula to compute rs . We set g(s, rs ) =
eαs rs , multiplying the process rs with the integrating factor. Calculating the
partial derivatives for g(s, x):
∂g
= αeαs x,
∂s
∂2g
= 0.
∂x2
∂g
= eαs ,
∂x
By Ito’s lemma,
∂g
∂g
1 ∂2g
(s, rs )ds +
(s, rs )drs + · 2 (s, rs )(drs )2
d g(s, rs ) =
∂x
2 ∂x
∂s
d g(s, rs ) = αeαs rs ds + eαs drs + 0
d g(s, rs ) = αeαs rs ds + eαs µds − αrs ds + σdBs
d g(s, rs ) = µeαs ds + σeαs dBs .
We rewrite in the differential form and use that g(s, rs ) = eαs rs ,
Z s
Z s
αs
αu
e rs = r0 +
µe du +
σeαu dBu .
0
(1)
0
The exact same calculations with t instead of s yields:
Z t
Z t
αt
αu
e rt = r0 +
µe du +
σeαu dBu .
0
0
3
(2)
We take expression (1) minus expression (2).
Z s
Z s
Z t
Z t
αs
αt
αu
αu
αu
e rs − e rt =
µe du +
σe dBu −
µe du −
σeαu dBu .
0
0
eαs rs = rt eαt +
Z
0
s
µeαu du +
t
Z
0
s
σeαu dBu .
t
Multiplying both sides with e−αs we get an expression for rs when rt is known.
Z s
Z s
−α(s−t)
−α(s−u)
rs = rt e
+
µe
du +
σe−α(s−u) dBu
t
t
To find the stationary distribution for rs we return to equation (1), and
calculate the deterministic integral.
Z s
Z s
αs
αu
e rs = r0 +
µe du +
σeαu dBu .
(1)
0
µ
Z
s
eαu du = µ
0
0
1 αu
e
α
s
0
=
µ αs µ
e − .
α
α
Replacing this in (1) and multiplying both sides with e−αs :
Z s
µ αs µ
αs
σeαu dBu .
e rs = r0 + e − +
α
α
0
Z s
µ µ −αs
−αs
−αs
rs = r0 e
+ − e
σeαu dBu
+e
α α
0
Z s
µ
µ
−αs
−αs
+e
r0 −
σeαu dBu
rs = + e
α
α
0
Taking the expectation: the expected value of a stochastic integral is 0.
µ
µ s→∞ µ
E[rs ] = + e−αs r0 −
−→
(3)
α
α
α
To calculate the variance we first calculate E[rs2 ], and we set A = µ/α,
B = e−αs (r0 − µ/α) and denote the stochastic integral as I. We use that all
the terms including I will have expectation 0 except I 2 . We use the linearity
of the expectation and that A and B are deterministic.
2 E[rs2 ] = E A + B + I
= E A2 + 2AB + B 2 + I 2 = A2 + 2AB + B 2 + E[I 2 ]
We use Ito isometry, and the expectation of the integrand is unchanged since
it is deterministic.
Z s
Z s
h
2 i
2
−αs
αu
−2αs
E[I ] = E e
σe dBu
=e
σ 2 e2αu du
0
0
4
σ2
σ 2 −2αs 2αs
1 − e−2αs .
e
e −1 =
0
2α
2α
2α
Now, when we let s → ∞ all the terms including B will tend to 0, and
E[I 2 ] → σ 2 /2α.
µ2
σ2
lim E[rs2 ] = A2 + E[I 2 ] = 2 +
.
s→∞
α
2α
We can now easily find the variance of rs , for s → ∞:
= e−2αs
h σ2
e2αu
Var[rs ] =
is
=
E[rs2 ]
µ2 σ 2
µ2
σ2
− E[rs ] = 2 +
−
=
2α α2
2α
α
2
These parameters
indicate rs has a normal stationary distribution, that is
µ σ2
rs ∼ N α , 2α .
(b)
From (a) we have:
rs = rt e
−α(s−t)
+
Z
s
µe
−α(s−u)
du +
t
Z
s
σe−α(s−u) dBu .
t
Calculating the deterministic integral
Z t
Z s
µ
−α(s−u)
−αs
eαu du = (1 − e−α(s−t) )
µe
du = µe
α
s
t
yields
Z s
µ
−α(s−t)
)+
σe−α(s−u) dBu .
rs = rt e
+ (1 − e
α
t
We integrate this expression for rs from t to T .
Z T
Z T
Z T
Z TZ s
µ µ −α(s−t)
−α(s−t)
rs ds =
rt e
ds +
− e
ds +
σe−α(s−u) dBu ds
α
t
t
t α
t
t
−α(s−t)
Calculating each term separately.
Z T
rt
rt e−α(s−t) ds = (1 − e−α(T −t) )
α
t
Z T
µ
µ
µ µ −α(s−t)
− e
ds = (T − t) + 2 (1 − e−α(T −t) )
α
α
α
t α
For the last term we use change of integral order and apply stochastic Fubini
so we can interchange the deterministic and stochastic integration variables.
Z TZ s
Z TZ T
−α(s−u)
σ
e
dBu ds = σ
e−α(s−u) dsdBu
t
t
t
5
u
We can calculate the inner, deterministic integral.
Z T
1
e−α(s−u) ds = (1 − e−α(T −u) )
α
u
Z T
Z
rt
µ
µ
σ T
−α(T −t)
−α(T −t)
rs ds = (1−e
(1−e−α(T −u) )dBu
)+ (T −t)+ 2 (1−e
)+
α
α
α
α t
t
Calculating the mean and variance. In the expectation the stochastic integral
is 0, and the rest of the expression is deterministic.
Z T
µ
µ
rt
E
rs ds = (1 − e−α(T −t) ) + (T − t) + 2 (1 − e−α(T −t) )
α
α
α
t
To calculate the variance we first square the expression. Denoting the
part as A and the integral as I we get the shorthand expression
Rdeterministic
T
rs ds = A + I. Hence (A + I)2 = A2 + 2I + I 2 . Taking the expectation of
t
RT
this gives E[( t rs ds)2 ] = E[A2 ] + E[I 2 ]. To calculate the variance, we use:
Var
Z
T
rs ds = E[(A + I)2 ] − E[A + I]2 = E[A]2 + E[I 2 ] − E[A]2 = E[I 2 ].
t
The variance is the expectation of the squared stochastic integral. To
calculate it we apply Ito isometry, and using that the expection of the
deterministic integrand is just the integrand:
" Z
2 #
Z
T
σ
σ2 T
2
−α(T −u)
E[I ] = E
(1 − e
)dBu
= 2
(1 − e−α(T −u) )2 du
α t
α t
Intermediate calculation:
Z T
Z
−α(T −u) 2
(1 − e
) du =
t
T
1 − 2e−α(T −u) + e−2α(T −u) du =
t
2
1
(T − t) − (1 − e−α(T −t) ) +
(1 − e−2α(T −t) ) =⇒
α
2α
Z T
σ2
Var
rs ds = E[I 2 ] = 3 2α(T − t) + 4e−α(T −t) − e−2α(T −t) − 3
2α
t
6
(c)
We are going to calculate
Z
P (t, T ) = 100E exp −
T
rs ds
t
Ft
RT
We use that t rs ds is normally distributed, so this expression equals the
exponential function of the conditional expectation and variance.
Z T
Z T
1
P (t, T ) = 100 exp −E
rs ds + Var
rs ds
2
t
t
The expectation and variance were found in b), and have the expression (with
b(t, T ) = (1 − e−α(T −t) ) and ignoring 100 for now).
µ
µ
σ2
rt
−α(T −t)
−2α(T −t)
−e
−3
exp − b(t, T ) − (T − t) − 2 b(t, T ) + 3 2α(T − t) + 4e
α
α
α
4α
−α(T −t)
After some algebra, and by defining B(t, T ) = ( 1−e α
), we get
σ2
σ2 µ
2
B(t, T ) − T + t −
−
B(t, T )
P (t, T ) = 100 exp −B(t, T )rt +
α 2α2
4α
(d)
Plotting for different values of µ, α, σ and rt .
1
2
3
4
5
6
T = 150; P = zeros(4,T);
r_t
= [0.03
0.52
0.2
mu
= [0.34
0.026
0.024
sigma = [0.63
0.025
0.36
alpha = [1.2
3
0.4
col
= ['r',
'k',
'b',
0.05];
0.022];
0.015];
0.9];
'g'];
7
8
9
10
11
12
13
14
15
16
17
18
19
20
for j=1:4
for i=1:T
B = (1 − exp(−alpha(j)*(1−(T−i)/T)))/(alpha(j));
f1 = (mu(j)/alpha(j) − sigma(j)^2/(2*alpha(j)^2));
f2 = sigma(j)^2/(4*alpha(j));
% This is the expression for P(t,T)
P(j,i) = 100*exp(−B*r_t(j) + f1*(B−1+(T−i)/T) − f2*B^2);
end
end
figure; hold on;
for i=1:4
plot(P(i,:), col(i))
end
7
100
98
96
94
92
90
88
86
84
0
50
100
150
These are the plots for same arbitrarily chosen values. From the code r, k, b
and g correspond to red, black, blue and green, respectively.
(e)
We will consider the 6 month data for NST469: a Norwegian government
bond, downloaded from oslobors.no (from 26.4.10 to 25.10.10).
1
2
Q = textread('rente.txt', '%f');
R = Q/Q(1);
% P*−data
% Scaling down
3
4
5
6
7
8
T
P
sigma
r_t
min
=
=
=
=
=
length(R);
zeros(1,T);
(0.02:0.04:2);
0.03;
999;
Pm
= zeros(1,T);
mu
= (0.02:0.04:2);
alpha = (0.02:0.08:4);
% Assume r_t is set
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
for i=1:50
% Unelegant brute force method
for j=1:50
%
running time: ca. 3 min
for k=1:50
for t=1:T
B = (1 − exp(−alpha(k)*(1−(T−t)/T)))/(alpha(k));
f1 = (mu(i)/alpha(k) − sigma(j)^2/(2*alpha(k)^2));
f2 = sigma(j)^2/(4*alpha(k));
P(t) = exp(−B*r_t + f1*(B−1+(T−t)/T) − f2*B^2);
S=0;
% Finding the minimizing values
for n=1:T
S = S + abs(P(n) − R(n));
end
if S < min
min=S; Pm=P; par=[mu(i) sigma(j) alpha(k)];
end
end
end
end
end
8
1.005
NST469
Vasicek
1
0.995
0.99
0.985
0.98
0
10
20
30
40
50
60
70
80
90
According to the plot, we can see that the Vasicek model catches the
general evolution of the bond, but it does not capture the short time
variations, and as we can see these differences can sometimes be significant.
However, a model that is more flexible would necessarily incorporate more
variables and would as a result be harder to work with.
Exercise 3
(a)
Using Ito’s formula, we are going to find the dynamics, dSt , of the Schwartz
model,
St = S0 eXt
where
dXt = µ − αXt dt + σdBt .
Using g(t, x) = ex , we find the partial derivatives,
∂g
= 0,
∂t
∂2g
= ex .
∂x2
∂g
= ex ,
∂x
Applying Ito’s integral.
1
d g(t, Xt) = S0 eXt dXt + S0 eXt (dXt )2 .
2
The expression for dXt is given.
2
1
= S0 eXt (µ − αXt dt + σdBt ) + S0 eXt (µ − αXt dt + σdBt
2
Using the calculation rules dt2 = dtdBt = dBt dt = 0 and dBt2 = dt,
(µ − αXt )dt + σdBt
9
2
= σ 2 dt.
By replacing this and collecting dt and dBt parts, we get
1
= S0 eXt (µ − αXt dt + σdBt ) + S0 eXt σ 2 dt, =⇒
2
1 dSt = S0 eXt µ − αXt + σ 2 dt + σdBt .
2
Xt
We can also use St = S0 e , which means Xt = ln St /S0 , so
dSt = µ − α ln
1 St
+ σ 2 St dt + σSt dBt .
S0 2
(b)
We are going to compute f (t, T ) = E[ST |Ft ].
1
XT
f (t, T ) = E S0 exp(XT ) Ft = S0 E[e |Ft ] = S0 exp E[XT |Ft ] + Var[XT |Ft ]
2
Now we observe that Xt is a Vasicek model, like we worked with in exercise
2. We derived the expectation and variance, but now we need the conditional
expectation and variance.
µ µ −α(T −t)
e
E[XT |Ft ] = + Xt −
α
α
σ2
(1 − e−2α(T −t) )
2α
Hence, we have an explicit expression for f (t, T ).
µ −α(T −t) σ 2
µ −2α(T −t)
e
+
+ Xt −
(1 − e
)
f (t, T ) = S0 exp
α
α
2α
µ
σ2
−α(T −t)
−2α(T −t)
−α(T −t)
.
= S0 exp
(1 − e
)+
(1 − e
) + Xt e
α
2α
Var[XT |Ft ] =
To calculate the dynamics, df (t, T ), we simply define g(t, Xt) = f (t, T ), and
by Ito’s formula:
df (t, T ) =
∂g
∂g
1 ∂2g
(t, Xt )dt +
(t, Xt )dXt + · 2 (t, Xt )(dXt )2 .
∂t
∂x
2 ∂x
Finding the partial derivatives for g(t, x).
∂g
1 2 −2α(T −t)
−α(T −t)
−α(T −t)
(t, x) = g(t, x) −µe
− σ e
+ αxe
∂t
2
10
(4)
∂2g
∂g
∂g
(t, x) = g(t, x)e−α(T −t) ,
(t, x) =
(t, x)e−α(T −t) = g(t, x)e−2α(T −t)
2
∂x
∂x
∂x
Now to shorten the notation, we define a = α(T − t) and g = g(t, Xt ).
Plugging the partial derivatives, the process dXt and (dXt )2 (which we found
in a) into (4):
σ 2 −2a
σ2
−a
−a
df (t, T ) = g −µe − e
dt+ge−a (µdt − αXt dt + σdBt )+ ge−2a
+ αXt e
2
2
Almost everything cancels out nicely, and we are left with:
df (t, T ) = ge−a σdBt = f (t, T )σe−α(T −t) dBt .
We can write this out in integral form (and define the integrand as A(u))
Z t
Z t
−α(T −u)
f (t, T ) =
f (u, T )σe
dBu =
A(u)dBu .
0
0
By corollary 3.26 in Øksendal all pure stochastic integrals are martingales,
so f (t, T ) is a martingale.
At time t = T , we get
f (T, T ) = E[S(T )|FT ] = S(T ).
The spot price S(T ) is measurable with respect to FT so we can factor it
out of the expectation, so the spot equals the price of the commodity when
t = T.
(c)
We are going to compute
p(t, τ, T, K) = exp(−r(τ − t))E max f (τ, T ) − K), 0 Ft
I ran out of time, so this part remains unanswered.
11
Download