Moving Together
prices has columns day, ticker and close, one row per ticker per day, in any order. A ticker's daily return is its close divided by its close the day before, minus 1.
Return [a, b] with a < b alphabetically: the two tickers whose daily returns have the highest correlation.
Example 1
prices {"day":[1,1,1,2,2,2,3,3,3,4,4,4,5,5,5],"ticker":["AAA","BBB","CCC","AAA","BBB","CCC","AAA","BBB","CCC","AAA","BBB","CCC","AAA","BBB","CCC"],"close":[10.0,20.0,50.0,11.0,22.0,45.0,10.0,20.5,49.0,12.0,23.0,44.0,12.5,24.5,46.0]}
returns ["AAA","BBB"]
AAA and BBB rise and fall on the same days, so their returns are almost perfectly correlated. CCC moves the other way.
Constraints
- 3 to 5 tickers, 5 to 20 days numbered from 1
- Every close is positive
- No two pairs tie
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More pandas problems
- Never Top, Never BottomHard
- Second SaleHard
- Teams Side by SideHard
- Three Month TotalsHard
- Winner of Each GroupHard
- Adult NamesBeginner
- Average AgeBeginner
- Biggest Daily JumpBeginner