# loading required libraries
library(xts)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(dplyr)
##
## ######################### Warning from 'xts' package ##########################
## # #
## # The dplyr lag() function breaks how base R's lag() function is supposed to #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or #
## # source() into this session won't work correctly. #
## # #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop #
## # dplyr from breaking base R's lag() function. #
## # #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning. #
## # #
## ###############################################################################
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:xts':
##
## first, last
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(zoo)
library(tseries)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(stats)
library(forecast)
library(astsa)
##
## Attaching package: 'astsa'
## The following object is masked from 'package:forecast':
##
## gas
library(corrplot)
## corrplot 0.92 loaded
library(AER)
## Loading required package: car
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
## Loading required package: lmtest
## Loading required package: sandwich
## Loading required package: survival
library(vars)
## Loading required package: MASS
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
## Loading required package: strucchange
## Loading required package: urca
library(dynlm)
library(vars)
library(TSstudio)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## âś” forcats 1.0.0 âś” readr 2.1.4
## âś” ggplot2 3.4.3 âś” stringr 1.5.0
## âś” lubridate 1.9.2 âś” tibble 3.2.1
## âś” purrr 1.0.1 âś” tidyr 1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## âś– stringr::boundary() masks strucchange::boundary()
## âś– dplyr::filter() masks stats::filter()
## âś– dplyr::first() masks xts::first()
## âś– dplyr::lag() masks stats::lag()
## âś– dplyr::last() masks xts::last()
## âś– car::recode() masks dplyr::recode()
## âś– MASS::select() masks dplyr::select()
## âś– purrr::some() masks car::some()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(sarima)
## Loading required package: stats4
##
## Attaching package: 'sarima'
##
## The following object is masked from 'package:astsa':
##
## sarima
##
## The following object is masked from 'package:stats':
##
## spectrum
library(dygraphs)
disney<-read.csv("C:\\Users\\maria\\OneDrive\\Desktop\\AD 2023\\ECONOMETRICS\\entretainment_stocks.csv")
disney
## Date Disney_Adj_Close Netflix_Adj_Close Nintendo_Adj_Close
## 1 1/1/2007 29.12 3.26 37.10
## 2 2/1/2007 28.36 3.22 33.10
## 3 3/1/2007 28.51 3.31 36.30
## 4 4/1/2007 28.96 3.17 40.05
## 5 5/1/2007 29.34 3.13 43.65
## 6 6/1/2007 28.65 2.77 45.85
## 7 7/1/2007 27.70 2.46 61.25
## 8 8/1/2007 28.20 2.50 58.15
## 9 9/1/2007 28.86 2.96 64.85
## 10 10/1/2007 29.07 3.78 78.50
## 11 11/1/2007 27.82 3.30 76.10
## 12 12/1/2007 27.09 3.80 74.05
## 13 1/1/2008 25.32 3.59 61.75
## 14 2/1/2008 27.50 4.51 62.40
## 15 3/1/2008 26.62 4.95 64.85
## 16 4/1/2008 27.51 4.57 68.69
## 17 5/1/2008 28.51 4.34 68.95
## 18 6/1/2008 26.47 3.72 69.85
## 19 7/1/2008 25.75 4.41 57.75
## 20 8/1/2008 27.45 4.41 61.10
## 21 9/1/2008 26.04 4.41 53.07
## 22 10/1/2008 21.98 3.54 39.00
## 23 11/1/2008 19.11 3.28 38.84
## 24 12/1/2008 19.25 4.27 47.75
## 25 1/1/2009 17.81 5.16 36.40
## 26 2/1/2009 14.44 5.18 35.25
## 27 3/1/2009 15.64 6.13 36.50
## 28 4/1/2009 18.86 6.47 33.65
## 29 5/1/2009 20.86 5.63 33.68
## 30 6/1/2009 20.09 5.91 34.47
## 31 7/1/2009 21.63 6.28 33.12
## 32 8/1/2009 22.42 6.23 33.55
## 33 9/1/2009 23.65 6.60 31.57
## 34 10/1/2009 23.57 7.64 31.41
## 35 11/1/2009 26.02 8.38 30.78
## 36 12/1/2009 27.77 7.87 29.82
## 37 1/1/2010 25.74 8.89 34.90
## 38 2/1/2010 27.21 9.44 33.87
## 39 3/1/2010 30.41 10.53 41.65
## 40 4/1/2010 32.09 14.13 41.90
## 41 5/1/2010 29.11 15.88 36.45
## 42 6/1/2010 27.44 15.52 37.27
## 43 7/1/2010 29.35 14.65 35.21
## 44 8/1/2010 28.34 17.93 34.75
## 45 9/1/2010 28.83 23.17 31.20
## 46 10/1/2010 31.47 24.80 32.15
## 47 11/1/2010 31.80 29.41 34.10
## 48 12/1/2010 32.67 25.10 36.33
## 49 1/1/2011 34.23 30.58 34.10
## 50 2/1/2011 38.52 29.52 36.65
## 51 3/1/2011 37.94 33.97 33.74
## 52 4/1/2011 37.95 33.24 29.79
## 53 5/1/2011 36.66 38.69 28.90
## 54 6/1/2011 34.38 37.53 23.30
## 55 7/1/2011 34.01 38.00 19.95
## 56 8/1/2011 29.99 33.57 21.98
## 57 9/1/2011 26.56 16.18 18.15
## 58 10/1/2011 30.71 11.73 18.90
## 59 11/1/2011 31.57 9.22 19.05
## 60 12/1/2011 33.02 9.90 16.94
## 61 1/1/2012 34.83 17.17 16.94
## 62 2/1/2012 37.60 15.82 18.51
## 63 3/1/2012 39.20 16.43 18.96
## 64 4/1/2012 38.60 11.45 16.72
## 65 5/1/2012 40.93 9.06 14.32
## 66 6/1/2012 43.42 9.78 14.52
## 67 7/1/2012 44.00 8.12 13.80
## 68 8/1/2012 44.29 8.53 13.93
## 69 9/1/2012 46.81 7.78 15.87
## 70 10/1/2012 43.98 11.32 16.15
## 71 11/1/2012 44.46 11.67 15.10
## 72 12/1/2012 44.58 13.23 13.31
## 73 1/1/2013 48.98 23.61 12.16
## 74 2/1/2013 49.63 26.87 12.06
## 75 3/1/2013 51.64 27.04 13.44
## 76 4/1/2013 57.13 30.87 13.75
## 77 5/1/2013 57.35 32.32 12.47
## 78 6/1/2013 57.41 30.16 14.67
## 79 7/1/2013 58.77 34.93 15.80
## 80 8/1/2013 55.30 40.56 14.09
## 81 9/1/2013 58.63 44.17 14.12
## 82 10/1/2013 62.36 46.07 14.01
## 83 11/1/2013 64.13 52.26 16.08
## 84 12/1/2013 69.46 52.60 16.68
## 85 1/1/2014 66.82 58.48 14.63
## 86 2/1/2014 74.37 63.66 15.40
## 87 3/1/2014 73.69 50.29 14.89
## 88 4/1/2014 73.02 46.01 13.08
## 89 5/1/2014 77.32 59.69 14.56
## 90 6/1/2014 78.91 62.94 14.95
## 91 7/1/2014 79.04 60.39 13.83
## 92 8/1/2014 82.72 68.23 13.89
## 93 9/1/2014 81.94 64.45 13.59
## 94 10/1/2014 84.10 56.11 13.67
## 95 11/1/2014 85.14 49.51 14.50
## 96 12/1/2014 86.69 48.80 12.95
## 97 1/1/2015 84.78 63.11 12.04
## 98 2/1/2015 97.00 67.84 13.34
## 99 3/1/2015 97.76 59.53 18.43
## 100 4/1/2015 101.33 79.50 21.04
## 101 5/1/2015 102.87 89.15 21.16
## 102 6/1/2015 106.38 93.85 20.98
## 103 7/1/2015 111.84 114.31 22.01
## 104 8/1/2015 95.51 115.03 25.62
## 105 9/1/2015 95.81 103.26 20.97
## 106 10/1/2015 106.62 108.38 20.22
## 107 11/1/2015 106.37 123.33 19.13
## 108 12/1/2015 98.51 114.38 17.26
## 109 1/1/2016 90.40 91.84 17.57
## 110 2/1/2016 90.12 93.41 17.39
## 111 3/1/2016 93.69 102.23 17.75
## 112 4/1/2016 97.42 90.03 17.06
## 113 5/1/2016 93.61 102.57 18.34
## 114 6/1/2016 92.29 91.48 17.78
## 115 7/1/2016 90.52 91.25 25.78
## 116 8/1/2016 89.77 97.45 27.28
## 117 9/1/2016 88.25 98.55 32.98
## 118 10/1/2016 88.08 124.87 30.09
## 119 11/1/2016 94.19 117.00 30.83
## 120 12/1/2016 99.04 123.80 25.95
## 121 1/1/2017 105.96 140.71 24.73
## 122 2/1/2017 105.42 142.13 26.11
## 123 3/1/2017 108.59 147.81 29.02
## 124 4/1/2017 110.70 152.20 31.68
## 125 5/1/2017 103.37 163.07 37.83
## 126 6/1/2017 101.75 149.41 41.82
## 127 7/1/2017 105.27 181.66 42.46
## 128 8/1/2017 97.63 174.71 41.63
## 129 9/1/2017 95.10 181.35 45.95
## 130 10/1/2017 94.36 196.43 48.65
## 131 11/1/2017 101.12 187.58 50.98
## 132 12/1/2017 103.72 191.96 45.07
## 133 1/1/2018 105.68 270.30 57.08
## 134 2/1/2018 100.32 291.38 57.05
## 135 3/1/2018 97.68 295.35 55.51
## 136 4/1/2018 97.57 312.46 52.48
## 137 5/1/2018 96.74 351.60 51.04
## 138 6/1/2018 101.93 391.43 40.79
## 139 7/1/2018 110.44 337.45 42.67
## 140 8/1/2018 109.82 367.68 44.95
## 141 9/1/2018 114.64 374.13 45.47
## 142 10/1/2018 112.57 301.78 39.13
## 143 11/1/2018 113.22 286.13 37.87
## 144 12/1/2018 107.49 267.66 33.10
## 145 1/1/2019 110.17 339.50 37.24
## 146 2/1/2019 111.48 358.10 34.25
## 147 3/1/2019 109.69 356.56 35.87
## 148 4/1/2019 135.32 370.54 43.08
## 149 5/1/2019 130.45 343.28 44.14
## 150 6/1/2019 137.95 367.32 45.77
## 151 7/1/2019 141.28 322.99 46.19
## 152 8/1/2019 136.44 293.75 47.25
## 153 9/1/2019 129.54 267.62 46.60
## 154 10/1/2019 129.15 287.41 46.52
## 155 11/1/2019 150.68 314.66 48.39
## 156 12/1/2019 143.77 323.57 49.90
## 157 1/1/2020 138.31 345.09 45.90
## 158 2/1/2020 117.65 369.03 41.98
## 159 3/1/2020 96.60 375.50 48.28
## 160 4/1/2020 108.15 419.85 51.44
## 161 5/1/2020 117.30 419.73 50.84
## 162 6/1/2020 111.51 455.04 55.90
## 163 7/1/2020 116.94 488.88 55.01
## 164 8/1/2020 131.87 529.56 67.37
## 165 9/1/2020 124.08 500.03 70.90
## 166 10/1/2020 121.25 475.74 67.73
## 167 11/1/2020 148.01 490.70 70.95
## 168 12/1/2020 181.18 540.73 80.52
## 169 1/1/2021 168.17 532.39 72.27
## 170 2/1/2021 189.04 538.85 77.12
## 171 3/1/2021 184.52 521.66 70.80
## 172 4/1/2021 186.02 513.47 71.89
## 173 5/1/2021 178.65 502.81 77.32
## 174 6/1/2021 175.77 528.21 72.53
## 175 7/1/2021 176.02 517.57 64.25
## 176 8/1/2021 181.30 569.19 60.08
## 177 9/1/2021 169.17 610.34 59.25
## 178 10/1/2021 169.07 690.31 55.25
## 179 11/1/2021 144.90 641.90 55.08
## 180 12/1/2021 154.89 602.44 58.37
## 181 1/1/2022 142.97 427.14 12.22
## 182 2/1/2022 148.46 394.52 12.71
## 183 3/1/2022 137.16 374.59 12.58
## 184 4/1/2022 111.63 190.36 11.40
## 185 5/1/2022 110.44 197.44 11.12
## 186 6/1/2022 94.40 174.87 10.76
## 187 7/1/2022 106.10 224.90 11.20
## 188 8/1/2022 112.08 223.56 10.22
## 189 9/1/2022 94.33 235.44 10.19
## 190 10/1/2022 106.54 291.88 10.12
## 191 11/1/2022 97.87 305.53 10.73
## 192 12/1/2022 86.88 294.88 10.42
## WBD_Adj_Close EA_Adj_Close Paramount_Adj_Close
## 1 8.47 49.48 22.05
## 2 8.21 49.90 21.48
## 3 9.78 49.84 21.64
## 4 11.11 49.89 22.64
## 5 11.95 48.36 23.70
## 6 11.75 46.83 23.90
## 7 12.12 48.13 22.75
## 8 12.84 52.39 22.60
## 9 14.74 55.41 22.60
## 10 14.57 60.48 20.75
## 11 12.50 55.61 19.84
## 12 12.85 57.80 19.89
## 13 11.87 46.88 18.40
## 14 11.53 46.80 16.66
## 15 10.84 49.40 16.29
## 16 11.83 50.93 17.02
## 17 13.38 49.68 15.92
## 18 11.22 43.97 14.56
## 19 10.16 42.73 12.22
## 20 10.34 48.30 12.08
## 21 7.28 36.61 11.07
## 22 6.97 22.54 7.37
## 23 7.67 18.86 5.06
## 24 7.24 15.87 6.22
## 25 7.41 15.28 4.55
## 26 7.93 16.14 3.40
## 27 8.19 18.00 3.06
## 28 9.70 20.14 5.69
## 29 11.47 22.75 5.96
## 30 11.50 21.49 5.59
## 31 12.52 21.25 6.66
## 32 13.25 18.03 8.41
## 33 14.76 18.85 9.79
## 34 14.05 18.05 9.61
## 35 16.33 16.71 10.46
## 36 15.67 17.57 11.47
## 37 15.16 16.11 10.60
## 38 15.92 16.41 10.64
## 39 17.27 18.47 11.42
## 40 19.79 19.17 13.33
## 41 19.24 16.34 11.97
## 42 18.25 14.25 10.63
## 43 19.73 15.76 12.20
## 44 19.29 15.07 11.41
## 45 22.25 16.28 13.09
## 46 22.83 15.67 14.02
## 47 20.84 14.76 13.95
## 48 21.31 16.21 15.78
## 49 19.93 15.43 16.47
## 50 22.03 18.60 19.81
## 51 20.39 19.33 20.79
## 52 22.62 19.97 20.99
## 53 22.26 24.16 23.26
## 54 20.93 23.35 23.71
## 55 20.34 22.02 22.86
## 56 21.60 22.35 20.93
## 57 19.22 20.24 17.02
## 58 22.21 23.11 21.65
## 59 21.45 22.95 21.85
## 60 20.94 20.39 22.77
## 61 21.91 18.39 23.99
## 62 23.84 16.17 25.18
## 63 25.86 16.32 28.56
## 64 27.81 15.22 28.21
## 65 25.60 13.48 26.97
## 66 27.59 12.22 27.70
## 67 25.87 10.91 28.36
## 68 28.02 13.19 30.80
## 69 30.46 12.56 30.80
## 70 30.16 12.22 27.56
## 71 30.87 14.66 30.60
## 72 32.44 14.37 32.36
## 73 35.45 15.57 35.60
## 74 37.48 17.35 37.03
## 75 40.24 17.52 39.85
## 76 40.28 17.43 39.17
## 77 40.30 22.75 42.36
## 78 39.47 22.75 41.82
## 79 40.74 25.85 45.33
## 80 39.61 26.36 43.84
## 81 43.14 25.28 47.32
## 82 45.41 25.98 50.85
## 83 44.59 21.94 50.35
## 84 46.20 22.70 54.80
## 85 40.77 26.13 50.59
## 86 42.58 28.29 57.79
## 87 42.26 28.71 53.24
## 88 38.78 28.01 49.85
## 89 39.33 34.76 51.45
## 90 37.96 35.50 53.63
## 91 43.54 33.25 49.14
## 92 43.72 37.45 51.27
## 93 37.80 35.24 46.27
## 94 35.35 40.54 47.01
## 95 34.90 43.47 47.58
## 96 34.45 46.53 47.98
## 97 28.99 54.29 47.65
## 98 32.30 56.59 51.38
## 99 30.76 58.21 52.71
## 100 32.36 57.49 54.15
## 101 33.94 62.11 53.79
## 102 33.26 65.81 48.37
## 103 33.02 70.81 46.72
## 104 26.60 65.46 39.53
## 105 26.03 67.05 34.86
## 106 29.44 71.32 40.79
## 107 31.14 67.08 44.26
## 108 26.68 68.01 41.32
## 109 27.59 63.88 41.77
## 110 25.00 63.57 42.55
## 111 28.63 65.42 48.45
## 112 27.31 61.21 49.31
## 113 27.85 75.95 48.69
## 114 25.23 74.97 48.01
## 115 25.09 75.53 46.19
## 116 25.51 80.38 45.13
## 117 26.92 84.51 48.42
## 118 26.11 77.70 50.25
## 119 27.09 78.42 53.89
## 120 27.41 77.94 56.47
## 121 28.35 82.56 57.41
## 122 28.76 85.60 58.68
## 123 29.09 88.59 61.74
## 124 28.78 93.83 59.41
## 125 26.50 112.15 54.54
## 126 25.83 104.62 56.93
## 127 24.60 115.53 58.93
## 128 22.21 120.24 57.35
## 129 21.29 116.83 51.92
## 130 18.88 118.36 50.38
## 131 19.02 105.24 50.33
## 132 22.38 103.97 52.97
## 133 25.07 125.64 51.88
## 134 24.32 122.41 47.71
## 135 21.43 119.98 46.28
## 136 23.65 116.75 44.46
## 137 21.09 129.55 45.52
## 138 27.50 139.55 50.81
## 139 26.58 127.41 47.77
## 140 27.83 112.23 48.09
## 141 32.00 119.24 52.11
## 142 32.39 90.03 52.19
## 143 30.72 83.20 49.30
## 144 24.74 78.09 39.78
## 145 28.38 91.28 45.17
## 146 28.90 94.78 45.85
## 147 27.02 100.57 43.40
## 148 30.90 93.67 46.99
## 149 27.26 92.11 44.25
## 150 30.70 100.21 45.74
## 151 30.31 91.54 47.39
## 152 27.60 92.71 38.69
## 153 26.63 96.80 37.14
## 154 26.96 95.40 33.29
## 155 32.94 99.96 37.30
## 156 32.74 106.39 38.77
## 157 29.26 106.80 31.53
## 158 25.70 100.32 22.73
## 159 19.44 99.13 12.94
## 160 22.42 113.07 16.19
## 161 21.75 121.60 19.45
## 162 21.10 130.68 21.87
## 163 21.10 140.15 24.70
## 164 22.07 138.02 26.38
## 165 21.77 129.05 26.54
## 166 20.24 118.58 27.29
## 167 26.91 126.42 33.70
## 168 30.09 142.11 35.59
## 169 41.42 141.90 46.64
## 170 53.03 132.75 62.02
## 171 43.46 134.14 43.37
## 172 37.66 140.96 39.56
## 173 32.11 141.81 40.91
## 174 30.68 142.70 43.59
## 175 29.01 143.00 39.70
## 176 28.84 144.24 40.20
## 177 25.38 141.47 38.32
## 178 23.44 139.48 35.34
## 179 23.27 123.54 30.20
## 180 23.54 131.17 29.45
## 181 27.91 131.28 31.67
## 182 28.05 128.74 28.98
## 183 24.92 125.20 35.79
## 184 18.15 116.98 27.77
## 185 18.45 137.40 32.74
## 186 13.42 120.55 23.54
## 187 15.00 130.22 22.77
## 188 13.24 125.89 22.52
## 189 11.50 114.99 18.33
## 190 13.00 125.17 17.83
## 191 11.40 129.96 19.54
## 192 9.48 121.60 16.42
# setting time series format
disney$Date<-as.Date(disney$Date,"%m/%d/%Y")
disney$quarter=as.yearqtr(disney$Date,format="%Y/%q")
disney
## Date Disney_Adj_Close Netflix_Adj_Close Nintendo_Adj_Close
## 1 2007-01-01 29.12 3.26 37.10
## 2 2007-02-01 28.36 3.22 33.10
## 3 2007-03-01 28.51 3.31 36.30
## 4 2007-04-01 28.96 3.17 40.05
## 5 2007-05-01 29.34 3.13 43.65
## 6 2007-06-01 28.65 2.77 45.85
## 7 2007-07-01 27.70 2.46 61.25
## 8 2007-08-01 28.20 2.50 58.15
## 9 2007-09-01 28.86 2.96 64.85
## 10 2007-10-01 29.07 3.78 78.50
## 11 2007-11-01 27.82 3.30 76.10
## 12 2007-12-01 27.09 3.80 74.05
## 13 2008-01-01 25.32 3.59 61.75
## 14 2008-02-01 27.50 4.51 62.40
## 15 2008-03-01 26.62 4.95 64.85
## 16 2008-04-01 27.51 4.57 68.69
## 17 2008-05-01 28.51 4.34 68.95
## 18 2008-06-01 26.47 3.72 69.85
## 19 2008-07-01 25.75 4.41 57.75
## 20 2008-08-01 27.45 4.41 61.10
## 21 2008-09-01 26.04 4.41 53.07
## 22 2008-10-01 21.98 3.54 39.00
## 23 2008-11-01 19.11 3.28 38.84
## 24 2008-12-01 19.25 4.27 47.75
## 25 2009-01-01 17.81 5.16 36.40
## 26 2009-02-01 14.44 5.18 35.25
## 27 2009-03-01 15.64 6.13 36.50
## 28 2009-04-01 18.86 6.47 33.65
## 29 2009-05-01 20.86 5.63 33.68
## 30 2009-06-01 20.09 5.91 34.47
## 31 2009-07-01 21.63 6.28 33.12
## 32 2009-08-01 22.42 6.23 33.55
## 33 2009-09-01 23.65 6.60 31.57
## 34 2009-10-01 23.57 7.64 31.41
## 35 2009-11-01 26.02 8.38 30.78
## 36 2009-12-01 27.77 7.87 29.82
## 37 2010-01-01 25.74 8.89 34.90
## 38 2010-02-01 27.21 9.44 33.87
## 39 2010-03-01 30.41 10.53 41.65
## 40 2010-04-01 32.09 14.13 41.90
## 41 2010-05-01 29.11 15.88 36.45
## 42 2010-06-01 27.44 15.52 37.27
## 43 2010-07-01 29.35 14.65 35.21
## 44 2010-08-01 28.34 17.93 34.75
## 45 2010-09-01 28.83 23.17 31.20
## 46 2010-10-01 31.47 24.80 32.15
## 47 2010-11-01 31.80 29.41 34.10
## 48 2010-12-01 32.67 25.10 36.33
## 49 2011-01-01 34.23 30.58 34.10
## 50 2011-02-01 38.52 29.52 36.65
## 51 2011-03-01 37.94 33.97 33.74
## 52 2011-04-01 37.95 33.24 29.79
## 53 2011-05-01 36.66 38.69 28.90
## 54 2011-06-01 34.38 37.53 23.30
## 55 2011-07-01 34.01 38.00 19.95
## 56 2011-08-01 29.99 33.57 21.98
## 57 2011-09-01 26.56 16.18 18.15
## 58 2011-10-01 30.71 11.73 18.90
## 59 2011-11-01 31.57 9.22 19.05
## 60 2011-12-01 33.02 9.90 16.94
## 61 2012-01-01 34.83 17.17 16.94
## 62 2012-02-01 37.60 15.82 18.51
## 63 2012-03-01 39.20 16.43 18.96
## 64 2012-04-01 38.60 11.45 16.72
## 65 2012-05-01 40.93 9.06 14.32
## 66 2012-06-01 43.42 9.78 14.52
## 67 2012-07-01 44.00 8.12 13.80
## 68 2012-08-01 44.29 8.53 13.93
## 69 2012-09-01 46.81 7.78 15.87
## 70 2012-10-01 43.98 11.32 16.15
## 71 2012-11-01 44.46 11.67 15.10
## 72 2012-12-01 44.58 13.23 13.31
## 73 2013-01-01 48.98 23.61 12.16
## 74 2013-02-01 49.63 26.87 12.06
## 75 2013-03-01 51.64 27.04 13.44
## 76 2013-04-01 57.13 30.87 13.75
## 77 2013-05-01 57.35 32.32 12.47
## 78 2013-06-01 57.41 30.16 14.67
## 79 2013-07-01 58.77 34.93 15.80
## 80 2013-08-01 55.30 40.56 14.09
## 81 2013-09-01 58.63 44.17 14.12
## 82 2013-10-01 62.36 46.07 14.01
## 83 2013-11-01 64.13 52.26 16.08
## 84 2013-12-01 69.46 52.60 16.68
## 85 2014-01-01 66.82 58.48 14.63
## 86 2014-02-01 74.37 63.66 15.40
## 87 2014-03-01 73.69 50.29 14.89
## 88 2014-04-01 73.02 46.01 13.08
## 89 2014-05-01 77.32 59.69 14.56
## 90 2014-06-01 78.91 62.94 14.95
## 91 2014-07-01 79.04 60.39 13.83
## 92 2014-08-01 82.72 68.23 13.89
## 93 2014-09-01 81.94 64.45 13.59
## 94 2014-10-01 84.10 56.11 13.67
## 95 2014-11-01 85.14 49.51 14.50
## 96 2014-12-01 86.69 48.80 12.95
## 97 2015-01-01 84.78 63.11 12.04
## 98 2015-02-01 97.00 67.84 13.34
## 99 2015-03-01 97.76 59.53 18.43
## 100 2015-04-01 101.33 79.50 21.04
## 101 2015-05-01 102.87 89.15 21.16
## 102 2015-06-01 106.38 93.85 20.98
## 103 2015-07-01 111.84 114.31 22.01
## 104 2015-08-01 95.51 115.03 25.62
## 105 2015-09-01 95.81 103.26 20.97
## 106 2015-10-01 106.62 108.38 20.22
## 107 2015-11-01 106.37 123.33 19.13
## 108 2015-12-01 98.51 114.38 17.26
## 109 2016-01-01 90.40 91.84 17.57
## 110 2016-02-01 90.12 93.41 17.39
## 111 2016-03-01 93.69 102.23 17.75
## 112 2016-04-01 97.42 90.03 17.06
## 113 2016-05-01 93.61 102.57 18.34
## 114 2016-06-01 92.29 91.48 17.78
## 115 2016-07-01 90.52 91.25 25.78
## 116 2016-08-01 89.77 97.45 27.28
## 117 2016-09-01 88.25 98.55 32.98
## 118 2016-10-01 88.08 124.87 30.09
## 119 2016-11-01 94.19 117.00 30.83
## 120 2016-12-01 99.04 123.80 25.95
## 121 2017-01-01 105.96 140.71 24.73
## 122 2017-02-01 105.42 142.13 26.11
## 123 2017-03-01 108.59 147.81 29.02
## 124 2017-04-01 110.70 152.20 31.68
## 125 2017-05-01 103.37 163.07 37.83
## 126 2017-06-01 101.75 149.41 41.82
## 127 2017-07-01 105.27 181.66 42.46
## 128 2017-08-01 97.63 174.71 41.63
## 129 2017-09-01 95.10 181.35 45.95
## 130 2017-10-01 94.36 196.43 48.65
## 131 2017-11-01 101.12 187.58 50.98
## 132 2017-12-01 103.72 191.96 45.07
## 133 2018-01-01 105.68 270.30 57.08
## 134 2018-02-01 100.32 291.38 57.05
## 135 2018-03-01 97.68 295.35 55.51
## 136 2018-04-01 97.57 312.46 52.48
## 137 2018-05-01 96.74 351.60 51.04
## 138 2018-06-01 101.93 391.43 40.79
## 139 2018-07-01 110.44 337.45 42.67
## 140 2018-08-01 109.82 367.68 44.95
## 141 2018-09-01 114.64 374.13 45.47
## 142 2018-10-01 112.57 301.78 39.13
## 143 2018-11-01 113.22 286.13 37.87
## 144 2018-12-01 107.49 267.66 33.10
## 145 2019-01-01 110.17 339.50 37.24
## 146 2019-02-01 111.48 358.10 34.25
## 147 2019-03-01 109.69 356.56 35.87
## 148 2019-04-01 135.32 370.54 43.08
## 149 2019-05-01 130.45 343.28 44.14
## 150 2019-06-01 137.95 367.32 45.77
## 151 2019-07-01 141.28 322.99 46.19
## 152 2019-08-01 136.44 293.75 47.25
## 153 2019-09-01 129.54 267.62 46.60
## 154 2019-10-01 129.15 287.41 46.52
## 155 2019-11-01 150.68 314.66 48.39
## 156 2019-12-01 143.77 323.57 49.90
## 157 2020-01-01 138.31 345.09 45.90
## 158 2020-02-01 117.65 369.03 41.98
## 159 2020-03-01 96.60 375.50 48.28
## 160 2020-04-01 108.15 419.85 51.44
## 161 2020-05-01 117.30 419.73 50.84
## 162 2020-06-01 111.51 455.04 55.90
## 163 2020-07-01 116.94 488.88 55.01
## 164 2020-08-01 131.87 529.56 67.37
## 165 2020-09-01 124.08 500.03 70.90
## 166 2020-10-01 121.25 475.74 67.73
## 167 2020-11-01 148.01 490.70 70.95
## 168 2020-12-01 181.18 540.73 80.52
## 169 2021-01-01 168.17 532.39 72.27
## 170 2021-02-01 189.04 538.85 77.12
## 171 2021-03-01 184.52 521.66 70.80
## 172 2021-04-01 186.02 513.47 71.89
## 173 2021-05-01 178.65 502.81 77.32
## 174 2021-06-01 175.77 528.21 72.53
## 175 2021-07-01 176.02 517.57 64.25
## 176 2021-08-01 181.30 569.19 60.08
## 177 2021-09-01 169.17 610.34 59.25
## 178 2021-10-01 169.07 690.31 55.25
## 179 2021-11-01 144.90 641.90 55.08
## 180 2021-12-01 154.89 602.44 58.37
## 181 2022-01-01 142.97 427.14 12.22
## 182 2022-02-01 148.46 394.52 12.71
## 183 2022-03-01 137.16 374.59 12.58
## 184 2022-04-01 111.63 190.36 11.40
## 185 2022-05-01 110.44 197.44 11.12
## 186 2022-06-01 94.40 174.87 10.76
## 187 2022-07-01 106.10 224.90 11.20
## 188 2022-08-01 112.08 223.56 10.22
## 189 2022-09-01 94.33 235.44 10.19
## 190 2022-10-01 106.54 291.88 10.12
## 191 2022-11-01 97.87 305.53 10.73
## 192 2022-12-01 86.88 294.88 10.42
## WBD_Adj_Close EA_Adj_Close Paramount_Adj_Close quarter
## 1 8.47 49.48 22.05 2007 Q1
## 2 8.21 49.90 21.48 2007 Q1
## 3 9.78 49.84 21.64 2007 Q1
## 4 11.11 49.89 22.64 2007 Q2
## 5 11.95 48.36 23.70 2007 Q2
## 6 11.75 46.83 23.90 2007 Q2
## 7 12.12 48.13 22.75 2007 Q3
## 8 12.84 52.39 22.60 2007 Q3
## 9 14.74 55.41 22.60 2007 Q3
## 10 14.57 60.48 20.75 2007 Q4
## 11 12.50 55.61 19.84 2007 Q4
## 12 12.85 57.80 19.89 2007 Q4
## 13 11.87 46.88 18.40 2008 Q1
## 14 11.53 46.80 16.66 2008 Q1
## 15 10.84 49.40 16.29 2008 Q1
## 16 11.83 50.93 17.02 2008 Q2
## 17 13.38 49.68 15.92 2008 Q2
## 18 11.22 43.97 14.56 2008 Q2
## 19 10.16 42.73 12.22 2008 Q3
## 20 10.34 48.30 12.08 2008 Q3
## 21 7.28 36.61 11.07 2008 Q3
## 22 6.97 22.54 7.37 2008 Q4
## 23 7.67 18.86 5.06 2008 Q4
## 24 7.24 15.87 6.22 2008 Q4
## 25 7.41 15.28 4.55 2009 Q1
## 26 7.93 16.14 3.40 2009 Q1
## 27 8.19 18.00 3.06 2009 Q1
## 28 9.70 20.14 5.69 2009 Q2
## 29 11.47 22.75 5.96 2009 Q2
## 30 11.50 21.49 5.59 2009 Q2
## 31 12.52 21.25 6.66 2009 Q3
## 32 13.25 18.03 8.41 2009 Q3
## 33 14.76 18.85 9.79 2009 Q3
## 34 14.05 18.05 9.61 2009 Q4
## 35 16.33 16.71 10.46 2009 Q4
## 36 15.67 17.57 11.47 2009 Q4
## 37 15.16 16.11 10.60 2010 Q1
## 38 15.92 16.41 10.64 2010 Q1
## 39 17.27 18.47 11.42 2010 Q1
## 40 19.79 19.17 13.33 2010 Q2
## 41 19.24 16.34 11.97 2010 Q2
## 42 18.25 14.25 10.63 2010 Q2
## 43 19.73 15.76 12.20 2010 Q3
## 44 19.29 15.07 11.41 2010 Q3
## 45 22.25 16.28 13.09 2010 Q3
## 46 22.83 15.67 14.02 2010 Q4
## 47 20.84 14.76 13.95 2010 Q4
## 48 21.31 16.21 15.78 2010 Q4
## 49 19.93 15.43 16.47 2011 Q1
## 50 22.03 18.60 19.81 2011 Q1
## 51 20.39 19.33 20.79 2011 Q1
## 52 22.62 19.97 20.99 2011 Q2
## 53 22.26 24.16 23.26 2011 Q2
## 54 20.93 23.35 23.71 2011 Q2
## 55 20.34 22.02 22.86 2011 Q3
## 56 21.60 22.35 20.93 2011 Q3
## 57 19.22 20.24 17.02 2011 Q3
## 58 22.21 23.11 21.65 2011 Q4
## 59 21.45 22.95 21.85 2011 Q4
## 60 20.94 20.39 22.77 2011 Q4
## 61 21.91 18.39 23.99 2012 Q1
## 62 23.84 16.17 25.18 2012 Q1
## 63 25.86 16.32 28.56 2012 Q1
## 64 27.81 15.22 28.21 2012 Q2
## 65 25.60 13.48 26.97 2012 Q2
## 66 27.59 12.22 27.70 2012 Q2
## 67 25.87 10.91 28.36 2012 Q3
## 68 28.02 13.19 30.80 2012 Q3
## 69 30.46 12.56 30.80 2012 Q3
## 70 30.16 12.22 27.56 2012 Q4
## 71 30.87 14.66 30.60 2012 Q4
## 72 32.44 14.37 32.36 2012 Q4
## 73 35.45 15.57 35.60 2013 Q1
## 74 37.48 17.35 37.03 2013 Q1
## 75 40.24 17.52 39.85 2013 Q1
## 76 40.28 17.43 39.17 2013 Q2
## 77 40.30 22.75 42.36 2013 Q2
## 78 39.47 22.75 41.82 2013 Q2
## 79 40.74 25.85 45.33 2013 Q3
## 80 39.61 26.36 43.84 2013 Q3
## 81 43.14 25.28 47.32 2013 Q3
## 82 45.41 25.98 50.85 2013 Q4
## 83 44.59 21.94 50.35 2013 Q4
## 84 46.20 22.70 54.80 2013 Q4
## 85 40.77 26.13 50.59 2014 Q1
## 86 42.58 28.29 57.79 2014 Q1
## 87 42.26 28.71 53.24 2014 Q1
## 88 38.78 28.01 49.85 2014 Q2
## 89 39.33 34.76 51.45 2014 Q2
## 90 37.96 35.50 53.63 2014 Q2
## 91 43.54 33.25 49.14 2014 Q3
## 92 43.72 37.45 51.27 2014 Q3
## 93 37.80 35.24 46.27 2014 Q3
## 94 35.35 40.54 47.01 2014 Q4
## 95 34.90 43.47 47.58 2014 Q4
## 96 34.45 46.53 47.98 2014 Q4
## 97 28.99 54.29 47.65 2015 Q1
## 98 32.30 56.59 51.38 2015 Q1
## 99 30.76 58.21 52.71 2015 Q1
## 100 32.36 57.49 54.15 2015 Q2
## 101 33.94 62.11 53.79 2015 Q2
## 102 33.26 65.81 48.37 2015 Q2
## 103 33.02 70.81 46.72 2015 Q3
## 104 26.60 65.46 39.53 2015 Q3
## 105 26.03 67.05 34.86 2015 Q3
## 106 29.44 71.32 40.79 2015 Q4
## 107 31.14 67.08 44.26 2015 Q4
## 108 26.68 68.01 41.32 2015 Q4
## 109 27.59 63.88 41.77 2016 Q1
## 110 25.00 63.57 42.55 2016 Q1
## 111 28.63 65.42 48.45 2016 Q1
## 112 27.31 61.21 49.31 2016 Q2
## 113 27.85 75.95 48.69 2016 Q2
## 114 25.23 74.97 48.01 2016 Q2
## 115 25.09 75.53 46.19 2016 Q3
## 116 25.51 80.38 45.13 2016 Q3
## 117 26.92 84.51 48.42 2016 Q3
## 118 26.11 77.70 50.25 2016 Q4
## 119 27.09 78.42 53.89 2016 Q4
## 120 27.41 77.94 56.47 2016 Q4
## 121 28.35 82.56 57.41 2017 Q1
## 122 28.76 85.60 58.68 2017 Q1
## 123 29.09 88.59 61.74 2017 Q1
## 124 28.78 93.83 59.41 2017 Q2
## 125 26.50 112.15 54.54 2017 Q2
## 126 25.83 104.62 56.93 2017 Q2
## 127 24.60 115.53 58.93 2017 Q3
## 128 22.21 120.24 57.35 2017 Q3
## 129 21.29 116.83 51.92 2017 Q3
## 130 18.88 118.36 50.38 2017 Q4
## 131 19.02 105.24 50.33 2017 Q4
## 132 22.38 103.97 52.97 2017 Q4
## 133 25.07 125.64 51.88 2018 Q1
## 134 24.32 122.41 47.71 2018 Q1
## 135 21.43 119.98 46.28 2018 Q1
## 136 23.65 116.75 44.46 2018 Q2
## 137 21.09 129.55 45.52 2018 Q2
## 138 27.50 139.55 50.81 2018 Q2
## 139 26.58 127.41 47.77 2018 Q3
## 140 27.83 112.23 48.09 2018 Q3
## 141 32.00 119.24 52.11 2018 Q3
## 142 32.39 90.03 52.19 2018 Q4
## 143 30.72 83.20 49.30 2018 Q4
## 144 24.74 78.09 39.78 2018 Q4
## 145 28.38 91.28 45.17 2019 Q1
## 146 28.90 94.78 45.85 2019 Q1
## 147 27.02 100.57 43.40 2019 Q1
## 148 30.90 93.67 46.99 2019 Q2
## 149 27.26 92.11 44.25 2019 Q2
## 150 30.70 100.21 45.74 2019 Q2
## 151 30.31 91.54 47.39 2019 Q3
## 152 27.60 92.71 38.69 2019 Q3
## 153 26.63 96.80 37.14 2019 Q3
## 154 26.96 95.40 33.29 2019 Q4
## 155 32.94 99.96 37.30 2019 Q4
## 156 32.74 106.39 38.77 2019 Q4
## 157 29.26 106.80 31.53 2020 Q1
## 158 25.70 100.32 22.73 2020 Q1
## 159 19.44 99.13 12.94 2020 Q1
## 160 22.42 113.07 16.19 2020 Q2
## 161 21.75 121.60 19.45 2020 Q2
## 162 21.10 130.68 21.87 2020 Q2
## 163 21.10 140.15 24.70 2020 Q3
## 164 22.07 138.02 26.38 2020 Q3
## 165 21.77 129.05 26.54 2020 Q3
## 166 20.24 118.58 27.29 2020 Q4
## 167 26.91 126.42 33.70 2020 Q4
## 168 30.09 142.11 35.59 2020 Q4
## 169 41.42 141.90 46.64 2021 Q1
## 170 53.03 132.75 62.02 2021 Q1
## 171 43.46 134.14 43.37 2021 Q1
## 172 37.66 140.96 39.56 2021 Q2
## 173 32.11 141.81 40.91 2021 Q2
## 174 30.68 142.70 43.59 2021 Q2
## 175 29.01 143.00 39.70 2021 Q3
## 176 28.84 144.24 40.20 2021 Q3
## 177 25.38 141.47 38.32 2021 Q3
## 178 23.44 139.48 35.34 2021 Q4
## 179 23.27 123.54 30.20 2021 Q4
## 180 23.54 131.17 29.45 2021 Q4
## 181 27.91 131.28 31.67 2022 Q1
## 182 28.05 128.74 28.98 2022 Q1
## 183 24.92 125.20 35.79 2022 Q1
## 184 18.15 116.98 27.77 2022 Q2
## 185 18.45 137.40 32.74 2022 Q2
## 186 13.42 120.55 23.54 2022 Q2
## 187 15.00 130.22 22.77 2022 Q3
## 188 13.24 125.89 22.52 2022 Q3
## 189 11.50 114.99 18.33 2022 Q3
## 190 13.00 125.17 17.83 2022 Q4
## 191 11.40 129.96 19.54 2022 Q4
## 192 9.48 121.60 16.42 2022 Q4
#Plot the stock price / variable using a time series format.
disneyxts<-xts(disney$Disney_Adj_Close,order.by=disney$Date)
plot(disneyxts)

dygraph(disneyxts, main = "Disney Stock Price") %>%
dyOptions(colors = RColorBrewer::brewer.pal(4, "Dark2")) %>%
dyShading(from = "2011-09-1",
to = "2022-12-26",
color = "#FFE6E6")
#### VISUALIZATION
# Decompose the time series data in observed, trend, seasonality, and random.
# Decomposition: observed + trend + seasonal + random
# observed: data observations
# trend: increasing / decreasing value of data observations
# seasonality: repeating short-term cycle in time series
# noise: random variation in time series
disneyts<-ts(disney$Disney_Adj_Close,start=c(2007,1),end=c(2022,4),frequency=4)
disney_ts_decompose<-decompose(disneyts)
plot(disney_ts_decompose)

# After decomposing the graph we can interpret the following:
# - Observed component: We can observe a stock behavior with low volatility during the first years, a sudden drop at 2013/2014, but recovering immediately, geting into an increasing trend to then once again drop in 2021.
# - Trend component: During the first years of our data, the stock maintained a remarkable constant behavior, however in 2013 there is clearly the drop we mentioned but getting into an increasing trend once again .
# - Seasonal component: Season trend is clearly observed in the graph, at the beginning of each year the stock is at its lowest, then peaks just to get back on bottom at the last trimester.
# - Random component: Here we can observe how the random component is negative correlated to the seasonal component. We noticed this because when seasonal drops, random peaks. This mean that there possibly is some unknown external variable that is related to the seasonal stock behavior.
#### ESTIMATION
# - Detect if the time series data is stationary.
#- Do the selected stock price display non-stationary series or stationary series?
adf.test(disneyts)
##
## Augmented Dickey-Fuller Test
##
## data: disneyts
## Dickey-Fuller = -2.1834, Lag order = 3, p-value = 0.5006
## alternative hypothesis: stationary
# Our p-value is 0.5005, so we accept HO, it is not stationary
# This means that we can confirm our assumption made though the graph earlier, Disney's stock price is non-stationary.
#- Detect if the time series data shows serial autocorrelation.
# 3) Serial Autocorrelation
# ACF plots: correlation between two periods in a time series is referred as autocorrelation function (acf)
acf(disney$Disney_Adj_Close,main="Significant Autocorrelations")

#In our autocorrelation bar we can see that the level of significance in autocorrelation is very high and it stays like that during our time series.
#We can also see that the values dosen’t get near to the blue line which is our line of significant level.
#This gives us the conclusion that the price of the stock has autocorrelation.
# ARMA
# time series modeling
summary(disney_ARMA<-arma(log(disney$Disney_Adj_Close),order=c(1,1)))
plot(disney_ARMA)
disney_estimated_stock_price<-exp(disney_ARMA$fitted.values)
plot(disney_estimated_stock_price)
# model evaluation
# Testing serial autocorrelation in regression residuals
# Ho: There is no serial autocorrelation
# Ha: There is serial autocorrelation
disney_ARMA_residuals<-disney_ARMA$residuals
Box.test(disney_ARMA_residuals,lag=5,type="Ljung-Box")
# this test shows residual autocorrelation. with a p-value of 0.5433 we reject Ho.
adf.test(na.omit(disney_estimated_stock_price))
# With a p value of 0.1778 the model shows stationarity within the residual with a p-value of 0.1778
# forecast (ARMA)
disney_ARMA_forecast<-forecast(disney_estimated_stock_price,h=5)
disney_ARMA_forecast
plot(disney_ARMA_forecast)
autoplot(disney_ARMA_forecast)
# In this graph we can see the possible values of the predictive variable.
#The purple part of the graph show us the range of values (high and low) that the price of the stock might reach.
.
### plotting log-transformation and differences
plot(BMW$Date,BMW$Adj.Close, type="l",col="blue", lwd=2, xlab ="Date",ylab ="Stock Price", main = "BMW Stock Price")
plot(BMW$Date,log(BMW$Adj.Close), type="l",col="blue", lwd=2, xlab ="Date",ylab ="log(Stock Price)", main = "BMW Stock Price")
plot(diff(log(BMW$Adj.Close)),type="l",ylab="first order difference",main = "Diff - BMW Stock Price")
adf.test(log(BMW$Adj.Close))
adf.test(diff(log(BMW$Adj.Close)))
# Though these graphs, escpecially the last one, we can de differences between the originas stock prices
# and the stock prices with log applied.
# The beahaviour of these shows
# ARIMA
disney_ARIMA <- Arima(disney$Disney_Adj_Close,order=c(1,1,1))
print(disney_ARIMA)
plot(disney_ARIMA$residuals,main="ARIMA(1,1,1) - Disney Stock Price")
acf(disney_ARIMA$residuals,main="ACF - ARIMA (1,1,1)")
# ACF plot displays weak or no autocorrelation.
Box.test(disney_ARIMA$residuals,lag=1,type="Ljung-Box")
# P-value is 0.9937 > 0.05 indicating that ARIMA model does NOT show residual serial autocorrelation.
adf.test(disney_ARIMA$residuals)
# ADF test shows a p-value of 0.01, which suggest that ARIMA residuals are stationary since p-value is < 0.05.
# forecast (ARIMA)
disney_ARIMA_forecast<-forecast(disney_ARIMA,h=5)
disney_ARIMA_forecast
plot(disney_ARIMA_forecast)
autoplot(disney_ARIMA_forecast)
## CONCLUSION
#Based on diagnostic tests, compare the 3 estimated time series regression models,and select the results that you consider might generate the best forecast.
#For our model, the best fit to use in the ARIMA. Since initially, our data was non-sationary, the conversion works better with ARIMA. Also this one the model that showed no autocorrelation with the residuals, which is perfect. As well as residuals that were stationary.
#Here we can observe once again the forecast with ARIMA.
# forecast (ARIMA)
disney_ARIMA_forecast<-forecast(disney_ARIMA,h=5)
disney_ARIMA_forecast
plot(disney_ARIMA_forecast)
autoplot(disney_ARIMA_forecast)