2022-02-03|閱讀時間 ‧ 約 5 分鐘

偏態 - 模擬與交易.9

在對稱分布的情況下,均數(Mean)、眾數(Mode)、中數(Middle),三個敘述統計量彼此相等。也就是說,在不對稱有所偏態的情況下,除去眾數不討論,右偏之下,極端值(大)會加大均數的數值,而有MeanMiddle;反之,左偏則有MiddleMean,因此本文利用Mean的平方與Middle的平方取差值,作為統計檢定量。透過標準常態分配亂數來模擬,制定一個查表值,用以確認偏態的訊號,以8筆資料為例,檢定統計量 = Mean的平方-Middle的平方,95%的顯著門檻值為0.71
Excel VBA參考程式碼 Public RankSort(1 To 8) As Variant Const FixConst As Variant = 0.398942284 '1/sqr(2*3.1415926)
Public Sub MeanModdle() '模擬常態分配隨機變數的順序統計量期望值 Dim seed, seedCalc, nextSeed, NorValue As Variant Dim ArrNorRandom(1 To 8), x(1 To 100000) As Variant Dim iith, testNum, xTemp, yTemp As Long
For testNum = 1 To 100000 iith = 1 Do seed = Int(Rnd() * 1000000) seedCalc = ((seed - 500000) * 0.000001) * 8 '模擬4個標準差範圍的 N(0,1) 常態分配變數 NorValue = Format(FixConst * Exp(-0.5 * seedCalc * seedCalc), "0.000000") '常態分配機率函數的數值 nextSeed = 0 nextSeed = Int(0.001 * (seed * seed)) nextSeed = Format(0.000001 * nextSeed - Int(0.000001 * nextSeed), "0.000000") nextSeed = Int(1000000 * nextSeed) nextSeed = Int(((23 + iith * 0.01) * nextSeed + 1011 * iith)) Mod 999999 nextSeed = Format(nextSeed * 0.00001 * FixConst, "0.000000")
If (nextSeed) NorValue Then ArrNorRandom(iith) = seedCalc iith = iith + 1 End If Loop While iith = 8
'泡沫排序法 Dim swapTemp, ii, jj As Variant For jj = 0 To 6 For ii = 1 To 7 - jj If ArrNorRandom(ii) ArrNorRandom(ii + 1) Then swapTemp = "" swapTemp = ArrNorRandom(ii + 1) ArrNorRandom(ii + 1) = ArrNorRandom(ii) ArrNorRandom(ii) = swapTemp End If Next ii Next jj
xTemp = (ArrNorRandom(4) + ArrNorRandom(5)) * 0.5 'Middle yTemp = (ArrNorRandom(1) + ArrNorRandom(2) + ArrNorRandom(3) + ArrNorRandom(4) + ArrNorRandom(5) + ArrNorRandom(6) + ArrNorRandom(7) + ArrNorRandom(8)) / 8 x(testNum) = yTemp * yTemp - xTemp * xTemp Next 'For testNum = 1 To 100000
For jj = 0 To 4999 '資料數據共計10萬筆,求解第95001序位 For ii = 1 To 100000 - 1 - jj If x(ii) x(ii + 1) Then xTemp = 0 xTemp = x(ii + 1) x(ii + 1) = x(ii) x(ii) = xTemp End If Next ii Next jj
Debug.Print x(95001) ' 0.709336686576 ' 0.706396410096 ' 0.708935433984 End Sub
分享至
成為作者繼續創作的動力吧!
© 2024 vocus All rights reserved.