[Uwgarp-commits] r91 - in pkg/GARPFRM: R man sandbox
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Feb 19 08:27:39 CET 2014
Author: tfillebeen
Date: 2014-02-19 08:27:38 +0100 (Wed, 19 Feb 2014)
New Revision: 91
Added:
pkg/GARPFRM/sandbox/test_VaR.R
Modified:
pkg/GARPFRM/R/backTestVaR.R
pkg/GARPFRM/man/backTestVaR.Rd
pkg/GARPFRM/sandbox/test_EWMA_GARCH.R
Log:
backTestVaR.R, test_VaR.R, test_EWMA_GARCH. modified, added, modified respectively
Modified: pkg/GARPFRM/R/backTestVaR.R
===================================================================
--- pkg/GARPFRM/R/backTestVaR.R 2014-02-17 03:23:25 UTC (rev 90)
+++ pkg/GARPFRM/R/backTestVaR.R 2014-02-19 07:27:38 UTC (rev 91)
@@ -3,13 +3,15 @@
#' Description of backTestVaR. The function should handle UV and MLM.
#'
#' @param R returns
-#' @param p confidence level
+#' @param CI confidence level
#' @export
-backTestVaR <- function(R, p = 0.95) {
- normalVaR = as.numeric(VaR(R, p=p, method="gaussian"))
- historicalVaR = as.numeric(VaR(R, p=p, method="historical"))
- modifiedVaR = as.numeric(VaR(R, p=p, method="modified"))
+backTestVaR <- function(R, CI = 0.95) {
+ if (ncol(R)>1){stop("One Asset at a time")}
+ normalVaR = as.numeric(VaR(R, p=CI, method="gaussian"))
+ historicalVaR = as.numeric(VaR(R, p=CI, method="historical"))
+ modifiedVaR = as.numeric(VaR(R, p=CI, method="modified"))
result = c(normalVaR, historicalVaR, modifiedVaR)
- names(result) = c("Normal", "HS", "Modified")
+ names(result) = c("Normal", "HS", "Modified")
+
return(result)
-}
\ No newline at end of file
+}
Modified: pkg/GARPFRM/man/backTestVaR.Rd
===================================================================
--- pkg/GARPFRM/man/backTestVaR.Rd 2014-02-17 03:23:25 UTC (rev 90)
+++ pkg/GARPFRM/man/backTestVaR.Rd 2014-02-19 07:27:38 UTC (rev 91)
@@ -2,12 +2,12 @@
\alias{backTestVaR}
\title{Backtesting VaR (backTestVaR)}
\usage{
-backTestVaR(R, p = 0.95)
+backTestVaR(R, CI = 0.95)
}
\arguments{
\item{R}{returns}
- \item{p}{confidence level}
+ \item{CI}{confidence level}
}
\description{
Description of backTestVaR. The function should handle UV
Modified: pkg/GARPFRM/sandbox/test_EWMA_GARCH.R
===================================================================
--- pkg/GARPFRM/sandbox/test_EWMA_GARCH.R 2014-02-17 03:23:25 UTC (rev 90)
+++ pkg/GARPFRM/sandbox/test_EWMA_GARCH.R 2014-02-19 07:27:38 UTC (rev 91)
@@ -87,11 +87,6 @@
# Forecasting conditional vol and cor, default wd = 100
fcstGarch11 = fcstGarch11(garch11,100)
-class(fcstGarch11)
-slotNames(fcstGarch11)
-class(fcstGarch11 at mforecast)
-names(fcstGarch11 at mforecast)
-
# Many method functions - see help on DCCforecast class
# rshape, rskew, fitted, sigma, plot, rcor, rcov, show
Added: pkg/GARPFRM/sandbox/test_VaR.R
===================================================================
--- pkg/GARPFRM/sandbox/test_VaR.R (rev 0)
+++ pkg/GARPFRM/sandbox/test_VaR.R 2014-02-19 07:27:38 UTC (rev 91)
@@ -0,0 +1,23 @@
+library(GARPFRM)
+data(crsp.short)
+R <- largecap.ts[, 1:4]
+temp = R[,1]
+# BackTesting Window
+initialWindow = 10
+testWindow = nrow(R) -initialWindow
+CI = 0.95
+lags = -1
+resultVaR = rollapply(temp, width= initialWindow, FUN = backTestVaR, p=CI, by.column = FALSE, align = "right")
+# VaR lags original data by definition
+resultVaR = lag(resultVaR, k=lags)
+# Chart together
+resultVaR = xts(resultVaR, index(R))
+temp = xts(temp, index(temp))
+
+chart.TimeSeries(cbind(resultVaR,temp), legend.loc="topright")
+
+# violations.mat = matrix(0, 3, 5)
+# rownames(violations.mat) = c("Normal", "HS", "Modified")
+# colnames(violations.mat) = c("En1", "n1", "1-CI", "Percent", "VaR")
+# violations.mat[, "En1"] = (1-CI)*testWindow
+# violations.mat[, "1-CI "] = 1 - CI
More information about the Uwgarp-commits
mailing list