Created
March 20, 2021 15:46
-
-
Save databyjp/5504741153a30201c5a144521efa84cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ========== DETERMINE SIMILARITIES ========== | |
# Calculate similarities between each stock | |
r_array = np.zeros([len(symbols), len(symbols)]) | |
p_array = np.zeros([len(symbols), len(symbols)]) | |
for i in range(len(symbols)): | |
for j in range(len(symbols)): | |
vals_i = df[df["symbol"] == symbols[i]]['close'].values | |
vals_j = df[df["symbol"] == symbols[j]]['close'].values | |
r_ij, p_ij = scipy.stats.pearsonr(vals_i, vals_j) | |
r_array[i, j] = r_ij | |
p_array[i, j] = p_ij |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment