Created
December 31, 2019 01:07
-
-
Save markusrenepae/7bf4e33f55ea1e89aa3ec2c878c07719 to your computer and use it in GitHub Desktop.
Code for medium correlation article.
This file contains 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
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