1. 程式人生 > >excel求最大回撤

excel求最大回撤

假設你是求excel中A2:A100的數值的最大回撤,那麼請按照步驟來進行以下操作

開啟excel,同時按alt+f11,然後輸入如下內容


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


然後在表格的任意單元格輸入函式maxdrawdown(a2:a100) #範圍改為自己的就行