Created
September 18, 2018 15:19
-
-
Save jcorrius/56b4983ca059e69f2d2df38a3a05e225 to your computer and use it in GitHub Desktop.
Variance Ratio Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def variance_ratio(ts, lag = 2): | |
""" | |
Returns the variance ratio test result | |
""" | |
# make sure we are working with an array, convert if necessary | |
ts = np.asarray(ts) | |
# Apply the formula to calculate the test | |
n = len(ts) | |
mu = sum(ts[1:n]-ts[:n-1])/n; | |
m=(n-lag+1)*(1-lag/n); | |
b=sum(np.square(ts[1:n]-ts[:n-1]-mu))/(n-1) | |
t=sum(np.square(ts[lag:n]-ts[:n-lag]-lag*mu))/m | |
return t/(lag*b); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment