Hello,
I am trying to calculate the Max Drawdown in a table of trades. A maximum drawdown (MDD) is the maximum loss from a peak to a trough of a portfolio, before a new peak is attained.
First, I calculate the cumulative profit with this measure:
Cumulative Profit$:= CALCULATE([TProfit$]; FILTER(ALLSELECTED('Calendar'); 'Calendar'[Date]<=MAX('Calendar'[Date])))
where TProfit$:=SUM(AllTrades[Profit$])
Then, I calculate the peak in the cumulative profit with this measure:
Peak:=MAXX(FILTER(ALLSELECTED('Calendar'); 'Calendar'[Date]<=MAX('Calendar'[Date])); [Cumulative Profit$])
Lastly, I calculate the max drawdown with this measure:
Max Drawdown:=MINX(AllTrades; [Cumulative Profit$]-[Peak])
In a test table with few rows these formulas are working correctly. The problem is the performance. If a table gets a bit larger then the formulas are running forever and finally a memory error occurs. This is probably because of the multiple iterations involved.
Does anyone has a suggestion for a max drawdown calculation with better performance? Thanks in advance.