0% found this document useful (0 votes)
13 views4 pages

Chapter 2

The document solves problem 12 from a textbook on statistics and data analysis for financial engineering. Code is provided to produce a plot of return vs log return for stock price data, showing the two are almost equal as expected from the theory discussed in the textbook.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

Chapter 2

The document solves problem 12 from a textbook on statistics and data analysis for financial engineering. Code is provided to produce a plot of return vs log return for stock price data, showing the two are almost equal as expected from the theory discussed in the textbook.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Solutions to Selected Computer Lab Problems and Exercises

in Chapter 2 of Statistics and Data Analysis for Financial


Engineering, 2nd ed. by David Ruppert and David S.
Matteson

c 2016 David Ruppert and David S. Matteson.

Problem 12. Code to produce the plot is below.

data = read.csv("MCD_PriceDaily.csv")
head(data)
adjPrice = data[,7]
logReturn = diff(log(adjPrice))
n = length(adjPrice)
return = adjPrice[-1]/adjPrice[-n] - 1
plot(return,logReturn,ylab = "log return")
abline(a = 0,b = 1,col = "red",lwd = 2)

We see that the return and log return for any day are almost equal. This is
reasonable in light of the discussion in Section 2.1.3, especially Figure 2.1.


0.04


●●

●●
0.02

●●●


●●●




●●

●●●

●●

●●

●●

●●

●●

●●


log return




●●




●●




●●


●●

●●
0.00


●●


●●

●●

●●

●●


●●

●●


●●




●●




●●




●●

●●

●●


●●
●●

●●

●●

●●



●●

−0.02


●●





●●●●


●●

●●



●●

−0.04



−0.04 −0.02 0.00 0.02 0.04

return

Problem 13. The R output is below. We see that the means of the returns and log returns
are somewhat similar and the standard deviations of the returns and log returns
agree to three significant digits. (sd(return) = 0.00890 but R did not print
the final zero.)

> options(digits = 4)
> mean(return)
[1] 0.0005027
> mean(logReturn)
[1] 0.0004631

1
> sd(return)
[1] 0.0089
> sd(logReturn)
[1] 0.008901

Problem 14. It is crucial to use a paired t-test because the return and log return on any given
day are highly correlated and the independent samples t-test assumes that they
are independent. The paired t-test has a p-value of 2.2 × 10−16 . Therefore,
using any reasonable significance level including, of course, 5%, we reject the
null hypothesis that the mean of the returns and mean of the log returns are
equal.

> t.test(return,logReturn,paired = TRUE)

Paired t-test

data: return and logReturn


t = 16, df = 1200, p-value <2e-16
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
3.478e-05 4.460e-05
sample estimates:
mean of the differences
3.969e-05

Note: The p-value would be non-significant if we incorrectly used an unpaired


t-test. See below.

> t.test(return,logReturn,paired = FALSE)

Welch Two Sample t-test

data: return and logReturn


t = 0.11, df = 2300, p-value = 0.9
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.0006801 0.0007595
sample estimates:
mean of x mean of y
0.0005027 0.0004631

Let dt be the difference between the return and log return on day t. The
assumptions of the paired t-test are that d1 , . . . , dn are independent, that they
are normally distributed, and that they have a constant variance. Here n is the
sample size.

2
The normality assumption is unlikely to hold, but it is not crucial since, by the
central limit theorem, the mean of d1 , . . . , dn will be approximately normal and
that is enough for the t-test to be valid.
The assumption of a constant variance is likely to be met, although it is not
crucial since the t-test is robust to this assumption.
The independence assumption is unlikely to be met, since we might expect
some serial correlation and volatility clustering is likely. However, the serial
correlation should be small and the t-test is not much affected by volatility
clustering.
In summary, the assumptions of the t-test are unlikely to hold exactly, but the
conclusion of the t-test should be valid, nonetheless.

Problem 16. The R output is below. The expect value of the bet is slightly positive, with a
95% confidence equal to (0.05583, 0.06517), so you should be willing to make
this bet.

> niter = 10000


> value = matrix(niter)
> set.seed(2015)
> for (i in 1:niter)
+ {
+ logR = rnorm(20,mean = mean(logReturn),sd = sd(logReturn))
+ prices = 93.07 * exp(cumsum(logR))
+ ind = (min(prices) < 85)
+ value[i] = 100*ind - (1 - ind)
+ }
> mu = mean(value)
> mu
[1] 0.0605
> mu + c(-1,1)* sqrt(mu*(1-mu)/niter)*qnorm(0.975)
[1] 0.05583 0.06517

Exercise 2. (a) R2 = (P2 + D2 )/P1 − 1 = 54.2/52 − 1


P4 +D4 P3 +D3 P2 +D2 59.25 53.2 54.2
(b) P3 P2 P1
−1= 53 54 52
−1

(c) log{(P3 + D3 )/P2 } = log(53.2/54)


 
Exercise 7. a) rt (4) is N (4)(0.06), (4)(0.47) .

(b) Using R, P (r1 (4) < 2) = pnorm(2,4*0.06,sd = sqrt(4*0.47)) = 0.9004.

> pnorm(2,4*0.06,sd = sqrt(4*0.47))


[1] 0.9004

3
(c) r2 (1) = r2 and r2 (2) = r2 + r1 . Therefore, cov(r2 (1), r2 (2)) = var(r2 ) = 0.47.

(d) rt (3) = rt + rt−1 + rt−2 . Therefore, given rt−2 = 0.6, rt (3) is N 0.6 +

(2)(0.06), (2)(0.47) .

Exercise 8. (a) P (X2 > 1.3X0 ) = P (r1 + r2 > log(1.3)) and r1 + r2 is N (2µ, 2σ 2 ). This
probability can be found using R:
pnorm(log(1.3),mean = 2*mu,sd = sqrt(2)*sigma,lower.tail = FALSE)

Of course, numerical values of mu and sigma must be supplied to use R.


(b) In (A.4), use g(x) = exp(x) and h(y) = log(y). The density is at x
 
1 1 2
√ exp − 2 {log(x) − (log(X0 ) + µ)} .
2πσx 2σ
h √ i
(c) exp {log(X0 ) + kµ} + σ kΦ−1 (0.9) where Φ is the standard normal cumu-
lative distribution function. See page 676 for a discussion of normal quantiles.
(d) Use the fact that Xk2 is lognormal(2kµ, 4kσ 2 ). Then

E(Xk2 ) = X02 exp(2kµ + 2kσ 2 ).

(e) Using Var(Xk ) = E(Xk2 ) − (E(Xk ))2 we have

X02 exp(2kµ + kσ 2 ){exp(kσ 2 ) − 1}.

Exercise 9. (a) P (X3 > 1.2X0 ) = P (log(X3 /X0 ) > log(1.2)) = pnorm(log(1.2),mean =
0.1 * 3,sd = sqrt(3) * 0.2,lower.tail = FALSE) = 0.633.

> pnorm(log(1.2),mean = 0.1 * 3,sd = sqrt(3) * 0.2,lower.tail = FALSE)


[1] 0.633

(c) P (Xt /X0 ≥ 2) = P (log(Xt /X0 ) ≥ log(2)) = pnorm(log(2),mean = t *


0.1, sd = sqrt(t) * 0.2, lower.tail = FALSE)
From the output below, we see that this probability exceeds 0.9 if t is 18 or
more. I found that the probability exceeds 0.9 if t = 100 so I tried all t between
1 and 1000.

> t = 1:100
> prob = pnorm(log(2),mean = t * 0.1, sd = sqrt(t) * 0.2,
lower.tail = FALSE)
> min(which(prob > 0.9))
[1] 18

You might also like