Created
March 27, 2021 22:59
-
-
Save sguzman/8c2d454dffcdbcdd814c281c1fbb862d to your computer and use it in GitHub Desktop.
Rank correlation of sp500 stocks for this year
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
Block[{tmp}, | |
items = EntityList@EntityClass["Financial", "SP500"]; | |
begin = DateObject[{2021, 1, 1}, "Day", "Gregorian", -7.`]; | |
end = DateObject[{2021, 3, 3}, "Day", "Gregorian", -7.`]; | |
fin[str_, beg_, en_] := | |
fin[str, beg, en] = FinancialData[str, "Close", {beg, en}]; | |
corr[stra_, strb_, beg_, en_] := | |
corr[stra, strb, beg, en] = | |
Correlation[fin[stra, beg, en], fin[strb, beg, en]]; | |
pairs = Subsets[items, {2}]; | |
final = Map[{ | |
First@#, | |
Last@#, | |
corr[First@#, Last@#, begin, end] | |
} &, pairs]; | |
sorted = TakeSmallestBy[final, Last, 100]; | |
Grid@ | |
sorted | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment