Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@databyjp
Created March 20, 2021 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save databyjp/5504741153a30201c5a144521efa84cc to your computer and use it in GitHub Desktop.
Save databyjp/5504741153a30201c5a144521efa84cc to your computer and use it in GitHub Desktop.
# ========== 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