Calculating The Drawdown Within A Numpy Array Python
I am trying to write a function that calculates how much the biggest dip was in each array. the function below calculates between the max and the min but it does not get Expected O
Solution 1:
The biggest dip does not necessarily happen at the global maximum or global minimum. We need an exhaustive approach to find the largest dip:
- check the maximum value so far, for which we can use
numpy.maximum.accumulate
; - calculate the biggest dip for each position.
- And take the largest dip among all the dips.
def calc(a):
acc_max = np.maximum.accumulate(a)
return (a - acc_max).min()
calc(A)
# -56
calc(B)
# -120
calc(C)
# -62
calc(D)
# 0
calc(E)
# -5
Post a Comment for "Calculating The Drawdown Within A Numpy Array Python"