[Uwgarp-commits] r133 - in pkg/GARPFRM: R demo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Mar 26 05:27:52 CET 2014
Author: rossbennett34
Date: 2014-03-26 05:27:50 +0100 (Wed, 26 Mar 2014)
New Revision: 133
Added:
pkg/GARPFRM/demo/backtest_VaR.R
Modified:
pkg/GARPFRM/R/backTestVaR.R
pkg/GARPFRM/demo/00Index.txt
Log:
Adding demo for VaR backtesting. Fixing bug in bootstrap VaR backtest
Modified: pkg/GARPFRM/R/backTestVaR.R
===================================================================
--- pkg/GARPFRM/R/backTestVaR.R 2014-03-26 03:16:35 UTC (rev 132)
+++ pkg/GARPFRM/R/backTestVaR.R 2014-03-26 04:27:50 UTC (rev 133)
@@ -97,7 +97,9 @@
for(i in window:n){
tmpR <- R[(i-window+1):i,]
# compute VaR estimate
- est[(i-window+1), j] <- bootVaR(R=tmpR, p=p, method=method[j], portfolio_method="single", replications=replications, parallel=bootParallel)
+ est[(i-window+1), j] <- bootVaR(R=tmpR,
+ ...=pairlist(p=p, method=method[j], portfolio_method="single"),
+ replications=replications, parallel=bootParallel)[1,]
}
}
} else {
Modified: pkg/GARPFRM/demo/00Index.txt
===================================================================
--- pkg/GARPFRM/demo/00Index.txt 2014-03-26 03:16:35 UTC (rev 132)
+++ pkg/GARPFRM/demo/00Index.txt 2014-03-26 04:27:50 UTC (rev 133)
@@ -3,4 +3,5 @@
demo_EWMA_GARCH11.R demonstrate exponentially weighted moving average and GARCH models
EWMA.R demonstrate exponentially weighted moving average model
monte_carlo.R demonstrate monte carlo method to simulate asset price paths
-univariate_GARCH.R demonstrate fitting a GARCH model to a univariate data set
\ No newline at end of file
+univariate_GARCH.R demonstrate fitting a GARCH model to a univariate data set
+backtest_VaR.R demonstrate Value at Risk backtesting
\ No newline at end of file
Added: pkg/GARPFRM/demo/backtest_VaR.R
===================================================================
--- pkg/GARPFRM/demo/backtest_VaR.R (rev 0)
+++ pkg/GARPFRM/demo/backtest_VaR.R 2014-03-26 04:27:50 UTC (rev 133)
@@ -0,0 +1,38 @@
+library(GARPFRM)
+
+data(crsp_weekly)
+R <- largecap_weekly
+
+# Run a VaR backtest on MSFT returns
+# Compute VaR estimate using gaussian, historical, and modified methods
+backtest <- backtestVaR(R[, "MSFT"], window=100, p=0.95,
+ method=c("gaussian", "historical", "modified"))
+backtest
+
+# get the VaR estimates
+head(getVaREstimates(backtest))
+
+# get the VaR violations
+head(getVaRViolations(backtest))
+
+# plot the VaR backtest
+plot(backtest, pch=18, legendLoc="topright")
+
+# Compare the historical VaR bootstrapped historical VaR estimates
+btHistorical <- backtestVaR(R[, "MSFT"], window=100, p=0.95, method="historical")
+
+btHistoricalBoot <- backtestVaR(R[, "MSFT"], window=100, p=0.95,
+ method="historical", replications=100,
+ bootstrap=TRUE)
+
+btHistorical
+btHistoricalBoot
+
+# plot the historical and boostrapped historical VaR backtest
+plot(btHistorical, colorset="blue")
+lines(getVaREstimates(btHistoricalBoot), col="red")
+legend("topright", legend=c("returns", "Historical VaR (0.05)",
+ "Boot Historical VaR (0.05)"),
+ lty=rep(1,3), col=c("black", "blue", "red"), bty="n", cex=0.75)
+
+
More information about the Uwgarp-commits
mailing list