I choose Nike and then I asked my wife who was Nike’s main competitor and she said Lululemon. I didn’t agree but compared anyway.
library(readr)
library(ggplot2)
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(tseries)
library(vars)
## Loading required package: MASS
## Loading required package: strucchange
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: sandwich
## Loading required package: urca
## Loading required package: lmtest
library(readxl)
LULU <- read_excel("Documents/Data Analysis and econometrics/LULU.xlsx")
NKE <- read_excel("Documents/Data Analysis and econometrics/NKE.xlsx")
str(NKE)
## Classes 'tbl_df', 'tbl' and 'data.frame': 253 obs. of 7 variables:
## $ Date : chr "2019-08-06" "2019-08-07" "2019-08-08" "2019-08-09" ...
## $ Open : num 79.8 80.5 81.8 83.1 81.4 ...
## $ High : num 81.6 81.8 83.4 83.4 81.9 ...
## $ Low : num 79.5 80.1 81.6 81.3 81.2 ...
## $ Close : num 81.3 81.3 83 82 81.7 ...
## $ Adj Close: num 80.5 80.4 82.1 81.1 80.8 ...
## $ Volume : num 8664500 6275000 6208900 5460200 3595500 ...
str(LULU)
## Classes 'tbl_df', 'tbl' and 'data.frame': 253 obs. of 7 variables:
## $ Date : chr "2019-08-06" "2019-08-07" "2019-08-08" "2019-08-09" ...
## $ Open : num 176 177 183 185 182 ...
## $ High : num 180 182 187 186 182 ...
## $ Low : num 176 176 182 181 178 ...
## $ Close : num 180 181 186 183 179 ...
## $ Adj Close: num 180 181 186 183 179 ...
## $ Volume : num 1371900 1009300 1481200 950700 965400 ...
ts(NKE['Adj Close']) %>% autoplot(series='NKE')+
+ + + ts(LULU['Adj Close']) %>% autolayer(series='LULU')
Lululemon has been more successful in recent months.
NKE.ts<-ts(NKE$`Adj Close`)
LULU.ts<-ts(LULU$`Adj Close`)
checkresiduals(NKE.ts)
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.
checkresiduals(LULU.ts)
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.
Nothing surprising in the residuals
price<-cbind(NKE$`Adj Close`,LULU$`Adj Close`)
names(price)<-c("NKE","LULU")
price.ts<-ts(price)
plot(price.ts)
price.var = VAR(price, type='const', lag.max=1, ic='AIC')
## Warning in VAR(price, type = "const", lag.max = 1, ic = "AIC"): No column names supplied in y, using: y1, y2 , instead.
summary(price.var)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: y1, y2
## Deterministic variables: const
## Sample size: 252
## Log Likelihood: -1296.836
## Roots of the characteristic polynomial:
## 1.002 0.9481
## Call:
## VAR(y = price, type = "const", lag.max = 1, ic = "AIC")
##
##
## Estimation results for equation y1:
## ===================================
## y1 = y1.l1 + y2.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## y1.l1 0.936368 0.024145 38.780 < 2e-16 ***
## y2.l1 0.006292 0.004186 1.503 0.13410
## const 4.472281 1.665217 2.686 0.00772 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 2.091 on 249 degrees of freedom
## Multiple R-Squared: 0.9304, Adjusted R-squared: 0.9299
## F-statistic: 1665 on 2 and 249 DF, p-value: < 2.2e-16
##
##
## Estimation results for equation y2:
## ===================================
## y2 = y1.l1 + y2.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## y1.l1 -0.12216 0.07418 -1.647 0.1008
## y2.l1 1.01379 0.01286 78.827 <2e-16 ***
## const 8.67138 5.11590 1.695 0.0913 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 6.424 on 249 degrees of freedom
## Multiple R-Squared: 0.9807, Adjusted R-squared: 0.9805
## F-statistic: 6313 on 2 and 249 DF, p-value: < 2.2e-16
##
##
##
## Covariance matrix of residuals:
## y1 y2
## y1 4.373 8.768
## y2 8.768 41.273
##
## Correlation matrix of residuals:
## y1 y2
## y1 1.0000 0.6527
## y2 0.6527 1.0000
select<-VARselect(price.ts,lag.max=8,type="const")[["selection"]]
select
## AIC(n) HQ(n) SC(n) FPE(n)
## 6 1 1 6
price1<-VAR(price.ts,p=6,type = "const")
price1
##
## VAR Estimation Results:
## =======================
##
## Estimated coefficients for equation Series.1:
## =============================================
## Call:
## Series.1 = Series.1.l1 + Series.2.l1 + Series.1.l2 + Series.2.l2 + Series.1.l3 + Series.2.l3 + Series.1.l4 + Series.2.l4 + Series.1.l5 + Series.2.l5 + Series.1.l6 + Series.2.l6 + const
##
## Series.1.l1 Series.2.l1 Series.1.l2 Series.2.l2 Series.1.l3 Series.2.l3
## 0.92089712 -0.01264333 -0.12100178 0.11084834 -0.01632529 -0.02619696
## Series.1.l4 Series.2.l4 Series.1.l5 Series.2.l5 Series.1.l6 Series.2.l6
## 0.01423062 -0.04000512 0.05922363 0.07274154 0.09194492 -0.10386282
## const
## 4.44436853
##
##
## Estimated coefficients for equation Series.2:
## =============================================
## Call:
## Series.2 = Series.1.l1 + Series.2.l1 + Series.1.l2 + Series.2.l2 + Series.1.l3 + Series.2.l3 + Series.1.l4 + Series.2.l4 + Series.1.l5 + Series.2.l5 + Series.1.l6 + Series.2.l6 + const
##
## Series.1.l1 Series.2.l1 Series.1.l2 Series.2.l2 Series.1.l3 Series.2.l3
## -0.21238727 1.00051867 -0.02177911 0.14889746 0.29269010 -0.11035199
## Series.1.l4 Series.2.l4 Series.1.l5 Series.2.l5 Series.1.l6 Series.2.l6
## -0.27026223 -0.04262446 -0.07756527 0.17862252 0.15836293 -0.16574259
## const
## 10.38136275
summary(price1)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: Series.1, Series.2
## Deterministic variables: const
## Sample size: 247
## Log Likelihood: -1247.886
## Roots of the characteristic polynomial:
## 1.006 0.9401 0.7467 0.7467 0.7207 0.7207 0.7037 0.5974 0.5974 0.4463 0.4463 0.08828
## Call:
## VAR(y = price.ts, p = 6, type = "const")
##
##
## Estimation results for equation Series.1:
## =========================================
## Series.1 = Series.1.l1 + Series.2.l1 + Series.1.l2 + Series.2.l2 + Series.1.l3 + Series.2.l3 + Series.1.l4 + Series.2.l4 + Series.1.l5 + Series.2.l5 + Series.1.l6 + Series.2.l6 + const
##
## Estimate Std. Error t value Pr(>|t|)
## Series.1.l1 0.92090 0.08345 11.035 < 2e-16 ***
## Series.2.l1 -0.01264 0.02625 -0.482 0.630457
## Series.1.l2 -0.12100 0.11599 -1.043 0.297922
## Series.2.l2 0.11085 0.03763 2.946 0.003548 **
## Series.1.l3 -0.01633 0.11598 -0.141 0.888180
## Series.2.l3 -0.02620 0.03829 -0.684 0.494559
## Series.1.l4 0.01423 0.11596 0.123 0.902437
## Series.2.l4 -0.04001 0.03827 -1.045 0.296926
## Series.1.l5 0.05922 0.11434 0.518 0.604989
## Series.2.l5 0.07274 0.03831 1.899 0.058848 .
## Series.1.l6 0.09194 0.08222 1.118 0.264619
## Series.2.l6 -0.10386 0.02743 -3.786 0.000194 ***
## const 4.44437 1.68138 2.643 0.008765 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 1.971 on 234 degrees of freedom
## Multiple R-Squared: 0.9397, Adjusted R-squared: 0.9366
## F-statistic: 303.7 on 12 and 234 DF, p-value: < 2.2e-16
##
##
## Estimation results for equation Series.2:
## =========================================
## Series.2 = Series.1.l1 + Series.2.l1 + Series.1.l2 + Series.2.l2 + Series.1.l3 + Series.2.l3 + Series.1.l4 + Series.2.l4 + Series.1.l5 + Series.2.l5 + Series.1.l6 + Series.2.l6 + const
##
## Estimate Std. Error t value Pr(>|t|)
## Series.1.l1 -0.21239 0.27300 -0.778 0.4374
## Series.2.l1 1.00052 0.08586 11.653 <2e-16 ***
## Series.1.l2 -0.02178 0.37944 -0.057 0.9543
## Series.2.l2 0.14890 0.12310 1.210 0.2277
## Series.1.l3 0.29269 0.37941 0.771 0.4412
## Series.2.l3 -0.11035 0.12526 -0.881 0.3792
## Series.1.l4 -0.27026 0.37935 -0.712 0.4769
## Series.2.l4 -0.04262 0.12519 -0.340 0.7338
## Series.1.l5 -0.07757 0.37406 -0.207 0.8359
## Series.2.l5 0.17862 0.12534 1.425 0.1554
## Series.1.l6 0.15836 0.26898 0.589 0.5566
## Series.2.l6 -0.16574 0.08974 -1.847 0.0660 .
## const 10.38136 5.50037 1.887 0.0603 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 6.449 on 234 degrees of freedom
## Multiple R-Squared: 0.9812, Adjusted R-squared: 0.9802
## F-statistic: 1018 on 12 and 234 DF, p-value: < 2.2e-16
##
##
##
## Covariance matrix of residuals:
## Series.1 Series.2
## Series.1 3.886 8.261
## Series.2 8.261 41.589
##
## Correlation matrix of residuals:
## Series.1 Series.2
## Series.1 1.0000 0.6498
## Series.2 0.6498 1.0000
price2<-VAR(price.ts,p=1,type = "const")
summary(price2)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: Series.1, Series.2
## Deterministic variables: const
## Sample size: 252
## Log Likelihood: -1296.836
## Roots of the characteristic polynomial:
## 1.002 0.9481
## Call:
## VAR(y = price.ts, p = 1, type = "const")
##
##
## Estimation results for equation Series.1:
## =========================================
## Series.1 = Series.1.l1 + Series.2.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## Series.1.l1 0.936368 0.024145 38.780 < 2e-16 ***
## Series.2.l1 0.006292 0.004186 1.503 0.13410
## const 4.472281 1.665217 2.686 0.00772 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 2.091 on 249 degrees of freedom
## Multiple R-Squared: 0.9304, Adjusted R-squared: 0.9299
## F-statistic: 1665 on 2 and 249 DF, p-value: < 2.2e-16
##
##
## Estimation results for equation Series.2:
## =========================================
## Series.2 = Series.1.l1 + Series.2.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## Series.1.l1 -0.12216 0.07418 -1.647 0.1008
## Series.2.l1 1.01379 0.01286 78.827 <2e-16 ***
## const 8.67138 5.11590 1.695 0.0913 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 6.424 on 249 degrees of freedom
## Multiple R-Squared: 0.9807, Adjusted R-squared: 0.9805
## F-statistic: 6313 on 2 and 249 DF, p-value: < 2.2e-16
##
##
##
## Covariance matrix of residuals:
## Series.1 Series.2
## Series.1 4.373 8.768
## Series.2 8.768 41.273
##
## Correlation matrix of residuals:
## Series.1 Series.2
## Series.1 1.0000 0.6527
## Series.2 0.6527 1.0000
plot(price1)
price1.fc<-forecast(price1)
price1.fc
## Series.1
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 254 100.2118 97.68538 102.7381 96.34800 104.0755
## 255 100.7662 97.37646 104.1559 95.58204 105.9504
## 256 101.0763 96.93927 105.2133 94.74928 107.4032
## 257 100.7101 95.95535 105.4649 93.43833 107.9819
## 258 101.5363 96.31681 106.7558 93.55378 109.5188
## 259 101.2023 95.31082 107.0938 92.19204 110.2126
## 260 101.0955 94.69677 107.4943 91.30947 110.8816
## 261 101.0191 94.17522 107.8630 90.55229 111.4859
## 262 100.7525 93.52643 107.9786 89.70116 111.8039
## 263 100.7687 93.23795 108.2994 89.25141 112.2860
##
## Series.2
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 254 340.2213 331.9566 348.4859 327.5816 352.8609
## 255 341.9477 330.4934 353.4021 324.4299 359.4656
## 256 343.8245 329.3442 358.3049 321.6787 365.9703
## 257 343.8206 326.6865 360.9547 317.6163 370.0250
## 258 346.1498 326.9060 365.3936 316.7190 375.5806
## 259 346.5413 324.8995 368.1831 313.4430 379.6396
## 260 347.2452 323.5956 370.8948 311.0762 383.4141
## 261 348.2344 322.7544 373.7144 309.2661 387.2027
## 262 348.6498 321.4779 375.8216 307.0940 390.2055
## 263 349.5302 320.8788 378.1816 305.7116 393.3488
autoplot(price1.fc)