Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import numpy as np
import pandas as pd
import pandas_datareader as pdr
from statsmodels.tsa.stattools import adfuller
pd.core.common.is_list_like = pd.api.types.is_list_like
import matplotlib.pyplot as plt
from numpy import cumsum, log, polyfit, sqrt, std, subtract
from datetime import datetime
import time
%matplotlib inline
start, end = datetime(2000, 1, 1), datetime(2019, 1, 1)
spy = pdr.DataReader(['^GSPC'],
'yahoo',
start,
end)
spy.columns = [col[0].lower().replace(' ', '_')
for col in spy.columns]
spy_close = spy[['adj_close']]
_ = spy_close.plot(figsize=(20, 10),
linewidth=3,
fontsize=14)
from numpy import cumsum, log, polyfit, sqrt, std, subtract
import seaborn as sns
sns.set();
spy_close = spy[['adj_close']].copy()
lag1, lag2 = 2, 20
lags = range(lag1, lag2)
tau = [sqrt(std(subtract(spy_close[lag:], spy_close[:-lag]))) for lag in lags]
m = polyfit(log(lags), log(tau), 1)
hurst = m[0]*2
print( 'hurst = ',hurst[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.