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) #范围改为自己的就行

你可能感兴趣的:(excel)