Dear all,
i just found a nice macro to calculate the maximum drawdown of a stock:
http://investexcel.net/2450/maximum-drawdown-vba/
But the macro failed to accommodate the date input to make it more flexible. For example, if I want to use the macro to calculate the maximum drawdown between 01-Dec-2008 and 31-OCT-2009, then the formula failed with #VALUE:
=MaxDrawDown(IF((A6:A100>=DATEVALUE("01-DEC-2008"))*(A6:A100<=DATEVALUE("31-OCT-2009")),B6:B100,""))
Can I ask how to adapt the macro to allow for flexible date input?
Original macro code:
Function MaxDrawDown(returns As Variant) As Variant
Dim TS As Variant
Dim n As Integer
Dim Min As Double
TS = returns
n = UBound(TS)
Min = 0
For i = 1 To n
For j = i To n
temp = TS(j, 1) / TS(i, 1) - 1
If temp < Min Then
Min = temp
End If
Next
Next
MaxDrawDown = Min
End Function
Bookmarks