时间序列指标(股票价格)之间的相关性

数据挖掘 机器学习 时间序列 统计数据 特征选择 相关性
2022-03-11 21:16:52

我是时间序列分析的新手,目前正在解决股市预测问题。

我有一组市场指标(例如布林带、ADX 等),这些指标源自时间相关的开盘价、最高价、最低价和收盘价(以美元计)。

我需要随着时间的推移找到该指标与开盘价、最低价、最高价和收盘价的相关性,并删除相关性不足的特征(小于 0.70)

我正在研究python。使用 Pandas 我也尝试过该pandas.dataframe.corr()方法,但我想知道 Pandas 中的 Pearson 和 Spearman 相关函数是否符合我的目的?这是正确的方法还是有另一种方法可以找到正确的相关性?

谢谢。

2个回答

对于时间序列,相关性是不同的。一个变量可能与其他变量的过去 N 个值相关。

本文解释了在时间序列中寻找关系背后的理论(跳到“时间序列中的平稳性”部分):https ://www.quantstart.com/articles/Serial-Correlation-in-Time-Series-Analysis

这是 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()

完毕。