setwd("~/desktop/ADEC7460.02 Spring 2019 Predictive Analytics/Dataset")
sina=read.csv("SINA.csv")
bidu=read.csv("BIDU.csv")
library(forecast)
library(ggplot2)
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(zoo)
stocks<-data.frame(sina$Adj.Close, bidu$Adj.Close)
mod<-stocks[-1,]
mod$sina.Adj.Close<-as.numeric(as.character(mod$sina.Adj.Close))
mod$bidu.Adj.Close<-as.numeric(as.character(mod$bidu.Adj.Close))
stocks.ts<-ts(mod, frequency=12,start = c(2014,5))
autoplot(stocks.ts)
The graph shows that the similiar trend of two stocks after 2016. And Baidu stock price is much higher than Sina’s.
stock.var1<-VAR(stocks.ts, p=1, type="both")
summary(stock.var1)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: sina.Adj.Close, bidu.Adj.Close
## Deterministic variables: both
## Sample size: 59
## Log Likelihood: -442.806
## Roots of the characteristic polynomial:
## 0.8734 0.8734
## Call:
## VAR(y = stocks.ts, p = 1, type = "both")
##
##
## Estimation results for equation sina.Adj.Close:
## ===============================================
## sina.Adj.Close = sina.Adj.Close.l1 + bidu.Adj.Close.l1 + const + trend
##
## Estimate Std. Error t value Pr(>|t|)
## sina.Adj.Close.l1 0.98964 0.06649 14.885 <2e-16 ***
## bidu.Adj.Close.l1 -0.06931 0.03692 -1.877 0.0658 .
## const 15.24423 6.55057 2.327 0.0237 *
## trend -0.01437 0.08252 -0.174 0.8624
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 7.522 on 55 degrees of freedom
## Multiple R-Squared: 0.9034, Adjusted R-squared: 0.8981
## F-statistic: 171.5 on 3 and 55 DF, p-value: < 2.2e-16
##
##
## Estimation results for equation bidu.Adj.Close:
## ===============================================
## bidu.Adj.Close = sina.Adj.Close.l1 + bidu.Adj.Close.l1 + const + trend
##
## Estimate Std. Error t value Pr(>|t|)
## sina.Adj.Close.l1 0.35813 0.14547 2.462 0.01698 *
## bidu.Adj.Close.l1 0.74564 0.08079 9.230 9.09e-13 ***
## const 39.47333 14.33290 2.754 0.00796 **
## trend -0.39386 0.18055 -2.181 0.03344 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 16.46 on 55 degrees of freedom
## Multiple R-Squared: 0.7373, Adjusted R-squared: 0.7229
## F-statistic: 51.45 on 3 and 55 DF, p-value: 5.633e-16
##
##
##
## Covariance matrix of residuals:
## sina.Adj.Close bidu.Adj.Close
## sina.Adj.Close 56.58 47.93
## bidu.Adj.Close 47.93 270.89
##
## Correlation matrix of residuals:
## sina.Adj.Close bidu.Adj.Close
## sina.Adj.Close 1.0000 0.3872
## bidu.Adj.Close 0.3872 1.0000
acf(residuals(stock.var1)[,1])
acf(residuals(stock.var1)[,2])
autoplot(forecast(stock.var1,h=12))
stock.var2<-VAR(stocks.ts,p=1, type="const")
summary(stock.var2)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: sina.Adj.Close, bidu.Adj.Close
## Deterministic variables: const
## Sample size: 59
## Log Likelihood: -445.514
## Roots of the characteristic polynomial:
## 0.8882 0.8882
## Call:
## VAR(y = stocks.ts, p = 1, type = "const")
##
##
## Estimation results for equation sina.Adj.Close:
## ===============================================
## sina.Adj.Close = sina.Adj.Close.l1 + bidu.Adj.Close.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## sina.Adj.Close.l1 0.98141 0.04635 21.176 <2e-16 ***
## bidu.Adj.Close.l1 -0.06752 0.03516 -1.920 0.0599 .
## const 14.98131 6.31875 2.371 0.0212 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 7.457 on 56 degrees of freedom
## Multiple R-Squared: 0.9034, Adjusted R-squared: 0.8999
## F-statistic: 261.7 on 2 and 56 DF, p-value: < 2.2e-16
##
##
## Estimation results for equation bidu.Adj.Close:
## ===============================================
## bidu.Adj.Close = sina.Adj.Close.l1 + bidu.Adj.Close.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## sina.Adj.Close.l1 0.13250 0.10567 1.254 0.2151
## bidu.Adj.Close.l1 0.79467 0.08016 9.913 6.26e-14 ***
## const 32.26621 14.40741 2.240 0.0291 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 17 on 56 degrees of freedom
## Multiple R-Squared: 0.7145, Adjusted R-squared: 0.7043
## F-statistic: 70.09 on 2 and 56 DF, p-value: 5.69e-16
##
##
##
## Covariance matrix of residuals:
## sina.Adj.Close bidu.Adj.Close
## sina.Adj.Close 55.60 47.92
## bidu.Adj.Close 47.92 289.07
##
## Correlation matrix of residuals:
## sina.Adj.Close bidu.Adj.Close
## sina.Adj.Close 1.000 0.378
## bidu.Adj.Close 0.378 1.000
acf(residuals(stock.var2)[,1])
acf(residuals(stock.var2)[,2])
autoplot(forecast(stock.var2,h=12))
From the analysis above,Sina and Baidu are internet giants in China and I deemed that there are some correlations between these two stocks.