1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
Option Explicit
Option Base 0
Function cross1(data As Range, lag As Integer)
Dim n As Long, nseries As Long
Dim t As Long, j As Long, i As Long, k As Long
Dim x() As Double, y() As Double
Dim somxy() As Double, somx() As Double, somx2() As Double, somy() As Double, somy2() As Double
Dim crosout() As Double
nseries = data.Columns.Count
n = data.Rows.Count
ReDim somxy(lag + 1)
ReDim somx(lag + 1)
ReDim somx2(lag + 1)
ReDim somy(lag + 1)
ReDim somy2(lag + 1)
ReDim crosout(lag + 1)
For i = 0 To lag Step 1
somxy(i) = 0
somx(i) = 0
somx2(i) = 0
somy(i) = 0
somy2(i) = 0
Next i
ReDim x(n)
ReDim y(n)
For i = 0 To n - 1 Step 1
x(i) = data(i, 1)
y(i) = data(i, 2)
Next i
For t = 0 To n - 1 Step 1
j = 0
While ((t - j >= 0) And j <= lag)
somxy(j) = somxy(j) + x(t) * y(t - j)
somx(j) = somx(j) + x(t)
somx2(j) = somx2(j) + x(t) * x(t)
somy(j) = somy(j) + y(t - j)
somy2(j) = somy2(j) + y(t - j) * y(t - j)
j = j + 1
Wend
Next t
ReDim crosout(lag + 1)
For j = 0 To lag Step 1
crosout(j) = ((n - j) * somxy(j) - somx(j) * somy(j)) / Sqr((n * somx2(0) - somx(0) * somx(0)) * ((n - j) * somy2(j) - somy(j) * somy(j)))
Next j
cross1 = crosout
End Function |
Partager