一、歷史模擬法計算1%之VaR
(一)語法
#產生var的變數
#series VaR=NA
smpl 1 1900
#迴圈
loop for j = 1901.. 1974
#宣告固定的變數值 sigma w0 c_001
scalar sigma = sd(Y)
scalar w0 = 1000000
scalar R = quantile(Y,0.01)
#$t2+1--目前使用中的子樣本最後一筆之位置
scalar k2 = $t2+1
#在前面不用加series,因中括號其中代表類似迴圈的意思。
VaR[k2]=-R
#結果值,1901
smpl +1 +1
end loop
smpl full
二、歷史模擬法計算5%之VaR
(一)語法
#產生var的變數
#series VaR=NA
smpl 1 1900
#迴圈
loop for j = 1901.. 1974
#宣告固定的變數值 sigma w0 c_001
scalar sigma = sd(Y)
scalar w0 = 1000000
scalar R = quantile(Y,0.05)
#$t2+1--目前使用中的子樣本最後一筆之位置
scalar k2 = $t2+1
#在前面不用加series,因中括號其中代表類似迴圈的意思。
VaR[k2]=-R
#結果值,1901
smpl +1 +1
end loop
smpl full
三、均數-變藝術法計算1%之VaR
(一)語法
#產生VaR的變數
#series VaR=NA
smpl 1 1900
#迴圈
loop for j=1901..1974
#宣告固定的變數值w0 sigma critical
scalar w0=1000000
scalar sigma=sd(Y)
scalar c_001=critical(z,0.01)
#$t2--目前使用中的子樣本最後一筆位置
scalar k2=$t2+1
#不需填入series scalar 變數,因為不屬於此兩種變數的定義
VaR[k2]=w0*c_001*sigma/100
#結果值,1901為1 1900的值,1902為2 1901的值....
smpl +1 +1
endloop
smpl full
(二)結果
(二)結果
(二)結果