[Returnanalytics-commits] r3655 - in pkg/Dowd: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed May 27 21:05:09 CEST 2015
Author: dacharya
Date: 2015-05-27 21:05:08 +0200 (Wed, 27 May 2015)
New Revision: 3655
Added:
pkg/Dowd/man/ChristoffersenBacktestForIndependence.Rd
Modified:
pkg/Dowd/NAMESPACE
pkg/Dowd/R/BlancoIhleBacktest.R
pkg/Dowd/R/ChristoffersenBacktestForIndependence.R
pkg/Dowd/R/ChristoffersenBacktestForUnconditionalCoverage.R
pkg/Dowd/R/LopezBacktest.R
pkg/Dowd/man/BlancoIhleBacktest.Rd
pkg/Dowd/man/ChristoffersenBacktestForUnconditionalCoverage.Rd
pkg/Dowd/man/LopezBacktest.Rd
Log:
Bugs removed from 4 new functions added today.
Modified: pkg/Dowd/NAMESPACE
===================================================================
--- pkg/Dowd/NAMESPACE 2015-05-27 16:59:26 UTC (rev 3654)
+++ pkg/Dowd/NAMESPACE 2015-05-27 19:05:08 UTC (rev 3655)
@@ -3,6 +3,7 @@
export(ADTestStat)
export(BinomialBacktest)
export(BlancoIhleBacktest)
+export(ChristoffersenBacktestForIndependence)
export(ChristoffersenBacktestForUnconditionalCoverage)
export(JarqueBeraBacktest)
export(KSTestStat)
Modified: pkg/Dowd/R/BlancoIhleBacktest.R
===================================================================
--- pkg/Dowd/R/BlancoIhleBacktest.R 2015-05-27 16:59:26 UTC (rev 3654)
+++ pkg/Dowd/R/BlancoIhleBacktest.R 2015-05-27 19:05:08 UTC (rev 3655)
@@ -16,7 +16,13 @@
#'
#' @author Dinesh Acharya
#' @examples
-#' # To be added
+#'
+#' # Has to be modified with appropriate data:
+#' # Christoffersen Backtest For Independence for given parameters
+#' a <- rnorm(1*100)
+#' b <- abs(rnorm(1*100))+2
+#' c <- abs(rnorm(1*100))+2
+#' BlancoIhleBacktest(a, b, c, 0.95)
#'
#' @export
BlancoIhleBacktest <- function(Ra, Rb, Rc, cl){
@@ -27,14 +33,17 @@
n <- length(profit.loss)
p <- 1-cl
- excess.loss <- -profit.loss(-profit.loss>VaR) # Derives excess loss
- benchmark <- double(length(excess_loss))
+ excess.loss <- -profit.loss[-profit.loss>VaR] # Derives excess loss
+ m <- length(excess.loss)
- for (i in 1:length(excess_loss)){
- benchmark[i] <- (ETL[i]-VaR[i])/Var[i]
+ benchmark <- double(m)
+ score <- double(m)
+ for (i in 1:m){
+ benchmark[i] <- (ETL[i]-VaR[i])/VaR[i]
score[i] <- (excess.loss[i]-VaR[i])/VaR[i]-benchmark[i]
}
# First Blanco-Ihle score measure
- return((2/n)*sum(score)^2)
+ y <- (2/n)*sum(score)^2
+ return(y)
}
\ No newline at end of file
Modified: pkg/Dowd/R/ChristoffersenBacktestForIndependence.R
===================================================================
--- pkg/Dowd/R/ChristoffersenBacktestForIndependence.R 2015-05-27 16:59:26 UTC (rev 3654)
+++ pkg/Dowd/R/ChristoffersenBacktestForIndependence.R 2015-05-27 19:05:08 UTC (rev 3655)
@@ -16,11 +16,17 @@
#' Review, 39(4), 1992, 841-862.
#'
#' @author Dinesh Acharya
+#' @author Dinesh Acharya
#' @examples
-#' # To be added
+#'
+#' # Has to be modified with appropriate data:
+#' # Christoffersen Backtest For Independence for given parameters
+#' a <- rnorm(1*100)
+#' b <- abs(rnorm(1*100))+2
+#' ChristoffersenBacktestForIndependence(a, b, 0.95)
#'
#' @export
-BlancoIhleBacktest <- function(Ra, Rb, cl){
+ChristoffersenBacktestForIndependence <- function(Ra, Rb, cl){
profit.loss <- as.vector(Ra)
VaR <- as.vector(Ra)
@@ -30,17 +36,17 @@
excess.loss <- -profit.loss-VaR # Derives excess loss
excess.loss <- excess.loss[excess.loss>0] # Gets rid of negative or zeros
##########################################
- # Read Documentation/Alternative Implementation.
+ # There are mistakes in original code and needs to be addressed.
# VaR <- VaR[excess.loss>0]
##########################################
t00 <- 0
t01 <- 0
t10 <- 0
t11 <- 0
- for (i in 2:n){
+ for (i in 2:length(excess.loss)){
if(excess.loss[i]<=0){
if(excess.loss[i-1]<=0){
- t00 <- t00+1;
+ t00 <- t00+1
} else {
t10 <- t10+1
}
@@ -58,7 +64,7 @@
pie1 <- t11/(t10+t11)
# Likelihood ratio test statistic
- LR=-2*log((((1-p)^(T00+T10))*(p^(T01+T11)))+2*log((((1-pie0)^T00))*(pie0^T01)*((1-pie1)^(T10))*pie1^T11))
+ LR=-2*log((((1-p)^(t00+t10))*(p^(t01+t11)))+2*log((((1-pie0)^t00))*(pie0^t01)*((1-pie1)^(t10))*pie1^t11))
# Probability that null hypothesis (independence is correct)
y <- 1-pchisq(LR,1)
Modified: pkg/Dowd/R/ChristoffersenBacktestForUnconditionalCoverage.R
===================================================================
--- pkg/Dowd/R/ChristoffersenBacktestForUnconditionalCoverage.R 2015-05-27 16:59:26 UTC (rev 3654)
+++ pkg/Dowd/R/ChristoffersenBacktestForUnconditionalCoverage.R 2015-05-27 19:05:08 UTC (rev 3655)
@@ -16,7 +16,12 @@
#'
#' @author Dinesh Acharya
#' @examples
-#' # To be added
+#'
+#' # Has to be modified with appropriate data:
+#' # Christoffersen Backtest For Unconditional Coverage for given parameters
+#' a <- rnorm(1*100)
+#' b <- abs(rnorm(1*100))+2
+#' ChristoffersenBacktestForUnconditionalCoverage(a, b, 0.95)
#'
#' @export
ChristoffersenBacktestForUnconditionalCoverage <- function(Ra, Rb, cl){
@@ -26,8 +31,8 @@
n <- length(profit.loss) # Number of observations
p <- 1-cl # Probability of failure under null hypothesis
- v <- length(which(VaR+profit.loss<0)) # Frequency of failures
-
+ x <- length(which(VaR+profit.loss<0)) # Number of Failures
+ phat <- x/n # Frequency of Failures
# Likelihood ratio test statistic
LR <- -2*log(((p^x)*(1-p)^(n-x))/((phat^x)*((1-phat)^(n-x))))
Modified: pkg/Dowd/R/LopezBacktest.R
===================================================================
--- pkg/Dowd/R/LopezBacktest.R 2015-05-27 16:59:26 UTC (rev 3654)
+++ pkg/Dowd/R/LopezBacktest.R 2015-05-27 19:05:08 UTC (rev 3655)
@@ -18,7 +18,12 @@
#'
#' @author Dinesh Acharya
#' @examples
-#' # To be added
+#'
+#' # Has to be modified with appropriate data:
+#' # LopezBacktest for given parameters
+#' a <- rnorm(1*100)
+#' b <- abs(rnorm(1*100))+2
+#' LopezBacktest(a, b, 0.95)
#'
#' @export
LopezBacktest <- function(Ra, Rb, cl){
Modified: pkg/Dowd/man/BlancoIhleBacktest.Rd
===================================================================
--- pkg/Dowd/man/BlancoIhleBacktest.Rd 2015-05-27 16:59:26 UTC (rev 3654)
+++ pkg/Dowd/man/BlancoIhleBacktest.Rd 2015-05-27 19:05:08 UTC (rev 3655)
@@ -1,59 +1,42 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
-% Please edit documentation in R/BlancoIhleBacktest.R, R/ChristoffersenBacktestForIndependence.R
+% Please edit documentation in R/BlancoIhleBacktest.R
\name{BlancoIhleBacktest}
\alias{BlancoIhleBacktest}
\title{Blanco-Ihle forecast evaluation backtest measure}
\usage{
-BlancoIhleBacktest(Ra, Rb, cl)
-
-BlancoIhleBacktest(Ra, Rb, cl)
+BlancoIhleBacktest(Ra, Rb, Rc, cl)
}
\arguments{
\item{Ra}{Vector of a portfolio profit and loss}
\item{Rb}{Vector of corresponding VaR forecasts}
-\item{cl}{VaR confidence interval}
-
\item{Rc}{Vector of corresponding Expected Tailed Loss forecasts}
-\item{Ra}{Vector of portfolio profit and loss observations}
-
-\item{Rb}{Vector of corresponding VaR forecasts}
-
-\item{cl}{Confidence interval for}
+\item{cl}{VaR confidence interval}
}
\value{
Something
-
-Probability that given the data set, the null hypothesis
-(i.e. independence) is correct.
}
\description{
Derives the Blanco-Ihle forecast evaluation loss measure for a VaR
risk measurement model.
-
-Carries out the Christoffersen backtest of independence for a VaR risk
-measurement model, for specified VaR confidence level.
}
\examples{
-# To be added
-# To be added
+# Has to be modified with appropriate data:
+ # Christoffersen Backtest For Independence for given parameters
+ a <- rnorm(1*100)
+ b <- abs(rnorm(1*100))+2
+ c <- abs(rnorm(1*100))+2
+ BlancoIhleBacktest(a, b, c, 0.95)
}
\author{
Dinesh Acharya
-
-Dinesh Acharya
}
\references{
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Blanco, C. and Ihle, G. How Good is Your Var? Using Backtesting to Assess
System Performance. Financial Engineering News, 1999.
-
-Dowd, K. Measuring Market Risk, Wiley, 2007.
-
-Christoffersen, P. Evaluating Interval Forecasts. International Economic
-Review, 39(4), 1992, 841-862.
}
Added: pkg/Dowd/man/ChristoffersenBacktestForIndependence.Rd
===================================================================
--- pkg/Dowd/man/ChristoffersenBacktestForIndependence.Rd (rev 0)
+++ pkg/Dowd/man/ChristoffersenBacktestForIndependence.Rd 2015-05-27 19:05:08 UTC (rev 3655)
@@ -0,0 +1,42 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/ChristoffersenBacktestForIndependence.R
+\name{ChristoffersenBacktestForIndependence}
+\alias{ChristoffersenBacktestForIndependence}
+\title{Christoffersen Backtest for Independence}
+\usage{
+ChristoffersenBacktestForIndependence(Ra, Rb, cl)
+}
+\arguments{
+\item{Ra}{Vector of portfolio profit and loss observations}
+
+\item{Rb}{Vector of corresponding VaR forecasts}
+
+\item{cl}{Confidence interval for}
+}
+\value{
+Probability that given the data set, the null hypothesis
+(i.e. independence) is correct.
+}
+\description{
+Carries out the Christoffersen backtest of independence for a VaR risk
+measurement model, for specified VaR confidence level.
+}
+\examples{
+# Has to be modified with appropriate data:
+ # Christoffersen Backtest For Independence for given parameters
+ a <- rnorm(1*100)
+ b <- abs(rnorm(1*100))+2
+ ChristoffersenBacktestForIndependence(a, b, 0.95)
+}
+\author{
+Dinesh Acharya
+
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measuring Market Risk, Wiley, 2007.
+
+Christoffersen, P. Evaluating Interval Forecasts. International Economic
+Review, 39(4), 1992, 841-862.
+}
+
Modified: pkg/Dowd/man/ChristoffersenBacktestForUnconditionalCoverage.Rd
===================================================================
--- pkg/Dowd/man/ChristoffersenBacktestForUnconditionalCoverage.Rd 2015-05-27 16:59:26 UTC (rev 3654)
+++ pkg/Dowd/man/ChristoffersenBacktestForUnconditionalCoverage.Rd 2015-05-27 19:05:08 UTC (rev 3655)
@@ -22,7 +22,11 @@
VaR risk measurement model, for specified VaR confidence level.
}
\examples{
-# To be added
+# Has to be modified with appropriate data:
+ # Christoffersen Backtest For Unconditional Coverage for given parameters
+ a <- rnorm(1*100)
+ b <- abs(rnorm(1*100))+2
+ ChristoffersenBacktestForUnconditionalCoverage(a, b, 0.95)
}
\author{
Dinesh Acharya
Modified: pkg/Dowd/man/LopezBacktest.Rd
===================================================================
--- pkg/Dowd/man/LopezBacktest.Rd 2015-05-27 16:59:26 UTC (rev 3654)
+++ pkg/Dowd/man/LopezBacktest.Rd 2015-05-27 19:05:08 UTC (rev 3655)
@@ -21,7 +21,11 @@
for a VaR risk measurement model.
}
\examples{
-# To be added
+# Has to be modified with appropriate data:
+ # LopezBacktest for given parameters
+ a <- rnorm(1*100)
+ b <- abs(rnorm(1*100))+2
+ LopezBacktest(a, b, 0.95)
}
\author{
Dinesh Acharya
More information about the Returnanalytics-commits
mailing list