Skip to content

Instantly share code, notes, and snippets.

Created March 20, 2021 15:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# ========== 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