<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>平稳性 on 格物堂</title><link>https://gewutang.cn/tags/%E5%B9%B3%E7%A8%B3%E6%80%A7/</link><description>Recent content in 平稳性 on 格物堂</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Sun, 09 Jan 2011 00:00:00 +0000</lastBuildDate><atom:link href="https://gewutang.cn/tags/%E5%B9%B3%E7%A8%B3%E6%80%A7/index.xml" rel="self" type="application/rss+xml"/><item><title>R与时间序列的平稳性</title><link>https://gewutang.cn/2011/01/09/r-and-the-stationary-of-time-series/</link><pubDate>Sun, 09 Jan 2011 00:00:00 +0000</pubDate><guid>https://gewutang.cn/2011/01/09/r-and-the-stationary-of-time-series/</guid><description>&lt;p&gt;“协整”算是计量经济学里面的明星概念，不了解计量经济学的人很容易被它笼罩的计量经济学光环给吓到。但事实上，协整并不神秘，是平易近人。&lt;/p&gt;&#10;&lt;p&gt;要了解“协整”，首先得提到一个名词——平稳。&lt;/p&gt;&#10;&lt;h2 id="什么是平稳时间序列"&gt;&lt;a href="#%e4%bb%80%e4%b9%88%e6%98%af%e5%b9%b3%e7%a8%b3%e6%97%b6%e9%97%b4%e5%ba%8f%e5%88%97" class="header-anchor"&gt;&lt;/a&gt;什么是平稳时间序列&#10;&lt;/h2&gt;&lt;p&gt;金融领域有很多类型的时间序列，学者们为了研究的方便通常会对这些时间序列进行分类。比如，按照时间序列数据产生时间间隔的长短分为高频时间序列和非高频时间序列。按照时间序列的平稳性与否，便可以将时间序列分为平稳的时间序列和非平稳的时间序列。&lt;/p&gt;&#10;&lt;p&gt;判断某个时间序列平稳与否主要看一下三点：&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;时间序列（随机过程）的均值是否是常数?或者说时间序列（随机过程）的均值是不是跟时间无关？如果不是常数则该时间序列是非平稳的；如果是常数，则该时间序列可能是平稳的，但不肯定，须进入第二步。&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;时间序列（随机过程）的方差是否是常数？或者说时间序列（随机过程）的方差是不是跟时间无关？如果不是常数则该时间序列是非平稳的；如果是常数，则该时间序列可能是平稳的，但不肯定，须进入第三步。&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;任意两个时期的时间序列之间的协方差是否仅仅依赖于两个时间序列的时间间隔。&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;如果一个时间序列同时满足上述三个条件，那么，该时间序列就是平稳的。&lt;/p&gt;&#10;&lt;p&gt;由于均值、方差和协方差可以被统一的成为统计特性，因此也可以说如果时间序列的统计特性不随着时间的推移而发生变化，则说明时间序列是平稳的。&lt;/p&gt;&#10;&lt;p&gt;平稳时间序列还可以进一步细分。根据平稳时间序列进行差分的次数，可以将平稳时间序列分为不同阶的平稳时间序列。如果一个时间序列本身是平稳的，那么该时间序列可被记作I(0),括号里面的0表示该时间序列没有进行差分。如果一个时间序列一阶差分之后平稳，那么可被记作I(1),以此类推。&lt;/p&gt;&#10;&lt;h2 id="平稳性的检验"&gt;&lt;a href="#%e5%b9%b3%e7%a8%b3%e6%80%a7%e7%9a%84%e6%a3%80%e9%aa%8c" class="header-anchor"&gt;&lt;/a&gt;平稳性的检验&#10;&lt;/h2&gt;&lt;p&gt;在应用过程中，时间序列的平稳性的判断要简单的多。常用的判断时间序列平稳性的方法有两个：图示法和单位根检验法。&lt;/p&gt;&#10;&lt;p&gt;图示法，顾名思义，就是画出时间序列的时序图，来目测时间序列是否平稳。如果画出的时间序列不存在明显的趋势，那么时间序列可能是平稳的。这个方法比较随意和主观，因此，只能作为辅助判断的手段。&lt;/p&gt;&#10;&lt;p&gt;单位根检验法是一个理论基础扎实的判断手段，单位根检验的方法非常多，一般常用的有DF检验(Dickey-Fuller Test)，ADF检验(Augmented Dickey-Fuller Test)和PP检验(Phillips-Perron Test)。这三个检验的理论基础在这里不讲,因为除却数理统计的专业人员，大部分人都不必深究这些理论，现实中只要懂得这些检验用软件的实现方法就可以了。&lt;/p&gt;&#10;&lt;p&gt;下面以R为例：&lt;/p&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;#生成两个时间序列：&#10;&#10;x=rnorm(500); #没有单位根&#10;&#10;y=cumsum(x); #有单位根&#10;&#10;# 绘制时序图&#10;&#10;plot.ts(x);&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/01/09/r-and-the-stationary-of-time-series/index_files/figure-html/unnamed-chunk-1-1.png" width="672" /&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;plot.ts(y);&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/01/09/r-and-the-stationary-of-time-series/index_files/figure-html/unnamed-chunk-1-2.png" width="672" /&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;# DF.test检验&#10;&#10;library(tseries) #载入tseries包&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## Registered S3 method overwritten by 'quantmod':&#10;## method from&#10;## as.zoo.data.frame zoo&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;adf.test(x)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## Warning in adf.test(x): p-value smaller than printed p-value&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## &#10;## &#9;Augmented Dickey-Fuller Test&#10;## &#10;## data: x&#10;## Dickey-Fuller = -7.863, Lag order = 7, p-value = 0.01&#10;## alternative hypothesis: stationary&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;p&gt;P值等于0.01，拒绝x是原假设（原假设为非平稳），即可以认为x是平稳的。&lt;/p&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;adf.test(y)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## &#10;## &#9;Augmented Dickey-Fuller Test&#10;## &#10;## data: y&#10;## Dickey-Fuller = -2.6979, Lag order = 7, p-value = 0.2829&#10;## alternative hypothesis: stationary&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;p&gt;P值等于0.303，因此y是非平稳的。&lt;/p&gt;&#10;&lt;p&gt;还可以用urca包中的ur.df()函数来完成上述过程：&lt;/p&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;# install.packages('urca') #安装urca包&#10;&#10;library(urca)#载入urca包&#10;&#10;?ur.df#查看ur.df()函数的帮助文档&#10;&#10;#用uroot包中的ADF.test()函数来完成上述过程&#10;&#10;# install.packages('uroot') #没有安装的话&#10;&#10;library(uroot) #载入uroot包&#10;?ADF.test#查看ADF.test()函数的帮助文档&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## 在指定的程序包和图书馆里没有与'ADF.test'有关的文档:&#10;## 你可以用用'??ADF.test'&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;h2 id="pp检验"&gt;&lt;a href="#pp%e6%a3%80%e9%aa%8c" class="header-anchor"&gt;&lt;/a&gt;PP检验&#10;&lt;/h2&gt;&lt;pre&gt;&lt;code class="language-r"&gt;library(tseries)&#10;&#10;pp.test(x)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## Warning in pp.test(x): p-value smaller than printed p-value&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## &#10;## &#9;Phillips-Perron Unit Root Test&#10;## &#10;## data: x&#10;## Dickey-Fuller Z(alpha) = -513.04, Truncation lag parameter = 5, p-value&#10;## = 0.01&#10;## alternative hypothesis: stationary&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;p&gt;P值等于0.01，拒绝x为非平稳序列的假设。&lt;/p&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;pp.test(y)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## &#10;## &#9;Phillips-Perron Unit Root Test&#10;## &#10;## data: y&#10;## Dickey-Fuller Z(alpha) = -15.795, Truncation lag parameter = 5, p-value&#10;## = 0.2286&#10;## alternative hypothesis: stationary&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;p&gt;P值等于0.2056，不能拒绝x是非平稳序列的假设，即x非平稳。&lt;/p&gt;&#10;&lt;p&gt;也可以用stats包中的PP.test()函数来完成PP检验。&lt;/p&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;?PP.test#查看PP.test()函数的帮助文档&#10;&lt;/code&gt;&lt;/pre&gt;&#10;</description></item></channel></rss>