### Econ 7933: Financial Time Series: Introduction

Sheng-Kai Chang (NTU)

Fall, 2015

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 1 / 39

Examples of Fnancial time series

Daily log returns of Apple stock: 2005 to 2014.

U.S. monthly unemployment rates

U.S. daily interesrate rate of 10-year Treasury Notes The VIX index

Exchange rate between US Dollar vs Euro

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 2 / 39

setwd("D:/R/FTS/Data") library(quantmod) library(downloader)

getSymbols("AAPL",from="2005-01-01",to="2014-12-31")

## [1] "AAPL"

chartSeries(AAPL,theme="white")

100 200 300 400 500 600 700

**AAPL** **[2005−01−03/2014−12−31]**

Last 110.379997

Volume (millions):

41,403,400

0 200 400 600 800

... 03 2005 ... 02 2007 ... 04 2010 ... 02 2012 ... 31 2014

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 3 / 39

chartSeries(AAPL$AAPL.Adjusted,theme="white")

0 20 40 60 80 100 120

**$**
**AAPL**
**AAPL.Adjusted**

**[2005−01−03/2014−12−31]**

Last 108.99538

... 03 2005 ... 02 2007 ... 04 2010 ... 02 2012 ... 31 2014

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 4 / 39

AAPL.rtn=diff(log(AAPL$AAPL.Adjusted)) hist(AAPL.rtn)

**Histogram of AAPL.rtn**

AAPL.rtn

Frequency

−0.20 −0.15 −0.10 −0.05 0.00 0.05 0.10 0.15

02004006008001000

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 5 / 39

chartSeries(AAPL.rtn, theme="white")

−0.20

−0.15

−0.10

−0.05 0.00 0.05 0.10

**AAPL.rtn** **[2005−01−04/2014−12−31]**

Last −0.0192020203673824

... 04 2005 ... 02 2007 ... 04 2010 ... 02 2012 ... 31 2014

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 6 / 39

getSymbols("UNRATE",src="FRED")

## [1] "UNRATE"

chartSeries(UNRATE,theme="white")

4
6
8
10
**UNRATE** **[1948−01−01/2015−08−01]**

Last 5.1

... 1948 ... 1960 ... 1975 ... 1990 ... 2005

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 7 / 39

U.S. Government Bonds: Treasury Bills, Treasury Notes, Treasury Bonds Treasury bills (T-Bills) mature in one year or less. They do not pay interest prior to maturity and are sold at a discount of the face value (par value).

The commonly used maturities are 28 days (1 months), 91 days (3 months), 182 days (6 months), and 364 days (1 year).

Treasury Notes (T-Notes) matures in 1-10 years. They have a coupon payment every 6 months and face value of $1, 000

The 10-year T-Notes has become the security most frequently quoted when discussing U.S. government bond market.

Treasury Bonds (T-Bonds) have longer maturities ranging from 20 to 30 years. Thay have coupon payment every 6 months.

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 8 / 39

Bond Yields and Prices

Current Yield= Annual interest paid in dollars

Market price of the bond × 100%

For zero-coupon bonds, Current Yield= (Purchase price^{Face value} )^{1/k}− 1, where
k is time to maturity in years.

EX: if an investor paid $90 for a bond with face value of $100 and the bond paid a coupon rate 5% per annum, then the current yield of the bond is (0.05 ∗ 100)/90 ∗ 100% = 5.56%.

The current yield does not consider the time value of money since it does not consider the present value of the coupon payments the investor will receive in the future.

A more commonly used measurement of bond investment is the Yield to Maturity (YTM).

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 9 / 39

Yield to Maturity (YTM)

YTM is the yield obtained by equating the bond price to the present value of all future payments.

Suppose that the bond holder will receive k payments between purchase and maturity. Let y and P be the YTM and price of the bond respectively. Then

P = C1

1 + y + C2

(1 + y )^{2} + ... + C_{k}+ F
(1 + y )^{k}

where F denotes the face value and Ci us the i th cash flow of coupon payment.

Suppose that the coupon rate is α per annum, the number of payments is m per year, and the time to maturity is n year. Then cash flow of coupon payment is F α/m and the number of payments is k = mn.

P = αF

m [ 1

1 + y + 1

(1 + y )^{2} + ... + 1

(1 + y )^{k}] + F
(1 + y )^{k}

= αF

my[1 − 1

(1 + y )^{k}] + F
(1 + y )^{k}

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 10 / 39

The table below shows some results between bond price and YTM assuming that F = $100 and coupon rate is 5% per annum payable semiannually, and time to maturity is 3 years.

Yield to Maturity (%) Semiannual Rat (% ) Bond price ($)

6 3.0 97.29

7 3.5 94.67

8 4.0 92.14

9 4.5 89.68

10 5.0 87.31

YTM is inversely proportional to the bond price.

In practice, we observe bond price, so that YTM can be calculated.

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 11 / 39

getSymbols("^TNX",from="2007-01-01",to="2015-6-30")

## [1] "TNX"

chartSeries(TNX,theme="white")

2 3 4 5

**TNX** **[2007−01−03/2015−06−30]**

Last 2.335

Volume (100s):

0

−1.0

−0.5 0.0 0.5 1.0

... 03 2007 ... 02 2009 ... 03 2011 ... 02 2013 ... 02 2015

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 12 / 39

TNX.rtn=diff(log(TNX$TNX.Adjusted)) chartSeries(TNX.rtn,theme="white")

−0.15

−0.10

−0.05 0.00 0.05 0.10

**TNX.rtn** **[2007−01−04/2015−06−30]**

Last 0.00171453106724051

... 04 2007 ... 02 2009 ... 03 2011 ... 02 2013 ... 02 2015

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 13 / 39

getSymbols("^VIX",from="2007-01-01",to="2015-6-30")

## [1] "VIX"

chartSeries(VIX,theme="white")

20 40 60 80

**VIX** **[2007−01−03/2015−06−30]**

Last 18.23

Volume (100,000s):

0

0 5 10 15 20

... 03 2007 ... 02 2009 ... 03 2011 ... 02 2013 ... 02 2015

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 14 / 39

getSymbols("DEXUSEU",src="FRED")

## [1] "DEXUSEU"

chartSeries(DEXUSEU,theme="white")

0.8
1.0
1.2
1.4
1.6
**DEXUSEU** **[1999−01−04/2015−09−11]**

Last 1.1338

... 04 1999 ... 02 2003 ... 02 2007 ... 03 2011 ... 02 2015

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 15 / 39

Asset Returns:Let P_{t} be the price of an asset at time t, and assume no
dividend.

One-period simple return
Gross return: 1 + Rt= _{P}^{P}^{t}

t−1

Simple return: Rt = _{P}^{P}^{t}

t−1 − 1.

Multiperiod simple return
Gross return: 1 + Rt(k) = _{P}^{P}^{t}

t−k = _{P}^{P}^{t}

t−1 ×^{P}_{P}^{t−1}

t−2 × ... ×^{P}_{P}^{t−k+1}

t−k

The k-period Simple net return: R_{t}(k) = _{P}^{P}^{t}

t−k − 1.

Time interval is important, default is one year.

Annualized (average) return:

Annualized [Rt(k)] = [Qk−1

j =0(1 + Rt−j)]^{1/k}− 1
Annualized [R_{t}(k)] ≈ _{k}^{1}P_{k−1}

j =0 R_{t−j}

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 16 / 39

Continuously compounding: Let C be the initial capital, r be the interest annum, and n be the number of years.

A = C × exp[r × n]

Present value: C = A × exp[−r × n]

Continuously compounding (log) return:

rt= ln(1 + Rt) = ln(_{P}^{P}^{t}

t−1) = pt− p_{t−1}
Multiperiod log return

rt(k) = ln(1 + Rt(k)) = ln[_{P}^{P}^{t}

t−1 ×^{P}_{P}^{t−1}

t−2 × · · · ×^{P}_{P}^{t−k+1}

t−k ]

= r_{t}+ r_{t−1}+ · · · + r_{t−k+1}

Portfolio return with N assets and weights w :
R_{p,t} =PN

i =1w_{i}R_{it}

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 17 / 39

Dividend (Dt): Rt = ^{P}_{P}^{t}^{+D}^{t}

t−1 − 1,r_{t} = ln(Pt+ Dt) − ln(Pt−1)

Excess return: Zt = Rt− R_{0t}, zt = rt− r_{0t}, where r0t denoted the log
return of a risk-free interest rate.

rt= ln(1 + Rt), Rt= e^{r}^{t} − 1.

If the returns are in percentage, then rt = 100 × ln(1 +_{100}^{R}^{t} ),
Rt= [exp(_{100}^{r}^{t} ) − 1] × 100.

Aggregation of the returns

1 + R_{t}(k) = (1 + R_{t})(1 + R_{t−1}) · · · (1 + R_{t−k+1})
r_{t}(k) = r_{t}+ r_{t−1}+ · · · + r_{t−k+1}

These two relations are important in practice, for example, obtain annual returns from monthly returns.

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 18 / 39

Distributional properties of returns: What is the distribution of r_{it}?
Moment of a random variable X with density f (x ): r -th moment
E (X^{r}) =R∞

−∞x^{r}f (x )dx .
First moment: mean of X .

r -th central moment: E ((X − µ_{X})^{r}) =R∞

−∞(x − µ_{X})^{r}f (x )dx
Second central moment: variance of X .

Skewness (symmetry): S (x ) = E [^{(X −µ}_{σ}3^{x}^{)}^{3}

x ].

Kurtosis (fat-tails) K (x ) = E [^{(X −µ}_{σ}4^{x}^{)}^{4}

x ], K (x ) − 3 is excess kurtosis.

The mean and variance are related to long-term retrun and risk, respectively. Symmetry has important implications in holding short or long financial positions and in risk management. Moreover, high kurtosis implies heavy (or long) tails in distribution.

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 19 / 39

Estimation: Data {x1, ..., xT}.

Sample mean: ˆµx = _{T}^{1} PT
t=1xt.
Sample variance: ˆσ^{2}_{x} = _{T −1}^{1} PT

t=1(xt− ˆµx)^{2}.
Sample skewness: ˆS (x ) =_{(T −1)ˆ}^{1} _{σ}3

x

PT

t=1(xt− ˆµx)^{3}.
Sample kurtosis: ˆK (x ) = _{(T −1)ˆ}^{1} _{σ}4

x

PT

t=1(xt− ˆµx)^{4}.

Assume that x_{t} is normally distributed, ˆS (x ) ∼ N(0,_{T}^{6}) and
K (x ) − 3 ∼ N(0,ˆ ^{24}_{T}).

Test for symmetry: S^{∗} = √^{S(x )}^{ˆ}

6/T ∼ N(0, 1) under normality. Decision
rule: Reject H0 of a symmetric distribution if |S^{∗}| > Z_{α/2} or p-value
is less than α.

Test for tail thickness: K^{∗}= ^{K (x )−3}√^{ˆ}

24/T ∼ N(0, 1) under normality.

Decision rule: Reject H_{0} of a symmetric distribution if |K^{∗}| > Z_{α/2} or
p-value is less than α.

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 20 / 39

A joint test (Jarque-Bera test): JB = (S^{∗})^{2}+ (K^{∗})^{2} ∼ χ^{2}_{2} under
normality. Decision rule: Reject H_{0} of normality if JB > χ^{2}_{2}(α) or
p-value is less than α.

Empirical distribution of asset returns tend to be skewed to the left with heavy tails and has a higher peak than normal distribution.

Normal and lognormal: Y is lognormal if X = ln(Y ) is normal.

If X ∼ N(µ, σ^{2}), then Y = exp(X ) is lognormal with
E (Y ) = exp(µ +^{σ}_{2}^{2}), V (Y ) = exp(2µ + σ^{2})[exp(σ^{2}) − 1].

If Y is lognormal with mean µ_{y} and variance σ^{2}_{y}, then X = ln(Y ) is
normal with E (X ) = ln[s^{µ}^{y}

1+^{σ2}^{y}

µ2y

], V (Y ) = ln[1 + ^{σ}

2y

µ^{2}_{y}].

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 21 / 39

library(fBasics)

#da=read.table("d-ibm3dx7008.txt",header=T) # Load data with header into R da=read.table("m-ibm6708.txt",header=T) # Load data with header into R da[1,]

## date ibm sprtn

## 1 19670331 0.048837 0.03941

dim(da) # Check dimension of the data (row = sample size, col = variables)

## [1] 502 3

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 22 / 39

ibm=da[,2] # Select the simple returns of IBM stock stored in Column 2.

plot(ibm,type='l')# Plot the simple returns.

0 100 200 300 400 500

−0.2−0.10.00.10.20.3

Index

ibm

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 23 / 39

basicStats(ibm) # Compute the descriptive statistics of simple returns.

## ibm

## nobs 502.000000

## NAs 0.000000

## Minimum -0.261905

## Maximum 0.353799

## 1. Quartile -0.036942

## 3. Quartile 0.049636

## Mean 0.008865

## Median 0.005274

## Sum 4.450050

## SE Mean 0.003262

## LCL Mean 0.002456

## UCL Mean 0.015273

## Variance 0.005341

## Stdev 0.073085

## Skewness 0.263914

## Kurtosis 1.822178

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 24 / 39

libm=log(ibm+1) # Compute the IBM log returns

basicStats(libm) # Compute descriptive statistics of log returns.

## libm

## nobs 502.000000

## NAs 0.000000

## Minimum -0.303683

## Maximum 0.302915

## 1. Quartile -0.037641

## 3. Quartile 0.048443

## Mean 0.006208

## Median 0.005260

## Sum 3.116457

## SE Mean 0.003237

## LCL Mean -0.000151

## UCL Mean 0.012567

## Variance 0.005259

## Stdev 0.072517

## Skewness -0.135343

## Kurtosis 1.693092

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 25 / 39

t.test(ibm) # Perform t-test for mean being zero.

##

## One Sample t-test

##

## data: ibm

## t = 2.7176, df = 501, p-value = 0.006804

## alternative hypothesis: true mean is not equal to 0

## 95 percent confidence interval:

## 0.002455871 0.015273412

## sample estimates:

## mean of x

## 0.008864641

t.test(ibm,alternative=c("greater"))# Perform one-sided test.

##

## One Sample t-test

##

## data: ibm

## t = 2.7176, df = 501, p-value = 0.003402

## alternative hypothesis: true mean is greater than 0

## 95 percent confidence interval:

## 0.003489285 Inf

## sample estimates:

## mean of x

## 0.008864641

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 26 / 39

hist(ibm,nclass=40) # Obtain histogram of IBM simple returns.

**Histogram of ibm**

ibm

Frequency

−0.3 −0.2 −0.1 0.0 0.1 0.2 0.3

010203040506070

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 27 / 39

d1=density(libm) # Compute density function of ibm log returns plot(d1$x,d1$y,type='l') # Plot the sample density of log returns

mu=mean(libm); s1=sd(libm)# compute the sample mean and standard deviation of IBM log returns.

x=seq(-0.4,0.4,0.01)# create a sequence of real numbers from -0.4 to 0.4 with increment 0.01.

y=dnorm(x,mean=mu,sd=s1)# obtain normal density with mean mu and standard deviation s1.

lines(x,y,lty=2)# impose a dashed line on the density plot for comparison with normal density.

lines(x,y,col="red")#will plot a red curve.

−0.3 −0.2 −0.1 0.0 0.1 0.2 0.3

0123456

d1$x

d1$y

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 28 / 39

normalTest(libm,method='jb') # Perform normality test.

##

## Title:

## Jarque - Bera Normalality Test

##

## Test Results:

## STATISTIC:

## X-squared: 62.8363

## P VALUE:

## Asymptotic p Value: 2.265e-14

##

## Description:

## Thu Sep 17 21:08:52 2015 by user: Sheng-Kai

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 29 / 39

Dependence: Consider two random variables X and Y , correlation coefficient: ρ = Cov (X ,Y )

std (X )std (Y ).

Kendall’s tau: Let ( ˜X , ˜Y ) be an random copy of (X , Y ).

ρ_{τ} = P[(X − ˜X )(Y − ˜Y ) > 0] − P[(X − ˜X )(Y − ˜Y ) < 0] =
E [sign[(X − ˜X )(Y − ˜Y )]].

Kendall’s tau quantifies the probability of concordant over discordant.

Here concordant means (X − ˜X )(Y − ˜Y ) > 0.

Spearman’s rho: rank correlation. Let Fx(x ) and Fy(y ) be the
cumulative distribution of X and Y . ρ_{S} = ρ(F_{x}(X ), F_{y}(Y )).

Spearman’s rho is the correlation of probability-transformed variables.

It is the correlation coefficient of the ranks of the data.

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 30 / 39

x= rnorm(1000) # Generate 1000 N(0,1) random numbers cor(x,x)

## [1] 1 cor(x,exp(x))

## [1] 0.7510654

cor(x,exp(x),method="kendall")

## [1] 1

cor(x,exp(x),method="spearman")

## [1] 1

ibm=da[,2]

sp=da[,3]

cor(ibm,sp)

## [1] 0.5949041

cor(ibm,sp,method="kendall")

## [1] 0.4223351

cor(ibm,sp,method="spearman")

## [1] 0.5897587

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 31 / 39

Basic concepts of Time Series Models Stationarity:

- Strict: distributions are time-invariant.

- Weak: first 2 moments (mean, variance and covariance) are time-invariant.

Sample mean and sample variance are used to estimate the mean and variance.

Lag-k autocovariance: let rt be log return,
γ_{k} = Cov (rt, t_{t−k}) = E [(rt− µ)(r_{t−k}− µ)].

Autocorrelations: ρ_{l} = ^{cov (r}_{var (r}^{t}^{,r}^{t−l}^{)}

t) . Note that ρ_{0} = 1 and ρ_{k} = ρ−k for
k 6= 0.

Existence of serial correlations implies that the return is predictable and indicating market inefficiency.

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 32 / 39

Basic concepts of Time Series Models

Sample autocorrelation function (ACF): ˆρ_{l} =

PT −l

t=1(rt−¯r )(r_{t+l}−¯r )
PT −l

t=1(rt−¯r )^{2} , where

¯

r is the sample mean and T is the sample size.

Test zero serial corellation (market efficiency)
- Individual test: H0: ρ1 = 0 v.s. H1 : ρ1 6= 0
t = √^{ρ}^{ˆ}^{1}

1/T =√

T ˆρ_{1}, which is asymptotically N(0, 1).

Decision rule: Reject H0 if |t| > Z_{α/2} or p-value is less than α.

- Joint test (Ljung-Box statistics) :H_{0}: ρ_{1} = · · · = ρ_{m} = 0 v.s.

H_{1}: ρ_{i} 6= 0

Q(m) = T (T + 2)Pm l =1

ˆ
ρ^{2}_{l}

T −l, which is asymptotically χ^{2}_{m}.

Decision rule: Reject H0 if Q(m) > χ^{2}_{m}(α) or p-value is less than α.

Significant sample ACF does not necessarily imply market inefficiency.

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 33 / 39

library(timeSeries)

par(mfcol=c(2,1)) # Put two plots on a sinlge page. c(2,1) means two rows and one column.

ts.plot(ibm) ts.plot(sp)

Time

ibm

0 100 200 300 400 500

−0.20.00.2

Time

sp

0 100 200 300 400 500

−0.20.00.1

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 34 / 39

tdx=(2+c(1:502))/12+1967# create a calendar time index. The data start at March 1967 so that the index is from 3:505 par(mfcol=c(1,1))# return to one plot per page

plot(tdx,ibm,type='l',xlab='year',ylab='ibm',main="Monthly IBM returns")

1970 1980 1990 2000 2010

−0.2−0.10.00.10.20.3

**Monthly IBM returns**

year

ibm

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 35 / 39

acf(ibm,lag=20) # specify the number of ACF to compute

0 5 10 15 20

0.00.20.40.60.81.0

Lag

ACF

**Series ibm**

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 36 / 39

pacf(ibm,lag=20)

5 10 15 20

−0.050.000.050.10

Lag

Partial ACF

**Series ibm**

Box.test(ibm,lag=10,type="Ljung")# Compute Ljung-Box Q(m) statistics

##

## Box-Ljung test

##

## data: ibm

## X-squared = 6.9444, df = 10, p-value = 0.7307

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 37 / 39

Lag operator: Lrt= rt−1, L^{2}rt = rt−2.

Available data at time t, Ft−1≡ {r_{1}, r2, · · · , rt−1}.

The return r_{t} is decomposed into two parts given information F_{t−1}:
rt= µt+ at= E (rt|F_{t−1}) + σtt.

µt is conditional mean of rt. It is the function of elements of Ft−1, and it is predictable part of rt.

at is shock or innovation at time t, it is unpredictable part of rt.

_{t} is an i .i .d . sequence with mean zero and variance 1.

σ_{t} is conditional standard deviation. (volatility)

Model for µ_{t}: mean equation; Model for σ_{t}^{2}: volatility equation.

Two purposes for time series models:

- A model for µ_{t}.

- Understanding models for σ_{t}^{2}. (properties, forcasting, etc.)

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 38 / 39

Linear time series

r_{t} is linear if the predictable part is a linear function of F_{t−1}and a_{t}s
are i .i .d . distributed.

That is, r_{t} can be written as r_{t} = µ +P∞

i =0ψ_{i}a_{t−i}, where µ is a
constant, ψ0 = 1 and at is an i .i .d . sequence with mean zero and
finite variance.

at is shock or innovation at time t and ψi are the impulse responses
of r_{t}.

Sheng-Kai Chang (NTU) Econ 7933: Financial Time Series Fall, 2015 39 / 39