I'm having a hard time trying to do this efficiently. I have some stocks and daily P&L info in a dataframe. In reality, I have millions of rows of data so efficiency matters a lot! The Dataframe looks like :
-------------------------------
| Date | Security | P&L |
-------------------------------
| 2016-01-01 | AAPL | 100 |
-------------------------------
| 2016-01-02 | AAPL | 200 |
-------------------------------
| 2016-01-03 | AAPL | 300 |
-------------------------------
| 2016-01-04 | AAPL | -200 |
-------------------------------
All, I want to do is roll the P&L over to the next business day (exclude all US holidays and weekends) So, the resultant Dataframe looks like this:
-------------------------------
| Date | Security | P&L |
-------------------------------
| 2016-01-04 | AAPL | 400 |
-------------------------------
I'm looking for an efficient way to achieve this. I do have thousands of securities and over 5 yrs of data to process so brute force can't work, unfortunately!
Thanks in advance and highly appreciate any pointers on this!