單從外觀上看,VAR&VaR兩個模型很容易混淆,但就模型方法和用處兩者截然不同,R語言作為數據分析的有力工具,其函數包庫中包含各種各樣的統計模型。通過vars包可以調用向量自回歸模型,通過PerformanceAnalytics包的VaR函數可以調用風險價值模型。 ...
單從外觀上看,VAR&VaR兩個模型很容易混淆,但就模型方法和用處兩者截然不同,R語言作為數據分析的有力工具,其函數包庫中包含各種各樣的統計模型。通過vars包可以調用向量自回歸模型,通過PerformanceAnalytics包的VaR函數可以調用風險價值模型。
模型簡介
- library(vars)
- 向量自回歸模型(Vector Autoregression),簡稱VAR模型,是一種常用的計量經濟模型,由克裡斯托弗·西姆斯(Christopher Sims)提出。VAR模型是用模型中所有當期變數對所有變數的若幹滯後變數進行回歸。VAR模型用來估計聯合內生變數的動態關係,而不帶有任何事先約束條件。它是AR模型的推廣,此模型目前已得到廣泛應用。
- library(PerformanceAnalytics)=>VaR()
- 風險價值模型(Value at Risk),通常被稱作VaR方法。VaR按字面的解釋就是“處於風險狀態的價值”,即在一定置信水平和一定持有期內,某一金融資產或其組合在未來資產價格波動下所面臨的最大損失額。JP.Morgan定義為:VaR是在既定頭寸被沖銷(be neutraliged)或重估前可能發生的市場價值最大損失的估計值;而Jorion則把VaR定義為:“給定置信區間的一個持有期內的最壞的預期損失”。
向量自回歸模型(Vector Autoregression)
VAR模型R語言實例:
library(vars)
library(astsa) #數據包
x = cbind(cmort, tempr, part)
plot.ts(x , main = "", xlab = "")
summary(VAR(x, p=1, type="both"))
##
## VAR Estimation Results:
## =========================
## Endogenous variables: cmort, tempr, part
## Deterministic variables: both
## Sample size: 507
## Log Likelihood: -5116.02
## Roots of the characteristic polynomial:
## 0.8931 0.4953 0.1444
## Call:
## VAR(y = x, p = 1, type = "both")
##
##
## Estimation results for equation cmort:
## ======================================
## cmort = cmort.l1 + tempr.l1 + part.l1 + const + trend
##
## Estimate Std. Error t value Pr(>|t|)
## cmort.l1 0.464824 0.036729 12.656 < 2e-16 ***
## tempr.l1 -0.360888 0.032188 -11.212 < 2e-16 ***
## part.l1 0.099415 0.019178 5.184 3.16e-07 ***
## const 73.227292 4.834004 15.148 < 2e-16 ***
## trend -0.014459 0.001978 -7.308 1.07e-12 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 5.583 on 502 degrees of freedom
## Multiple R-Squared: 0.6908, Adjusted R-squared: 0.6883
## F-statistic: 280.3 on 4 and 502 DF, p-value: < 2.2e-16
##
##
## Estimation results for equation tempr:
## ======================================
## tempr = cmort.l1 + tempr.l1 + part.l1 + const + trend
##
## Estimate Std. Error t value Pr(>|t|)
## cmort.l1 -0.244046 0.042105 -5.796 1.20e-08 ***
## tempr.l1 0.486596 0.036899 13.187 < 2e-16 ***
## part.l1 -0.127661 0.021985 -5.807 1.13e-08 ***
## const 67.585598 5.541550 12.196 < 2e-16 ***
## trend -0.006912 0.002268 -3.048 0.00243 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 6.4 on 502 degrees of freedom
## Multiple R-Squared: 0.5007, Adjusted R-squared: 0.4967
## F-statistic: 125.9 on 4 and 502 DF, p-value: < 2.2e-16
##
##
## Estimation results for equation part:
## =====================================
## part = cmort.l1 + tempr.l1 + part.l1 + const + trend
##
## Estimate Std. Error t value Pr(>|t|)
## cmort.l1 -0.124775 0.079013 -1.579 0.115
## tempr.l1 -0.476526 0.069245 -6.882 1.77e-11 ***
## part.l1 0.581308 0.041257 14.090 < 2e-16 ***
## const 67.463501 10.399163 6.487 2.10e-10 ***
## trend -0.004650 0.004256 -1.093 0.275
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 12.01 on 502 degrees of freedom
## Multiple R-Squared: 0.3732, Adjusted R-squared: 0.3683
## F-statistic: 74.74 on 4 and 502 DF, p-value: < 2.2e-16
##
##
##
## Covariance matrix of residuals:
## cmort tempr part
## cmort 31.172 5.975 16.65
## tempr 5.975 40.965 42.32
## part 16.654 42.323 144.26
##
## Correlation matrix of residuals:
## cmort tempr part
## cmort 1.0000 0.1672 0.2484
## tempr 0.1672 1.0000 0.5506
## part 0.2484 0.5506 1.0000
風險價值模型(Value at Risk)
VaR模型R語言實例:
library(PerformanceAnalytics)
data(edhec)
# first do normal VaR calc
VaR(edhec, p=.95, method="historical")
## Convertible Arbitrage CTA Global Distressed Securities
## VaR -0.01916 -0.0354 -0.018875
## Emerging Markets Equity Market Neutral Event Driven
## VaR -0.044605 -0.006385 -0.02254
## Fixed Income Arbitrage Global Macro Long/Short Equity Merger Arbitrage
## VaR -0.00929 -0.01624 -0.02544 -0.013455
## Relative Value Short Selling Funds of Funds
## VaR -0.013175 -0.07848 -0.021265
# now use Gaussian
VaR(edhec, p=.95, method="gaussian")
## Convertible Arbitrage CTA Global Distressed Securities
## VaR -0.02645782 -0.03471098 -0.0221269
## Emerging Markets Equity Market Neutral Event Driven
## VaR -0.05498927 -0.008761813 -0.02246202
## Fixed Income Arbitrage Global Macro Long/Short Equity Merger Arbitrage
## VaR -0.01900198 -0.02023018 -0.02859264 -0.01152478
## Relative Value Short Selling Funds of Funds
## VaR -0.01493049 -0.08617027 -0.02393888
# now use modified Cornish Fisher calc to take non-normal distribution into account
VaR(edhec, p=.95, method="modified")
## Convertible Arbitrage CTA Global Distressed Securities
## VaR -0.03247395 -0.03380228 -0.0274924
## Emerging Markets Equity Market Neutral Event Driven
## VaR -0.06363081 -0.01134637 -0.02812515
## Fixed Income Arbitrage Global Macro Long/Short Equity Merger Arbitrage
## VaR -0.0246791 -0.01548247 -0.03037494 -0.01486869
## Relative Value Short Selling Funds of Funds
## VaR -0.01926435 -0.07431463 -0.02502852
# now use p=.99
VaR(edhec, p=.99)
## Convertible Arbitrage CTA Global Distressed Securities
## VaR -0.1009223 -0.04847019 -0.06533764
## Emerging Markets Equity Market Neutral Event Driven
## VaR -0.1397195 -0.04404136 -0.06385154
## Fixed Income Arbitrage Global Macro Long/Short Equity Merger Arbitrage
## VaR -0.05850228 -0.02437999 -0.05508705 -0.03630211
## Relative Value Short Selling Funds of Funds
## VaR -0.050531 -0.122236 -0.05500037
# or the equivalent alpha=.01
VaR(edhec, p=.01)
## Convertible Arbitrage CTA Global Distressed Securities
## VaR -0.1009223 -0.04847019 -0.06533764
## Emerging Markets Equity Market Neutral Event Driven
## VaR -0.1397195 -0.04404136 -0.06385154
## Fixed Income Arbitrage Global Macro Long/Short Equity Merger Arbitrage
## VaR -0.05850228 -0.02437999 -0.05508705 -0.03630211
## Relative Value Short Selling Funds of Funds
## VaR -0.050531 -0.122236 -0.05500037
# now with outliers squished
VaR(edhec, clean="boudt")
## Convertible Arbitrage CTA Global Distressed Securities
## VaR -0.0192821 -0.03380228 -0.02281122
## Emerging Markets Equity Market Neutral Event Driven
## VaR -0.05335613 -0.006583541 -0.02588255
## Fixed Income Arbitrage Global Macro Long/Short Equity Merger Arbitrage
## VaR -0.01947099 -0.01612116 -0.02997413 -0.01255334
## Relative Value Short Selling Funds of Funds
## VaR -0.0147671 -0.07881339 -0.02474761
# add Component VaR for the equal weighted portfolio
VaR(edhec, clean="boudt", portfolio_method="component")
## $MVaR
## [,1]
## [1,] 0.01206124
##
## $contribution
## Convertible Arbitrage CTA Global Distressed Securities
## 1.189614e-03 7.392667e-05 1.380388e-03
## Emerging Markets Equity Market Neutral Event Driven
## 3.044882e-03 3.255042e-04 1.633369e-03
## Fixed Income Arbitrage Global Macro Long/Short Equity
## 1.122597e-03 9.551128e-04 1.725166e-03
## Merger Arbitrage Relative Value Short Selling
## 5.594788e-04 9.422577e-04 -2.647415e-03
## Funds of Funds
## 1.756359e-03
##
## $pct_contrib_MVaR
## Convertible Arbitrage CTA Global Distressed Securities
## 0.098631120 0.006129276 0.114448260
## Emerging Markets Equity Market Neutral Event Driven
## 0.252451840 0.026987629 0.135422963
## Fixed Income Arbitrage Global Macro Long/Short Equity
## 0.093074804 0.079188612 0.143033874
## Merger Arbitrage Relative Value Short Selling
## 0.046386511 0.078122792 -0.219497771
## Funds of Funds
## 0.145620091
反饋與建議
- 作者:ShangFR
- 郵箱:[email protected]