7 Chapter 8 (Copulas)
79
8 Chapter 9 (Regression: Basics)
93
9 Chapter 10 (Regression: Troubleshooting)
102
10 Chapter 11 (Regression: Advanced Topics)
109
11 Chapter 12 (Time Series Models: Basics)
118
12 Chapter 13 (Time Series Models: Further Topics)
137
13 Chapter 14 (GARCH Models)
154
14 Chapter 15 (Cointegration)
171
15 Chapter 16 (Portfolio Theory)
176
16 Chapter 17 (The Capital Asset Pricing Model)
185
17 Chapter 18 (Factor Models and Principal Components)
195
18 Chapter 19 (Risk Management)
207
19 Chapter 20 (Bayesian Data Analysis and MCMC)
220
20 Chapter 21 (Nonparametric Regression and Splines)
228
5
0.1
0.15 0.10
0.0
0.05
−0.1
MRK return
0.00
FReturn
−0.05
−0.2
−0.10 −0.15
−0.2
−0.1
0.0
0.1
−0.3
GMReturn
−0.2
−0.1
0.0
0.1
0.2
MSFT return
Figure 1: Left: A scatter plot of the returns of Ford as a function of the returns of GM. Left: A scatter plot of the returns of Merck as a function of the returns of Microsoft.
1
Chapter 2 (Returns)
R Lab See the R script Rlab.R where the problem for this chapter are worked.
Problem 1 (GM and Ford returns) In Figure 1 (left) we show the scatter plot of the returns of Ford as a function of the returns of GM. We notice that these returns do appear to be correlated (they are distributed somewhat symmetrically about a line) and the outliers of each stocks return do appear together.
Problem 2 In the accompanying R code we plot the two returns. The two sets of points lie almost exactly on the line y = x. They have a correlation (using the R function cor) given by 0.9995408.
6
Problem 3 (MSFT and MRK returns) In Figure 1 (right) we show the scatter plot of the returns of Merck as a function of the returns of Microsoft. We notice that these returns are much less correlated (they have a correlation coefficient of 0.2710328) than the returns between GM and Ford (which have a correlation coefficient of 0.6139335).
Problem 4 I get with a certainty of 51% that the value of the stock will be below $950000 at the close of at least one of the 45 trading days.
Problem 5-8 I get that the hedge fund will make a profit with a probability of 0.38775. I get that the hedge fund will suffer a loss with a probability of 0.58844. I get that the hedge funds expected profit is given by 9922.63 but the expected return (in units of days) -0.01783836.
Problem 9 Based on the expression used to compute the logr variable the mean log-return for one year is 0.05 or 5% and the standard deviation of the log-returns for one year is 0.2 or 20%
Prob1em 10 Looking at the plots generated many of them seem to “trend”. The trending is “real” in the sense that the mean return each day is positive and each step should result in a larger price (in expectation). The variance of this process is very large (as is true with financial data) which adds noise to the time series.
Problem 11 That command simulates the prices of an geometric random walk where Pt = P0 exp(rt + rt−1 + rt−2 + · · · + r1 ) .
7
Problem 12 In the R code for this problem we plot the log-returns of McDonald’s as a function of the return. The two are indistinguishable. The correlation between these two series is 0.9999536 indicating that the two types of returns move in the same manner.
Problem 13 Computing the mean and the standard deviation of the two series I get [1] "returns: mean= 0.000503; std= 0.008900" [1] "log-returns: mean= 0.000463; std= 0.008901" Notice that the mean is smaller for the log-returns while the standard deviation looks about the same.
Problem 14-15 We can use the R command t.test to compare these two series of numbers. Running that we get the following > t.test(x=rets, y=lrets, paired=TRUE) t = 15.866, df = 1175, p-value < 2.2e-16 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 3.478409e-05 4.460108e-05 sample estimates: mean of the differences 3.969258e-05 This indicates that the mean difference is significant between the two samples. The assumptions of the t-test are that the random variables come from a normal distributions. While that is normally not strictly true in financial data sets the t-test is normally robust to deviations in the distribution of the inputs. There are some evidence that the log-returns will have a smaller mean than the mean of the simple returns see https://papers.ssrn.com/sol3/papers.cfm?abstract_id=1549328
8
While the above t-test shows that there is a significant difference in the mean returns between the two different ways of calculating them, this difference is very small (four-tenths of a basis point) especially compared to the standard deviation of the returns (89 basis points). Thus while statistically significant the observation made by the t-test may not be practically significant. The two returns seem close enough for small values to consider them equivalent.
Problem 16 Running the R code for this problem we run a Monte Carlo simulation and find an expected profit from playing this game to be 0.060500 which is larger than zero and one should play this game.
Problem 17 Running our Monte-Carlo simulation with these new rules gives an expected profit for playing this game of 0.243000 which is also larger than zero and one should like to play this game even more than before.
Exercises Exercise 2.1 Part (a): To have a value less than $990 means that we must have a log return less than 990 log = −0.01005034 . 1000 To find this probability we evaluate pnorm(−0.01005034, mean = 0.001, sd = 0.015) to get the value 0.2306556. Part (b): In five trading days our log return √ will be normally distributed with a mean 5(0.001) = 0.005 and a standard deviation of 5(0.015) = 0.03354102. To be less than $990 we need to have a logarithm less than -0.01005034 (as computed above). Thus in this case we need to evaluate pnorm(−0.01005034, mean = 0.005, sd = 0.03354102) to get the value 0.3268188. 9
Exercise 2.2 To have a price greater than 110 we must have a log return greater than log 0.09531018 in one years time. This will happen with a probability of
110 100
=
1 − pnorm(0.09531018, mean = 0.1, sd = 0.2) = 0.509354 . Exercise 2.3 The log-return for two years would√be a normal random variable with a mean of by 2(0.1) = 0.2 with a standard deviation of 2(0.15) = 0.212132. To have the price in two years be larger than $90 means that the log return must be larger than log(90/80) = 0.117783. Using the theory of normal random variables this will happen with a probability of 0.6508345. This calculation is done in the following R code m = 0.2 s = sqrt(2)*0.15 lr = log(90/80) z = ( lr - m ) / s 1 - pnorm(z)
Exercise 2.4 For this problem we will need to recall the definitions of the net return Rt (k) =
Pt − Pt−k , Pt−k
(1)
and the log return rt (k) = log(1 + Rt (k)) . Using the above formulas we have that R3 (2) =
P3 − P1 98 − 95 P3 − P3−2 = = = 0.03061224 . P3−2 P1 95
Then r3 (2) = log(1 + 0.03061224) = 0.03015304.
Exercise 2.5 Part (a): With dividends our single period net return Rt is given by Rt =
Pt + Dt − Pt−1 , Pt−1 10
(2)
so that with the numbers for this problem we get R2 =
54 + 0.2 − 52 P 2 + D2 − P 1 = = 0.04230769 . P1 52
Part (b): Next recall that with dividends the multiperiod gross returns 1 + Rt (k) is given by Pt + Dt Pt−1 + Dt−1 Pt−k+1 + Dt−k+1 1 + Rt (k) = ··· . (3) Pt−1 Pt−2 Pt−k Using the above we have P 4 + D4 P 3 + D3 P2 + D2 1 + R4 (3) = P3 P P 2 1 53 + 0.2 54 + 0.2 59 + 0.25 = 1.147959 . = 53 54 52 Thus R4 (3) = 0.1479588. Part (c): For this part we will use P 3 + D3 53 + 0.2 = log = −0.01492565 . r3 = log(1 + R3 ) = log P2 54 Exercise 2.6 Part (a): Using the formula in the book for Rt (k) when we have dividends we have that P 2 + D2 P 3 + D3 . 1 + R3 (2) = P2 P1 Using the numbers given in this exercise we compute the above to be R3 (2) = 0.01460689. Part (b): Using the formula in the book for rt (k) when we have dividends we have that r4 (3) = log(1 + R4 ) + log(1 + R3 ) + log(1 + R2 ) P 4 + D4 P 3 + D3 P2 + D2 = log + log + log P3 P2 P 1 87 + 0.125 83 + 0.1 85 + 0.1 = log + log + log . 83 85 82 Evaluating this we find r4 (3) = 0.06300449.
Exercise 2.7 Part (a): The variable rt (4) would be a normal random variable with a mean 4(0.06) = 0.24 and a variance of 4(0.47) = 1.88 (assuming that the number 0.47 quoted is the one period variance and not standard deviation). 11
Part (b): We would compute this using the R command pnorm(2, mean = 0.24, sd = sqrt(1.88)) = 0.9003611 . Part (c): For this recall that r1 (2) = r1 + r0 r2 (2) = r2 + r1 , where each of rt is i.i.d. from N(0.06, 0.47). Thus we have that Cov(r1 (2), r2 (2)) = Cov(r1 + r0 , r2 + r1 ) = Cov(r1 , r2 ) + Cov(r1 , r1 ) + Cov(r0 , r2 ) + Cov(r0 , r1 ) = 0 + σ 2 + 0 + 0 = 0.47 .
Part (d): For this note that rt (3) = rt + rt−1 + rt−2 . Thus if we know that rt−2 was equal to 0.6 then rt (3) is made of only two random components (and a known constant) thus rt (3)|{rt−2 = 0.6} is a normal random variable with a mean 2(0.06) + 0.6 = 0.72 and a variance of 2(0.47) = 0.94.
Exercise 2.8 Part (a): For this we have X2 > 1.3 P (X2 > 1.3X0 ) = P X0 = P (r1 + r2 > log(1.3)) = 1 − P (r1 + r2 < log(1.3))
= 1 − pnorm(log(1.3), mean = 2µ, sd =
√
2σ) .
Part (b): For this we first recall that A.4 (with X replaced with R) is given by fY (y) = fR (h(y))|h′(y)| . For this problem these functions are (r − µ)2 1 exp − fR (r) = √ 2σ 2 2πσ Y = g(R) = X0 eR 1 Y so h′ (Y ) = . R = h(Y ) = log X0 Y 12
(4)
Then using Equation 4 we have (log(Y /X0 ) − µ)2 1 exp − fY (y) = √ , 2σ 2 2πσy for the density of Y = X1 . Part (c): As we can write Xk = X0 eR where R is a normal random variable with mean a kµ and variance kσ 2 the probability density function of the random variable Xk is derived just like the one for X1 above. In fact we have if Y = Xk we have (log(Y /X0 ) − kµ)2 1 exp − . fY (y) = √ 2kσ 2 2πkσy Then since the transformation from R to Xk is a monotone transformation the quantiles of R transform to the quantiles of Xk using the same monotone transformation. Thus finding the 0.9 quantile of R (by using the qnorm command in R for a normal with a mean kµ and a variance kσ 2 ) which we will denote as µ0.9 . Given this we find the 0.9 quantile of Xk by computing X0 eµ0.9 . Part (d): Now Xk2 is equal to Xk2 = X02 exp
(
2
k X
rj
j=1
)
= X02
k Y
e2rj .
j=1
The expectation of this is given by integrating the above against the density p(r1 , r2 , . . . , rk−1, rk ) =
k Y
p(rj ) .
j=1
This gives E[Xk2 ] = X02
Z ∞
−∞
k Y
2rj
e
p(rj )drj
j=1
!
= X02
k 1 (r − µ)2 dr . e √ exp − 2σ 2 2πσ −∞
Z ∞
2r
1 Lets now evaluate the integral above (dropping for now the coefficient √2πσ ) we have
Z ∞
Z ∞
(r − µ)2 dr dr = exp 2r − I= e e 2σ 2 −∞ −∞ Z ∞ r2 rµ µ2 = exp 2r − 2 + 2 − 2 dr 2σ σ 2σ −∞ Z ∞ 2 r µ µ2 = exp − 2 + 2 + 2 r − 2 dr 2σ σ 2σ −∞ Z ∞ 2 2 µ r − µ2 exp − 2 + 2 + 2 r dr . = e 2σ 2σ σ −∞ (r−µ) 2r − 2σ 2
2
13
Working with the exponent in the above exponential we have 1 2 µ 1 2 − 2 r − 2σ 2 + 2 r = − 2 r 2 − 2 2σ 2 + µ r 2σ σ 2σ 1 = − 2 r 2 − 2(2σ 2 + µ)r + (2σ 2 + µ)2 − (2σ 2 + µ)2 2σ 2 1 2 2 2 = − 2 r − (2σ + µ) − (2σ + µ) . 2σ Putting this back into the expression for I we get Z ∞ 2 2 (2σ 2 +µ)2 1 − µ2 2 2 I = e 2σ e 2σ dr exp − 2 r − (2σ + µ) 2σ −∞ Z ∞ 4σ 4 +4σ 2 µ 1 2 2 e− 2σ2 r dr . = e 2σ −∞
In deriving this last integral I have made the centering substitution v = r − (2σ 2 + µ) (and then dv = dr) where since 2σ 2 + µ is constant and the limits of the integrand are infinite only replaces this “center” value of 2σ 2 + µ to zero and effectively removes that shift. To keep evaluating the expression for I we recall [3] that r Z ∞ π −αx2 . e = α −∞ Using this we have that I=
√
(5)
2
2πσe2µ+2σ .
1 Putting back the factor of √2πσ we get
2 k 2 E[Xk2 ] = X02 e2µ+2σ = X02 e2(kµ+kσ ) .
Part (e): Now we want to compute Var (Xk ) which we do using Var (Xk ) = E[Xk2 ] − E[Xk ]2 .
Thus we use this formula we need to compute E[Xk ]. Following the same procedure as used above to compute E[Xk2 ] we get
E[Xk ] = X0 e
σ2 +µ 2
k
.
Using this we get 2 2 Var (Xk ) = X02 e2kµ+2kσ − ekσ +2kµ 2
2
= X02 e2kµ ekσ (ekσ − 1) .
14
Exercise 2.9 The terms Xn of a log-normal geometric random walk are generated as Xn = X0 er1 +r2 +···+rn , where each ri are iid N(µ, σ 2 ) random variables. Part (a): The desired condition is equivalent to X3 > ln(1.2) = P (r1 + r2 + r3 > ln(1.2)) . P log X0 Given the distribution of rt we know that r1 + r2 + r3 is also a normal random variable with mean 3µ and a variance 3σ 2 . Using that we can compute the above and find the probability given by Z ∞
P =
N(x; 3µ; 3σ 2 )dx .
ln(1.2)
2
Here N(x; µ, σ ) is the probability density function for a normal random variable. Using the numbers given in this exercise I find this to be 0.6329619. Part (b): We are asked to find Var
Xk k
=
1 Var (Xk ) . k2
√ k is a log-normal random variable with µ = 0.1k and σ = 0.2 k and so using formulas Now X X0 for the variance of a log-normal random variable (with these parameters) we find Xk = e0.1k+0.04k (e0.04k − 1) . Var X0 Using this we can compute Var (Xk ) and thus what we are asked for. We find Xk X2 Var = 20 e0.1k+0.04k (e0.04k − 1) . k k
Part (c): Assuming Pt is a log-normal geometric random walk we know that log PP0t is normal with a mean 0.1t and a variance 0.04t. Transforming to normal random variables the condition we want to impose is to find the smallest t such that ln(2) − 0.1t √ 1−P Z ≤ ≥ 0.9 . 0.2 t Evaluating the above for several values of t in the following R code ts = 5:20 # When is the first time this is less than 1 - 0.9 = 0.1 pnorm( ( log(2) - 0.1 * ts ) / ( 0.2 * sqrt(ts) ) ) we see that the above will be satisfied for all t ≥ 18. 15
Exercise 2.10 To have the stock price greater than $100 means that the log return needs to be larger than 100 = 0.03045921 . log 97 In 20 days the log return should be a normal random variable and have a mean value of √ 20(0.0002) = 0.004 with a standard deviation of 20 × 0.03 = 0.1341641. The probability we have a return larger than the above (and a final price greater than 100) is given by 1 − pnorm(0.03045921, mean = 0.004, sd = 0.1341641) = 0.4218295 . Exercise 2.11 To have Rt = Pt /P0 ≥ 2 means that the net return is larger than two. From the exercise description in t days the log-return should be a normal random variable and have a mean value of 0.0005t , and a variance of 0.012t . To work this exercise we will make the assumption that Rt ∼ N(0.0005t, 0.012t) and we want to know the value of t such that 2 − 0.0005t Rt − 0.0005t √ ≥ 0.9 . ≥ √ P (Rt ≥ 2) = P 0.012t 0.012t In the above the expression Rt√−0.0005t is a standard normal random variable. From the normal 0.012t distribution we know that P (Z ≥ zc ) = 0.9 if zc = qnorm(1 − 0.9) = −1.281552 . Thus we must find the first t such that 2 − 0.0005t √ ≤ −1.281552 . 0.012t Solving for t in the above we find that t ≥ 184.6523 days.
16
1200 800
1000
price of bond
1400
1600
par= 1000, coupon payment= 40, T= 30
0.020
0.025
0.030
0.035
0.040
0.045
0.050
yield to maturity
Figure 2: A plot of the value of a bond for various yields to maturity.
2
Chapter 3 (Fixed Income Securities)
R Lab See the R script Rlab.R where the problem for this chapter are worked.
Problem 1 When we run the given Rlab.R function we get the plot in Figure 2. There we see graphically that the value found by the spline function (which was 0.03239813) intersects the curve at $1200.
Problem 2 The given code with the uniroot function finds the root of the given function. In this case that is equivalent to finding the square root of 0.5.
17
Problem 3 For this we would execute uniroot( function(r) bondvalue(C, T, r, par) - 1200, c(0.03,0.04) ) which gives the following output $root [1] 0.03241618 $f.root [1] -0.5497406 $iter [1] 3 $estim.prec [1] 6.103516e-05 The value of the “root” field gives the desired yield-to-maturity.
Problem 4 For this we would execute uniroot( function(r) bondvalue(280, 8, r, 10000) - 9800, c(0.01,0.04) ) which gives an output structure with a root field with a value 0.02956445.
Problem 5 Using the uniroot and the bondvalue function we find this to be r = 0.06041274.
Problem 6 Using the uniroot and the bondvalue function we find this to be C = 28.99996 dollars.
18
short end
long end
0.09 yield
0.08 0.07
0.08 0.07
yield
0.09
1985−12−01 1986−01−01 1986−02−01 1986−03−01
1985−12−01 1986−01−01 1986−02−01 1986−03−01 0.0
0.5
1.0
1.5
2.0
2.5
3.0
20
maturity (monthly)
22
24
26
28
30
maturity (monthly)
Figure 3: Left: The time evolution of the short end of the yield curves for the dates given in Problem 7. Right: The time evolution of the long end of the yield curves for the dates given in Problem 7. Problem 7 See Figure 3 (left) for the requested plot of the short end of the yield curves. There we see that the yields seemed to increase as the maturity increases. See Figure 3 (right) for the requested plot of the long end of the yield curves. There we see that the yields gets smaller as time progresses.
Problem 8 See Figure 4 for the plot of the yield curves at these four points in time. There we see that the yields seemed increase to a maximum with a duration at about 22.5 months and then decrease.
Problem 9 See Figure 5 for the plot of the numerically computed forward rates (from the yield rates) at the requested four points in time. We see the the wiggles mentioned in the comments in the book in these plots.
19
0.08 0.07 0.06
yield 0.05
1986−12−01 1987−01−01 1987−02−01 1987−03−01 0
5
10
15
20
25
30
maturity (monthly)
0.09 0.07
0.08
forward rate
0.10
0.11
Figure 4: The evolution of the yield curves with duration for the dates given in Problem 8.
0.06
1986−12−01 1987−01−01 1987−02−01 1987−03−01 0
5
10
15
20
maturity (month)
Figure 5: The evolution of the yield curves with duration for the dates given in Problem 9. 20
Exercises Exercise 3.1 Part (a): The yield to maturity is given by 1 yT = T
Z T
r(t)dt ,
(6)
0
thus with what we are given here we have Z 20 1 y20 = (0.028 + 0.00042t)dt 20 0 0.00042 2 1 0.028(20) + (20 ) = 0.0322 . = 20 2 Part (b): Using the same steps as in the previous part we find y15 = 0.03115 then the price is given by P (T ) = PAR exp {−T yT } . (7) Thus for the numbers here we get P (15) = 1000e−0.3115(15) = 626.7234 .
Exercise 3.2 Part (a): The yield to maturity is given by Equation 6 thus with what we are given here we have Z 1 8 (0.04 + 0.0002t − 0.00003t2 )dt y8 = 8 0 1 0.0002 2 0.00003 3 = 0.04(8) + (8 ) − (8 ) = 0.04016 . 8 2 3 Part (b): Using the same steps as in the previous part we find y5 = 0.04025 then the price is given by Equation 7. Thus for the numbers here we get P (5) = 1000e−0.04025(5) = 817.708 . Part (c): See Figure 6 where these two functions are plotted. As the second derivative of both functions is negative both functions are concave. The two curves differ only in the numerical value of the coefficients of the polynomial terms. Part (d): Using arguments like the above the ten year zero-coupon bond will cost 670.32. After a year has passed the nine year zero-coupon bond will be worth 697.1114 to give a net return of 0.03996806 or about 4%. 21
0.04020 0.04000
0.04010
r(t)
0.04030
forward rate
0.0
0.5
1.0
1.5
2.0
2.5
3.0
2.0
2.5
3.0
t
0.04000 0.04005 0.04010 0.04015 0.04020
y(t)
yield curve
0.0
0.5
1.0
1.5 t
Figure 6: The forward rate and yield curve for the given function r(t). Exercise 3.3 Part (a): As the coupon rate is larger than the current yield following the discussion in the book in the section titled “Yield to Maturity” the bond is selling above par value. Part (b): As the bond is selling above par value, the yield to maturity is smaller than the current yield and thus is below 2.8%.
Exercise 3.4 Part (a): This would be given by y5 and is computed using Equation 6 for the forward rate function r(t) given here we find y5 = 0.03616667. Part (b): This would be given by Equation 7 with PAR = 1 where we find P (5) = 0.8345744.
22
Exercise 3.5 We are given the values of the half year spot rates r1 , r2 , r3 , r4 , T = 2, a coupon amount of C = 35 and a par value of $1000. The price of this bond will be given by C C C PAR + C + + + . (8) 1 + r1 (1 + r2 )2 (1 + r3 )3 (1 + r4 )4 Using what we know we find this expression to be given by $1008.058.
Exercise 3.6 For this we will use the identity N X
rt =
t=1
r − r N +1 , 1−r
to write the sum on the left-hand-side as 2T +1 (r+1) 1 1 1 − (r+1) − 1+r 2T +1 1 1+r = = 1 (1 + r)t 1+r−1 1 − 1+r t=1 1 1 = 1− . r (1 + r)2T
2T X
Using this we see that the left-hand-side of the given expression becomes 1 PAR C C C 1− (1 + r)−2T , + = + PAR − r (1 + r)2T (1 + r)2T r r
(9)
the desired expression.
Exercise 3.7 Part (a): When the bond is issued the annual interest rate is 8.5% (or a semiannual rate of 4.25%) thus the semiannual coupon payment would be for 0.0425(1000) = 42.5. Part (b): The semiannual interest rate now is 3.8%. After two coupons payments and with the new interest rates the bond is now worth 38 X 1000 42.5 + = 1089.718 , t 38 1.038 1.038 t=1 when we evaluate.
Part (c): In this case the lower limit on the first summation would start at t = 0 and we would have 38 X 1000 42.5 + = 1132.218 . t 1.038 1.03838 t=0 23
Exercise 3.8 Part (a): We are told that P (5) = 818 =
1000 , exp(5r)
which has r = 0.044017. so exp(5r) = 1000 818 Part (b): The price of the bond would now be P (4) =
1000 = 845.3538 . exp(4(0.042))
Part (c): The net return is Rt =
Pt − Pt−1 845.3538 − 818 Pt −1 = = = 0.0335 , Pt−1 Pt−1 818
or about 3.3%.
Exercise 3.9 Part (a): We are told that PAR = 1000, C = 21, and r = 0.04 (so the semiannual rate is 0.02). To compute the price of the bond we can use the right-hand-side of Equation 9 with T = 10 to get 21 21 1.02−20 = 1016.351 . + 1000 − 0.02 0.02
C 21 Part (b): The coupon rate is 1000 = 1000 = 0.021. Since the coupon rate is larger than the current yield of 0.02 this bond is selling above par value.
Exercise 3.10 Part (a): We are told that PAR = 1000 and T = 7. We find to find the value of r such that Equation 9 gives 23 C 23 C −2T (1 + r) = (1 + r)−14 . + 1000 − 1040 = + PAR − r r r r Using the bondvalue function with uniroot we get r = 0.01970275. 23 Part (b): The current yield is 1040 = 0.02211538 semiannually.
Part (c): The yield to maturity is less than the current yield since the bond is selling above par. 24