# Correlation between Time Series Indicators ( Stock Prices )

I am new to time series analysis and I am currently tackling a stock market prediction problem.

I have a set of market indicators (such as Bollinger Bands, ADX etc) which are derived from the time dependent Open, High, Low and Close prices ( in Dollars ).

I need to find correlations of this indicators with the Open, Low, High and Close prices over time and drop the features which are not correlated enough ( less than 0.70 )

I am working on python. Using Pandas I have tried the pandas.dataframe.corr() method as well, but I want to know if Pearson and Spearman correlation fucntions in pandas serve my purpose ? Is it the right way or is there another way of finding correct correlations ?

Thanks.

## 2 Answers

For time series, correlation is a different. A variable might b related past N values of other variables.

This article explains theory behind finding relationships in time series (Skip to section "Stationarity in Time Series") : https://www.quantstart.com/articles/Serial-Correlation-in-Time-Series-Analysis

This is an implementation in Python : https://machinelearningmastery.com/gentle-introduction-autocorrelation-partial-autocorrelation/

import pandas as pd
import numpy as np

# load your data and select only numerics for corr analysis
df = pd.read_csv("C:\\your_path\\stock_data.csv")
numerics = ['int16', 'int32', 'int64', 'float16', 'float32', 'float64']
newdf = df.select_dtypes(include=numerics)
for col in newdf.columns:
print(col)

# Correlation Matrix Heatmap
corrmat = newdf.corr()
f, ax = plt.subplots(figsize=(12, 9))
sns.heatmap(corrmat, vmax=.8, square=True);

# Top 10 Heatmap; you may want to filter for >.7 corr here...
k = 10 #number of variables for heatmap
cols = corrmat.nlargest(k, 'Price')['Price'].index
cm = np.corrcoef(train[cols].values.T)
sns.set(font_scale=1.25)
hm = sns.heatmap(cm, cbar=True, annot=True, square=True, fmt='.2f', annot_kws={'size': 10}, yticklabels=cols.values, xticklabels=cols.values)
plt.show()


Done.