計量經濟與時間序列_自共變數(AutoCovariance)演算法解析(Python)

來源:互聯網
上載者:User

標籤:表示   小數點   time   pow   var   函數   相關   5.6   小數   

1  樣本的自共變數函數的通式如下:

2  其實,後面要計算的自相關函數也可以用自共變數來表示:

 1 TimeSeries = [11.67602657, 5.637492979, 1.375516942, 0.618705492, -0.152047234, -0.508555434, -6.065288121, -9.417602801,  2               -10.47205437, -8.018063902, 0.523277554, 4.86893283, 4.23977562, -10.2344375, -3.463362573, 36.51326577,  3               -8.518370963, -15.37474905, -7.687911176, 4.818978874, 7.876681639, 1.763788865] 4 Zt = [] 5 LZt = [] 6 AutoCovariance = [] 7 # 自共變數存為列表形式,顯示格式如下: 8 # [γ0,γ1,γ2,γ3,....] 9 # [γk,....]  k = 0,1,2,3....10 total = 011 i = 112 while i < len(TimeSeries):13     L = TimeSeries[i::]14     LL = TimeSeries[:-i:]15     total = total + TimeSeries[i - 1]16     Zt.append(L)17     LZt.append(LL)18     i += 119 total = total + TimeSeries[-1]20 avg = total / len(TimeSeries)21 22 k = 023 result_temp0 = 024 # 首先求γ0的值25 while k < len(TimeSeries):26     result_temp0 = result_temp0 + pow((TimeSeries[k] - avg), 2)27     k += 128 AutoCovariance.append(result_temp0)29 print(AutoCovariance)30 # 顯示結果:31 #[2418.4380925669107]32 33 # 然後計算分子34 p = 035 q = 036 while p < len(Zt):37     q = 038     result_temp1 = 039     while q < len(Zt[p]):40         result_temp1 = result_temp1 + (Zt[p][q] - avg) * (LZt[p][q] - avg)41         q += 142     AutoCovariance.append(result_temp1)  # 保留小數點後三位43     p += 144 print(AutoCovariance)45 print(len(AutoCovariance))46 # 顯示結果:47 # [2418.4380925669107, 154.73148259271665, -909.2825195711046, -216.01009095585525, 381.064309087456, 253.8899860047866,48 #  -455.76866093122146, -513.7425279639118, -234.77764765735802, 51.726042700512416, 266.05419016606146, 116.26795577123028,49 #  -76.63272849007276, -209.6990237967077, 78.50856193561651, 336.9664948029677, -195.8237009651655, -211.6227696432054, -50.67152070500246,50 #  103.09738426011762, 101.91169142979405, 20.59404564489024]

 

計量經濟與時間序列_自共變數(AutoCovariance)演算法解析(Python)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.