Skip to content

Instantly share code, notes, and snippets.

View jcorrius's full-sized avatar

Jesús Corrius jcorrius

View GitHub Profile
@jcorrius
jcorrius / variance_ratio.py
Created September 18, 2018 15:19
Variance Ratio Test
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
@jcorrius
jcorrius / hurst.py
Last active September 18, 2018 15:17
Hurst Exponent
def hurst(ts):
"""
Returns the Hurst Exponent of the time series vector ts
"""
# make sure we are working with an array, convert if necessary
ts = np.asarray(ts)
# Helper variables used during calculations
lagvec = []
tau = []
@jcorrius
jcorrius / adf.py
Created September 18, 2018 15:09
Augmented Dickey-Fuller unit root test
import numpy as np
from statsmodels.regression.linear_model import OLS
from statsmodels.tsa.tsatools import lagmat, add_trend
from statsmodels.tsa.adfvalues import mackinnonp
def adf(ts):
"""
Augmented Dickey-Fuller unit root test
"""
# make sure we are working with an array, convert if necessary