Linear Time Series in Finance - L. Ferrara

Stationarity, co-movement, cluster of volatility ... ▻ How to make ... Box.test(rcac40,lag=1,type="'Ljung"') ... (i) parameter significance (Student test or Fischer test).
474KB taille 19 téléchargements 329 vues
Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

TD4: ARMA modelling

Linear Time Series in Finance Laurent Ferrara Summer School in Quantitative Finance - July 2008

Objective

TD1: First analysis

TD2: Simulation

Plan

Objective TD1: First analysis TD2: Simulation TD3: AR modelling TD4: ARMA modelling

TD3: AR modelling

TD4: ARMA modelling

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

Objective

How to deal with financial and economic ts ? I

Monte-Carlo simulations

I

Analyze

I

Modelling

I

Forecasting

How to do this with R ? I

basic functions in R

I

Package tseries

I

Package Rmetrics

TD4: ARMA modelling

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

TD4: ARMA modelling

Package tseries Procedure I

Go to the nearest mirror site (France: Toulouse, URL: cran.cict.fr)

I

Go to Software/Packages (left column)

I

Click on tseries in the list of contributed packages

I

Download the .zip file (exe) and the .pdf file (manual)

I

Repeat the previous steps for the packages zoo and quadprog (needeed to run tseries)

I

Go back to R, from the toolbar go to Packages/Install packages from the zip files and select the right package

I

From the toolbar, go to Packages/Charge the package and select tseries

I

To verify that it is correctly installed type: > help(arma)

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

TD4: ARMA modelling

Example of four European Stock Markets

I

Getting the data: > data() > EuStockMarkets > data.class(EuStockMarkets) > EuStockMarkets > plot(EuStockMarkets) > plot(EuStockMarkets[,"’CAC"’])

I

Comments ?

I

Stationarity, co-movement, volatility ...

I

How to make a prediction ? What are the difficulties ? Propositions ...

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

TD4: ARMA modelling

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

TD4: ARMA modelling

A solution: Stationarization

I

First order differencing > dcac40=diff(EuStockMarkets[,"’CAC"’])

I

Log returns > rcac40=diff(log(EuStockMarkets[,3]))*100 > plot(rcac40) > plot(dcac40) > summary(dcac40) > plot(diff(log(EuStockMarkets)))

I

Comments ?

I

Stationarity, co-movement, cluster of volatility ...

I

How to make a prediction ? What are the difficulties ? Propositions ...

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

TD4: ARMA modelling

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

Data Analysis

I

Underlying distribution function > hist(rcac40) > density(rcac40) > plot(density(rcac40)) > qqnorm(rcac40) > jarque.bera.test(rcac40)

I

Serial dependence > acf(rcac40) > pacf(rcac40) > Box.test(rcac40,lag=1,type="’Box"’) > Box.test(rcac40,lag=10,type="’Box"’) > Box.test(rcac40,lag=1,type="’Ljung"’)

TD4: ARMA modelling

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

TD4: ARMA modelling

I

Dependence on higher moments ? > rcac40.2=rcac40*rcac40 > acf(rcac40.2) > pacf(rcac40.2) > Box.test(rcac40.2,lag=1,type="’Box"’)

I

Conclusions? Normality ? Auro-Correlation ? Independence ?

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

TD4: ARMA modelling

Ex1: Gaussian White Noise

I

Simulation of 1000 observations from a standard GWN > eps=rnorm(1000,mean=0,sd=1) > ts.plot(eps) > plot(density(eps)) > qqnorm(eps) > acf(eps) > pacf(eps) > Box.test(eps,lag=1,type="’Ljung"’) > eps2=eps*eps > acf(eps2) > pacf(eps2) > Box.test(eps2,lag=1,type="’Ljung"’)

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

TD4: ARMA modelling

Ex2: Student White Noise

I

Simulation of 1000 observations from a 3 df Student WN > epst=tnorm(1000,df=3) > ts.plot(epst) > plot(density(epst)) > qqnorm(epst) > acf(epst) > pacf(epst) > Box.test(epst,lag=1,type="’Ljung"’)

I

Comments ?

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

Ex3: AR(1) process I

1000 observations of a zero-mean Gaussian AR(1) > nobs=1000 > phi1=0.2 > eps=rnorm(nobs) > y=rep(0,nobs) > for(i in 2:nobs) y[i]=phi1*y[i-1]+eps[i] > ts.plot(y) > plot(density(y)) > qqnorm(y) > acf(y) > pacf(y) > Box.test(y,lag=10,type="’Ljung"’)

I

repeat same commands with phi1=0.8

I

repeat same commands with phi1=0.99

I

Comments ?

TD4: ARMA modelling

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

Ex4: MA(1) process I

1000 observations of a zero-mean Gaussian MA(1) > nobs=1000 > theta1=0.2 > eps=rnorm(nobs) > z=eps[2:1000]+theta1*eps[1:999] > length(z) > ts.plot(z) > plot(density(z)) > qqnorm(z) > acf(z) > pacf(z) > Box.test(z,lag=10,type="’Ljung"’)

I

repeat same commands with theta1=0.8

I

repeat same commands with theta1=0.99

I

Comments ? How to include a mean ?

TD4: ARMA modelling

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

TD4: ARMA modelling

Modelling steps 1. Model specification Choice of p, q and d R functions: acf(), pacf(), Box.test() 2. Parameter estimation ˆ θˆ and σ Computation of φ, ˆε R functions: ar() or arima() (stats) and arma() (tseries) 3. Model validation (i) parameter significance (Student test or Fischer test) P-values provided by R estimation functions (ii) residuals (Gaussian WN) R functions: tsdiag(), acf(), pacf(), Box.test(),jarque.bera.test() ... 4. Forecasting Prediction over h steps R functions: predict()

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

Ex1: Sunspots time series I

Data analysis: Monthly Jan. 1749 - Dec. 1983 > sunspots > summary(sunspots) > frequency(sunspots) > start(sunspots) > end(sunspots)

I

Specification > acf(sunspots,lag.max=240) > pacf(sunspots,lag.max=240)

I

Automatic specification by AIC > sunc = sunspots-mean(sunspots) > sunc.ar=ar(sunc,order.max=100,aic=T) > sunc.ar$aic > plot(sunc.ar$aic[2:100]) Where is the min ? p = 28

TD4: ARMA modelling

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

TD4: ARMA modelling

Ex1: Sunspots time series

I

Estimation methods > ar(sunc,order.max=100,aic=T,method=yw)$order > ar(sunc,order.max=100,aic=T,method=burg)$order > ar(sunc,order.max=100,aic=T,method=mle)$order > ar(sunc,order.max=100,aic=T,method=ols)$order Yule-Walker is OK

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

Ex1: Sunspots time series

I

Validation > res=sunc.ar$resid > res.std=res/sqrt(var(res)) > summary(res.std) > plot(res.std) > acf(res.std) > pacf(res.std) > Box.test(res.std) > plot(density(res.std))) > jarque.bera.test(res.std)

I

Conclusion ? GWN ? Why ?

TD4: ARMA modelling

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

Ex1: Sunspots time series

I

Validation > res=sunc.ar$resid > res.std=res/sqrt(var(res)) > summary(res.std) > plot(res.std) > acf(res.std) > pacf(res.std) > Box.test(res.std) > plot(density(res.std))) > jarque.bera.test(res.std)

I

Conclusion ? GWN ? Why ?

TD4: ARMA modelling

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

Ex1: Sunspots time series

I

Forecasting > horiz=120 > prev=predict(sunc.ar,n.ahead=horiz) > prev > prev.mean=prev$pred+mean(sunspots) > ts.plot(prev.mean,sunspots)

I

Confidence bounds (1 − α = 0.95) > prev.se=prev$se > bornesup=prev.mean+1.96*prev.se > borneinf=prev.mean-1.96*prev.se > ts.plot(prev,bornesup,borneinf)

I

Remark : Normality assumption

TD4: ARMA modelling

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

Ex2: Nile river series

I

Data analysis: Annual 1871-1970 > Nile > plot(Nile) > acf(Nile,lag.max=50) > pacf(Nile,lag.max=50) > Box.test(Nile)

I

In favour of a AR(1) model

I

Automatic AR Specification > Nilec=Nile-mean(Nile) > Nilec.ar=ar(Nilec,lag.max=10) > Nilec.ar

I

Conclusion: p? q?

TD4: ARMA modelling

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

TD4: ARMA modelling

Ex2: Nile river series

I

Automatic ARMA specification > arima(Nilec,order=c(1,0,0),include.mean=F)$aic > arima(Nilec,order=c(2,0,0),include.mean=F)$aic > arima(Nilec,order=c(1,0,1),include.mean=F)$aic > arima(Nilec,order=c(1,0,2),include.mean=F)$aic > arima(Nilec,order=c(2,0,1),include.mean=F)$aic > arima(Nilec,order=c(2,0,2),include.mean=F)$aic > arima(Nilec,order=c(2,0,3),include.mean=F)$aic > arima(Nilec,order=c(2,0,4),include.mean=F)$aic > Nc.arma=arima(Nilec,order=c(1,0,1),include.mean=F) > Nc.arma > coef(Nilec.arma) > residuals(Nilec.arma)

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

TD4: ARMA modelling

Ex2: Nile river series

I

Validation White Noise ? > summary(Nilec.arma) > tsdiag(Nilec.arma) > Box.test(resid(Nilec.arma)) Gaussian ? > qqnorm(resid(Nilec.arma)) > plot(density(resid(Nilec.arma))) > ynorm=dnorm(density(resid(Nilec.arma))$x, mean=mean(resid(Nilec.arma)), sd=sqrt(var(resid(Nilec.arma)))) > matplot(density(resid(Nilec.arma))$x, cbind(density(resid(Nilec.arma))$y,ynorm), type="l") > jarque.bera.test(resid(Nilec.arma))

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

TD4: ARMA modelling

Ex2: Nile river series

I

Forecasting > horiz=50 > predict(Nilec.arma,n.ahead=horiz) > Nile.prev=predict(Nilec.arma,n.ahead=horiz) $pred+mean(Nile) > ts.plot(Nile,Nile.prev) > bsup=Nile.prev+1.96*predict(Nilec.arma, n.ahead=horiz)$se > binf=Nile.prev-1.96*predict(Nilec.arma, n.ahead=horiz)$se > lines(bsup,col=3) > lines(binf,col=2)

Objective

TD1: First analysis

TD2: Simulation

TD3: AR modelling

TD4: ARMA modelling