Longest time underwater
Asked at Millennium, Balyasny
Drawdown depth is only half the risk story; investors also care about drawdown duration, the "time underwater." A strategy is underwater at time if its equity is strictly below the highest value reached before . The longest underwater stretch is the maximum number of consecutive periods spent below a prior peak, ending when the curve makes a new high.
equity = [100, 120, 90, 105, 60, 80, 130]
-> 4 # days at 90, 105, 60, 80 are all below the peak of 120
Return the length of the longest underwater run, in time and space.
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.