這也是一個評估波動度的方法,假設共有A、B、C、D、E、F、G七筆資料,
由A開始,依據計算AB、AC、AD、AE、AF之間的距離,然後找出該組的最大距離亦即該組的MaxError,
然後依序對B資料計算BA、BC、BD、BE、BF、BG ...
最後在各組所計算出的MaxError數值,找出最小的值,此即為MinMaxError。以下提供Excel VBA程式碼參考
'波動度求解 minMaxError
'最小最大化離差值,最為資料重心位置,並以離差作為波動度的評估依據, 'Output = 1 求解離散資料均衡點、Output = 2 求解MinMaxError
Public Function minMaxErrorBP(ByVal InputData As Range, ByVal TickScale As Variant, ByVal Output As Variant) As Variant
Dim ArrDataX() As Variant
Dim DataCount As Variant
Dim ii As Variant
ArrDataX = InputData
DataCount = InputData.Count
Dim Max As Variant
Dim Min As Variant
Max = ArrDataX(1, 1)
Min = ArrDataX(1, 1)
minMaxErrorBP = ArrDataX(1, 1)
'利用迴圈求解最大、最小值
For ii = 1 To DataCount
If ArrDataX(ii, 1) > Max Then Max = ArrDataX(ii, 1)
If ArrDataX(ii, 1) < Min Then Min = ArrDataX(ii, 1)
Next 'For ii = 1 To DataCount
Dim HLrange As Variant
HLrange = Max - Min
Dim MaxError As Variant
Dim MaxErrorTemp As Variant
Dim jj As Variant
Dim MinMaxError As Variant
Dim TempBP As Variant
MinMaxError = HLrange
For ii = 0 To HLrange Step TickScale
TempBP = Min + ii
MaxError = 0
For jj = 1 To DataCount
MaxErrorTemp = Abs(ArrDataX(jj, 1) - TempBP)
'Debug.Print "ii", ii, "jj", jj, "TempBP", TempBP
If MaxErrorTemp > MaxError Then MaxError = MaxErrorTemp
'Debug.Print "MaxError:", MaxError
Next 'For jj = 1 To DataCount
If MaxError < MinMaxError Then
MinMaxError = MaxError
If Output = 1 Then minMaxErrorBP = Min + ii
If Output = 2 Then minMaxErrorBP = MinMaxError
End If
Next 'For ii = 0 To HLrange Step TickScale
'Application.Volatile True
'無論何時工作表中任意單格重新計算,都會強制計算該函數
'Application.Volatile False
'只有在該函數的一個或多個參數發生改變時,才會重新計算該函數
'Debug.Print ArrDataX(1, 1), ArrDataX(2, 1)
'Debug.Print "DataCount:", DataCount, "TickScale:", TickScale
'Debug.Print "Max:", Max, "Min:", Min, "HLrange:", HLrange, "minMaxErrorBP:", minMaxErrorBP
End Function