时间序列分析之协整检验
协整关系
协整(Cointegration)理论是恩格尔(Engle)和格兰杰(Granger)在1978年提出的。平稳性是进行时间序列分析的一个很重要的前提,很多模型都是基于平稳下进行的,而现实中,很多时间序列都是非平稳的,所以协整是从分析时间序列的非平稳性入手的。
协整的内容是:
设序列Xt是 d 阶单整的,记为Xt∼I(d),如果存在一个非零向量 β使得Yt=βXt∼I(d−b),则称Xt具有 d, b 阶协整关系,记为Xt∼CI(d,b),则 β称为协整向量。
特别当 Xt和 Yt都是一阶单整时,一般而言,Xt和 Yt的线性组合 Yt−βXt仍然是一阶单整的,但是对于某些非零向量 β,会使得 Yt−βXt∼I(0),此时非零向量 β称作协整向量,其中每一项 βt为 t 时刻的协整系数。通俗点说,如果两组序列都是非平稳的,但是经过一阶差分后是平稳的,且这两组序列经过某种线性组合也是平稳的,则它们之间就存在协整关系。
协整理论的意义在于:
首先,因为或许单个序列是非平稳的,但是通过协整我们可以建立起两个或者多个序列之间的平稳关系,进而充分应用平稳性的性质。
其次,可以避免伪回归。如果一组非平稳的时间序列不存在协整关系,那么根据它们构造的回归模型就可能是伪回归。
区别变量之间长期均衡关系和短期波动关系。
非平稳序列很容易出现伪回归,而协整的意义就是检验它们的回归方程所描述的因果关系是否是伪回归的,所以常用的协整检验有两种:Engel-Granger 两步协整检验法和 Johansen 协整检验法,它们二者的区别在于 Engler-Granger 采用的是一元方程技术,而 Johansen 则是多元方程技术,所以Johansen 协整检验法受限更小。
Engel-Granger 两步协整检验法
EG检验的方法实际上就是对回归方程的残差进行单位根检验。
因为从协整的角度来看,因变量能被自变量的线性组合所解释,说明二者之间具有稳定的均衡关系;因变量不能被自变量解释的部分就构成了一个残差序列,这个残差序列不应该是序列相关的,也就是说残差应该是平稳的。所以EG检验一组变量是否具有协整关系也就是检验残差序列是否是平稳的。
Engle-Granger提出的两步法的步骤如下:
1、用 OLS 估计协整回归方程,从而得到协整系数:
\large : \begin{center} Y_{t} = \beta X_{t} + \epsilon_{t}\end{center}
\large : \begin{center} Y_{t} = \beta X_{t} + \epsilon_{t}\end{center}
2、检验 ϵt的平稳性,如果 ϵt平稳,则 Xt,Yt是协整的,否则不成立。对于ϵt平稳性的检验通常用 ADF 检验。
Johansen Test 协整检验法
当协整检验的VAR模型中如果含有多个滞后项时,如下:
\large : \begin{center} Y_{t} = \beta_{1} X_{t} + \beta_{2} X_{t-1} + \beta_{3} X_{t-2} + …+ \epsilon_{t}\end{center}
\large : \begin{center} Y_{t} = \beta_{1} X_{t} + \beta_{2} X_{t-1} + \beta_{3} X_{t-2} + …+ \epsilon_{t}\end{center}
采用EG检验就不能找出两个以上的协整向量了,此时可以用 Johansen Test 来进行协整检验,它的思想是采用极大似然估计来检验多变量之间的协整关系。
具体步骤以后填
用 python 代码进行协整检验
我们从 rb 期货中选择两个品种进行分析,具体的品种根据相关性选择,后期会另外补充。
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
a_price = pd.read_csv('./CloseA.csv')[:200]
b_price = pd.read_csv('./CloseB.csv')[:200]
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(range(len(a_price)), a_price)
ax.plot(range(len(b_price)), b_price)
ax.legend(['a','b'])
plt.show()
从图中看,两个品种具有很强的相关性,并且都是不稳定的。

下面,我们通过ADF检验来看一下,两个序列是否是一阶单整的:
from statsmodels.tsa.stattools import adfuller
a_price = np.reshape(a_price.values, -1)
a_price_diff = np.diff(a_price)
b_price = np.reshape(b_price.values, -1)
b_price_diff = np.diff(b_price)
print(adfuller(a_price_diff))
print(adfuller(b_price_diff))
(-15.436034211511204, 2.90628134201655e-28, 0, 198, {'1%': -3.4638151713286316, '5%': -2.876250632135043, '10%': -2.574611347821651}, 1165.1556545612445)
(-14.259156751414892, 1.4365811614283181e-26, 0, 198, {'1%': -3.4638151713286316, '5%': -2.876250632135043, '10%': -2.574611347821651}, 1152.4222884399824)
从结果来看,两个序列都满足一阶单整,下面来判断两者是否存在协整关系。statsmodels 模块中有 coint 函数可以用来检测协整关系,它的内部实现就是基于 EG 协整检验的。
coint 函数如下:
def coint(y0, y1, trend='c', method='aeg', maxlag=None, autolag='aic',
return_results=None):
"""Test for no-cointegration of a univariate equation
The null hypothesis is no cointegration. Variables in y0 and y1 are
assumed to be integrated of order 1, I(1).
This uses the augmented Engle-Granger two-step cointegration test.
Constant or trend is included in 1st stage regression, i.e. in
cointegrating equation.
**Warning:** The autolag default has changed compared to statsmodels 0.8.
In 0.8 autolag was always None, no the keyword is used and defaults to
'aic'. Use `autolag=None` to avoid the lag search.
Parameters
----------
y1 : array_like, 1d
first element in cointegrating vector
y2 : array_like
remaining elements in cointegrating vector
trend : str {'c', 'ct'}
trend term included in regression for cointegrating equation
* 'c' : constant
* 'ct' : constant and linear trend
* also available quadratic trend 'ctt', and no constant 'nc'
method : string
currently only 'aeg' for augmented Engle-Granger test is available.
default might change.
maxlag : None or int
keyword for `adfuller`, largest or given number of lags
autolag : string
keyword for `adfuller`, lag selection criterion.
* if None, then maxlag lags are used without lag search
* if 'AIC' (default) or 'BIC', then the number of lags is chosen
to minimize the corresponding information criterion
* 't-stat' based choice of maxlag. Starts with maxlag and drops a
lag until the t-statistic on the last lag length is significant
using a 5%-sized test
return_results : bool
for future compatibility, currently only tuple available.
If True, then a results instance is returned. Otherwise, a tuple
with the test outcome is returned.
Set `return_results=False` to avoid future changes in return.
Returns
-------
coint_t : float
t-statistic of unit-root test on residuals
pvalue : float
MacKinnon's approximate, asymptotic p-value based on MacKinnon (1994)
crit_value : dict
Critical values for the test statistic at the 1 %, 5 %, and 10 %
levels based on regression curve. This depends on the number of
observations.
Notes
-----
from statsmodels.tsa.stattools import coint
print(coint(a_price, b_price))
(-3.9532731584015215, 0.008362293067615467, array([-3.95232129, -3.36700631, -3.06583125]))
从返回结果可以看出 t-statistic 值要小于1%的置信度,所以有99%的把握拒绝原假设,而且p-value的值也比较小,所以说存在协整关系。
Ref :
《统计套利:理论与实战》金志宏著

This message is used to verify that this feed (feedId:72612612358506496) belongs to me (userId:72598526190095360). Join me in enjoying the next generation information browser https://follow.is.
Heya i am for the first time here. I came across this
board and I find It truly helpful & it helped me out a lot.
I am hoping to offer something back and help others such as you aided me.
my blog … Nordvpn Coupons Inspiresensation
I know this web site provides quality depending content and
extra material, is there any other website which gives these kinds of stuff in quality?
Here is my blog nordvpn coupons inspiresensation (ourl.in)
Hi, yup this paragraph is genuinely pleasant and I have learned lot of things from it concerning blogging.
thanks.
my web blog – nordvpn coupons inspiresensation [shorter.me]
That is a very good tip especially to those fresh to the blogosphere.
Brief but very precise information… Thank you for sharing this one.
A must read post!
my web-site :: nordvpn coupons inspiresensation
350fairfax nordvpn special coupon code 2025
I for all time emailed this web site post page to all my contacts, for the reason that
if like to read it next my links will too.
It’s perfect time to make some plans for the future and it is time to
be happy. I’ve read this post and if I could I want to suggest you some interesting things or tips.
Maybe you could write next articles referring to this article.
I want to read even more things about it!
Review my site … eharmony special coupon code 2025
Thank you for the good writeup. It in reality was once a leisure account it.
Glance complex to far brought agreeable from you! By the way,
how can we keep in touch?
My page vpn
Everything is very open with a very clear explanation of the issues.
It was truly informative. Your website is extremely
helpful. Many thanks for sharing! gamefly https://tinyurl.com/2cab6g88
What’s up colleagues, good post and good urging commented here, I am genuinely enjoying by these.
https://tinyurl.com/28555853 gamefly 3 month free trial
May I simply say what a relief to discover someone who
truly knows what they are talking about online. You certainly realize how
to bring an issue to light and make it important. More people ought to
check this out and understand this side of your story.
I can’t believe you are not more popular given that
you surely have the gift. https://tinyurl.com/2atd6fak how does vpn work
Howdy! I know this is kinda off topic however I’d figured I’d ask.
Would you be interested in exchanging links or maybe guest
writing a blog post or vice-versa? My website addresses a lot of the same topics
as yours and I feel we could greatly benefit from each other.
If you are interested feel free to shoot me an email.
I look forward to hearing from you! Excellent blog by the way!
https://tinyurl.com/24dyn2m6 what does vpn do
It’s very simple to find out any topic on web as
compared to books, as I found this article at this site.
Hi, I do believe this is an excellent website. I stumbledupon it 😉
I may come back once again since i have saved as a favorite it.
Money and freedom is the best way to change, may you be rich and continue to guide other people.
Greetings, I think your blog might be having internet browser
compatibility problems. Whenever I look at your blog in Safari,
it looks fine but when opening in IE, it has some overlapping issues.
I simply wanted to provide you with a quick heads up! Besides
that, fantastic website!
Hurrah! In the end I got a weblog from where I be able to actually obtain valuable information concerning my study and knowledge.
I loved as much ass you will receive carried out right here.
The sketch is attractive, yoour authored
subject mater stylish. nonetheless, you command
get bought an impatience over that you wish be delivering the following.
unwell unquestionably come further formerly again as exactly the same nearly
a lot often inside case you shield this increase. https://Z42mi.mssg.me/
Your style is very unique compared to other people I have read stuff from.
Thanks for posting when youu havve the opportunity,Guess I
will just book mark this web site. https://w4i9o.mssg.me/
Психолог Психолог 526
Heya i am for the primary time here. I found this board
and I to find It truly helpful & it helped me out much.
I am hoping to give one thing again and help others like you helped me.
https://tinyurl.com/ypubsnjg eharmony special coupon code 2025
fishing frenzy demo slot, online hard rock casino card (Iris)
instant withdrawal uk and casinos in saskatchewan united states, or australia online gambling stock
uk casino no deposit bonus no wagering, online poker in australia legal and casino bonus usa,
or bingo no deposit bonus win real money united states
Feel free to visit my blog – goplayslots.net
are pokies open in new zealand, best bingo sites usa 2021 and aristocrat free slots
united states, or 21 dusaes machine learning casino games (Ngan) login
excellent points altogether, you just gained a new reader.
What would you suggest in regards to your publish that you just made a few days in the past?
Any certain?
Feel free to surf to my blog – http://winkler-martin.de/messages/61849.html
usa online slots no deposit bonus, real money online
gambling canada and largest casino in australia 2021, or new
zealandn online ocean casino online promo code (Veronica)
no deposit bonus 2021
online 1Xbet basketball wetten beste anbieter
netent casino list usa, united kingdom roulette for mobile phones and how old do what happens when you call Gambling helpline have to be to go
in a casino usa, or native united statesn tribal casinos
united kingdom casino no deposit bonus 2021, real pokies canada
link between gambling and domestic violence (Celinda) free spins new usa, or united statesn casino
guide coupons
25 free spins on sign up australia, online how to win casino
vault game (Gerardo) real money free bonus australia
and united statesn pokies history, or usa $200 no deposit bonus 200 free spins
can you gamble online in korea; Finlay, casino legal
united states, claiming gambling winnings in united kingdom
and online casino australia free spins sign up, or new casino
canada
was ist ein buchmacher
Feel free to visit my homepage :: wettquoten papst
new 2021 usa players online casino, dollar 5 deposit online casino united states and usa
slot machine categories, or betsoft no deposit bonus
united states
Here is my homepage – roulette Bet table
sportwetten prognose heute
Here is my web site: wetten doppelte chance strategie (Marina)
sportwetten tipps verkaufen
my homepage :: 1xbet basketball wetten (Constance)
daglfing pferderennen wetten
Here is my webpage :: wett prognosen
online wettanbieter vergleich
Look into my web site :: software sportwetten vorhersage
wettbüro amberg
My blog :: beste Wettanbieter app
sportwetten bester bonus
Visit my website :: wetten ergebnisse Tipps
wetten Gratis ohne Einzahlung gutschein ohne einzahlung
app für eigene schweiz deutschland wetten (Tommie)
beste sportwetten seite – Kassie,
vorhersagen heute
doppelte chance wetten
my webpage: Livescore FüR Sportwetten (Hinweisgeber-Portal.Online)
sportwetten Bonus Wetten forum
wettanbieter mit Gratiswette
esports
beste sport wett (Craze.cl) tipps kostenlos
neue sportwetten Die besten seiten
hunderennen pferderennen mannheim Wetten (http://kmrec.Myjino.ru) deutschland
ohne einzahlung bonus wetten
Feel free to surf to my web site – WettbüRo Mainz
back lay europameister wetten quoten (http://Www.Mimartresital.com) deutschland
wetten gewinn ideen
Feel free to surf to my web-site … Sportwetten online Schweiz
beste sportwetten quoten
my page :: Pferderennen Wetten Gewinn, https://Mitsubishikimlienquangbinh.Com.Vn/W/2025/10/14/Besten-Online-Wettanbieter/,
beste wettstrategie sportwetten
Visit my web site; wetten gutschein ohne einzahlung – Mellissa,
wett strategie (Theron) tipps-heute
sportwetten app
Here is my web page: quotenvergleich wetten
wettquote erklärt
Here is my page … Asiatische Wetten Tore
deutsche sportwetten
My site Was Ist Ein WettbüRo
arbeiten im wettbüro
Here is my webpage; Sichere Wett Tipps Heute
pferderennen dresden wetten
my webpage: aktuelle sportwetten tipps
strategie sportwetten
My web blog – wetten prognosen heute
sichere wetten
Also visit my web blog :: Englische wettanbieter
pferderennen mannheim wetten
Stop by my web-site :: deutsche sportwetten lizenz –
Lindsay –
wettstrategien
My blog post; sportwetten Seiten
höchster sportwetten bonus
Also visit my website: die besten wett tipps für
heute (Remona)
online wetten ohne einzahlung
Here is my web site … Handicap Live wette
tipps bei sportwetten
Look into my webpage Beste Wett Seite
wettanbieter curacao
Check out my web-site; pferderennen münchen wetten – staging.apollaz.com –
wetten esc gewinner
Take a look at my blog buchmacher kreuzworträtsel, James,
gratis tipps sportwetten
My web site … quote von wetten dass
sichere wetten finden
Stop by my website :: Geburtstermin wette gewinn
sportwetten mit paypal
my homepage; wetten startguthaben ohne einzahlung
(https://themodernremodel.com)
beste wimbledon wettanbieter
Here is my website; wettseiten mit bonus ohne einzahlung [navtecs.com.tr]
sportwetten anbieter schweiz
Here is my website; wettanbieter ohne lugas
sport-wetten
my site: beste Sportwetten anbieter österreich
Thanks to my father who stated to me regarding this web site,
this blog Illegal Gambling Is Legal Gambling truly amazing.
pokie machine laws canada, best australian casino play With real Money
sites and free spins no deposit uk low wagering, or new zealandn online poker alliance
pferderennen wetten gewinn
Also visit my web page … beste sportwetten (https://Tamatruck.hu/)
sportwetten app schweiz (Lee) online bonus
We absolutely love your blog and find nearly all of
your post’s to be precisely what I’m looking for.
Do you offer guest writers to write content for you personally?
I wouldn’t mind producing a post or elaborating on a lot of the
subjects you write regarding here. Again, awesome
web site!
Review my blog post … interesting info about gambling (Maricruz)
beste online wettseite
Also visit my homepage; sportwetten bonus test
(Lida)
Online wetten gutschein Ohne einzahlung
tipps heute
wetten dass heute live ticker
Here is my webpage: tipp sportwetten (https://honeytech.eu)
live wetten erklärung
Feel free to surf to my website: sportwetten tipps vorhersagen gratis
südamerika strategie sportwetten
Here is my site: wettanbieter bester bonus
bester wettanbieter mit bonus
My web-site; wettstrategien Forum
online wettanbieter bonus
Feel free to visit my page … handicap Wette erkläRt (Zabagroup.pl)
dfb pokal quoten wetten
Also visit my blog post: Wett Tipps Heute Ki
erklärung handicap wette
My blog; Wett Tipps Morgen
wettbüro osnabrück
Also visit my homepage :: Vergleich Sportwetten (Hispanonetglobal.com)
sportwetten anbieter paysafecard – Cheryl – bonus bedingungen