Skip to content

Instantly share code, notes, and snippets.

@markusrenepae
Created December 31, 2019 01:07
Show Gist options
  • Save markusrenepae/7bf4e33f55ea1e89aa3ec2c878c07719 to your computer and use it in GitHub Desktop.
Save markusrenepae/7bf4e33f55ea1e89aa3ec2c878c07719 to your computer and use it in GitHub Desktop.
Code for medium correlation article.
import pandas as pd
stocks = []
f = open("symbols.txt", "r")
for line in f:
stocks.append(line.strip())
f.close()
volumes = pd.read_csv("volume.csv")
prices = pd.read_csv("adjclose.csv")
results = {}
for stock in stocks:
corr = volumes[stock].corr(prices[stock])
results[stock] = corr
output = pd.DataFrame(list(results.items()), columns=['Symbol', 'Correlation'])
output = output.sort_values(by=['Correlation'])
print(output.to_string())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment