I have a DataFrame with cash, inflows and outflows.
I need to create a feature survival that is the maximum number of periods the cash is enough to pay the projection of outflows (excluding the inflows from the computation).
Let's take an example from the table below.
(Again, the inflows do not count in this exercise).
In t=1, from the starting cash = 100, I can add the outflows: -20, -50, -10, -10 e still having a positive cash (100-20-50-10-10 = 10 > 0) while with the outflow in t=5 the cash would be negative. So, as long as I can "survive" 4 periods in t=1 the survival = 4.
In t=2 the survival = 3 and so on.
As it is a big DataFrame, how can I do it efficiently with Pandas?
| t | cash | outflow | inflow | survival |
|---|---|---|---|---|
| 1 | 100 | -20 | 10 | 4 |
| 2 | 90 | -50 | 10 | 3 |
| 3 | 50 | -10 | 80 | 2 |
| 4 | 120 | -10 | 70 | ... |
| 5 | 40 | -50 | 60 | ... |