Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
152 views

AR Model Session2 Output: Install - Packages ("Forecast")

This document contains output from running various time series analysis functions and models in R. It starts with installing and loading packages, generates random data, runs unit root and stationarity tests, fits ARIMA models and examines residuals. Both stationary and non-stationary processes are examined.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views

AR Model Session2 Output: Install - Packages ("Forecast")

This document contains output from running various time series analysis functions and models in R. It starts with installing and loading packages, generates random data, runs unit root and stationarity tests, fits ARIMA models and examines residuals. Both stationary and non-stationary processes are examined.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

AR model Session2 output

R version 4.0.0 (2020-04-24) -- "Arbor Day"


Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.


You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors.


Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or


'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> install.packages("forecast")
WARNING: Rtools is required to build R packages but is not currently
installed. Please download and install the appropriate version of Rtools
before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘C:/Users/maddu/OneDrive/Documents/R/win-
library/4.0’
(as ‘lib’ is unspecified)
trying URL
'https://cran.rstudio.com/bin/windows/contrib/4.0/forecast_8.13.zip'
Content type 'application/zip' length 2538207 bytes (2.4 MB)
downloaded 2.4 MB

package ‘forecast’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in


C:\Users\maddu\AppData\Local\Temp\RtmpczUDxb\downloaded_packages
> library("forecast")
Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
Warning message:
package ‘forecast’ was built under R version 4.0.3
> library("urca")
Warning message:
package ‘urca’ was built under R version 4.0.3
> z_t= c(rep(0,100))
> y_t = rnorm(100, 0,1)
> y_t
[1] 0.347165883 0.973628192 1.096358151 0.480331654 -2.147528564
-1.345122129 1.300911223 -0.050943554
[9] 1.273390195 0.826273528 -1.326245410 -0.101729956 0.689847166
-0.521013909 0.076932149 0.060523813
[17] 0.148496875 -0.230886600 -1.951325646 -1.491086023 0.991114174
0.654390037 0.142079617 0.097201038
[25] -0.520249641 0.154888468 -1.384329620 0.268353265 0.767992165
0.993109818 0.784061459 -0.425403183
[33] -0.622334548 -0.363573835 1.238439640 0.224704023 -0.858226883
1.765513261 0.452015039 1.732848901
[41] 0.198573250 -0.829108605 0.120229978 -0.276969826 0.326864753
0.004019083 0.727487091 -0.914168445
[49] 1.272966028 0.739677160 1.568955556 1.559548095 0.493859905
1.451697681 0.527572820 -0.484270259
[57] -0.914812125 0.942299305 0.900138587 -0.489171127 -0.683596124
-0.902489906 -0.304861479 -2.117893463
[65] -0.188579696 0.475643220 0.431569408 0.119073100 -0.430424446
0.430258831 -0.150466764 1.391320223
[73] -0.635981938 -0.354514491 -2.145500010 0.702412448 0.841722990
1.821355376 -0.924299937 1.797730952
[81] 1.640441445 -1.389695250 -0.601481732 -0.138424220 -0.405688294
-1.447990422 1.115816909 0.053900649
[89] -1.883055827 -0.262242229 -1.605690229 0.531830482 -0.825381102
0.319861231 0.326592110 0.170724097
[97] 0.387151487 -1.211615024 1.279526077 -0.215039897
> z_t[1] = 5+y_t[1]
>
> for(i in 2:100){
+ z_t[i]= 5+0.5*z_t[(i-1)]+ y_t[i]
+ }
> z_t
[1] 5.347166 8.647211 10.419964 10.690314 8.197628 7.753692
10.177757 10.037935 11.292358 11.472452 9.409981
[12] 9.603260 10.491477 9.724725 9.939295 10.030171 10.163582
9.850905 7.974127 7.495977 9.739103 10.523941
[23] 10.404050 10.299226 9.629363 9.969570 8.600455 9.568581
10.552283 11.269251 11.418687 10.283940 9.519636
[34] 9.396244 10.936562 10.692985 9.488266 11.509646 11.206838
12.336268 11.366707 9.854245 10.047352 9.746706
[45] 10.200218 10.104128 10.779551 9.475607 11.010770 11.245062
12.191487 12.655291 11.821506 12.362450 11.708798
[56] 10.370129 9.270252 10.577425 11.188851 10.105255 9.369031
8.782026 9.086151 7.425182 8.524011 9.737649
[67] 10.300394 10.269270 9.704211 10.282364 9.990715 11.386678
10.057357 9.674164 7.691582 9.548203 10.615825
[78] 12.129268 10.140334 11.867898 12.574390 9.897500 9.347268
9.535210 9.361917 8.232968 10.232301 10.170051
[89] 8.201970 8.838743 7.813681 9.438671 8.893954 9.766838
10.210011 10.275730 10.525016 9.050893 10.804973
[100] 10.187446
> ts.plot(z_t)
> df@teststat
Error: trying to get slot "teststat" from an object of a basic class
("function") with no slots
> df$teststat
Error in df$teststat : object of type 'closure' is not subsettable
> df@teststat
Error: trying to get slot "teststat" from an object of a basic class
("function") with no slots
> teststatdf
Error: object 'teststatdf' not found
> df@cvalue
Error: trying to get slot "cvalue" from an object of a basic class
("function") with no slots
> library("qrmdata")
Warning message:
package ‘qrmdata’ was built under R version 4.0.3
> library("moments")
Warning message:
package ‘moments’ was built under R version 4.0.3
> library("urca")
> df= ur.df(z_t,type = "drift")
> df@teststat
tau2 phi1
statistic -5.562717 15.49809
> df@cval
1pct 5pct 10pct
tau2 -3.51 -2.89 -2.58
phi1 6.70 4.71 3.86
> lju_box= Box.test(z_t,lag = 12,type = "Ljung-Box")
> lju_box

Box-Ljung test

data: z_t
X-squared = 32.311, df = 12, p-value = 0.001239

> acf(z_t,plot = TRUE)


> pacf(z_t)
> ord= ar(z_t,method = "mle")
> ord$aic
0 1 2 3 4 5 6
7 8 9 10 11
28.933046 0.000000 1.432803 3.414124 3.526406 5.450073 7.092618
8.019502 7.496604 9.115280 9.187229 11.174706
12
13.033117
> ord

Call:
ar(x = z_t, method = "mle")

Coefficients:
1
0.5548

Order selected 1 sigma^2 estimated as 1.09


> AutoArimaModel=auto.arima(z_t)
> AutoArimaModel
Series: z_t
ARIMA(1,0,0) with non-zero mean

Coefficients:
ar1 mean
0.5548 9.9661
s.e. 0.0915 0.2325

sigma^2 estimated as 1.113: log likelihood=-146.4


AIC=298.8 AICc=299.05 BIC=306.61
> fit_model= arima(z_t,order= c(1,0,0))
> res= fit_model$residuals
> res
Time Series:
Start = 1
End = 100
Frequency = 1
[1] -3.842900539 1.243651011 1.185574901 0.472421121 -2.170251282
-1.231273194 1.439082965 -0.045583842
[9] 1.286410619 0.770565429 -1.391820710 -0.054304567 0.726682962
-0.532842602 0.107113039 0.078948648
[17] 0.161942678 -0.224750266 -1.928058018 -1.364991671 1.143405836
0.683783169 0.128472252 0.090162382
[25] -0.521545091 0.190294106 -1.367563557 0.360131709 0.806728011
0.977949667 0.729619345 -0.488032734
[33] -0.622792500 -0.322156322 1.286617654 0.188489625 -0.881095960
1.808649510 0.384401939 1.681826336
[41] 0.085670389 -0.888890236 0.143314590 -0.264465374 0.355841292
0.008148193 0.736880867 -0.941780400
[49] 1.316795818 0.699396984 1.515838744 1.454577658 0.363478080
1.366998118 0.413235445 -0.562794694
[57] -0.919992252 0.997380276 0.883600889 -0.539208216 -0.674264065
-0.852820928 -0.223031078 -2.052725794
[65] -0.032409244 0.571609956 0.461042197 0.117713676 -0.430078627
0.461563674 -0.150838357 1.406927768
[73] -0.696857741 -0.342558176 -2.112548947 0.843987131 0.881575302
1.802713822 -1.025861470 1.805141047
[81] 1.553200093 -1.515644595 -0.580767014 -0.087562876 -0.365124079
-1.397931649 1.227729617 0.056271970
[89] -1.877273904 -0.148631162 -1.526967292 0.666715482 -0.779527622
0.395559172 0.354465637 0.174316639
[97] 0.387143384 -1.225281283 1.346625506 -0.244044672
> Box.test(res,lag = 12,type = "Ljung-Box")

Box-Ljung test
data: res
X-squared = 8.1934, df = 12, p-value = 0.7698

> now taking 2nd example non stationary one in example


Error: unexpected symbol in "now taking"
> z_t[1] = 5+y_t[1]
>
> for(i in 2:100){
+ z_t[i]= 5+z_t[(i-1)]+ y_t[i]
+ }
> df= ur.df(z_t,type = "drift")
> df

###############################################################
# Augmented Dickey-Fuller Test Unit Root / Cointegration Test #
###############################################################

The value of the test statistic is: -0.417 40.3311

> df@teststat
tau2 phi1
statistic -0.416982 40.33106
> df@cval
1pct 5pct 10pct
tau2 -3.51 -2.89 -2.58
phi1 6.70 4.71 3.86
> z_t <- diff(z_t, 1)
> df= ur.df(z_t,type = "drift")
> df@teststat
tau2 phi1
statistic -6.994696 24.47025
> df@cval
1pct 5pct 10pct
tau2 -3.51 -2.89 -2.58
phi1 6.70 4.71 3.86
> acf(z_t,plot = TRUE)
> pacf(z_t)
> ord= ar(z_t,method = "mle")
> ord

Call:
ar(x = z_t, method = "mle")

Order selected 0 sigma^2 estimated as 0.9388


> AutoArimaModel=auto.arima(z_t)
> AutoArimaModel
Series: z_t
ARIMA(0,0,0) with non-zero mean

Coefficients:
mean
5.0585
s.e. 0.0974

sigma^2 estimated as 0.9484: log likelihood=-137.35


AIC=278.7 AICc=278.82 BIC=283.89

Euro session output


library("qrmdata")
> library("moments")
> library("urca") #needed for dickeyfuller test
> data= data("SP500")
> data= CAD_USD
Error: object 'CAD_USD' not found
> l= length(data)
> l
[1] 1
> l
[1] 1
> data= data("SP500")
> #data("CAD_USD")
>
> data= SP500
> l= length(data)
> l
[1] 16607
> data= data$'^GSPC'
> data= as.numeric(data)
> l1= length(data)
> l1
[1] 16607
> data
[1] 16.66 16.85 16.93 16.98 17.08 17.03 17.09 16.76 16.67 16.72 16.86
16.85 16.87 16.90 16.92 16.86 16.74 16.73 16.82
[20] 17.02 17.05 17.05 17.23 17.29 17.32 17.23 17.21 17.28 17.24 17.06
17.06 16.99 17.15 17.20 17.17 17.21 17.28 17.28
[39] 17.22 17.24 17.23 17.29 17.32 17.20 17.19 17.07 17.09 17.12 17.25
17.45 17.49 17.45 17.44 17.45 17.55 17.56 17.56
[58] 17.46 17.53 17.44 17.30 17.29 17.53 17.55 17.63 17.78 17.85 17.75
17.94 17.98 17.96 17.88 18.03 18.05 17.93 17.96
[77] 17.83 17.83 17.76 17.86 17.96 18.22 18.11 18.27 18.12 18.22 18.27
18.27 18.29 18.29 18.18 18.26 18.44 18.52 18.56
[96] 18.68 18.60 18.71 18.69 18.69 18.67 18.72 18.78 18.77 18.79 18.60
18.88 18.93 19.14 19.26 19.40 19.25 18.98 18.93
[115] 18.97 18.92 18.83 19.00 19.16 19.14 18.11 17.91 18.11 17.44 17.69
17.64 17.81 17.91 17.67 17.59 17.32 16.87 16.69
[134] 16.87 16.68 17.06 17.36 17.61 17.59 17.48 17.23 17.27 17.50 17.69
17.84 18.02 17.95 17.99 18.14 18.41 18.46 18.61
[153] 18.48 18.28 18.29 18.32 18.34 18.54 18.68 18.70 18.68 18.82 18.79
18.54 18.53 18.54 18.43 18.42 18.55 18.68 18.54
[172] 18.59 18.75 18.61 18.87 19.09 19.18 19.29 19.37 19.31 19.21 19.37
19.44 19.42 19.14 19.41 19.42 19.45 19.69 19.66
[191] 20.00 19.89 20.12 20.00 19.78 19.86 19.85 19.71 19.89 20.01 20.02
19.96 19.96 20.08 20.05 19.61 19.77 19.61 19.53
[210] 19.56 19.73 19.85 19.36 19.56 19.79 19.94 20.01 19.86 19.82 19.72
19.86 19.93 19.88 20.16 20.32 20.18 19.56 19.37
[229] 19.51 19.66 19.00 19.31 19.45 19.40 19.40 19.72 19.68 19.67 19.43
19.33 19.85 19.96 19.97 19.98 20.07 19.92 20.30
[248] 20.38 20.43 20.77 20.69 20.87 20.87 21.00 21.12 20.85 21.19 21.11
21.30 21.46 21.55 21.40 21.36 21.18 21.26 21.16
[267] 21.03 21.26 21.67 21.74 21.66 21.77 21.96 22.20 22.12 21.99 22.09
22.17 22.18 22.12 22.00 22.13 21.83 21.79 21.86
[286] 21.92 21.93 21.76 21.80 21.85 21.93 21.79 21.79 21.86 21.95 21.95
21.70 21.41 21.25 21.29 21.64 21.56 21.52 21.64
[305] 21.73 21.53 21.51 21.26 21.33 21.48 21.32 21.26 21.40 21.69 21.72
21.68 21.65 21.64 21.83 22.09 22.04 22.09 22.13
[324] 22.04 22.04 22.05 21.96 21.97 22.16 22.39 22.43 22.53 22.62 22.81
22.77 22.63 22.61 22.64 22.51 22.33 22.18 21.76
[343] 21.69 21.91 21.51 21.46 21.36 21.16 21.05 21.03 21.21 21.35 21.52
21.48 21.24 21.33 21.48 21.56 21.49 21.61 21.52
[362] 21.55 21.84 22.04 22.05 22.02 21.91 21.78 21.55 21.29 21.30 21.37
21.10 20.96 21.10 21.23 21.64 21.64 21.73 21.63
[381] 21.68 21.80 21.98 21.73 21.92 21.88 21.84 21.88 22.10 22.44 22.32
22.47 22.53 22.63 22.40 22.51 22.82 22.85 23.01
[400] 23.03 22.93 22.84 22.79 22.80 22.70 22.79 22.87 22.94 22.93 22.83
22.75 22.90 22.88 22.85 22.90 23.08 23.24 23.28
[419] 23.28 23.42 23.47 23.53 23.62 23.50 23.60 23.71 23.69 23.62 23.59
23.59 23.57 23.40 23.30 23.38 23.40 23.27 23.26
[438] 23.47 23.64 23.79 23.72 23.78 23.75 23.65 23.61 23.70 23.85 23.77
23.69 23.67 23.32 22.75 22.84 23.03 22.96 22.81
[457] 22.69 22.66 22.94 23.10 22.93 22.82 22.49 22.47 22.75 22.79 22.85
22.84 22.82 22.73 22.68 22.64 22.40 22.43 22.66
[476] 22.61 22.67 22.88 23.01 23.14 23.07 23.34 23.38 23.42 23.30 23.37
23.39 23.37 23.41 23.49 23.57 23.57 23.51 23.54
[495] 23.44 23.65 23.69 23.77 23.80 23.88 23.92 23.91 23.82 23.74 23.86
23.98 24.16 24.06 24.09 24.20 24.25 24.46 24.66
[514] 24.54 24.56 24.55 24.61 24.57 24.23 24.14 24.30 24.12 24.11 24.18
24.11 24.24 24.11 23.92 23.87 23.86 23.74 23.36
[533] 23.09 23.16 23.23 23.15 23.18 23.29 23.26 23.29 23.68 23.71 23.69
23.72 23.60 23.62 23.73 23.75 23.75 23.92 23.87
[552] 23.82 23.89 23.93 23.93 23.79 23.78 23.99 24.18 24.37 24.18 24.12
24.12 24.02 23.80 23.91 23.94 24.11 23.95 23.65
[571] 23.58 23.41 23.50 23.69 23.58 23.48 23.43 23.54 23.55 23.49 23.32
23.17 23.56 23.66 23.67 23.81 23.86 23.84 23.75
[590] 23.78 23.68 23.60 23.56 23.61 23.74 23.78 23.91 23.89 23.94 23.88
23.84 23.86 23.80 23.78 23.95 24.10 24.26 24.37
[609] 24.23 24.31 24.31 24.37 24.30 24.33 24.43 24.51 24.59 24.56 24.60
24.66 24.75 24.83 24.96 25.12 25.06 25.05 24.97
[628] 24.96 24.86 24.81 24.98 25.03 25.16 25.16 25.05 24.85 24.95 25.00
25.11 25.24 25.16 25.20 25.26 25.37 25.40 25.45
[647] 25.43 25.46 25.44 25.52 25.55 25.52 25.31 25.28 25.28 25.20 24.94
24.89 24.95 24.98 24.99 24.87 24.83 24.94 24.97
[666] 25.03 25.15 25.25 25.24 25.21 25.11 24.86 24.69 24.72 24.71 24.45
24.53 24.58 24.51 24.57 24.59 24.70 24.79 24.81
[685] 24.73 24.68 24.54 24.48 24.52 24.50 24.44 24.40 24.58 24.57 24.55
24.48 24.06 23.91 24.20 24.13 24.07 23.80 23.87
[704] 24.03 24.09 24.13 24.15 24.15 24.52 24.60 24.67 24.77 24.78 24.77
24.65 24.71 24.75 24.80 25.16 25.33 25.28 25.27
[723] 25.42 25.36 25.52 25.66 25.68 25.74 25.71 25.61 25.62 25.76 25.93
25.98 25.96 26.04 26.04 26.07 26.04 26.03 26.15
[742] 26.30 26.19 26.21 26.25 26.40 26.59 26.57 26.54 26.66 26.48 26.37
26.33 26.08 25.86 26.02 26.08 26.13 26.02 26.01
[761] 26.14 26.09 26.12 26.07 26.02 26.05 26.13 26.20 26.38 26.51 26.54
26.42 26.15 26.51 25.69 25.62 25.64 25.74 25.65
[780] 25.50 25.48 25.57 25.63 25.75 25.91 25.95 25.90 25.93 26.00 25.78
25.79 25.84 25.83 25.91 26.12 26.13 26.18 26.22
[799] 26.33 26.24 26.22 26.18 26.02 26.17 26.10 25.95 25.99 25.61 25.29
25.25 25.23 24.61 24.71 24.93 24.88 24.82 24.77
[818] 24.86 24.96 24.91 24.62 24.73 24.67 24.46 24.19 24.20 24.34 24.52
24.68 24.62 24.73 25.00 25.03 25.00 24.90 24.90
[837] 24.91 24.74 24.71 24.85 24.84 24.75 24.70 24.93 25.06 25.03 24.99
24.87 24.64 24.46 24.54 24.15 24.22 24.18 24.03
[856] 24.09 24.01 23.60 23.54 23.75 23.82 23.62 23.55 23.85 23.84 23.84
23.96 24.12 24.09 24.19 24.21 24.14 24.14 24.24
[875] 24.31 24.36 24.38 24.51 24.50 24.43 24.41 24.17 24.08 24.15 24.18
24.35 24.22 24.16 24.19 24.23 24.23 24.07 24.11
[894] 24.26 24.49 24.75 24.84 24.78 24.68 24.80 24.78 24.75 24.72 24.78
24.73 24.62 24.56 24.46 24.31 24.29 24.35 24.09
[913] 23.93 23.86 23.79 23.74 23.32 23.42 23.56 23.51 23.57 23.61 23.65
23.41 23.14 22.71 22.90 23.01 23.07 22.95 22.88
[932] 23.20 23.23 23.24 23.30 23.45 23.49 23.35 23.49 23.59 23.48 23.39
23.58 23.62 23.66 23.57 23.68 23.95 24.14 24.16
[951] 24.17 24.19 24.30 24.35 24.31 24.26 24.29 24.58 24.54 24.66 24.51
24.64 24.61 24.66 24.37 24.46 24.54 24.38 24.25
[970] 24.29 24.40 24.44 24.36 24.50 24.52 24.66 24.76 24.78 24.95 24.97
24.98 24.95 24.87 24.84 24.78 24.76 24.69 24.71
[989] 24.96 24.94 24.99 24.95 24.76 24.69 24.80 24.71 24.55 24.76 24.81
24.95
[ reached getOption("max.print") -- omitted 15607 entries ]
> log_ret= c(rep(0,l))
>
> for(i in 2:l){
+ log_ret[i]= log(data[i])-log(data[(i-1)])
+ }
> log_ret
[1] 0.0000000000 0.0113400201 0.0047365393 0.0029489847
0.0058720075 -0.0029316350 0.0035169437 -0.0194984021
[9] -0.0053843983 0.0029948511 0.0083384640 -0.0005933551
0.0011862990 0.0017766661 0.0011827322 -0.0035523423
[17] -0.0071429468 -0.0005975501 0.0053651395 0.0118204686
0.0017610219 0.0000000000 0.0105019055 0.0034763070
[25] 0.0017335456 -0.0052098526 -0.0011614984 0.0040592691
-0.0023175560 -0.0104957818 0.0000000000 -0.0041115478
[33] 0.0093732379 0.0029112683 -0.0017457670 0.0023268772
0.0040592691 0.0000000000 -0.0034783803 0.0011608243
[41] -0.0005802147 0.0034763070 0.0017335456 -0.0069524612
-0.0005815644 -0.0070053408 0.0011709603 0.0017539320
[49] 0.0075647144 0.0115275625 0.0022895831 -0.0022895831
-0.0005732301 0.0005732301 0.0057141870 0.0005696383
[57] 0.0000000000 -0.0057110381 0.0040012628 -0.0051472802
-0.0080600321 -0.0005780862 0.0137853984 0.0011401370
[65] 0.0045480468 0.0084723466 0.0039292219 -0.0056179923
0.0106473965 0.0022271167 -0.0011130218 -0.0044642934
[73] 0.0083543789 0.0011085367 -0.0066703418 0.0016717196
-0.0072645753 0.0000000000 -0.0039336943 0.0056148939
[81] 0.0055833758 0.0143728298 -0.0060555098 0.0087960433
-0.0082440146 0.0055034811 0.0027405334 0.0000000000
[89] 0.0010941467 0.0000000000 -0.0060324283 0.0043907864
0.0098093972 0.0043289569 0.0021574443 0.0064447593
[97] -0.0042918521 0.0058965061 -0.0010694119 0.0000000000
-0.0010707174 0.0026744601 0.0032001094 -0.0005326764
[105] 0.0010650160 -0.0101632859 0.0149415270 0.0026448575
0.0110323686 0.0062500726 0.0072426597 -0.0077620053
[113] -0.0141252676 -0.0026378280 0.0021107660 -0.0026391676
-0.0047682210 0.0089876365 0.0083857934 -0.0010444388
[121] -0.0553160067 -0.0111051110 0.0111051110 -0.0376978513
0.0142330889 -0.0028305708 0.0095910473 0.0055991749
[129] -0.0134909297 -0.0045377276 -0.0154686556 -0.0263249473
-0.0107271582 0.0107271582 -0.0113265589 0.0225260865
[137] 0.0174322834 0.0142982125 -0.0011364205 -0.0062731885
-0.0144053197 0.0023188416 0.0132299888 0.0107986838
[145] 0.0084435625 0.0100391250 -0.0038920815 0.0022258773
0.0083033416 0.0147746057 0.0027121797 0.0080929495
[153] -0.0070100582 -0.0108814455 0.0005468963 0.0016388422
0.0010911076 0.0108461472 0.0075228187 0.0010701445
[161] -0.0010701445 0.0074667014 -0.0015952675 -0.0133942526
-0.0005395198 0.0005395198 -0.0059508424 -0.0005427409
[169] 0.0070327043 0.0069836977 -0.0075228187 0.0026931877
0.0085699507 -0.0074946280 0.0138742880 0.0115912254
[177] 0.0047034317 0.0057188093 0.0041386503 -0.0031024844
-0.0051921199 0.0082946043 0.0036073214 -0.0010293876
[185] -0.0145231291 0.0140080634 0.0005150657 0.0015436586
0.0122638220 -0.0015248287 0.0171461588 -0.0055152310
[193] 0.0114973523 -0.0059821214 -0.0110608968 0.0040363322
-0.0005037018 -0.0070779367 0.0090909722 0.0060151060
[201] 0.0004996253 -0.0030015531 0.0000000000 0.0059940740
-0.0014951909 -0.0221894127 0.0081259460 -0.0081259460
[209] -0.0040878951 0.0015348174 0.0086537066 0.0060636871
-0.0249948736 0.0102774800 0.0116901967 0.0075510045
[217] 0.0035043339 -0.0075244396 -0.0020161801 -0.0050582304
0.0070744105 0.0035184253 -0.0025119833 0.0139862923
[225] 0.0079051795 -0.0069136078 -0.0312054014 -0.0097610844
0.0072016256 0.0076589601 -0.0341471356 0.0161840655
[233] 0.0072240768 -0.0025740554 0.0000000000 0.0163602324
-0.0020304068 -0.0005082592 -0.0122763690 -0.0051599702
[241] 0.0265457139 0.0055262136 0.0005008766 0.0005006759
0.0044943896 -0.0075019107 0.0188965846 0.0039331419
[249] 0.0024504301 0.0165052291 -0.0038590978 0.0086622289
0.0000000000 0.0062096687 0.0056980685 -0.0128665579
[257] 0.0161754712 -0.0037825102 0.0089601165 0.0074836648
0.0041850795 -0.0069848481 -0.0018708611 -0.0084627207
[265] 0.0037700327 -0.0047147659 -0.0061625697 0.0108773356
0.0191014426 0.0032250661 -0.0036866401 0.0050656337
[273] 0.0086896959 0.0108697628 -0.0036101121 -0.0058944173
0.0045372129 0.0036150062 0.0004509583 -0.0027087601
[281] -0.0054397685 0.0058916555 -0.0136489383 -0.0018339757
0.0032073336 0.0027409336 0.0004561003 -0.0077821404
[289] 0.0018365019 0.0022909976 0.0036546409 -0.0064043676
0.0000000000 0.0032073336 0.0041086566 0.0000000000
[297] -0.0114548784 -0.0134542040 -0.0075012072 0.0018806305
0.0163058819 -0.0037037081 -0.0018569644 0.0055606725
[305] 0.0041503865 -0.0092464364 -0.0009294145 -0.0116905704
0.0032871596 0.0070077372 -0.0074766703 -0.0028182264
[313] 0.0065635491 0.0134604489 0.0013820781 -0.0018432725
-0.0013847221 -0.0004620467 0.0087417628 0.0118398469
[321] -0.0022659878 0.0022659878 0.0018090914 -0.0040750792
0.0000000000 0.0004535269 -0.0040899854 0.0004552698
[329] 0.0086110210 0.0103255241 0.0017849626 0.0044484503
0.0039867161 0.0083644776 -0.0017551124 -0.0061674646
[337] -0.0008840849 0.0013258786 -0.0057585542 -0.0080285891
-0.0067400839 -0.0191175599 -0.0032220510 0.0100917827
[345] -0.0184252103 -0.0023272527 -0.0046706297 -0.0094074539
-0.0052120944 -0.0009504754 0.0085226842 0.0065790182
[353] 0.0079309956 -0.0018604657 -0.0112360733 0.0042283361
0.0070077372 0.0037174300 -0.0032519890 0.0055685061
[361] -0.0041734815 0.0013930349 0.0133673807 0.0091158788
0.0004535269 -0.0013614252 -0.0050079777 -0.0059509902
[369] -0.0106163933 -0.0121382443 0.0004694999 0.0032810904
-0.0127150756 -0.0066572287 0.0066572287 0.0061422352
[377] 0.0191281321 0.0000000000 0.0041503865 -0.0046126005
0.0023089828 0.0055197474 0.0082230251 -0.0114391547
[385] 0.0087056678 -0.0018265302 -0.0018297810 0.0018297810
0.0100046767 0.0152675167 -0.0053619877 0.0066979042
[393] 0.0026667571 0.0044286166 -0.0102154566 0.0048986961
0.0136776895 0.0013137729 0.0069777867 0.0008688532
[401] -0.0043516604 -0.0039327121 -0.0021914977 0.0004386050
-0.0043955236 0.0039569186 0.0035041646 0.0030561035
[409] -0.0004360584 -0.0043706363 -0.0035103151 0.0065717652
-0.0008737878 -0.0013120055 0.0021857932 0.0078295311
[417] 0.0069084903 0.0017197338 0.0000000000 0.0059956924
0.0021326091 0.0025532780 0.0038176079 -0.0050934320
[425] 0.0042462909 0.0046501459 -0.0008437975 -0.0029592073
-0.0012709597 0.0000000000 -0.0008481765 -0.0072386946
[433] -0.0042827047 0.0034275956 0.0008551091 -0.0055710450
-0.0004298302 0.0089878202 0.0072171830 0.0063252161
[441] -0.0029468344 0.0025264013 -0.0012624028 -0.0042194155
-0.0016927215 0.0038046969 0.0063091270 -0.0033599360
[449] -0.0033712210 -0.0008446369 -0.0148970620 -0.0247462161
0.0039482394 0.0082843725 -0.0030442294 -0.0065545354
[457] -0.0052746496 -0.0013230873 0.0122808997 0.0069504622
-0.0073865207 -0.0048087524 -0.0145665785 -0.0008897243
[465] 0.0123841037 0.0017567417 0.0026292302 -0.0004377326
-0.0008760404 -0.0039517066 -0.0022021590 -0.0017652697
[473] -0.0106572503 0.0013383897 0.0102019071 -0.0022089251
0.0026501340 0.0092206583 0.0056657812 0.0056337745
[481] -0.0030296064 0.0116355547 0.0017122864 0.0017094449
-0.0051370405 0.0029998737 0.0008553465 -0.0008553465
[489] 0.0017100902 0.0034115172 0.0033999183 0.0000000000
-0.0025488544 0.0012752818 -0.0042571369 0.0089191076
[497] 0.0016899454 0.0033712210 0.0012612573 0.0033557080
0.0016736824 -0.0004181476 -0.0037712175 -0.0033641747
[505] 0.0050420694 0.0050166910 0.0074782235 -0.0041477041
0.0012461476 0.0045558579 0.0020639429 0.0086224720
[513] 0.0081434084 -0.0048780177 0.0008145825 -0.0004072491
0.0024410915 -0.0016267185 -0.0139346517 -0.0037213606
[521] 0.0066061349 -0.0074348959 -0.0004146796 0.0028991115
-0.0028991115 0.0053774275 -0.0053774275 -0.0079118046
[529] -0.0020924468 -0.0004190237 -0.0050420694 -0.0161361884
-0.0116255774 0.0030270293 0.0030178941 -0.0034497663
[537] 0.0012950574 0.0047342889 -0.0012889797 0.0012889797
0.0166066832 0.0012660479 -0.0008437975 0.0012654716
[545] -0.0050718199 0.0008471411 0.0046462173 0.0008424600
0.0000000000 0.0071323986 -0.0020924468 -0.0020969183
[553] 0.0029343556 0.0016729824 0.0000000000 -0.0058675356
-0.0004204330 0.0087921435 0.0078887683 0.0078270635
[561] -0.0078270635 -0.0024844319 0.0000000000 -0.0041545967
-0.0092012780 0.0046112428 0.0012539604 0.0070759918
[569] -0.0066583681 -0.0126052507 -0.0029642198 -0.0072356136
0.0038371396 0.0080526392 -0.0046541653 -0.0042499001
[577] -0.0021317424 0.0046838918 0.0004246337 -0.0025509793
-0.0072634372 -0.0064530230 0.0166919779 0.0042355422
[585] 0.0004225650 0.0058971950 0.0020978401 -0.0008386164
-0.0037823117 0.0012624028 -0.0042141233 -0.0033840980
[593] -0.0016963957 0.0021200771 0.0054909957 0.0016835441
0.0054518482 -0.0008368620 0.0020908224 -0.0025094953
[601] -0.0016764045 0.0008386164 -0.0025179199 -0.0008406053
0.0071234323 0.0062434749 0.0066170630 0.0045240052
[609] -0.0057613738 0.0032962124 0.0000000000 0.0024651615
-0.0028765995 0.0012338476 0.0041017285 0.0032693123
[617] 0.0032586587 -0.0012207937 0.0016273804 0.0024360548
0.0036429913 0.0032271105 0.0052219039 0.0063898780
[625] -0.0023914718 -0.0003991220 -0.0031987234 -0.0004005608
-0.0040143771 -0.0020133689 0.0068287473 0.0019996407
[633] 0.0051802864 0.0000000000 -0.0043816442 -0.0080160351
0.0040161097 0.0020019626 0.0043903881 0.0051638247
[641] -0.0031746058 0.0015886024 0.0023780827 0.0043452961
0.0011817610 0.0019666083 -0.0007862029 0.0011789744
[649] -0.0007857761 0.0031396807 0.0011748190 -0.0011748190
-0.0082629234 -0.0011859262 0.0000000000 -0.0031695746
[657] -0.0103710539 -0.0020069041 0.0024077861 0.0012016424
0.0004002401 -0.0048134468 -0.0016096985 0.0044203808
[665] 0.0012020839 0.0024000812 0.0047827512 0.0039682592
-0.0003961180 -0.0011893361 -0.0039744885 -0.0100060867
[673] -0.0068617824 0.0012142483 -0.0004046126 -0.0105777227
0.0032666422 0.0020362051 -0.0028519066 0.0024449890
[681] 0.0008136697 0.0044634279 0.0036371023 0.0008063710
-0.0032296759 -0.0020238825 -0.0056887190 -0.0024480224
[689] 0.0016326534 -0.0008159935 -0.0024519423 -0.0016380429
0.0073499718 -0.0004069176 -0.0008143730 -0.0028553559
[697] -0.0173057887 -0.0062538875 0.0120558930 -0.0028968363
-0.0024895864 -0.0112807131 0.0029369436 0.0066806091
[705] 0.0024937253 0.0016590216 0.0008285419 0.0000000000
0.0152047310 0.0032573319 0.0028414876 0.0040453130
[713] 0.0004036731 -0.0004036731 -0.0048563430 0.0024310790
0.0016175095 0.0020181238 0.0144118190 0.0067340322
[721] -0.0019758552 -0.0003956874 0.0059183444 -0.0023630968
0.0062892895 0.0054709007 0.0007791196 0.0023337233
[729] -0.0011662198 -0.0038970431 0.0003903962 0.0054495657
0.0065776983 0.0019264117 -0.0007701579 0.0030770024
[737] 0.0000000000 0.0011513722 -0.0011513722 -0.0003840983
0.0045994331 0.0057197106 -0.0041912045 0.0007632825
[745] 0.0015250099 0.0056980211 0.0071711951 -0.0007524455
-0.0011296932 0.0045112482 -0.0067745837 -0.0041626928
[753] -0.0015180648 -0.0095402364 -0.0084713250 0.0061680611
0.0023032640 0.0019153042 -0.0042185682 -0.0003843936
[761] 0.0049855905 -0.0019145708 0.0011492435 -0.0019161147
-0.0019197549 0.0011522567 0.0030663115 0.0026754077
[769] 0.0068466604 0.0049159109 0.0011310463 -0.0045317675
-0.0102721086 0.0136728298 -0.0314201703 -0.0027285145
[777] 0.0007802576 0.0038926091 -0.0035026306 -0.0058651195
-0.0007846215 0.0035259586 0.0023437121 0.0046711258
[785] 0.0061943675 0.0015426536 -0.0019286794 0.0011576308
0.0026959385 -0.0084975017 0.0003878224 0.0019368202
[793] -0.0003870718 0.0030923875 0.0080723481 0.0003826986
0.0019117192 0.0015266797 0.0041865333 -0.0034240094
[801] -0.0007625239 -0.0015266797 -0.0061302874 0.0057482435
-0.0026784022 -0.0057636662 0.0015402005 -0.0147289094
[809] -0.0125738390 -0.0015829445 -0.0007923931 -0.0248808576
0.0040550745 0.0088639180 -0.0020076699 -0.0024144479
[817] -0.0020165363 0.0036268828 0.0040143771 -0.0020051742
-0.0117101679 0.0044579202 -0.0024291510 -0.0085488412
[825] -0.0110997234 0.0004133085 0.0057684131 0.0073680235
0.0065040880 -0.0024340377 0.0044579202 0.0108587433
[833] 0.0011993205 -0.0011993205 -0.0040080214 0.0000000000
0.0004015258 -0.0068479623 -0.0012133874 0.0056497730
[841] -0.0004024955 -0.0036297681 -0.0020222049 0.0092686134
0.0052010120 -0.0011977642 -0.0015994005 -0.0048134468
[849] -0.0092911999 -0.0073320087 0.0032653907 -0.0160200999
0.0028943167 -0.0016528517 -0.0062227538 0.0024937253
[857] -0.0033264064 -0.0172236982 -0.0025455677 0.0088813862
0.0029430334 -0.0084317108 -0.0029680751 0.0126584393
[865] -0.0004193751 0.0000000000 0.0050208893 0.0066556818
-0.0012445967 0.0041425493 0.0008263637 -0.0028955554
[873] 0.0000000000 0.0041339870 0.0028835860 0.0020547367
0.0008205991 0.0053181145 -0.0004080800 -0.0028612323
[881] -0.0008190009 -0.0098806897 -0.0037305743 0.0029027597
0.0012414651 0.0070060043 -0.0053531527 -0.0024803238
[889] 0.0012409929 0.0016521689 0.0000000000 -0.0066252830
0.0016604819 0.0062021698 0.0094359674 0.0105606181
[897] 0.0036297681 -0.0024183405 -0.0040437175 0.0048504138
-0.0008066963 -0.0012114275 -0.0012128969 0.0024243244
[905] -0.0020198350 -0.0044579202 -0.0024400988 -0.0040799732
-0.0061513422 -0.0008229630 0.0024670653 -0.0107350329
[913] -0.0066639147 -0.0029294433 -0.0029380922 -0.0021039772
-0.0178500277 0.0042789967 0.0059599582 -0.0021244538
[921] 0.0025488544 0.0016956765 0.0016927215 -0.0101998334
-0.0116006030 -0.0187573665 0.0083315985 0.0047919935
[929] 0.0026041681 -0.0052150921 -0.0030548573 0.0138891990
0.0012922250 0.0004303852 0.0025783857 0.0064172199
[937] 0.0017042611 -0.0059778146 0.0059778146 0.0042480947
-0.0046738985 -0.0038404571 0.0080903573 0.0016949580
[945] 0.0016920054 -0.0038111416 0.0046560931 0.0113375556
0.0079018086 0.0008281988 0.0004138216 0.0008271712
[953] 0.0045369432 0.0020555403 -0.0016441023 -0.0020588437
0.0012358807 0.0118683200 -0.0016286241 0.0048780177
[961] -0.0061013002 0.0052899005 -0.0012181930 0.0020295927
-0.0118295891 0.0036861807 0.0032653907 -0.0065413970
[969] -0.0053464657 0.0016481668 0.0045183481 0.0016380429
-0.0032786913 0.0057306337 0.0008159935 0.0056933867
[977] 0.0040469501 0.0008074687 0.0068369457 0.0008012020
0.0004004405 -0.0012016424 -0.0032115643 -0.0012070410
[985] -0.0024183405 -0.0008074687 -0.0028311040 0.0008096357
0.0100665239 -0.0008015231 0.0020027645 -0.0016018826
[993] -0.0076444145 -0.0028311040 0.0044452690 -0.0036356333
-0.0064961660 0.0085176343 0.0020173096 0.0056271049
[ reached getOption("max.print") -- omitted 15607 entries ]
> log_ret= log_ret[-1]
> df= ur.df(log_ret,type = "drift")
> df@teststat
tau2 phi1
statistic -93.75273 4394.787
> df@cval
1pct 5pct 10pct
tau2 -3.43 -2.86 -2.57
phi1 6.43 4.59 3.78
> Box.test(log_ret,type = "Ljung-Box")

Box-Ljung test

data: log_ret
X-squared = 13.579, df = 1, p-value = 0.0002287

> acf(log_ret)
> ord= ar(log_ret,method = "mle")
> ord

Call:
ar(x = log_ret, method = "mle")
Coefficients:
1 2 3 4 5 6 7 8
9 10 11 12
0.0308 -0.0447 0.0034 -0.0090 -0.0130 -0.0041 -0.0203 0.0123
-0.0115 0.0145 -0.0164 0.0284

Order selected 12 sigma^2 estimated as 9.409e-05


> pacf(log_ret)
> AutoArimaModel=auto.arima(log_ret)
> AutoArimaModel
Series: log_ret
ARIMA(2,0,0) with non-zero mean

Coefficients:
ar1 ar2 mean
0.0298 -0.0431 3e-04
s.e. 0.0078 0.0078 1e-04

sigma^2 estimated as 9.431e-05: log likelihood=53398.9


AIC=-106789.8 AICc=-106789.8 BIC=-106758.9
> Box.test(AutoArimaModel$residuals,type = "Ljung-Box")

Box-Ljung test

data: AutoArimaModel$residuals
X-squared = 0.00026939, df = 1, p-value = 0.9869

FTSF Session-4

> install.packages("forecast")
Error in install.packages : Updating loaded packages
> library("forecast")
> library("urca")
> z_t= c(rep(0,100))
> y_t = rnorm(100, 0,1)
> z_t[1] = 5+y_t[1]
>
> for(i in 2:100){
+ z_t[i]= 5+0.5*y_t[(i-1)]+ y_t[i]
+ }
> install.packages("forecast")
WARNING: Rtools is required to build R packages but is not currently
installed. Please download and install the appropriate version of Rtools
before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Warning in install.packages :
package ‘forecast’ is in use and will not be installed
> z_t= c(rep(0,100))
> y_t = rnorm(100, 0,1)
> z_t[1] = 5+y_t[1]
>
> for(i in 2:100){
+ z_t[i]= 5+0.5*y_t[(i-1)]+ y_t[i]
+ }
> ts.plot(z_t)
> z_t=arima.sim(list(order = c(0,0,1), ma=0.5), n = 100)+5
> z_t
Time Series:
Start = 1
End = 100
Frequency = 1
[1] 5.0242342 4.8453968 4.8584243 4.6033240 5.2688283 4.9035807
7.4560917 7.1434442 6.6476980 6.2253627 3.7865403
[12] 3.5646702 5.1747833 5.3783744 3.6393971 4.5083998 7.0351671
5.4861782 6.0007565 4.6842743 4.1434144 4.8573163
[23] 5.9800631 5.2176776 4.0164573 4.8164887 6.6463998 6.0340895
4.8407095 4.0113495 5.5214101 6.3407039 6.0681925
[34] 5.5117255 4.2886997 3.9148973 6.4789170 4.5936915 5.8728098
5.6468288 3.5105896 5.2583142 4.0316147 4.4844996
[45] 6.8634453 6.7061088 5.6659409 5.7434562 5.5568100 5.6543257
5.0586071 5.2699855 5.3627883 5.0589015 5.5112081
[56] 5.7995450 6.4279352 4.7815953 4.4643449 6.7636955 6.1252957
5.9109806 5.2541809 5.4207764 5.1482033 6.0165262
[67] 4.5758677 3.3746121 5.0181018 5.2068377 5.4112417 5.1176143
4.6874169 6.7451481 7.0376738 4.9990650 5.1852922
[78] 3.3433849 1.1951205 0.5995327 4.1751790 4.9307716 5.2869642
4.0007528 5.4996597 6.3468528 5.7718259 3.4220988
[89] 4.4099023 5.4486823 5.0441666 5.3574729 4.5157895 5.7378482
6.2336834 5.6399210 5.1568855 5.4415682 4.9350828
[100] 5.6317134
> df= ur.df(z_t,type = "drift")
> df

###############################################################
# Augmented Dickey-Fuller Test Unit Root / Cointegration Test #
###############################################################

The value of the test statistic is: -6.6291 21.9753

> df@teststat
tau2 phi1
statistic -6.629055 21.9753
> df@cval
1pct 5pct 10pct
tau2 -3.51 -2.89 -2.58
phi1 6.70 4.71 3.86
> lju_box= Box.test(z_t,lag = 12,type = "Ljung-Box")
> lju_box

Box-Ljung test

data: z_t
X-squared = 35.711, df = 12, p-value = 0.0003606
> acf(z_t,plot = TRUE)
> ord= ar(z_t,method = "mle")
> ord

Call:
ar(x = z_t, method = "mle")

Coefficients:
1 2
0.5031 -0.2209

Order selected 2 sigma^2 estimated as 0.9341


> pacf(z_t)
> AutoArimaModel=auto.arima(z_t)
> AutoArimaModel
Series: z_t
ARIMA(0,0,1) with non-zero mean

Coefficients:
ma1 mean
0.5154 5.1873
s.e. 0.0852 0.1457

sigma^2 estimated as 0.9495: log likelihood=-138.45


AIC=282.89 AICc=283.14 BIC=290.71
> Box.test(AutoArimaModel$residuals,lag = 12,type = "Ljung-Box")

Box-Ljung test

data: AutoArimaModel$residuals
X-squared = 8.6756, df = 12, p-value = 0.7304

Stock price data session 4

> data= data("DJ")


> data= DJ
> l= length(data)
> l
[1] 7797
> data= data$`^DJI`
> # making numeric
> data= as.numeric(data)
> data
[1] 1292.62 1287.88 1286.77 1277.72 1290.08 1285.23 1280.59 1290.08
1289.97 1276.06 1276.61 1297.92 1287.88 1282.02
[15] 1280.59 1283.13 1279.04 1275.84 1277.50 1286.11 1281.03 1284.01
1299.36 1289.53 1291.85 1280.37 1271.53 1269.66
[29] 1268.55 1271.75 1261.70 1260.05 1247.35 1249.67 1271.09 1265.24
1268.22 1267.45 1259.94 1259.72 1264.91 1260.71
[43] 1266.78 1272.75 1265.68 1258.06 1259.05 1252.98 1253.86 1259.94
1263.69 1265.68 1266.78 1269.55 1272.31 1265.13
[57] 1266.56 1266.56 1278.71 1278.49 1284.78 1275.18 1259.72 1258.06
1242.05 1242.27 1247.24 1247.79 1252.75 1249.78
[71] 1260.27 1274.18 1277.50 1273.30 1273.52 1278.05 1285.34 1304.88
1309.70 1303.76 1296.71 1301.97 1301.52 1302.98
[85] 1305.78 1315.41 1310.93 1315.30 1320.56 1327.28 1316.42 1318.44
1313.84 1306.34 1290.10 1300.96 1298.39 1304.77
[99] 1297.38 1299.73 1324.48 1320.56 1323.03 1323.81 1332.21 1335.46
1337.14 1334.01 1326.39 1334.45 1328.41 1321.91
[113] 1332.89 1337.70 1338.60 1335.46 1347.89 1357.97 1350.92 1359.54
1357.64 1351.81 1348.90 1353.61 1357.08 1343.86
[127] 1346.10 1347.45 1355.62 1353.05 1346.89 1325.16 1325.04 1329.86
1320.79 1314.29 1315.30 1316.98 1317.76 1312.72
[141] 1312.50 1323.70 1329.53 1318.10 1318.32 1317.65 1322.47 1331.09
1335.13 1334.01 1329.19 1326.72 1325.83 1335.69
[155] 1339.27 1333.45 1319.44 1312.39 1307.68 1309.14 1298.16 1300.40
1306.79 1297.94 1316.31 1321.12 1312.05 1320.79
[169] 1328.63 1340.95 1333.67 1333.11 1328.74 1324.37 1325.49 1326.72
1328.07 1339.94 1354.73 1350.81 1368.50 1369.29
[183] 1368.84 1364.14 1364.36 1367.16 1362.34 1356.52 1359.99 1368.73
1375.57 1374.31 1390.25 1389.68 1396.67 1403.44
[197] 1399.54 1404.36 1431.88 1433.60 1427.75 1439.22 1435.09 1440.02
1438.99 1439.22 1462.27 1464.33 1456.65 1456.77
[211] 1475.69 1472.13 1457.91 1459.06 1484.40 1482.91 1477.18 1497.02
1499.20 1511.70 1511.24 1535.21 1553.10 1544.50
[225] 1542.43 1543.92 1543.00 1528.78 1519.15 1526.49 1543.00 1550.46
1546.67 1537.73 1549.20 1547.59 1565.71 1526.61
[239] 1518.23 1513.53 1520.53 1519.04 1527.29 1541.63 1536.70 1529.13
1514.45 1502.29 1511.24 1529.93 1537.61 1556.42
[253] 1558.94 1552.18 1570.99 1594.27 1593.23 1593.12 1600.69 1613.42
1626.38 1622.82 1629.93 1645.07 1664.45 1678.78
[267] 1658.26 1672.82 1697.71 1698.28 1692.66 1696.90 1713.99 1709.06
1696.67 1686.42 1686.66 1696.60 1699.83 1702.95
[281] 1746.05 1745.45 1753.71 1792.74 1776.86 1789.87 1787.95 1804.24
1768.56 1782.93 1778.50 1810.70 1821.72 1818.61
[295] 1790.11 1795.26 1766.40 1739.22 1735.51 1769.76 1778.62 1794.30
1790.18 1805.31 1809.65 1847.97 1855.03 1840.40
[309] 1855.90 1830.98 1829.61 1831.72 1835.57 1843.75 1825.89 1783.98
1777.78 1774.68 1793.77 1787.95 1775.30 1786.21
[323] 1789.43 1787.33 1785.34 1808.28 1774.68 1759.80 1758.18 1783.98
1775.17 1806.30 1823.29 1853.03 1878.28 1882.35
[337] 1876.71 1861.95 1870.43 1863.29 1879.44 1885.90 1840.15 1837.19
1846.07 1838.13 1874.19 1871.77 1865.78 1868.94
[351] 1855.86 1879.54 1864.26 1875.55 1885.05 1880.20 1885.26 1892.72
1903.54 1909.03 1900.87 1838.86 1820.73 1826.07
[365] 1831.83 1821.43 1793.45 1768.70 1774.18 1781.78 1777.98 1779.11
1795.13 1798.37 1791.62 1810.04 1773.90 1766.87
[379] 1779.39 1775.31 1763.64 1769.97 1777.00 1779.53 1786.28 1782.62
1811.16 1835.49 1844.49 1844.91 1855.60 1869.52
[393] 1862.91 1881.33 1881.19 1887.80 1871.77 1904.25 1904.53 1900.17
1898.34 1870.36 1881.33 1919.71 1899.75 1888.64
[407] 1884.14 1879.50 1792.89 1758.72 1767.58 1778.54 1769.40 1774.18
1762.65 1793.45 1797.81 1803.29 1768.56 1769.69
[421] 1755.20 1767.58 1782.90 1781.21 1774.18 1784.45 1784.45 1803.85
1796.82 1793.17 1798.37 1800.20 1831.69 1836.19
[435] 1837.04 1811.02 1805.68 1808.35 1834.93 1832.36 1841.82 1845.47
1851.80 1878.37 1877.71 1894.26 1892.44 1899.04
[449] 1891.59 1886.53 1892.29 1895.95 1893.70 1862.20 1873.59 1860.52
1817.21 1826.63 1860.66 1893.56 1906.07 1912.12
[463] 1916.76 1914.23 1912.54 1955.57 1947.27 1939.68 1925.06 1930.26
1916.90 1932.93 1923.65 1912.26 1922.81 1936.16
[477] 1918.31 1912.82 1928.85 1926.18 1914.37 1926.88 1930.40 1912.12
1908.61 1895.95 1927.31 1971.32 1974.83 1993.95
[491] 2002.25 2005.91 2009.42 2012.94 2035.01 2070.73 2076.63 2102.50
2104.47 2094.07 2145.67 2101.52 2107.28 2150.45
[505] 2163.39 2160.01 2158.04 2179.42 2168.45 2191.23 2201.49 2186.87
2176.74 2158.04 2171.96 2165.78 2183.35 2237.49
[519] 2237.63 2244.09 2235.24 2216.54 2223.28 2226.24 2216.68 2223.99
2220.47 2226.52 2257.45 2276.43 2280.23 2260.12
[533] 2280.09 2268.98 2267.34 2258.66 2248.44 2284.80 2286.93 2299.57
2333.52 2363.78 2369.18 2363.49 2372.59 2335.80
[547] 2278.41 2304.69 2316.05 2320.45 2390.34 2405.54 2360.94 2372.16
2339.20 2338.78 2287.07 2252.98 2282.95 2275.99
[561] 2270.60 2337.07 2285.94 2280.97 2235.37 2230.54 2231.96 2254.26
2286.36 2280.40 2286.22 2338.07 2342.19 2334.66
[575] 2322.30 2307.30 2322.60 2329.68 2325.49 2272.52 2258.66 2221.28
2215.87 2225.77 2243.20 2297.94 2295.81 2310.68
[589] 2291.57 2288.23 2278.22 2320.69 2337.08 2326.15 2351.64 2352.70
2353.61 2360.13 2377.73 2391.54 2407.35 2407.35
[603] 2408.13 2420.85 2445.51 2439.73 2428.41 2451.05 2436.86 2446.91
2418.53 2409.76 2436.70 2429.53 2449.78 2463.97
[617] 2451.21 2455.99 2452.97 2481.35 2483.74 2496.97 2510.04 2487.82
2467.95 2470.18 2471.94 2485.33 2493.94 2519.77
[631] 2539.54 2567.44 2572.07 2557.08 2546.72 2566.65 2594.23 2592.00
2635.84 2680.48 2669.32 2691.49 2685.43 2700.57
[645] 2654.66 2665.82 2706.79 2709.50 2697.07 2722.42 2701.85 2675.06
2639.35 2662.95 2610.97 2602.04 2599.49 2561.38
[659] 2545.12 2549.27 2576.05 2608.74 2613.04 2566.58 2530.19 2527.90
2524.64 2492.82 2568.05 2585.67 2566.42 2570.17
[673] 2601.50 2590.57 2596.28 2639.20 2640.99 2640.18 2548.63 2551.08
2516.64 2482.21 2471.44 2508.16 2412.70 2355.09
[687] 2246.73 1738.74 1841.01 2027.85 1950.43 1950.76 1793.93 1846.49
1846.82 1938.33 1993.53 2014.09 1963.53 1945.29
[701] 1985.41 1959.05 1900.20 1878.15 1899.20 1960.21 1935.01 1949.10
1922.25 1939.16 1895.39 1913.63 1923.08 1963.53
[715] 1946.95 1910.48 1833.55 1842.34 1848.97 1776.53 1766.74 1812.17
1868.37 1902.52 1855.44 1867.04 1932.86 1941.48
[729] 1974.47 1924.40 1975.30 1990.38 1978.45 2005.64 1999.67 1942.97
1926.89 1950.10 1938.83 2015.25 2031.50 2037.80
[743] 2051.89 1911.31 1945.13 1928.55 1924.73 1916.11 1956.07 1963.86
1936.34 1879.14 1879.31 1903.51 1946.45 1920.59
[757] 1911.14 1930.04 1958.22 1944.63 1952.92 1924.57 1923.57 1910.48
1895.72 1914.46 1962.04 1961.54 1983.26 2005.97
[771] 2000.99 1986.41 2014.59 2040.29 2039.12 2039.95 2017.57 2023.21
2071.62 2070.47 2071.29 2063.49 2057.86 2056.37
[785] 2081.07 2074.27 2026.03 2034.98 2050.07 2047.41 2064.32 2086.04
2087.37 2067.14 2066.15 2067.64 2023.87 1978.95
[799] 1979.77 1998.34 1978.12 1988.06 1980.60 1997.51 2061.67 2062.17
2090.19 2095.99 2110.08 2107.10 2005.64 2013.93
[813] 2008.12 1999.50 1985.41 1987.40 2015.09 2035.97 2044.76 2047.91
2041.28 2032.33 2043.27 2058.36 2036.31 2020.23
[827] 2007.46 1997.35 2003.64 1965.85 1968.00 1990.55 2007.63 1986.41
1951.09 1958.72 1952.59 1941.48 1962.53 1961.37
[841] 1966.70 1956.44 2031.12 2064.01 2052.45 2071.31 2075.21 2054.59
2102.95 2093.35 2101.71 2099.40 2124.47 2131.40
[855] 2094.24 2104.02 2083.93 2109.17 2152.20 2148.29 2142.96 2108.46
2130.87 2121.98 2141.71 2131.58 2158.61 2130.16
[869] 2122.69 2106.15 2111.31 2092.64 2104.37 2113.62 2129.45 2117.89
2097.26 2110.60 2086.59 2060.99 2071.83 2073.97
[883] 2053.70 2082.33 2128.73 2130.51 2131.22 2134.07 2126.60 2119.13
2107.40 2079.13 2034.14 2039.30 2037.52 2004.27
[897] 2021.51 2025.96 2027.03 2016.00 1990.22 1989.33 2026.67 2010.85
2017.43 2041.43 2038.23 2031.65 2002.31 2054.59
[911] 2065.26 2065.79 2063.12 2068.81 2072.37 2083.04 2100.64 2092.28
2098.15 2081.08 2087.48 2090.50 2080.01 2090.68
[925] 2085.17 2082.33 2085.53 2119.31 2112.91 2105.26 2102.06 2106.51
2107.75 2150.25 2158.96 2156.47 2126.24 2133.36
[939] 2133.18 2140.47 2159.85 2137.27 2181.19 2183.50 2170.34 2173.36
2165.18 2140.83 2149.89 2148.65 2150.96 2156.83
[953] 2170.34 2145.80 2124.64 2127.49 2118.24 2114.69 2067.03 2065.08
2077.17 2038.58 2052.45 2062.41 2065.97 2077.70
[967] 2092.28 2074.68 2081.44 2101.53 2114.51 2101.88 2092.28 2123.76
2149.36 2153.63 2141.71 2143.49 2139.58 2143.49
[981] 2134.25 2133.00 2150.71 2172.68 2166.07 2164.64 2160.36 2168.93
2162.68 2166.43 2182.68 2168.57 2144.64 2177.68
[995] 2190.54 2194.29 2199.46 2193.21 2206.43 2222.32
[ reached getOption("max.print") -- omitted 6797 entries ]
> ur.df(data,type = "drift")

###############################################################
# Augmented Dickey-Fuller Test Unit Root / Cointegration Test #
###############################################################

The value of the test statistic is: -0.3721 2.0102

> df@teststat
tau2 phi1
statistic -6.629055 21.9753
> df@cval
1pct 5pct 10pct
tau2 -3.51 -2.89 -2.58
phi1 6.70 4.71 3.86
> ts.plot(data)
> log_ret= c(rep(0,l))
>
> for(i in 2:l){
+ log_ret[i]= log(data[i])-log(data[(i-1)])
+ }
> log_ret= log_ret[-1]
> df= ur.df(log_ret,type = "drift")
> df@teststat
tau2 phi1
statistic -67.23783 2260.463
> df@cval
1pct 5pct 10pct
tau2 -3.43 -2.86 -2.57
phi1 6.43 4.59 3.78
> ts.plot(log_ret)
> kutosis(log_ret)
Error in kutosis(log_ret) : could not find function "kutosis"
> kurtosis(log_ret)
[1] 44.94525
> Box.test(log_ret,type = "Ljung-Box")

Box-Ljung test

data: log_ret
X-squared = 9.4741, df = 1, p-value = 0.002084

> acf(log_ret)
> pacf(log_ret)
> AutoArimaModel=auto.arima(log_ret)
> AutoArimaModel
Series: log_ret
ARIMA(0,0,2) with non-zero mean

Coefficients:
ma1 ma2 mean
-0.0362 -0.0578 3e-04
s.e. 0.0113 0.0115 1e-04

sigma^2 estimated as 0.000126: log likelihood=23940.18


AIC=-47872.36 AICc=-47872.36 BIC=-47844.52

FTSF Session 5 R

> library("forecast")
> library("urca")
> library("TSA")
Registered S3 methods overwritten by 'TSA':
method from
fitted.Arima forecast
plot.Arima forecast

Attaching package: ‘TSA’

The following objects are masked from ‘package:moments’:

kurtosis, skewness
The following objects are masked from ‘package:stats’:

acf, arima

The following object is masked from ‘package:utils’:

tar

Warning message:
package ‘TSA’ was built under R version 4.0.3
> e_t= rnorm(100,0,1)
> y_t= rnorm(100,0,1)
> timeseries= c(rep(0,100))
> timeseries[1]= 5+y_t[1]
> for(i in 2:100){
+ timeseries[i]= 5+ 0.5*timeseries[i-1]+ e_t[i]+ 0.6*e_t[i-1]
+ }
> ts.plot(timeseries)
> ur.df(timeseries,type = "drift")

###############################################################
# Augmented Dickey-Fuller Test Unit Root / Cointegration Test #
###############################################################

The value of the test statistic is: -4.8895 11.9538


> df@teststat
tau2 phi1
statistic -67.23783 2260.463
> df@cval
1pct 5pct 10pct
tau2 -3.43 -2.86 -2.57
phi1 6.43 4.59 3.78
> acf(timeseries)
> pacf(timeseries)
> eacf(timeseries)
AR/MA
0 1 2 3 4 5 6 7 8 9 10 11 12 13
0 x x x o o x x x o o o o o o
1 x o o o o o x x o o o o o o
2 o x o o o o o x o o o o o o
3 x x o o o o o o o o o o o o
4 x x o o o o o o o o o o o o
5 x x x o o o o o o o o o o o
6 o x x o o o o o o o o o o o
7 o o x o o o o o o o o o o o
> AutoArimaModel=auto.arima(timeseries)
> AutoArimaModel
Series: timeseries
ARIMA(1,0,1) with non-zero mean

Coefficients:
ar1 ma1 mean
0.6574 0.4983 9.6784
s.e. 0.0921 0.1068 0.4320

sigma^2 estimated as 1.038: log likelihood=-142.93


AIC=293.87 AICc=294.29 BIC=304.29
> 0.6574/0.0921
[1] 7.137894
> 0.4983/0.1068
[1] 4.66573

Exchange rate data session5 R

> library("forecast")
> library("urca")
> library("TSA")
> library("qrmdata")
> data= data("JPY_USD")
> data= JPY_USD
> l= length(data)
> #reading the data
> data= data$`JPY/USD`
> # making numeric
> data= as.numeric(data)
> l
[1] 5844
> ts.plot(data)
> a= ur.df(data,type = "drift")
> a= ur.df(data,type = "drift")
> a

###############################################################
# Augmented Dickey-Fuller Test Unit Root / Cointegration Test #
###############################################################

The value of the test statistic is: -1.2061 0.7966

> log_ret= c(rep(0,l))


>
> for(i in 2:l){
+ log_ret[i]= log(data[i])-log(data[(i-1)])
+ }
> log_ret= log_ret[-1]
> df= ur.df(log_ret,type = "drift")
> df

###############################################################
# Augmented Dickey-Fuller Test Unit Root / Cointegration Test #
###############################################################

The value of the test statistic is: -50.0321 1251.604

> ts.plot(log_ret)
> Box.test(log_ret,type = "Ljung-Box")

Box-Ljung test

data: log_ret
X-squared = 88.708, df = 1, p-value < 2.2e-16

> acf(log_ret)
> pacf(log_ret)
> eacf(log_ret)
AR/MA
0 1 2 3 4 5 6 7 8 9 10 11 12 13
0 x x o x o o o o o o o o o x
1 x x o x o o o o o o o o o x
2 x x x o o o o o o o o o o x
3 x x x o o o o o o o o o o o
4 x x x x x o o o o o o o o o
5 x x x x x o o o o o o o o x
6 x x x x x o o o o o o o o o
7 x x x x x x o o o o o o o o
> AutoArimaModel=auto.arima(log_ret)
> AutoArimaModel
Series: log_ret
ARIMA(3,0,1) with zero mean

Coefficients:
ar1 ar2 ar3 ma1
0.6692 -0.0518 -0.0351 -0.5478
s.e. 0.2035 0.0297 0.0131 0.2035
sigma^2 estimated as 2.126e-05: log likelihood=23142
AIC=-46274 AICc=-46273.99 BIC=-46240.63
> Box.test(AutoArimaModel$residuals,type = "Ljung-Box")

Box-Ljung test

data: AutoArimaModel$residuals
X-squared = 0.0011124, df = 1, p-value = 0.9734

Forecasting using ARIMA Model R

> library("forecast")
Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
Warning message:
package ‘forecast’ was built under R version 4.0.3
> library("urca")
Warning message:
package ‘urca’ was built under R version 4.0.3
> e_t= rnorm(100,0,1)
> y_t= rnorm(100,0,1)
> timeseries= c(rep(0,100))
> timeseries[1]= 5+y_t[1]
>
> for(i in 2:100){
+ timeseries[i]= 5+ 0.5*timeseries[i-1]+ e_t[i]+ 0.6*e_t[i-1]
+ }
>
> ts.plot(timeseries)
> ur.df(timeseries,type = "drift")

###############################################################
# Augmented Dickey-Fuller Test Unit Root / Cointegration Test #
###############################################################

The value of the test statistic is: -5.9188 17.5208

> AutoArimaModel=auto.arima(train_series)
Error in as.ts(x) : object 'train_series' not found
> train_series=timeseries[1:90]
> test_series=timeseries[91:100]
> AutoArimaModel=auto.arima(train_series)
> AutoArimaModel
Series: train_series
ARIMA(1,0,1) with non-zero mean

Coefficients:
ar1 ma1 mean
0.5163 0.6327 9.6035
s.e. 0.1145 0.0896 0.3420

sigma^2 estimated as 0.9755: log likelihood=-125.76


AIC=259.51 AICc=259.98 BIC=269.51
> forecast1=predict(AutoArimaModel, 10)
> forecast1
$pred
Time Series:
Start = 91
End = 100
Frequency = 1
[1] 9.446463 9.522415 9.561631 9.581880 9.592335 9.597733 9.600521
9.601960 9.602703 9.603087
$se
Time Series:
Start = 91
End = 100
Frequency = 1
[1] 0.9876791 1.5044913 1.6145809 1.6426857 1.6500976 1.6520680 1.6525929
1.6527328 1.6527701 1.6527801

> predi= forecast1$pred


> predi
Time Series:
Start = 91
End = 100
Frequency = 1
[1] 9.446463 9.522415 9.561631 9.581880 9.592335 9.597733 9.600521
9.601960 9.602703 9.603087
> se= c(rep(0,10))
> for(i in 1:10){
+ se[i]= (test_series[i]- predi[i])^2
+ }
>
> mse= sum(se[1:10])/10
> mse
[1] 1.273267
> auto.arima(timeseries)
Series: timeseries
ARIMA(1,0,1) with non-zero mean

Coefficients:
ar1 ma1 mean
0.5056 0.6414 9.5476
s.e. 0.1088 0.0840 0.3135

sigma^2 estimated as 0.9348: log likelihood=-137.69


AIC=283.39 AICc=283.81 BIC=293.81
> predict= c(rep(0,10))
>
>
> for(q in 1:10){
+
+ start= q
+ end= 89+q
+
+
+ train_data= timeseries[start:end]
+ arima_fit= arima(train_data,order = c(1,0,1))
+ rolling_forecast= predict(arima_fit,1)
+ predict[q]= rolling_forecast$pred
+ }
> predict
[1] 9.446463 9.287748 9.377417 8.733468 9.832307 10.382955 9.789861
10.352747 8.879625 7.269057
> se_1= c(rep(0,10))
> for(i in 1:10){
+ se_1[i]= (test_series[i]- predict[i])^2
+ }
>
> mse_1= sum(se_1[1:10])/10
> mse_1
[1] 0.5943927

2nd data example within this only

> data= data("JPY_USD")


> data= JPY_USD
>
> l= length(data)
> #reading the data
> data= data$`JPY/USD`
> # making numeric
> data= as.numeric(data)
> data
[1] 0.009785693 0.009789525 0.009838646 0.009682417 0.009588647
0.009502090 0.009493971 0.009502993 0.009514748
[10] 0.009508415 0.009429514 0.009440196 0.009425071 0.009455371
0.009431293 0.009445546 0.009537434 0.009460738
[19] 0.009491268 0.009497578 0.009541985 0.009541985 0.009501188
0.009463424 0.009433072 0.009461633 0.009510223
[28] 0.009334453 0.009339684 0.009339684 0.009310120 0.009277298
0.009237022 0.009290227 0.009330969 0.009313589
[37] 0.009325748 0.009201325 0.009132420 0.009132420 0.009154994
0.009190332 0.009181893 0.009181893 0.009184423
[46] 0.009168424 0.009142439 0.009036689 0.009008197 0.009004953
0.009016320 0.008980692 0.009020386 0.008988764
[55] 0.008990380 0.009071940 0.009067005 0.009063718 0.009134923
0.009074410 0.009334453 0.009267841 0.009283327
[64] 0.009265265 0.009270418 0.009305788 0.009420631 0.009420631
0.009375586 0.009413537 0.009405568 0.009405568
[73] 0.009466111 0.009508415 0.009508415 0.009475081 0.009368559
0.009368559 0.009357163 0.009399380 0.009351038
[82] 0.009344921 0.009312721 0.009312721 0.009312721 0.009348415
0.009368559 0.009446439 0.009467904 0.009479572
[91] 0.009772305 0.009710623 0.009704027 0.009536525 0.009530163
0.009531980 0.009548362 0.009480470 0.009492169
[100] 0.009485866 0.009395847 0.009346668 0.009452689 0.009452689
0.009541985 0.009524717 0.009564802 0.009573042
[109] 0.009546539 0.009539254 0.009458948 0.009449117 0.009463424
0.009484966 0.009453583 0.009441979 0.009409108
[118] 0.009400263 0.009247272 0.009246417 0.009266982 0.009192021
0.009215740 0.009166743 0.009248983 0.009214891
[127] 0.009181893 0.009211496 0.009167583 0.009155832 0.009130752
0.009212345 0.009212345 0.009218289 0.009217439
[136] 0.009135757 0.009125753 0.009132420 0.009209799 0.009351912
0.009347542 0.009342302 0.009343175 0.009387027
[145] 0.009269559 0.009269559 0.009269559 0.009269559 0.009269559
0.009269559 0.009269559 0.009269559 0.009269559
[154] 0.009269559 0.009269559 0.009269559 0.009269559 0.009269559
0.009269559 0.009269559 0.009269559 0.009269559
[163] 0.009269559 0.009360666 0.009347542 0.009374707 0.009380863
0.009417083 0.009386146 0.009391435 0.009456265
[172] 0.009478673 0.009467904 0.009584971 0.009554749 0.009526531
0.009502993 0.009463424 0.009491268 0.009477775
[181] 0.009505703 0.009435743 0.009435743 0.009435743 0.009464320
0.009425071 0.009337940 0.009305788 0.009266123
[190] 0.009264406 0.009275577 0.009339684 0.009331840 0.009235316
0.009239582 0.009272137 0.009272137 0.009272137
[199] 0.009243853 0.009231905 0.009233610 0.009292817 0.009181893
0.009170946 0.009188643 0.009189487 0.009160026
[208] 0.009154156 0.009154156 0.009124920 0.009124088 0.009128252
0.009144947 0.009149968 0.009173470 0.009225943
[217] 0.009208103 0.009205560 0.009208951 0.009170105 0.009208103
0.009269559 0.009188643 0.009206408 0.009210648
[226] 0.009208103 0.009133254 0.009166743 0.009200478 0.009211496
0.009218289 0.009230201 0.009229349 0.009203866
[235] 0.009237875 0.009334453 0.009355412 0.009351912 0.009358914
0.009356287 0.009392317 0.009421519 0.009394082
[244] 0.009374707 0.009439305 0.009441979 0.009441088 0.009446439
0.009449117 0.009440196 0.009517465 0.009421519
[253] 0.009430404 0.009429514 0.009429514 0.009350164 0.009333582
0.009298001 0.009321402 0.009337068 0.009338812
[262] 0.009351912 0.009348415 0.009385265 0.009375586 0.009259259
0.009260117 0.009256688 0.009283327 0.009292817
[271] 0.009313589 0.009296272 0.009296272 0.009296272 0.009240436
0.009188643 0.009200478 0.009144947 0.009180207
[280] 0.009191176 0.009188643 0.009180207 0.009188643 0.009274717
0.009293680 0.009295408 0.009277298 0.009272137
[289] 0.009274717 0.009250694 0.009258402 0.009272137 0.009243853
0.009185267 0.009185267 0.009182736 0.009233610
[298] 0.009268700 0.009242998 0.009231053 0.009204713 0.009207255
0.009201325 0.009177680 0.009165063 0.009243853
[307] 0.009248983 0.009346668 0.009337068 0.009337068 0.009308387
0.009345794 0.009321402 0.009310987 0.009263548
[316] 0.009267841 0.009260117 0.009289364 0.009247272 0.009182736
0.009172629 0.009187799 0.009186955 0.009188643
[325] 0.009103323 0.009074410 0.009070295 0.009062897 0.008982305
0.008986341 0.008995233 0.009035872 0.009078529
[334] 0.008994423 0.009059612 0.008991997 0.008980692 0.008971828
0.009013881 0.008995233 0.009063718 0.009045681
[343] 0.008982305 0.009013069 0.008979079 0.009026085 0.008973439
0.008900757 0.008915835 0.008882572 0.008886519
[352] 0.008892841 0.008915835 0.008892051 0.008874689 0.008902341
0.008858181 0.008858181 0.008857396 0.008864462
[361] 0.008802817 0.008747376 0.008736677 0.008738967 0.008738967
0.008738967 0.008738203 0.008739731 0.008799718
[370] 0.008643042 0.008580745 0.008576329 0.008574123 0.008615491
0.008562377 0.008583691 0.008500510 0.008437395
[379] 0.008438819 0.008450228 0.008411136 0.008500510 0.008412552
0.008473140 0.008533151 0.008533151 0.008542628
[388] 0.008596974 0.008543358 0.008487523 0.008562377 0.008522969
0.008532423 0.008523696 0.008568980 0.008630362
[397] 0.008592542 0.008654262 0.008645284 0.008643789 0.008646031
0.008716876 0.008712319 0.008594757 0.008570449
[406] 0.008509190 0.008512087 0.008506295 0.008514986 0.008574123
0.008585902 0.008664760 0.008637070 0.008637070
[415] 0.008637070 0.008619947 0.008638563 0.008579272 0.008552857
0.008627383 0.008634833 0.008632597 0.008585165
[424] 0.008611039 0.008522969 0.008514986 0.008401243 0.008390670
0.008390670 0.008396306 0.008409722 0.008334028
[433] 0.008354917 0.008366101 0.008366101 0.008382230 0.008304958
0.008350731 0.008258320 0.008171938 0.008128760
[442] 0.008128760 0.008128760 0.008128760 0.008178621 0.008103071
0.008091924 0.008142659 0.008146640 0.008140671
[451] 0.008145312 0.008184646 0.008171270 0.008090615 0.007918283
0.007918283 0.007918283 0.007891414 0.007964954
[460] 0.007971939 0.008048938 0.008073632 0.008084074 0.008084074
0.007998080 0.008044405 0.008014105 0.008088652
[469] 0.008050233 0.008050233 0.008051530 0.008027615 0.008105698
0.008175278 0.008235197 0.008171270 0.008171270
[478] 0.008196721 0.008251506 0.008187996 0.008175946 0.008119519
0.008065167 0.008059966 0.008059966 0.008088652
[487] 0.008194706 0.008206812 0.008239947 0.008246743 0.008244023
0.008242664 0.008255593 0.008244703 0.008185986
[496] 0.008149959 0.008163265 0.008163265 0.008164598 0.008112274
0.008099133 0.008090615 0.008162599 0.008093889
[505] 0.008093234 0.008094544 0.008148631 0.008147967 0.008346549
0.008340284 0.008289125 0.008288438 0.008288438
[514] 0.008259002 0.008325008 0.008308408 0.008392078 0.008384338
0.008384338 0.008387151 0.008384338 0.008311861
[523] 0.008310480 0.008322930 0.008268563 0.008271299 0.008270615
0.008196721 0.008217602 0.008196721 0.008239947
[532] 0.008122817 0.008149959 0.008143986 0.008107670 0.008132726
0.008081461 0.008026326 0.008033419 0.008033419
[541] 0.008037293 0.008080808 0.008072328 0.008037939 0.008020533
0.008017960 0.008016675 0.008019246 0.008043758
[550] 0.008038585 0.008032129 0.007949758 0.007937138 0.007951654
0.007952919 0.007971939 0.007975754 0.008042464
[559] 0.008069722 0.008006405 0.008006405 0.008016032 0.007970033
0.007998080 0.008071676 0.008101758 0.008135373
[568] 0.008128760 0.008128099 0.008036647 0.008069722 0.008087343
0.008087343 0.008097822 0.008094544 0.008101758
[577] 0.007995523 0.007996162 0.008032774 0.008086689 0.008084074
0.008078197 0.008078197 0.008073632 0.008095200
[586] 0.008088652 0.008204792 0.008202773 0.008194706 0.008192021
0.008163932 0.008212203 0.008373106 0.008337502
[595] 0.008319468 0.008320160 0.008317392 0.008285691 0.008364701
0.008302200 0.008341675 0.008328475 0.008318775
[604] 0.008327781 0.008336807 0.008322930 0.008320852 0.008371704
0.008419635 0.008418217 0.008410429 0.008419635
[613] 0.008393487 0.008286377 0.008265146 0.008329863 0.008329863
0.008325701 0.008269931 0.008396306 0.008396306
[622] 0.008411844 0.008519339 0.008519339 0.008519339 0.008489685
0.008522969 0.008504848 0.008601411 0.008569715
[631] 0.008572653 0.008510638 0.008505571 0.008499788 0.008492569
0.008363302 0.008370302 0.008365401 0.008355615
[640] 0.008318084 0.008278146 0.008287064 0.008297378 0.008300133
0.008298755 0.008302200 0.008339588 0.008316008
[649] 0.008309098 0.008229775 0.008244703 0.008257638 0.008262414
0.008269247 0.008248103 0.008248783 0.008255593
[658] 0.008252187 0.008246063 0.008246063 0.008160601 0.008154611
0.008137359 0.008136034 0.008148631 0.008143986
[667] 0.008147303 0.008198065 0.008198737 0.008165932 0.008198065
0.008218953 0.008220304 0.008218277 0.008212203
[676] 0.008252187 0.008269931 0.008322237 0.008311170 0.008308408
0.008303579 0.008307718 0.008218953 0.008225037
[685] 0.008170602 0.008136697 0.008134711 0.008140671 0.008121498
0.008160601 0.008124137 0.008067769 0.008046994
[694] 0.008045052 0.008045700 0.008063216 0.008069071 0.008124137
0.008077544 0.008103071 0.008101102 0.008108985
[703] 0.008058018 0.008051530 0.008052827 0.008017317 0.007964954
0.007962417 0.007963686 0.007932730 0.007926443
[712] 0.007945336 0.007935248 0.007847446 0.007849910 0.007841292
0.007838834 0.007823502 0.007813110 0.007777864
[721] 0.007713074 0.007722604 0.007716645 0.007701194 0.007641755
0.007647599 0.007594168 0.007626020 0.007626020
[730] 0.007626020 0.007595321 0.007600517 0.007568304 0.007594744
0.007636502 0.007634753 0.007638252 0.007633005
[739] 0.007535795 0.007525587 0.007544323 0.007570023 0.007565441
0.007560293 0.007572889 0.007612088 0.007586678
[748] 0.007544892 0.007542616 0.007543185 0.007547739 0.007544892
0.007467702 0.007442691 0.007419498 0.007442137
[757] 0.007441584 0.007423905 0.007490076 0.007500188 0.007526720
0.007422252 0.007513713 0.007516536 0.007507508
[766] 0.007556865 0.007470492 0.007481110 0.007485030 0.007427213
0.007421701 0.007423354 0.007493443 0.007537499
[775] 0.007495128 0.007570596 0.007542047 0.007535227 0.007542047
0.007534659 0.007482230 0.007475518 0.007451565
[784] 0.007461016 0.007459347 0.007460460 0.007473842 0.007426662
0.007442691 0.007482790 0.007500188 0.007492320
[793] 0.007490076 0.007560865 0.007566013 0.007654038 0.007867202
0.007779679 0.007776654 0.007781496 0.007791196
[802] 0.007756147 0.007721411 0.007735149 0.007744134 0.007748334
0.007748334 0.007613247 0.007574036 0.007606298
[811] 0.007580352 0.007527853 0.007524454 0.007523888 0.007497376
0.007523322 0.007535795 0.007538636 0.007530688
[820] 0.007539204 0.007533524 0.007494566 0.007496814 0.007535795
0.007556865 0.007594168 0.007596475 0.007591862
[829] 0.007600517 0.007631258 0.007645844 0.007602828 0.007577480
0.007580352 0.007580352 0.007572889 0.007621951
[838] 0.007653452 0.007694083 0.007676364 0.007675186 0.007668124
0.007693491 0.007679902 0.007717240 0.007770612
[847] 0.007823502 0.007816164 0.007821054 0.007809449 0.007779679
0.007841907 0.007817997 0.007875876 0.007878358
[856] 0.007878358 0.007863490 0.007816775 0.007756147 0.007789375
0.007835148 0.007833921 0.007834535 0.007821054
[865] 0.007779679 0.007835762 0.007807620 0.007939659 0.007950390
0.007933989 0.007973846 0.008053475 0.008050233
[874] 0.008000640 0.008017960 0.008019889 0.008012179 0.008015390
0.008026326 0.008034710 0.008103071 0.008050882
[883] 0.008043758 0.008048290 0.008089960 0.008054772 0.008037293
0.008058667 0.008039878 0.008037939 0.008038585
[892] 0.008016675 0.007980846 0.007954184 0.008007046 0.008054124
0.008051530 0.008050882 0.008041171 0.008039878
[901] 0.008070374 0.008097822 0.008235875 0.008240626 0.008238590
0.008206138 0.008240626 0.008329863 0.008364001
[910] 0.008369602 0.008364701 0.008360505 0.008357012 0.008338197
0.008347245 0.008331945 0.008306338 0.008320160
[919] 0.008331251 0.008446659 0.008472422 0.008498343 0.008549932
0.008557980 0.008555784 0.008555784 0.008589589
[928] 0.008625151 0.008596235 0.008577801 0.008629617 0.008631852
0.008632597 0.008604371 0.008506295 0.008566044
[937] 0.008591065 0.008416800 0.008412552 0.008417508 0.008353521
0.008319468 0.008338893 0.008381527 0.008409014
[946] 0.008408307 0.008413967 0.008354917 0.008280202 0.008316700
0.008264463 0.008326395 0.008322237 0.008325008
[955] 0.008400538 0.008441668 0.008522969 0.008520065 0.008494733
0.008494012 0.008494733 0.008428860 0.008412552
[964] 0.008435259 0.008336112 0.008361204 0.008356313 0.008361903
0.008352126 0.008460953 0.008422471 0.008464534
[973] 0.008450942 0.008423890 0.008443094 0.008462385 0.008537522
0.008472422 0.008448087 0.008434548 0.008433837
[982] 0.008433125 0.008411136 0.008338893 0.008310480 0.008331945
0.008214227 0.008213552 0.008206138 0.008179290
[991] 0.008198737 0.008234519 0.008231808 0.008110958 0.008108327
0.008103728 0.008067118 0.008106355 0.008136697
[1000] 0.008179959
[ reached getOption("max.print") -- omitted 4844 entries ]
> ur.df(data,type = "drift")
Error in ur.df(data, type = "drift") : could not find function "ur.df"
> log_ret= c(rep(0,l))
>
> for(i in 2:l){
+ log_ret[i]= log(data[i])-log(data[(i-1)])
+ }
> log_ret= log_ret[-1]
> log_ret
[1] 3.915044e-04 5.005163e-03 -1.600659e-02 -9.731734e-03 -9.067976e-
03 -8.548227e-04 9.498481e-04 1.236153e-03
[9] -6.658106e-04 -8.332592e-03 1.132182e-03 -1.603547e-03 3.209670e-
03 -2.549697e-03 1.510147e-03 9.681169e-03
[17] -8.074136e-03 3.221835e-03 6.646096e-04 4.664676e-03
0.000000e+00 -4.284701e-03 -3.982558e-03 -3.212399e-03
[25] 3.023148e-03 5.122379e-03 -1.865515e-02 5.602241e-04
0.000000e+00 -3.170461e-03 -3.531602e-03 -4.350852e-03
[33] 5.743416e-03 4.375967e-03 -1.864455e-03 1.304753e-03 -1.343172e-
02 -7.516765e-03 0.000000e+00 2.468798e-03
[41] 3.852509e-03 -9.186111e-04 0.000000e+00 2.754947e-04 -1.743520e-
03 -2.838180e-03 -1.163438e-02 -3.157850e-03
[49] -3.602630e-04 1.261489e-03 -3.959332e-03 4.410250e-03 -3.511777e-
03 1.797914e-04 9.031038e-03 -5.441683e-04
[57] -3.626145e-04 7.825336e-03 -6.646358e-03 2.825385e-02 -7.161822e-
03 1.669604e-03 -1.947601e-03 5.560704e-04
[65] 3.808113e-03 1.226550e-02 0.000000e+00 -4.793017e-03 4.039650e-
03 -8.468596e-04 0.000000e+00 6.416327e-03
[73] 4.458999e-03 0.000000e+00 -3.511939e-03 -1.130594e-02
0.000000e+00 -1.217172e-03 4.501555e-03 -5.156342e-03
[81] -6.543585e-04 -3.451657e-03 0.000000e+00 0.000000e+00 3.825524e-
03 2.152450e-03 8.278504e-03 2.269719e-03
[89] 1.231586e-03 3.041328e-02 -6.331910e-03 -6.795127e-04 -1.741182e-
02 -6.673340e-04 1.906214e-04 1.717230e-03
[97] -7.135752e-03 1.233221e-03 -6.642312e-04 -9.535121e-03 -5.247880e-
03 1.127938e-02 0.000000e+00 9.402225e-03
[105] -1.811336e-03 4.199682e-03 8.612029e-04 -2.772336e-03 -7.634317e-
04 -8.454099e-03 -1.039943e-03 1.513003e-03
[113] 2.273805e-03 -3.314240e-03 -1.228211e-03 -3.487444e-03 -9.404684e-
04 -1.640909e-02 -9.246845e-05 2.221606e-03
[121] -8.121872e-03 2.577084e-03 -5.330895e-03 8.931508e-03 -3.692766e-
03 -3.587365e-03 3.218838e-03 -4.778542e-03
[129] -1.282639e-03 -2.742984e-03 8.896285e-03 0.000000e+00 6.450721e-
04 -9.217864e-05 -8.901183e-03 -1.095690e-03
[137] 7.303269e-04 8.437321e-03 1.531281e-02 -4.674863e-04 -5.606953e-
04 9.342738e-05 4.682533e-03 -1.259286e-02
[145] 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
[153] 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
[161] 0.000000e+00 0.000000e+00 9.780712e-03 -1.403115e-03 2.901944e-
03 6.564449e-04 3.853569e-03 -3.290559e-03
[169] 5.633274e-04 6.879356e-03 2.366865e-03 -1.136794e-03 1.228879e-
02 -3.158048e-03 -2.957594e-03 -2.473836e-03
[177] -4.172600e-03 2.937973e-03 -1.422678e-03 2.942435e-03 -7.387097e-
03 0.000000e+00 0.000000e+00 3.024005e-03
[185] -4.155654e-03 -9.287557e-03 -3.449083e-03 -4.271527e-03 -1.853053e-
04 1.205099e-03 6.887592e-03 -8.402185e-04
[193] -1.039742e-02 4.618724e-04 3.517219e-03 0.000000e+00
0.000000e+00 -3.055134e-03 -1.293303e-03 1.846552e-04
[201] 6.391574e-03 -1.200827e-02 -1.192934e-03 1.927756e-03 9.189065e-
05 -3.211159e-03 -6.409963e-04 0.000000e+00
[209] -3.198833e-03 -9.124504e-05 4.563085e-04 1.827319e-03 5.488474e-
04 2.565279e-03 5.703787e-03 -1.935574e-03
[217] -2.762049e-04 3.682902e-04 -4.227170e-03 4.135085e-03 6.651909e-
03 -8.767533e-03 1.931479e-03 4.604264e-04
[225] -2.762813e-04 -8.161813e-03 3.659991e-03 3.673436e-03 1.196778e-
03 7.371913e-04 1.291394e-03 -9.229775e-05
[233] -2.764979e-03 3.688340e-03 1.040032e-02 2.242782e-03 -3.741465e-
04 7.484330e-04 -2.807280e-04 3.843454e-03
[241] 3.104278e-03 -2.916414e-03 -2.064565e-03 6.867061e-03 2.832193e-
04 -9.441533e-05 5.666258e-04 2.834333e-04
[249] -9.444655e-04 8.151704e-03 -1.013218e-02 9.425960e-04 -9.429959e-
05 0.000000e+00 -8.450755e-03 -1.774955e-03
[257] -3.819465e-03 2.513617e-03 1.679262e-03 1.867588e-04 1.401804e-
03 -3.740065e-04 3.934063e-03 -1.031847e-03
[265] -1.248502e-02 9.259688e-05 -3.703361e-04 2.873698e-03 1.021688e-
03 2.232767e-03 -1.860985e-03 0.000000e+00
[273] 0.000000e+00 -6.024394e-03 -5.620839e-03 1.287238e-03 -6.053954e-
03 3.848273e-03 1.194140e-03 -2.756973e-04
[281] -9.184424e-04 9.184424e-04 9.323862e-03 2.042522e-03 1.858909e-
04 -1.950133e-03 -5.564830e-04 2.782028e-04
[289] -2.593555e-03 8.329092e-04 1.482443e-03 -3.055134e-03 -6.358003e-
03 0.000000e+00 -2.755200e-04 5.524876e-03
[297] 3.792964e-03 -2.776751e-03 -1.293183e-03 -2.857540e-03 2.761795e-
04 -6.443003e-04 -2.573058e-03 -1.375705e-03
[305] 8.560041e-03 5.547850e-04 1.050635e-02 -1.027605e-03
0.000000e+00 -3.076495e-03 4.010638e-03 -2.613405e-03
[313] -1.117943e-03 -5.107975e-03 4.632847e-04 -8.337580e-04 3.153406e-
03 -4.541460e-03 -7.003346e-03 -1.101322e-03
[321] 1.652438e-03 -9.187377e-05 1.837560e-04 -9.328767e-03 -3.181098e-
03 -4.536176e-04 -8.159935e-04 -8.932256e-03
[329] 4.492161e-04 9.889864e-04 4.507761e-03 4.709727e-03 -9.307436e-
03 7.221552e-03 -7.491348e-03 -1.258088e-03
[337] -9.873884e-04 4.676268e-03 -2.071047e-03 7.584686e-03 -1.992033e-
03 -7.030856e-03 3.419114e-03 -3.778342e-03
[345] 5.221474e-03 -5.849812e-03 -8.132669e-03 1.692575e-03 -3.737657e-
03 4.442273e-04 7.111744e-04 2.582255e-03
[353] -2.671180e-03 -1.954340e-03 3.110975e-03 -4.972926e-03
0.000000e+00 -8.857788e-05 7.974835e-04 -6.978519e-03
[361] -6.318027e-03 -1.223883e-03 2.621347e-04 0.000000e+00
0.000000e+00 -8.738585e-05 1.747793e-04 6.840332e-03
[369] -1.796508e-02 -7.233928e-03 -5.147122e-04 -2.572568e-04 4.813073e-
03 -6.183993e-03 2.486177e-03 -9.737841e-03
[377] -7.452609e-03 1.687621e-04 1.351123e-03 -4.636859e-03 1.056958e-
02 -1.040135e-02 7.176357e-03 7.057552e-03
[385] 0.000000e+00 1.109925e-03 6.341610e-03 -6.256180e-03 -6.556842e-
03 8.780586e-03 -4.613027e-03 1.108600e-03
[393] -1.023367e-03 5.298705e-03 7.137666e-03 -4.391826e-03 7.157363e-
03 -1.037973e-03 -1.728907e-04 2.593473e-04
[401] 8.160476e-03 -5.228758e-04 -1.358564e-02 -2.832255e-03 -7.173387e-
03 3.404255e-04 -6.807352e-04 1.021277e-03
[409] 6.921034e-03 1.372802e-03 9.142724e-03 -3.200833e-03
0.000000e+00 0.000000e+00 -1.984556e-03 2.157312e-03
[417] -6.887080e-03 -3.083778e-03 8.675912e-03 8.631107e-04 -2.590114e-
04 -5.509656e-03 3.009331e-03 -1.028022e-02
[425] -9.370874e-04 -1.344800e-02 -1.259393e-03 0.000000e+00 6.714790e-
04 1.596572e-03 -9.041502e-03 2.503339e-03
[433] 1.337681e-03 0.000000e+00 1.926057e-03 -9.261257e-03 5.496350e-
03 -1.112783e-02 -1.051517e-02 -5.297702e-03
[441] 0.000000e+00 0.000000e+00 0.000000e+00 6.115230e-03 -9.280431e-
03 -1.376574e-03 6.250274e-03 4.886789e-04
[449] -7.329289e-04 5.700094e-04 4.817319e-03 -1.635591e-03 -9.919587e-
03 -2.153030e-02 0.000000e+00 0.000000e+00
[457] -3.399078e-03 9.275842e-03 8.765290e-04 9.612378e-03 3.063283e-
03 1.292616e-03 0.000000e+00 -1.069443e-02
[465] 5.775263e-03 -3.773741e-03 9.258953e-03 -4.760953e-03
0.000000e+00 1.610176e-04 -2.974637e-03 9.679837e-03
[473] 8.547408e-03 7.302597e-03 -7.792993e-03 0.000000e+00 3.109913e-
03 6.661483e-03 -7.726489e-03 -1.472754e-03
[481] -6.925518e-03 -6.716594e-03 -6.450053e-04 0.000000e+00 3.552688e-
03 1.302632e-02 1.476136e-03 4.029445e-03
[489] 8.243344e-04 -3.298153e-04 -1.648669e-04 1.567334e-03 -1.320023e-
03 -7.147289e-03 -4.410691e-03 1.631322e-03
[497] 0.000000e+00 1.632786e-04 -6.429320e-03 -1.621140e-03 -1.052333e-
03 8.857886e-03 -8.453273e-03 -8.093562e-05
[505] 1.618778e-04 6.659653e-03 -8.148299e-05 2.407967e-02 -7.509074e-
04 -6.152842e-03 -8.288781e-05 0.000000e+00
[513] -3.557692e-03 7.960241e-03 -1.996009e-03 1.002012e-02 -9.227027e-
04 0.000000e+00 3.354298e-04 -3.354298e-04
[521] -8.681914e-03 -1.662234e-04 1.497006e-03 -6.553593e-03 3.307972e-
04 -8.270957e-05 -8.974578e-03 2.544217e-03
[529] -2.544217e-03 5.259710e-03 -1.431693e-02 3.335913e-03 -7.332275e-
04 -4.469190e-03 3.085670e-03 -6.323491e-03
[537] -6.845756e-03 8.832859e-04 0.000000e+00 4.821213e-04 5.399538e-
03 -1.049954e-03 -4.269208e-03 -2.167892e-03
[545] -3.207699e-04 -1.603463e-04 3.207184e-04 3.051966e-03 -6.432937e-
04 -8.035356e-04 -1.030813e-02 -1.588689e-03
[553] 1.827210e-03 1.590457e-04 2.388726e-03 4.784308e-04 8.329377e-
03 3.383553e-03 -7.877221e-03 0.000000e+00
[561] 1.201682e-03 -5.754952e-03 3.512978e-03 9.159633e-03 3.719881e-
03 4.140456e-03 -8.132065e-04 -8.128429e-05
[569] -1.131508e-02 4.107113e-03 2.181202e-03 0.000000e+00 1.294813e-
03 -4.048091e-04 8.907965e-04 -1.319939e-02
[577] 7.995842e-05 4.568231e-03 6.689527e-03 -3.234153e-04 -7.273021e-
04 0.000000e+00 -5.653140e-04 2.667854e-03
[585] -8.091925e-04 1.425628e-02 -2.461135e-04 -9.838486e-04 -3.277345e-
04 -3.434743e-03 5.895374e-03 1.940359e-02
[593] -4.261192e-03 -2.165404e-03 8.319814e-05 -3.327510e-04 -3.818700e-
03 9.490581e-03 -7.500035e-03 4.743487e-03
[601] -1.583664e-03 -1.165307e-03 1.082026e-03 1.083198e-03 -1.665973e-
03 -2.496567e-04 6.092745e-03 5.709024e-03
[609] -1.683785e-04 -9.255754e-04 1.093954e-03 -3.110422e-03 -1.284314e-
02 -2.565483e-03 7.799575e-03 0.000000e+00
[617] -4.996669e-04 -6.721180e-03 1.516569e-02 0.000000e+00 1.848895e-
03 1.269805e-02 0.000000e+00 0.000000e+00
[625] -3.486843e-03 3.912901e-03 -2.128476e-03 1.128989e-02 -3.691784e-
03 3.428474e-04 -7.260335e-03 -5.955673e-04
[633] -6.802143e-04 -8.496177e-04 -1.533824e-02 8.366801e-04 -5.857496e-
04 -1.170471e-03 -4.501883e-03 -4.812888e-03
[641] 1.076738e-03 1.243833e-03 3.319502e-04 -1.659889e-04 4.150239e-
04 4.493268e-03 -2.831448e-03 -8.312552e-04
[649] -9.592400e-03 1.812192e-03 1.567722e-03 5.782018e-04 8.265830e-
04 -2.560186e-03 8.248443e-05 8.252187e-04
[657] -4.126945e-04 -7.424212e-04 0.000000e+00 -1.041804e-02 -7.341845e-
04 -2.117955e-03 -1.627339e-04 1.547043e-03
[665] -5.702416e-04 4.072822e-04 6.211200e-03 8.198401e-05 -4.009333e-
03 3.927349e-03 2.544635e-03 1.643926e-04
[673] -2.465787e-04 -7.393716e-04 4.856976e-03 2.147874e-03 6.304982e-
03 -1.330672e-03 -3.323916e-04 -5.814195e-04
[681] 4.983389e-04 -1.074213e-02 7.399795e-04 -6.640185e-03 -4.158349e-
03 -2.440711e-04 7.323921e-04 -2.358012e-03
[689] 4.803201e-03 -4.478288e-03 -6.962463e-03 -2.578359e-03 -2.413807e-
04 8.045376e-05 2.174702e-03 7.259528e-04
[697] 6.801095e-03 -5.751565e-03 3.155215e-03 -2.430626e-04 9.726050e-
04 -6.305089e-03 -8.054773e-04 1.610436e-04
[705] -4.419275e-03 -6.552684e-03 -3.185474e-04 1.592610e-04 -3.894612e-
03 -7.929586e-04 2.380765e-03 -1.270446e-03
[713] -1.112657e-02 3.139471e-04 -1.098384e-03 -3.136025e-04 -1.957791e-
03 -1.329112e-03 -4.521367e-03 -8.365009e-03
[721] 1.234854e-03 -7.719624e-04 -2.004318e-03 -7.748111e-03 7.644676e-
04 -7.011155e-03 4.185539e-03 0.000000e+00
[729] 0.000000e+00 -4.033644e-03 6.838127e-04 -4.247257e-03 3.487494e-
03 5.483221e-03 -2.290688e-04 4.581902e-04
[737] -6.872065e-04 -1.281729e-02 -1.355524e-03 2.486533e-03 3.400721e-
03 -6.054185e-04 -6.806580e-04 1.664649e-03
[745] 5.162869e-03 -3.343722e-03 -5.522995e-03 -3.017502e-04 7.542900e-
05 6.036369e-04 -3.773158e-04 -1.028345e-02
[753] -3.354832e-03 -3.121055e-03 3.046631e-03 -7.441860e-05 -2.378476e-
03 8.873702e-03 1.349123e-03 3.531316e-03
[761] -1.397683e-02 1.224718e-02 3.757562e-04 -1.201923e-03 6.552955e-
03 -1.149567e-02 1.420402e-03 5.238149e-04
[769] -7.754289e-03 -7.424456e-04 2.226758e-04 9.397444e-03 5.862034e-
03 -5.637205e-03 1.001854e-02 -3.778152e-03
[777] -9.046363e-04 9.046363e-04 -9.799858e-04 -6.982797e-03 -8.974647e-
04 -3.209317e-03 1.267569e-03 -2.238054e-04
[785] 1.491981e-04 1.792115e-03 -6.332672e-03 2.156055e-03 5.373147e-
03 2.322359e-03 -1.049475e-03 -2.996479e-04
[793] 9.406699e-03 6.807095e-04 1.156698e-02 2.746914e-02 -1.118729e-
02 -3.889083e-04 6.223260e-04 1.245815e-03
[801] -4.508714e-03 -4.488477e-03 1.777503e-03 1.160946e-03 5.422364e-
04 0.000000e+00 -1.758810e-02 -5.163653e-03
[809] 4.250481e-03 -3.416990e-03 -6.949718e-03 -4.515692e-04 -7.524171e-
05 -3.529990e-03 3.454754e-03 1.656502e-03
[817] 3.768608e-04 -1.054852e-03 1.130242e-03 -7.536363e-04 -5.184668e-
03 2.998276e-04 5.186227e-03 2.792139e-03
[825] 4.924066e-03 3.038129e-04 -6.075334e-04 1.139428e-03 4.036409e-
03 1.909637e-03 -5.641979e-03 -3.339662e-03
[833] 3.789458e-04 0.000000e+00 -9.849605e-04 6.457762e-03 4.124347e-
03 5.294875e-03 -2.305565e-03 -1.535155e-04
[841] -9.205985e-04 3.302741e-03 -1.767939e-03 4.850081e-03 6.892040e-
03 6.783387e-03 -9.383798e-04 6.254887e-04
[849] -1.484897e-03 -3.819327e-03 7.966925e-03 -3.053677e-03 7.376054e-
03 3.150847e-04 0.000000e+00 -1.889021e-03
[857] -5.958465e-03 -7.786382e-03 4.275006e-03 5.859163e-03 -1.566907e-
04 7.834228e-05 -1.722114e-03 -5.304225e-03
[865] 7.183042e-03 -3.597970e-03 1.677007e-02 1.350654e-03 -2.064968e-
03 5.010947e-03 9.936775e-03 -4.025927e-04
[873] -6.179547e-03 2.162509e-03 2.405677e-04 -9.619239e-04 4.006892e-
04 1.363545e-03 1.043967e-03 8.472234e-03
[881] -6.461536e-03 -8.852051e-04 5.632216e-04 5.164217e-03 -4.359064e-
03 -2.172427e-03 2.655830e-03 -2.334287e-03
[889] -2.411673e-04 8.038262e-05 -2.729391e-03 -4.479291e-03 -3.346350e-
03 6.623862e-03 5.862293e-03 -3.221131e-04
[897] -8.051206e-05 -1.206904e-03 -1.608105e-04 3.785900e-03 3.395314e-
03 1.690457e-02 5.766775e-04 -2.471882e-04
[905] -3.946724e-03 4.193913e-03 1.077061e-02 4.089985e-03 6.693441e-
04 -5.857006e-04 -5.017562e-04 -4.179379e-04
[913] -2.253851e-03 1.084554e-03 -1.834710e-03 -3.078077e-03 1.662649e-
03 1.332112e-03 1.375745e-02 3.045430e-03
[921] 3.054733e-03 6.052100e-03 9.409350e-04 -2.567065e-04
0.000000e+00 3.943426e-03 4.131526e-03 -3.358164e-03
[929] -2.146753e-03 6.022560e-03 2.589220e-04 8.632224e-05 -3.275018e-
03 -1.146389e-02 6.999602e-03 2.916704e-03
[937] -2.049304e-02 -5.048805e-04 5.890521e-04 -7.630744e-03 -4.084871e-
03 2.332168e-03 5.099706e-03 3.274150e-03
[945] -8.408661e-05 6.728909e-04 -7.042873e-03 -8.982843e-03 4.398165e-
03 -6.300800e-03 7.465817e-03 -4.994589e-04
[953] 3.329449e-04 9.031672e-03 4.884220e-03 9.584873e-03 -3.408607e-
04 -2.977585e-03 -8.494372e-05 8.494372e-05
[961] -7.784774e-03 -1.936761e-03 2.695646e-03 -1.182354e-02 3.005512e-
03 -5.851131e-04 6.687286e-04 -1.169982e-03
[969] 1.294571e-02 -4.558509e-03 4.981646e-03 -1.606970e-03 -3.206213e-
03 2.277041e-03 2.282238e-03 8.839837e-03
[977] -7.654400e-03 -2.876483e-03 -1.603850e-03 -8.434192e-05 -8.433481e-
05 -2.610858e-03 -8.626158e-03 -3.413115e-03
[985] 2.579573e-03 -1.422923e-02 -8.213890e-05 -9.030829e-04 -3.277080e-
03 2.374812e-03 4.354799e-03 -3.293265e-04
[993] -1.478966e-02 -3.243857e-04 -5.674219e-04 -4.527821e-03 4.852023e-
03 3.735893e-03 5.302888e-03 -2.369379e-03
[ reached getOption("max.print") -- omitted 4843 entries ]
> ts.plot(log_ret)
> df= ur.df(log_ret,type = "drift")
Error in ur.df(log_ret, type = "drift") : could not find function "ur.df"
> a = ur.df(data,type = "drift")
Error in ur.df(data, type = "drift") : could not find function "ur.df"
> Box.test(log_ret,type = "Ljung-Box")

Box-Ljung test
data: log_ret
X-squared = 88.708, df = 1, p-value < 2.2e-16

> acf(log_ret)
> pacf(log_ret)
> eacf(log_ret)
Error in eacf(log_ret) : could not find function "eacf"
> eacf(log_ret)
Error in eacf(log_ret) : could not find function "eacf"
> library("TSA")

Attaching package: ‘TSA’

The following objects are masked from ‘package:stats’:

acf, arima

The following object is masked from ‘package:utils’:

tar

Warning message:
package ‘TSA’ was built under R version 4.0.3
> library("qrmdata")
> eacf(log_ret)
AR/MA
0 1 2 3 4 5 6 7 8 9 10 11 12 13
0 x x o x o o o o o o o o o x
1 x x o x o o o o o o o o o x
2 x x x o o o o o o o o o o x
3 x x x o o o o o o o o o o o
4 x x x x x o o o o o o o o o
5 x x x x x o o o o o o o o x
6 x x x x x o o o o o o o o o
7 x x x x x x o o o o o o o o
> arima_order= auto.arima(log_ret)
Error in auto.arima(log_ret) : could not find function "auto.arima"
> auto.arima(log_ret)
Error in auto.arima(log_ret) : could not find function "auto.arima"
> library("TSA")
> library("qrmdata")
> library("urca")
Warning message:
package ‘urca’ was built under R version 4.0.3
> auto.arima(log_ret)
Error in auto.arima(log_ret) : could not find function "auto.arima"
> arima_order= auto.arima(log_ret)
Error in auto.arima(log_ret) : could not find function "auto.arima"
> arima_order= auto.arima(log_ret)
Error in auto.arima(log_ret) : could not find function "auto.arima"
> library("forecast")
Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
Registered S3 methods overwritten by 'forecast':
method from
fitted.Arima TSA
plot.Arima TSA
Warning message:
package ‘forecast’ was built under R version 4.0.3
> auto.arima(log_ret)
Series: log_ret
ARIMA(3,0,1) with zero mean

Coefficients:
ar1 ar2 ar3 ma1
0.6692 -0.0518 -0.0351 -0.5478
s.e. 0.2035 0.0297 0.0131 0.2035
sigma^2 estimated as 2.126e-05: log likelihood=23142
AIC=-46274 AICc=-46273.99 BIC=-46240.63
> arima0(log_ret, order = (2,0,3))
Error: unexpected ',' in "arima0(log_ret, order = (2,"
> arima(log_ret, order = (2,0,3))
Error: unexpected ',' in "arima(log_ret, order = (2,"
> arima(log_ret, order= c(2,0,3))

Call:
arima(x = log_ret, order = c(2, 0, 3))

Coefficients:
ar1 ar2 ma1 ma2 ma3 intercept
0.267 -0.6406 -0.1449 0.6438 0.0665 0e+00
s.e. NaN 0.0163 NaN NaN NaN 1e-04

sigma^2 estimated as 2.124e-05: log likelihood = 23142.88, aic =


-46273.76
Warning message:
In sqrt(diag(x$var.coef)) : NaNs produced
> # checking the residuals are uncorrelated or not.
> Box.test(AutoArimaModel$residuals,type = "Ljung-Box")

Box-Ljung test

data: AutoArimaModel$residuals
X-squared = 0.89449, df = 1, p-value = 0.3443

> l
[1] 5844
> predict= c(rep(0,10))
>
>
> for(q in 1:10){
+
+ start= q
+ end= 5833+q
+
+
+ train_data= log_ret[start:end]
+ arima_fit= arima(train_data,order = c(3,0,1)) #order should be
the same of auto arima
+ rolling_forecast= predict(arima_fit,1)
+ predict[q]= rolling_forecast$pred
+ }
> predict
[1] 2.924681e-05 9.369404e-05 3.718153e-04 2.267182e-04 -1.198793e-04
-1.415584e-04 -2.104004e-04 -7.275641e-05
[9] -1.329470e-04 9.385690e-05
> se_1= c(rep(0,10))
> for(i in 1:10){
+ se_1[i]= (test_series[i]- predict[i])^2
+ }
>
> mse_1= sum(se_1[1:10])/10
> mse_1
[1] 83.97259

You might also like