I am choosing AMD and Nvidia as they are both the most recognizing company in the micro chip catagory.

library(forecast)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(xts)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(TTR)
library(vars)
## Loading required package: MASS
## Loading required package: strucchange
## Loading required package: sandwich
## Loading required package: urca
## Loading required package: lmtest
library(tseries)
AMD=read.csv("C:/Users/yiq00/Downloads/AMD.csv",header=TRUE)
NVDA=read.csv("C:/Users/yiq00/Downloads/NVDA.csv",header=TRUE)
str(AMD)
## 'data.frame':    60 obs. of  7 variables:
##  $ Date     : chr  "2015-11-01" "2015-12-01" "2016-01-01" "2016-02-01" ...
##  $ Open     : num  2.13 2.36 2.77 2.17 2.16 2.79 3.58 4.6 5.09 6.89 ...
##  $ High     : num  2.4 3.06 2.82 2.19 2.98 3.99 4.71 5.52 7.16 8 ...
##  $ Low      : num  1.94 2.2 1.75 1.81 2.12 2.6 3.45 4.07 4.82 6.15 ...
##  $ Close    : num  2.36 2.87 2.2 2.14 2.85 3.55 4.57 5.14 6.86 7.4 ...
##  $ Adj.Close: num  2.36 2.87 2.2 2.14 2.85 3.55 4.57 5.14 6.86 7.4 ...
##  $ Volume   : num  1.36e+08 2.66e+08 3.55e+08 1.93e+08 3.33e+08 ...
head(AMD)
##         Date Open High  Low Close Adj.Close    Volume
## 1 2015-11-01 2.13 2.40 1.94  2.36      2.36 136451200
## 2 2015-12-01 2.36 3.06 2.20  2.87      2.87 266450600
## 3 2016-01-01 2.77 2.82 1.75  2.20      2.20 355489300
## 4 2016-02-01 2.17 2.19 1.81  2.14      2.14 192749800
## 5 2016-03-01 2.16 2.98 2.12  2.85      2.85 333321700
## 6 2016-04-01 2.79 3.99 2.60  3.55      3.55 472576300
summary(AMD)
##      Date                Open            High            Low        
##  Length:60          Min.   : 2.13   Min.   : 2.19   Min.   : 1.750  
##  Class :character   1st Qu.:10.31   1st Qu.:11.61   1st Qu.: 9.325  
##  Mode  :character   Median :14.29   Median :15.60   Median :12.300  
##                     Mean   :22.65   Mean   :26.32   Mean   :20.414  
##                     3rd Qu.:30.55   3rd Qu.:34.31   3rd Qu.:27.485  
##                     Max.   :91.92   Max.   :94.28   Max.   :76.100  
##      Close         Adj.Close         Volume         
##  Min.   : 2.14   Min.   : 2.14   Min.   :1.365e+08  
##  1st Qu.:10.35   1st Qu.:10.35   1st Qu.:9.883e+08  
##  Median :14.51   Median :14.51   Median :1.206e+09  
##  Mean   :23.68   Mean   :23.68   Mean   :1.273e+09  
##  3rd Qu.:30.56   3rd Qu.:30.56   3rd Qu.:1.592e+09  
##  Max.   :90.82   Max.   :90.82   Max.   :3.063e+09
str(NVDA)
## 'data.frame':    60 obs. of  7 variables:
##  $ Date     : chr  "2015-12-01" "2016-01-01" "2016-02-01" "2016-03-01" ...
##  $ Open     : num  32 32.3 29.3 31.4 35.4 ...
##  $ High     : num  33.9 33.4 32.1 36.2 37.5 ...
##  $ Low      : num  32 26.5 24.8 31 34.6 ...
##  $ Close    : num  33 29.3 31.4 35.6 35.5 ...
##  $ Adj.Close: num  32.3 28.7 30.7 35 34.9 ...
##  $ Volume   : int  140679300 203474500 225001200 164447600 168356300 259195900 204947500 180251300 232628000 216631300 ...
head(NVDA)
##         Date  Open  High   Low Close Adj.Close    Volume
## 1 2015-12-01 32.00 33.94 31.97 32.96  32.25914 140679300
## 2 2016-01-01 32.29 33.44 26.45 29.29  28.66718 203474500
## 3 2016-02-01 29.26 32.12 24.75 31.36  30.69317 225001200
## 4 2016-03-01 31.44 36.25 31.04 35.63  34.99941 164447600
## 5 2016-04-01 35.41 37.46 34.63 35.53  34.90119 168356300
## 6 2016-05-01 35.87 46.82 34.40 46.72  45.89315 259195900
summary(NVDA)
##      Date                Open             High             Low        
##  Length:60          Min.   : 29.26   Min.   : 32.12   Min.   : 24.75  
##  Class :character   1st Qu.:104.66   1st Qu.:117.92   1st Qu.: 95.65  
##  Mode  :character   Median :173.80   Median :189.80   Median :158.85  
##                     Mean   :187.98   Mean   :210.43   Mean   :172.45  
##                     3rd Qu.:238.58   3rd Qu.:259.75   3rd Qu.:218.30  
##                     Max.   :550.32   Max.   :589.07   Max.   :495.80  
##      Close          Adj.Close          Volume         
##  Min.   : 29.29   Min.   : 28.67   Min.   :140679300  
##  1st Qu.:108.38   1st Qu.:107.20   1st Qu.:203201450  
##  Median :176.42   Median :175.46   Median :266070900  
##  Mean   :195.93   Mean   :194.99   Mean   :276868287  
##  3rd Qu.:242.72   3rd Qu.:240.85   3rd Qu.:339431000  
##  Max.   :541.22   Max.   :541.06   Max.   :586138000
AMDts=ts(AMD[,2], start=c(2015,11,01), end=c(2020,10,01), frequency = 12)
plot(AMDts, main="Monthly AMD Volume (2015-2020)",ylab="Volume")

NVDAts=ts(NVDA[,2], start=c(2015,12,01), end=c(2020,11,01), frequency = 12)
plot(NVDAts, main="Monthly NVDA Volume (2015-2020)",ylab="Volume")

Forcasting

tech <- data.frame(AMD$Adj.Close, NVDA$Adj.Close)
tech.ts <- ts(tech, frequency = 12, start = c(2015,11))
plot(tech.ts)

acf(tech.ts)

plot(diff(tech.ts))

acf(diff(tech.ts))

Var Model without Differencing

VARselect(tech.ts, lag.max=8, type="const")$selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      7      3      2      7
varfit<-VAR(tech.ts, p=1, type="const")
summary(varfit)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: AMD.Adj.Close, NVDA.Adj.Close 
## Deterministic variables: const 
## Sample size: 59 
## Log Likelihood: -445.625 
## Roots of the characteristic polynomial:
## 1.035 0.8685
## Call:
## VAR(y = tech.ts, p = 1, type = "const")
## 
## 
## Estimation results for equation AMD.Adj.Close: 
## ============================================== 
## AMD.Adj.Close = AMD.Adj.Close.l1 + NVDA.Adj.Close.l1 + const 
## 
##                   Estimate Std. Error t value Pr(>|t|)    
## AMD.Adj.Close.l1   0.91022    0.06488  14.029   <2e-16 ***
## NVDA.Adj.Close.l1  0.02095    0.01096   1.912    0.061 .  
## const             -0.67958    1.23199  -0.552    0.583    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 4.803 on 56 degrees of freedom
## Multiple R-Squared: 0.9492,  Adjusted R-squared: 0.9474 
## F-statistic: 522.9 on 2 and 56 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation NVDA.Adj.Close: 
## =============================================== 
## NVDA.Adj.Close = AMD.Adj.Close.l1 + NVDA.Adj.Close.l1 + const 
## 
##                   Estimate Std. Error t value Pr(>|t|)    
## AMD.Adj.Close.l1   0.24923    0.36385   0.685    0.496    
## NVDA.Adj.Close.l1  0.99378    0.06145  16.171   <2e-16 ***
## const              4.03153    6.90909   0.584    0.562    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 26.94 on 56 degrees of freedom
## Multiple R-Squared: 0.955,   Adjusted R-squared: 0.9534 
## F-statistic: 594.7 on 2 and 56 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##                AMD.Adj.Close NVDA.Adj.Close
## AMD.Adj.Close          23.07          53.93
## NVDA.Adj.Close         53.93         725.53
## 
## Correlation matrix of residuals:
##                AMD.Adj.Close NVDA.Adj.Close
## AMD.Adj.Close         1.0000         0.4168
## NVDA.Adj.Close        0.4168         1.0000
varfit.fc<-forecast(varfit, h=12 )
varfit.fc
## AMD.Adj.Close
##          Point Forecast     Lo 80     Hi 80    Lo 95     Hi 95
## Nov 2020       79.08032  72.92499  85.23565 69.66656  88.49408
## Dec 2020       82.93800  74.38354  91.49246 69.85508  96.02092
## Jan 2021       86.87424  76.51565  97.23283 71.03215 102.71634
## Feb 2021       90.89950  79.01015 102.78884 72.71631 109.08268
## Mar 2021       95.02357  81.74912 108.29802 74.72205 115.32509
## Apr 2021       99.25574  84.67658 113.83489 76.95885 121.55262
## May 2021      103.60485  87.76380 119.44590 79.37805 127.83164
## Jun 2021      108.07941  90.99603 125.16279 81.95263 134.20619
## Jul 2021      112.68765  94.36644 131.00887 84.66777 140.70754
## Aug 2021      117.43761  97.87289 137.00232 87.51596 147.35925
## Sep 2021      122.33715 101.51617 143.15812 90.49422 154.18008
## Oct 2021      127.39407 105.29890 149.48923 93.60243 161.18571
## 
## NVDA.Adj.Close
##          Point Forecast    Lo 80    Hi 80    Lo 95     Hi 95
## Nov 2020       555.5202 521.0008 590.0396 502.7274  608.3131
## Dec 2020       575.8040 526.6652 624.9428 500.6527  650.9553
## Jan 2021       596.9230 536.2507 657.5953 504.1328  689.7133
## Feb 2021       618.8916 548.1669 689.6163 510.7276  727.0557
## Mar 2021       641.7268 561.8064 721.6472 519.4990  763.9545
## Apr 2021       665.4476 576.8666 754.0287 529.9747  800.9206
## May 2021       690.0757 593.1773 786.9741 541.8824  838.2689
## Jun 2021       715.6344 610.6361 820.6327 555.0534  876.2154
## Jul 2021       742.1493 629.1803 855.1182 569.3782  914.9204
## Aug 2021       769.6476 648.7720 890.5232 584.7844  954.5109
## Sep 2021       798.1587 669.3903 926.9272 601.2244  995.0931
## Oct 2021       827.7135 691.0260 964.4011 618.6679 1036.7591
plot(varfit.fc)

tsdisplay(residuals(varfit))

Var Model Creation with Differencing

diff.ts <- (diff(tech.ts))
VARselect(diff.ts, lag.max=8, type="const")$selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      6      1      1      1
varfit.diff<-VAR(diff.ts, p=1, type="const")
summary(varfit.diff)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: AMD.Adj.Close, NVDA.Adj.Close 
## Deterministic variables: const 
## Sample size: 58 
## Log Likelihood: -427.656 
## Roots of the characteristic polynomial:
## 0.3909 0.3909
## Call:
## VAR(y = diff.ts, p = 1, type = "const")
## 
## 
## Estimation results for equation AMD.Adj.Close: 
## ============================================== 
## AMD.Adj.Close = AMD.Adj.Close.l1 + NVDA.Adj.Close.l1 + const 
## 
##                   Estimate Std. Error t value Pr(>|t|)    
## AMD.Adj.Close.l1  -0.19973    0.12437  -1.606    0.114    
## NVDA.Adj.Close.l1  0.12010    0.02231   5.384 1.56e-06 ***
## const              0.55144    0.56161   0.982    0.330    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 4.039 on 55 degrees of freedom
## Multiple R-Squared: 0.3514,  Adjusted R-squared: 0.3278 
## F-statistic:  14.9 on 2 and 55 DF,  p-value: 6.743e-06 
## 
## 
## Estimation results for equation NVDA.Adj.Close: 
## =============================================== 
## NVDA.Adj.Close = AMD.Adj.Close.l1 + NVDA.Adj.Close.l1 + const 
## 
##                   Estimate Std. Error t value Pr(>|t|)  
## AMD.Adj.Close.l1   -1.8303     0.7942  -2.305   0.0250 *
## NVDA.Adj.Close.l1   0.3355     0.1424   2.355   0.0221 *
## const               8.5473     3.5861   2.383   0.0206 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 25.79 on 55 degrees of freedom
## Multiple R-Squared:  0.12,   Adjusted R-squared: 0.088 
## F-statistic:  3.75 on 2 and 55 DF,  p-value: 0.02974 
## 
## 
## 
## Covariance matrix of residuals:
##                AMD.Adj.Close NVDA.Adj.Close
## AMD.Adj.Close          16.32          34.36
## NVDA.Adj.Close         34.36         665.26
## 
## Correlation matrix of residuals:
##                AMD.Adj.Close NVDA.Adj.Close
## AMD.Adj.Close         1.0000         0.3298
## NVDA.Adj.Close        0.3298         1.0000
varfit.diff.fc<-forecast(varfit.diff, h=12 )
varfit.diff.fc
## AMD.Adj.Close
##          Point Forecast      Lo 80     Hi 80     Lo 95    Hi 95
## Nov 2020      6.0572485  0.8806283 11.233869 -1.859709 13.97421
## Dec 2020      3.2394010 -3.1574794  9.636282 -6.543783 13.02259
## Jan 2021      0.9072792 -5.5539246  7.368483 -8.974279 10.78884
## Feb 2021      1.0211700 -5.4612390  7.503579 -8.892819 10.93516
## Mar 2021      1.3930112 -5.0917496  7.877772 -8.524575 11.31060
## Apr 2021      1.4261043 -5.0590025  7.911211 -8.492011 11.34422
## May 2021      1.3737770 -5.1114072  7.858961 -8.544456 11.29201
## Jun 2021      1.3616138 -5.1235755  7.846803 -8.556627 11.27985
## Jul 2021      1.3679582 -5.1172333  7.853150 -8.550286 11.28620
## Aug 2021      1.3706784 -5.1145131  7.855870 -8.547566 11.28892
## Sep 2021      1.3700784 -5.1151132  7.855270 -8.548166 11.28832
## Oct 2021      1.3695812 -5.1156104  7.854773 -8.548663 11.28783
## 
## NVDA.Adj.Close
##          Point Forecast       Lo 80    Hi 80     Lo 95    Hi 95
## Nov 2020      32.453392  -0.6012661 65.50805 -18.09935 83.00613
## Dec 2020       8.349808 -26.8082006 43.50782 -45.41973 62.11934
## Jan 2021       5.419789 -29.9824163 40.82199 -48.72321 59.56279
## Feb 2021       8.705185 -26.7609357 44.17131 -45.53557 62.94594
## Mar 2021       9.599090 -25.8706556 45.06884 -44.64720 63.84538
## Apr 2021       9.218439 -26.2529972 44.68987 -45.03044 63.46732
## May 2021       9.030147 -26.4413644 44.50166 -45.21885 63.27914
## Jun 2021       9.062744 -26.4088048 44.53429 -45.18631 63.31180
## Jul 2021       9.095944 -26.3756074 44.56750 -45.15311 63.34500
## Aug 2021       9.095471 -26.3760806 44.56702 -45.15359 63.34453
## Sep 2021       9.090334 -26.3812182 44.56189 -45.15872 63.33939
## Oct 2021       9.089708 -26.3818437 44.56126 -45.15935 63.33877
plot(varfit.diff.fc)

tsdisplay(residuals(varfit.diff))