Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
GauFei
Regular Visitor

How to calculate the final drawdown for several trading strategies

Hi, I would like to calculate the final drawdown for several strategies. What I did so far yields correct results as long as the page is filtered for a single strategy, but I like to get the result for all strategies at once. The data looks like this: 

GauFei_0-1642423710979.png

 

There are different datetime stamps. The strategy and its profit or los are recorded. To calculate the drawdown I used the following formulas:  

 

CumProfit = sum(Trades[Profit])

CumProfitByDateTime = CALCULATE([CumProfit], FILTER(ALLSELECTED('Trades'), 'Trades'[DateTime] <= MAX('Trades'[DateTime])))

PeakByDateTime = MAXX(FILTER(ALLSELECTED('Trades'), 'Trades'[DateTime] <= MAX('Trades'[DateTime])), [CumProfitByDateTime])

DrawDownByDateTime = [CumProfitByDateTime] - [PeakByDateTime]

LastDateTime = LASTNONBLANK('Trades'[DateTime], TRUE())

As long as I only select one strategy the result is correct:
 
 GauFei_1-1642423249455.png 

As soon as I select more than one the result is not correct: 

GauFei_2-1642423295916.png

How do I need to change the formulas, so that I get the correct result also when all strategies are selected?



6 REPLIES 6
Patrader
Frequent Visitor

I would like to get the Max Drawdown for specific Strategy,

Also when I select a combination of multiple Strategies\(Where I built Portfolio) for a filtered period, could be a couple days/month or 2-3 -4 years.

 

My Model and Relationship are

All my trades are in one table.

All trategies in 1 table.

All portfolio are in 1 table, combination of multiple Strategies

Calendar table

Patrader_1-1677548829928.png

 

Definition of Max Drawdown (MDD) is the maximum observed loss from a peak to a trough of a portfolio, before a new peak is attained

Below picture is from my trading software, Green graph is Cumulative net profit, and red is Max Drawdown, I need to be able to get in BI the same MDD, so the MDDhas been reached from Peak Dec 16/21 to march 10,22.

Patrader_2-1677548999439.png

 

_1_Master_Trade_Combined

TradeIDBots.AccountData.Exit timeP & L
7757Bot_ES_MU2023-01-05 10:30-568
7743Bot_ES_MU2023-01-06 16:002558
2757Bot_CL_WC2023-01-09 10:35-675
7737Bot_ES_MU2023-01-09 13:3082
2756Bot_CL_WC2023-01-09 16:00375
7698Bot_ES_MU2023-01-12 15:00-568
7690Bot_ES_AP2023-01-13 10:30-1318
2751Bot_CL_PP2023-01-13 16:35335
7686Bot_ES_MU2023-01-17 11:00-568
2749Bot_CL_MG2023-01-18 16:00705
2750Bot_CL_WC2023-01-18 16:00715
7671Bot_ES_MU2023-01-18 16:001895
7669Bot_ES_MU2023-01-19 13:3045
7659Bot_ES_MU2023-01-20 16:002432
2747Bot_CL_PP2023-01-20 16:35165
2746Bot_CL_WC2023-01-23 10:10-665
7635Bot_ES_MU2023-01-24 10:30-568
7623Bot_ES_MU2023-01-25 10:30-568
7628Bot_ES_AP2023-01-25 11:308
2744Bot_CL_MG2023-01-27 14:30205
2745Bot_CL_WC2023-01-27 14:30225
2742Bot_CL_PP2023-01-27 16:35-225
2741Bot_CL_WC2023-01-30 11:40-175
7604Bot_ES_AP2023-01-30 16:00808
7597Bot_ES_MU2023-01-30 16:00745
7588Bot_ES_MU2023-01-31 16:00995

 

Portfolio

PortfolioBots.Account
Port #1Bot_ES_MU
 Bot_ES_MU
 Bot_CL_WC
 Bot_CL_PP
Port#2Bot_CL_WC
 Bot_ES_MU
 Bot_ES_AP
Port#3Bot_CL_PP
 Bot_ES_MU
 Bot_CL_MG
 Bot_ES_AP

 

I need to add Column of MDD first (and be able to generate a bar graph), the previous suggestion in this thread is not reflecting the MDD as I described above.

Thanks

 

adding my DAX

CumProfit = SUMX(_1_Master_Trade_Combined, _1_Master_Trade_Combined[P & L])

 

CumProfitByDateTime = CALCULATE([CumProfit], FILTER(ALLSELECTED('_1_Master_Trade_Combined'), '_1_Master_Trade_Combined'[Data.Exit time] <= MAX('_1_Master_Trade_Combined'[Data.Exit time])))

 

PeakByDateTime = MAXX(FILTER(ALLSELECTED('_1_Master_Trade_Combined') , '_1_Master_Trade_Combined'[Data.Exit time].[Date] <= MAX('_1_Master_Trade_Combined'[Data.Exit time].[Date])), [CumProfitByDateTime])

 

DrawDownByDateTime = calculate(_1_Master_Trade_Combined[CumProfitByDateTime] - _1_Master_Trade_Combined[PeakByDateTime], all (_1_Master_Trade_Combined[Bots.Account]))

 

High Water Mark =

MAXX (

    ADDCOLUMNS (

        FILTER ( ALL ( '_1_Master_Trade_Combined' ), '_1_Master_Trade_Combined'[TradeID] <= MAX ( '_1_Master_Trade_Combined'[TradeID] ) ),

        "Bal", [CumProfitByDateTime]

    ),

    [Bal]

)

Patrader
Frequent Visitor

Hello, 

The above works DAX however, it is for every day 

Instead to get Drawdonw per day, I would like to find MaxDrawdown for a period I would select. Not per trade or per Day!

 

1-if only one Strategy Selected, the Drawdown for the Period selected, 

2- Multiple stategy selected to get the Max Drawdown for the period selected, (the Max Drawdown for the selected Strategy, as exemple a portfolio of multiple strategy)

mh2587
Super User
Super User

DrawDownByDateTime = calculate(table[CumProfitByDateTime] - table[PeakByDateTime],all(table[stragtegy])


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



Hi, @mh2587 , Thanks, but this gives the total drawdown over all strategies (also nice), but I wanted to have the final drawdown of each single strategy in one table/ visual. It should look like this: 

GauFei_0-1642431858601.png

 

Then use sumx function 


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.