歷史波動率計算不適合給定數據
首先,我不得不說抱歉——我的問題非常基本。我對數學和統計學沒有很好的理解。在發帖之前我做了很多研究,但我無法對我的問題給出 100% 滿意的答案。這是我的情況:
所以有一個非常簡潔的金融網站,它向我展示了某個證券交易所中某隻股票的 250 天和 30 天的波動率百分比。
我有這個非常簡潔的 C# 程式碼,它計算給定返回數組的標準變化。
我還擁有該資產在該證券交易所的最後 250 個交易日的所有收盤價。當我對所有計算的返回執行我的 C# 邏輯時,結果與我在該網站上看到的數字完全匹配 - 250d Volatiliy 為 40.8%。
到目前為止,一切都很好。
但是,當我執行相同的程式碼僅交出最近 30 個交易日的回報時,它得出了 6.6%——而不是該網站上 30 天的數字,大約為 20.07%。
所以我想我做錯了什麼。我搜尋了許多網站以找到正確計算數字的正確方法,但我沒有設法得到接近 20.07% 的結果。
我最接近的方法是:我猜那個網站上的 30 天數字是年化波動率。所以我想我必須將我的 6.6% 的結果乘以我學到的相應乘數應該是 250 / 30 的平方根。在這種情況下,結果是 19.05% - 這顯然不是 20.07%。
有人可以告訴我我的方法是否正確嗎?當然,也可能是網站不採用收盤價來計算揮發物,這是一種解釋。我只想知道我的方法是否正確。
編輯:計算波動率的程式碼(不是我寫的):
public static class Volatility { public static double stdDeviation; public static double semiDeviation; public static void CalcVolatility(List<float> returns, Predicate<int> filter) { double tempStandard = 0; double tempSemi = 0; int count = 0; double averageLogReturn = logAverage(returns, filter); for (int ii = 0; ii < returns.Count; ii++) { if (!filter.Invoke(ii)) continue; double logReturn = Math.Log(1 + returns[ii]); double add = Math.Pow(logReturn - averageLogReturn, 2); tempStandard = tempStandard + add; count++; if (logReturn < averageLogReturn) tempSemi = tempSemi + add; } stdDeviation = Math.Sqrt(tempStandard/(count - 1)*count); semiDeviation = Math.Sqrt(tempSemi/(count - 1)*count); } private static double logAverage(List<float> returns, Predicate<int> filter) { double sum = 0; int count = 0; for (int ii = 0; ii < returns.Count; ii++) { if (!filter.Invoke(ii)) continue; sum += Math.Log(1 + returns[ii]); count++; } return sum/count; } }
以下是退貨清單,從最舊的開始:
-0.02970294,-0.03061228,0.03157898,-0.0204082,-0.05208328,-0.02197807,-0.02247189,-0.02298848,0,0.03529408,0.01477274,-0.04703247,0.04347826,0.007882848,-0.002234608,-0.03919376,0.04895104,0.00777781,-0.0154355,0.003359486,-0.03236612,0.00922724,-0.03428568,0.02958577,-0.00114941,-0.02991947,-0.007117417,0.01194742,-0.005903182,0.01781471,0.002333762,0,-0.01979048,0.00356297,-0.004733737,0.009512433,-0.01295639,-0.002386604,-0.01315794,-0.001212106,-0.01820387,0.0321384,0.03113775,0.00464577,0.004624287,-0.01726127,-0.02341918,-0.002398051,0.01322113,-0.01542113,0.03734942,-0.01858301,-0.002366904,-0.03084226,-0.02692773,-0.04905665,-0.003968203,-0.01859229,0.04194852,0.02987013,-0.001261018,0.003787905,0.04402512,-0.1638554,-0.03458212,0.04626859,0.03708991,0.01100415,-0.0122449,0.0247934,-0.001344149,-0.1184388,-0.0396946,0.02543716,0.007751931,-0.01230763,0.01713392,0.02143951,0.001499231,0.002994063,0.03432836,-0.01731605,0.005873727,0.01605836,-0.02586208,0.07669624,0.04931501,-0.03263704,0.0202429,0.002645548,-0.02506595,-0.01082546,0.02188779,0.02275772,0.003926729,-0.01434164,0.001322813,0.03698811,-0.003821683,0.003836344,-0.02929937,0.02362198,0.03076929,-0.01368164,-0.01639346,0.001282111,0.03072982,-0.004968954,0.008739113,-0.001237682,0.01239156,0.002448022,-0.006105,0.001228485,-0.007361942,-0.00247223,-0.001239141,0.003722111,-0.01606924,-0.006281401,0,-0.05183313,-0.009333372,-0.0107671,-0.01360543,-0.001379375,0.02762437,0.03494618,-0.012987,-0.02894739,-0.009485054,0.02462381,0.005340465,-0.04913678,0.03212291,-0.01894452,-0.001379375,-0.006906071,0.02503478,-0.02713702,-0.01394699,-0.01414426,0.02439019,0.02380955,0.03146375,-0.007957536,0.01069513,0.02116407,0.01295335,0.0102302,0.01012653,-0.03007518,0.01162791,0.00638569,0.001269019,0.001267486,-0.02151901,-0.03104785,0.01068093,0,-0.02113611,-0.01349526,-0.02872781,-0.02535212,0.008670582,0.007163317,-0.004267455,-0.01714281,-0.03052329,0.04647679,0.002865293,0,0.01571434,-0.02531646,0.007215,0.01575928,-0.004231341,0.01558079,-0.009762942,-0.02957742,0.08708273,0.01735649,-0.001312397,-0.01314059,0.01597873,0.009174271,0.02337663,0.0177665,0.03241898,0.01086957,0.001194728,-0.0250597,0.04406366,0.01992968,-0.04022992,0.008383268,0,0.01068884,0.003525219,0.00234196,-0.003504697,-0.01289564,-0.02969125,0.01223996,0.02055618,-0.005924165,0.01549465,-0.01877931,-0.01196178,0.01089589,0.007185679,-0.007134413,-0.001197589,-0.01678657,0.001219496,-0.02436051,-0.02996253,0.01673103,0.005063301,0,0.0201511,0.02962962,-0.02637891,0.01354684,-0.01579588,0.007407385,-0.006127445,-0.01356347,-0.01125,0.002528413,-0.01513236,-0.007682512,-0.006451607,-0.012987,0.01710528,-0.02328591,0.01456951,-0.006527409,0.01445471,0.01683939,0.001273869,-0.007633641,0.002564146,-0.01406647,0.01426716,0.007672612,-0.002538038,-0.008905889,0.005134799,0.02043427,0.01376718,0.004938282,0.002456971,0.007352993
有人可以告訴我我的方法是否正確嗎?當然,也可能是網站不採用收盤價來計算揮發物,這是一種解釋。我只想知道我的方法是否正確。
正確的方法如下:對於使用 250(我使用 252)日交易年的 1 個月曆史波動率,您不會使用過去 30 個交易日。30 天對應於 360 天或 365 天的交易年。您應該使用 20 個交易日。這是一個 Excel 公式,我現在恰好在我的桌面上打開了它。希望能幫助到你。
[Std Dev of Daily Returns of the last 20 trading days]*[Square Root of 252] =(STDEV.P(I2807:I2826))*SQRT(252)
要計算 HV,您需要每天更改百分比。如果您的消息來源沒有使用收盤價來推導他們的每日百分比變化,那麼他們沒有正確的 HV 用於您所引用的證券,您將不會得出相同的數字。