I am working on an analysis to look at features correlated with an uptrend in another feature. In order to remove noise, I've removed all dates besides where my dependent variable y is trending upwards, say in a 7-day period. For my independent variables, I'm looking at the same week y is trending upwards, plus the two previous weeks, for a total of 21 days.
When I compute the cross-correlation function for the time series, my coefficients are NaN because the two weeks prior to the start of the 7-day period would be null for the dependent variable since they are outside of the trending period.
For context, I am using this python function that mimics the r ccf function:
from scipy import signal
import numpy as np
import pandas as pd
def ccf_values(series1, series2):
p = series1
q = series2
p = (p - np.mean(p)) / (np.std(p) * len(p))
q = (q - np.mean(q)) / (np.std(q))
c = np.correlate(p, q, 'full')
return c
ccf = ccf_values(df['y'], df['x'])
lags = signal.correlation_lags(len(df['y']), len(df['x']))