Skip to content

Instantly share code, notes, and snippets.

@jcheong0428
Created March 6, 2019 19:30
Show Gist options
  • Save jcheong0428/6f6360432b0133e8192a899042f3b202 to your computer and use it in GitHub Desktop.
Save jcheong0428/6f6360432b0133e8192a899042f3b202 to your computer and use it in GitHub Desktop.
Cross Correlation Function
def crosscorr(datax, datay, lag=0):
""" Lag-N cross correlation.
Calculates cross correlations using pandas functionality that can be used in a list comprehension.
Parameters
----------
lag : int, default 0
datax, datay : pandas.Series objects of equal length
Returns
----------
crosscorr : float
Examples
----------
rs = [crosscorr(d1,d2, lag) for lag in range(-60,61)]
"""
return datax.corr(datay.shift(lag))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment