{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

097 0047 0050 0075 0231 0376 0316 now we want to get

Info iconThis preview shows pages 5–8. Sign up to view the full content.

View Full Document Right Arrow Icon
0.097 -0.047 -0.050 -0.075 -0.231 -0.376 -0.316 #Now we want to get the same results by ourselves #we know from example 4.3 #lag=0 correl_lag0= covar_lag0/covar_lag0 print(correl_lag0) #lag=1 correl_lag1= covar_lag1/covar_lag0 print(correl_lag1) #lag=2 correl_lag2= covar_lag2/covar_lag0 print(correl_lag2) #Model identification (i.e. find p, q) #Example 4.5 data=c(60,43,67,50,56,42,50,65,68,43,65,34,47,34,49,41, 13,35,53,56,16,43,69,59,48,59,86,55,68,51,33,49, 67,77,81,67,71,81,68,70,77,56) datats = ts(data) plot(datats ) datatsdiff1 <- diff(datats, differences=1) acf(datatsdiff1, lag.max=20) #find p by the plot pacf(datatsdiff1, lag.max=20) #find q by the plot install.packages("forecast")
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
library("forecast") auto.arima(data) #get p and q by auto.ariam() datatsarima <- arima(datats, order=c(0,1,1)) plot( datatsforecasts <- forecast.Arima( datatsarima, h=5) ) #Predicting values using arima #Example 4.6 data<-c(100.8, 81.6, 66.5, 34.8, 30.6, 7, 19.8 , 92.5 , 154.4, 125.9, 84.8, 68.1, 38.5, 22.8, 10.2, 24.1, 82.9 , 132 , 130.9, 118.1, 89.9, 66.6, 60 , 46.9, 41 , 21.3, 16 , 6.4 , 4.1 , 6.8 , 14.5, 34 , 45 , 43.1, 47.5, 42.2, 28.1 , 10.1 , 8.1 , 2.5 , 0, 1.4 , 5 , 12.2, 13.9, 35.4, 45.8 , 41.1 , 30.4 , 23.9 , 15.7, 6.6 , 4 , 1.8 , 8.5 , 16.6, 36.3 , 49.7 , 62.5 , 67 , 71, 47.8, 27.5, 8.5 , 13.2, 56.9, 121.5, 138.3, 103.2, 85.8 , 63.2, 36.8, 24.2, 10.7, 15 , 40.1, 61.5 , 98.5 , 124.3, 95.9 , 66.5, 64.5, 54.2, 39 , 20.6, 6.7 , 4.3 ,? 22.8, 54.8 , 93.8 , 95.7, 77.2, 59.1, 44 , 47 ,?30.5, 16.3 , 7.3 , 37.3 , 73.9 ) data.ts=ts(data) aa <- arima(data.ts, order=c(2,1,1)) aaa <- forecast.Arima(aa, h=5) data.arma <- arima(data.ts, order=c(2,1,1)) predict <- forecast.Arima(data.arma, h=5) #Is it real stock price time series? #Example 4.7 x = arima.sim(list(order=c(0,1,0)), n=500) plot(x) #Which is AR and which is MA #Example 4.8 ar1 = arima.sim(list(order=c(0,0,1), ma=.9), n=500) ma1 = arima.sim(list(order=c(1,0,0), ar=.9), n=500) plot(ar1, col='red/green') lines(ma1, col='red/green') #Which is which #Example 4.9 arima1.1.0 = arima.sim(list(order=c(1,1,0), ar=.9), n=500) arima0.0.1 = arima.sim(list(order=c(0,0,1), ma=.9), n=500) plot(arima1.1.0 , col='red/green') lines(arima0.0.1 , col='red/green') #Spot the difference #Example 4.10 madiff=diff(ma0.1.1) ardiff=diff(ar1.1.0) HK0001=getSymbols("0001.HK", auto.assign=FALSE) l=length(HK0001[,4]) hk=HK0001[,4][c(1096:1596)] plot(diff(hk))
Background image of page 6
#Garch(1,1) Price Simulation #Example 4.11 T=500 #process parameters eta = 0.2 #eta = 0 is equivalent to Geometric Brownian Motion mu = 100 #the mean of the process #GARCH volatility model specs = garchSpec(model = list(omega = 0.000001, alpha = 0.5, beta = 0.4)) sigma = garchSim(spec = specs, n = T) P_0 = mu #starting price, known P = rep(P_0,T) for(i in 2:T) { P[i] = P[i-1] + eta * (mu - P[i-1]) + sigma[i] * P[i-1] } plot(P, type="l",xlab="Time", main="", ylab = "Price") #Forecast Volatilty #Example 4.12 predictVolatility =function(yahooStockCode) { stock=getSymbols(yahooStockCode, auto.assign=FALSE) lgstk <- diff(log(stock[,4]))
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page5 / 15

097 0047 0050 0075 0231 0376 0316 Now we want to get the...

This preview shows document pages 5 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon bookmark
Ask a homework question - tutors are online