I have two excel files of stock market data. First includes daily price multiples and the second daily stock returns. Companies are in the same order in the both files. I have 3073 days and 684 companies, thus excel files are 3074x685 (the first row is company name and the fist column is date).
For every day/row, I need to sort companies in 5 equal size portfolios based on their price multiples and calculate those next day average returns.
Results should be documented something as following. Q1 is the portfolio with the lowest multiples and so on:
Q1 Q2 Q3 Q4 Q5
Is there a code to do that? Would take ages to sort one by one manually.