波動性

了解揚張波動率估計器

  • October 17, 2021

在 R 中使用 TTR,並且試圖了解 Yang Zhang 波動率估計器(無漂移)。以下等式似乎暗示了一個值:

$$ \sigma = \sqrt{{\sigma_o^2}+k\sigma_c^2+(1-k)\sigma_{rs}^2} $$

$$ \sigma_o^2 = \frac{1}{N-1}\sum_{i=1}^{N}ln{\frac{o_i}{c_{i-1}}^2} $$ $$ \sigma_c^2 = \frac{1}{N-1}\sum_{i=1}^{N}ln{\frac{c_i}{o_{i-1}}^2} $$ $$ \sigma_{rs}^2 = \frac{1}{N-1}\sum_{i=1}^{N}(ln{\frac{h_i}{c_i}})(ln{\frac{h_i}{o_i}}) + (ln{\frac{l_i}{c_i}})(ln{\frac{l_i}{o_i}}) $$ $$ k = \frac{0.34}{1.34 + \frac{N+1}{N-1}} $$

但是,當我執行時,volatility(my_data, n = 100, calc = "yang.zhang")我會得到一個前面有一堆 NA 的向量。我的波動率估計是多少?它是數據框中的最後一個值嗎?如果是,其他數據點的剩餘值是多少?如果這是微不足道的,我深表歉意 - 但我似乎無法在 TTR 文件中找到任何內容。

謝謝!

n=100指定 vol 估計的周期數(滾動) - 請參閱原始連結https://web.archive.org/web/20100326215050/http://www.sitmo.com/eq/409n引用as用於波動率估計的歷史價格數量

R中的一個例子:

library(TTR)
library(quantmod)

getSymbols("AAPL")
nrow(AAPL) # we have 2384 price points


vol <- volatility(AAPL, n = 100, calc = "yang.zhang")
# if n = 100, then we have 2384 - 100 = 2284 vol estimates for all the "100-day rolling period"
nrow(na.omit(vol))
# and we have 100 NA for the initial 100 periods
sum(is.na(vol))

# if n = 2383 then we have only a single vol estimae (i.e. massive 2383 period window)
vol2 <- volatility(AAPL, n = 2383, calc = "yang.zhang")
nrow(na.omit(vol2))
sum(is.na(vol2))

生產

[1] "AAPL"
> nrow(AAPL) # we have 2384 price points
[1] 2384
> 
> 
> vol <- volatility(AAPL, n = 100, calc = "yang.zhang")
> # if n = 100, then we have 2384 - 100 = 2284 vol estimates for all the "100-day rolling period"
> nrow(na.omit(vol))
[1] 2284
> # and we have 100 NA for the initial 100 periods
> sum(is.na(vol))
[1] 100
> 
> # if n = 2383 then we have only a single vol estimae (i.e. massive 2383 period window)
> vol2 <- volatility(AAPL, n = 2383, calc = "yang.zhang")
> nrow(na.omit(vol2))
[1] 1
> sum(is.na(vol2))
[1] 2383

引用自:https://quant.stackexchange.com/questions/27741