I'm trying to create a function that calculates Drawdown. It would work as follows:
- I have a series of quotes for a specific stock in column B: B (example)
- I want to know the maximum drawdown, that is, how much would be the biggest decrease in the quote.

In this case the biggest indentation occurs in the yellow area!that is, the formula would look like: Drawdown = (MaxValue/Value)-1 ==> Drawdown = (13/9)-1
I tried as follows, with no result:
Public Function MDD(ByVal Selection0, ByVal Selection1)
'Function Max DrawDown
Dim i As Long
Dim Drawdown0 As Long
Dim Drawdown1 As Long
i = 2
Drawdown0 = "(" & Selection0 & "/MAX(" & Selection1 & ")) - 1"
While i < Plan1.Range("B" & Rows.Count).End(xlUp).Row + 1
Drawdown1 = "(" & Selection0 & "/MAX(" & Selection1 & ")) - 1"
If Drawdown1 > Drawdown0 Then
Drawdown0 = Drawdown1
End If
i = i + 1
Wend
MDD = Drawdown0
End Function
Sub lsMDD()
Application.MacroOptions Macro:="MDD", Category:=4
End Sub
Where's the error?
Drawdown0 = "(" & Selection0 & "/MAX(" & Selection1 & ")) - 1"is trying to assign a string (text) to aLong.Application.Maxmight be helpful. You have to actually translate the formula logic to VBA.