当前位置:首页 > [原创]R语言恩格尔-格兰杰检验Engle-Granger 多元garch VAR 脉冲模型分析报告附代码数据
有问题到淘宝找“大数据部落”就可以了
# 软件:R语言
# 主要内容:分析汇率和股价指数的联系,用格兰杰因果检验和脉冲响应函数 # 基本思路是:
topix=read.csv(\,header=F)
\日元兑人民币汇率(2012).csv\ ## [1] \日元兑人民币汇率(2012).csv\ 汇率=read.csv(\日元兑人民币汇率(2012).csv\)
# (一)描绘时序图→ 单位根检验(ADF检验)→平稳性检验,不平稳的话进行协整检验→
格兰杰因果检验
plot(topix[,1],topix[,2],type=\,xlab=\,ylab=\股价指数\ )
plot(汇率[,1],汇率[,2],type=\,xlab=\,ylab=\汇率\ )
##平稳性检验
# install.packages(\ library(urca)
有问题到淘宝找“大数据部落”就可以了
library(lmtest)
## Loading required package: zoo ##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base': ##
## as.Date, as.Date.numeric
# attach(data)
lc.df <-ur.df(y=topix[,2], lags=6, type='trend') summary(lc.df)
##
## ############################################### ## # Augmented Dickey-Fuller Test Unit Root Test # ## ############################################### ##
## Test regression trend ## ##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag) ##
## Residuals:
## Min 1Q Median 3Q Max
有问题到淘宝找“大数据部落”就可以了
## -94.672 -7.561 0.450 8.866 93.071 ##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|) ## (Intercept) 5.904667 2.796226 2.112 0.0349 * ## z.lag.1 -0.005841 0.003228 -1.809 0.0706 . ## tt 0.003041 0.002508 1.212 0.2256 ## z.diff.lag1 0.010590 0.028745 0.368 0.7126 ## z.diff.lag2 0.037838 0.028758 1.316 0.1885 ## z.diff.lag3 -0.044856 0.028735 -1.561 0.1188 ## z.diff.lag4 -0.049196 0.028726 -1.713 0.0871 . ## z.diff.lag5 0.010258 0.028746 0.357 0.7213 ## z.diff.lag6 -0.026627 0.028745 -0.926 0.3545 ## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ##
## Residual standard error: 16.84 on 1210 degrees of freedom
## Multiple R-squared: 0.009994, Adjusted R-squared: 0.003448 ## F-statistic: 1.527 on 8 and 1210 DF, p-value: 0.1432 ## ##
## Value of test-statistic is: -1.8094 1.8787 1.7898 ##
## Critical values for test statistics: ## 1pct 5pct 10pct ## tau3 -3.96 -3.41 -3.12 ## phi2 6.09 4.68 4.03 ## phi3 8.27 6.25 5.34 library(\)
## Loading required package: timeDate ## Loading required package: timeSeries ##
## Attaching package: 'timeSeries'
## The following object is masked from 'package:zoo': ##
## time<-
## Loading required package: fBasics ##
## Rmetrics Package fBasics
## Analysing Markets and calculating Basic Statistics ## Copyright (C) 2005-2014 Rmetrics Association Zurich
有问题到淘宝找“大数据部落”就可以了
## Educational Software for Financial Engineering and Computational Science
## Rmetrics is free software and comes with ABSOLUTELY NO WARRANTY. ## https://www.rmetrics.org --- Mail to: info@rmetrics.org ##
## Attaching package: 'fUnitRoots'
## The following objects are masked from 'package:urca': ##
## punitroot, qunitroot, unitrootTable unitrootTest(topix[,2])
##
## Title:
## Augmented Dickey-Fuller Test ##
## Test Results: ## PARAMETER:
## Lag Order: 1 ## STATISTIC: ## DF: 0.9535 ## P VALUE: ## t: 0.91 ## n: 0.9043 ##
## Description:
## Thu Mar 30 11:54:58 2017 by user: Administrator
##恩格尔-格兰杰检验Engle-Granger
# 第一步:建立两变量(y1,y2)的回归方程,
# 第二部:对该回归方程的残差(resid)进行单位根检验其中, # 原假设两变量不存在协整关系,备择假设是两变量存在协整关系。
# 利用最小二乘法对回归方程进行估计,从回归方程中提取残差进行检验。
##检验协整关系
library(\) adf.test(topix[,2])
##
## Augmented Dickey-Fuller Test ##
## data: topix[, 2]
## Dickey-Fuller = -1.9275, Lag order = 10, p-value = 0.609 ## alternative hypothesis: stationary adf.test(汇率[,2])
共分享92篇相关文档