Skip to content

Instantly share code, notes, and snippets.

@quantra-go-algo
Created August 11, 2023 20:54
Show Gist options
  • Save quantra-go-algo/324894c60b1ba745e6decb8b3c947091 to your computer and use it in GitHub Desktop.
Save quantra-go-algo/324894c60b1ba745e6decb8b3c947091 to your computer and use it in GitHub Desktop.
def d_estimates_db(DF,minimum,maximum):
# Create the output dataframe
out=pd.DataFrame(columns=['adfStat','pVal','lags',\
'nObs','95% conf','corr'])
# Copy the dataframe in order to not change it
df0=DF.copy()
# Create a range of posible d values and loop throughout them
for d in np.linspace(minimum,maximum,11):
# Create the log of close prices
df1=np.log(df0['Close'])
# Estimate the ARFIMA residuals
df2=fracDiff_FFD(df1,d,thres=1e-5)
# Compute the correlation between the log prices and the ARFIMA residuals
corr=np.corrcoef(df1.loc[df2.index],df2['Close'])[0,1]
# Estimate a unit root test to the ARFIMA residuals
df2=adfuller(df2['Close'],regression='c',autolag='AIC')
# Save all the results in the out dataframe
out.loc[d]=list(df2[:4])+[df2[4]['5%']]+[corr] # with critical value
# Return the out dataframe
return out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment