[Returnanalytics-commits] r3663 - in pkg/Dowd: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Jun 8 23:51:12 CEST 2015
Author: dacharya
Date: 2015-06-08 23:51:11 +0200 (Mon, 08 Jun 2015)
New Revision: 3663
Added:
pkg/Dowd/R/HillEstimator.R
pkg/Dowd/R/HillPlot.R
pkg/Dowd/R/HillQuantileEstimator.R
pkg/Dowd/R/PickandsEstimator.R
pkg/Dowd/R/PickandsPlot.R
pkg/Dowd/man/HillEstimator.Rd
pkg/Dowd/man/HillPlot.Rd
pkg/Dowd/man/HillQuantileEstimator.Rd
pkg/Dowd/man/PickandsEstimator.Rd
pkg/Dowd/man/PickandsPlot.Rd
Modified:
pkg/Dowd/NAMESPACE
Log:
HillPlot, HillEstimator, HillQuantileEstimator, PickandsPlot.R and PickandsEstimator: (source and documentation)
Modified: pkg/Dowd/NAMESPACE
===================================================================
--- pkg/Dowd/NAMESPACE 2015-06-07 00:59:53 UTC (rev 3662)
+++ pkg/Dowd/NAMESPACE 2015-06-08 21:51:11 UTC (rev 3663)
@@ -20,8 +20,13 @@
export(GumbelCopulaVaR)
export(HSES)
export(HSVaR)
+export(HillEstimator)
+export(HillPlot)
+export(HillQuantileEstimator)
export(JarqueBeraBacktest)
export(KSTestStat)
export(KuiperTestStat)
export(LopezBacktest)
+export(PickandsEstimator)
+export(PickandsPlot)
export(ProductCopulaVaR)
Added: pkg/Dowd/R/HillEstimator.R
===================================================================
--- pkg/Dowd/R/HillEstimator.R (rev 0)
+++ pkg/Dowd/R/HillEstimator.R 2015-06-08 21:51:11 UTC (rev 3663)
@@ -0,0 +1,39 @@
+#' Hill Estimator
+#'
+#' Estimates the value of the Hill Estimator for a given specified data set and
+#' chosen tail size. Notes: 1) We estimate Hill Estimator by looking at the
+#' upper tail. 2) If the specified tail size is such that any included
+#' observations are negative, the tail is truncated at the point before
+#' observations become negative. 3) The tail size must be a scalar.
+#'
+#' @param Ra Data set
+#' @param tail.size Number of observations to be used to estimate the Hill
+#' estimator.
+#' @param cl ES confidence level
+#' @return Estimated value of Hill Estimator
+#'
+#' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
+#'
+#' @author Dinesh Acharya
+#' @examples
+#'
+#' # Estimates Hill Estimator of
+#' Ra <- rnorm(15)
+#' HillEstimator(Ra, 10)
+#'
+#' @export
+HillEstimator <- function(Ra, tail.size){
+
+ data <- as.vector(Ra)
+ n <- length(data)
+ i <- which(data <= 0)
+ i <- max(i)
+ k <- min(tail.size, n - i)
+ logsum <- 0
+ for (i in 2:k){
+ logsum <- logsum + log(data[n - 1])
+ }
+ y <- logsum / (k - 1) - log(data[n - k - 1])
+ return(y)
+
+}
\ No newline at end of file
Added: pkg/Dowd/R/HillPlot.R
===================================================================
--- pkg/Dowd/R/HillPlot.R (rev 0)
+++ pkg/Dowd/R/HillPlot.R 2015-06-08 21:51:11 UTC (rev 3663)
@@ -0,0 +1,40 @@
+#' Hill Plot
+#'
+#' Displays a plot of the Hill Estimator against tail sample size.
+#'
+#' @param Ra The data set
+#' @param maximum.tail.size maximum tail size and should be greater than a
+#' quarter of the sample size.
+#'
+#' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
+#'
+#'
+#' @author Dinesh Acharya
+#' @examples
+#'
+#' # Hill Estimator - Tail Sample Size Plot for random normal dataset
+#' Ra <- rnorm(1000)
+#' HillPlot(Ra, 180)
+#'
+#' @export
+HillPlot <- function(Ra, maximum.tail.size){
+
+ data <- as.vector(Ra)
+ data <- sort(data)
+ n <- length(data)
+ i <- which(data <= 0)
+ i <- max(i)
+ max.k <- min(maximum.tail.size, n - i)
+ he <- double(max.k)
+ # Derivation of Hill Estimators and tail size series
+ for (k in 2:max.k){
+ he[k] <- HillEstimator(data,k)
+ }
+ # Plot of Hill Estimator against tail size
+ j <- which(he != 0)
+ he <- he[j]
+ k <- 2:max.k
+ plot(k, he, type = "l", col="red", main = "Hill Estimator against Tail Size",
+ xlab="Number of observations in tail (k)", ylab = "Hill estimator")
+
+}
\ No newline at end of file
Added: pkg/Dowd/R/HillQuantileEstimator.R
===================================================================
--- pkg/Dowd/R/HillQuantileEstimator.R (rev 0)
+++ pkg/Dowd/R/HillQuantileEstimator.R 2015-06-08 21:51:11 UTC (rev 3663)
@@ -0,0 +1,35 @@
+#' Hill Quantile Estimator
+#'
+#' Estimates value of Hill Quantile Estimator for a specified data set, tail
+#' index, in-sample probability and confidence level.
+#'
+#' @param Ra A data set
+#' @param tail.index Assumed tail index
+#' @param in.sample.prob In-sample probability (used as basis for projection)
+#' @param cl Confidence level
+#' @return Value of Hill Quantile Estimator
+#'
+#' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
+#'
+#' Next reference
+#'
+#' @author Dinesh Acharya
+#' @examples
+#'
+#' # Computes estimates value of hill estimator for a specified data set
+#' Ra <- rnorm(1000)
+#' HillQuantileEstimator(Ra, 40, .5, .9)
+#'
+#' @export
+HillQuantileEstimator <- function(Ra, tail.index, in.sample.prob, cl){
+
+ data <- as.vector(Ra)
+ data <- sort(data)
+ n <- length(data)
+ a <- in.sample.prob * n
+ k <- ((a>=0)*floor(a)+(a<0)*ceiling(a))
+ p <- 1 - cl
+ y <- data[n - k] * (p * n / k) ^ (- tail.index)
+ return(y)
+
+}
\ No newline at end of file
Added: pkg/Dowd/R/PickandsEstimator.R
===================================================================
--- pkg/Dowd/R/PickandsEstimator.R (rev 0)
+++ pkg/Dowd/R/PickandsEstimator.R 2015-06-08 21:51:11 UTC (rev 3663)
@@ -0,0 +1,34 @@
+#' Pickands Estimator
+#'
+#' Estimates the Value of Pickands Estimator for a specified data set
+#' and chosen tail size. Notes: (1) We estimate the Pickands Estimator by
+#' looking at the upper tail. (2) The tail size must be less than one quarter
+#' of the total sample size. (3) The tail size must be a scalar.
+#'
+#' @param Ra A data set
+#' @param tail.size Number of observations to be used to estimate the Pickands
+#' estimator
+#' @return Value of Pickands estimator
+#'
+#' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
+#'
+#' @author Dinesh Acharya
+#' @examples
+#'
+#' # Computes estimated Pickands estimator for randomly generated data.
+#' Ra <- rnorm(1000)
+#' PickandsEstimator(Ra, 40)
+#'
+#' @export
+PickandsEstimator <- function (Ra, tail.size) {
+
+ data <- as.vector(Ra)
+ data <- sort(data)
+ n <- length(data)
+ k <- tail.size
+ num <- data[n - k] - data[n - 2 * k]
+ den <- data[n - 2 * k] - data[n - 4 * k]
+ y <- log(num / den) / log(2)
+ return(y)
+
+}
\ No newline at end of file
Added: pkg/Dowd/R/PickandsPlot.R
===================================================================
--- pkg/Dowd/R/PickandsPlot.R (rev 0)
+++ pkg/Dowd/R/PickandsPlot.R 2015-06-08 21:51:11 UTC (rev 3663)
@@ -0,0 +1,37 @@
+#' Pickand Estimator - Tail Sample Size Plot
+#'
+#' Displays a plot of the Pickands Estimator against Tail Sample Size.
+#'
+#' @param Ra The data set
+#' @param maximum.tail.size maximum tail size and should be greater than a
+#' quarter of the sample size.
+#'
+#' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
+#'
+#'
+#' @author Dinesh Acharya
+#' @examples
+#'
+#' # Pickand - Sample Tail Size Plot for random standard normal data
+#' Ra <- rnorm(1000)
+#' PickandsPlot(Ra, 40)
+#'
+#'
+#' @export
+PickandsPlot <- function(Ra, maximum.tail.size){
+
+ data <- as.vector(Ra)
+ x <- sort(data)
+ n <- length(x)
+ # Derivation of Pickands estimators and tail size series
+ pe <- double(maximum.tail.size)
+ for(k in 2:maximum.tail.size){
+ pe[k] <- PickandsEstimator(x, k)
+ }
+ # Plot of Pickands Estimator against tail size
+ k <- 1:maximum.tail.size
+ plot(k, pe, type="l", main = "Pickands Estimator against Tail Size",
+ xlab = "Number of observations in tail (k)",
+ ylab = "Pickands Estimator")
+
+}
\ No newline at end of file
Added: pkg/Dowd/man/HillEstimator.Rd
===================================================================
--- pkg/Dowd/man/HillEstimator.Rd (rev 0)
+++ pkg/Dowd/man/HillEstimator.Rd 2015-06-08 21:51:11 UTC (rev 3663)
@@ -0,0 +1,38 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/HillEstimator.R
+\name{HillEstimator}
+\alias{HillEstimator}
+\title{Hill Estimator}
+\usage{
+HillEstimator(Ra, tail.size)
+}
+\arguments{
+\item{Ra}{Data set}
+
+\item{tail.size}{Number of observations to be used to estimate the Hill
+estimator.}
+
+\item{cl}{ES confidence level}
+}
+\value{
+Estimated value of Hill Estimator
+}
+\description{
+Estimates the value of the Hill Estimator for a given specified data set and
+chosen tail size. Notes: 1) We estimate Hill Estimator by looking at the
+upper tail. 2) If the specified tail size is such that any included
+observations are negative, the tail is truncated at the point before
+observations become negative. 3) The tail size must be a scalar.
+}
+\examples{
+# Estimates Hill Estimator of
+ Ra <- rnorm(15)
+ HillEstimator(Ra, 10)
+}
+\author{
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measuring Market Risk, Wiley, 2007.
+}
+
Added: pkg/Dowd/man/HillPlot.Rd
===================================================================
--- pkg/Dowd/man/HillPlot.Rd (rev 0)
+++ pkg/Dowd/man/HillPlot.Rd 2015-06-08 21:51:11 UTC (rev 3663)
@@ -0,0 +1,29 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/HillPlot.R
+\name{HillPlot}
+\alias{HillPlot}
+\title{Hill Plot}
+\usage{
+HillPlot(Ra, maximum.tail.size)
+}
+\arguments{
+\item{Ra}{The data set}
+
+\item{maximum.tail.size}{maximum tail size and should be greater than a
+quarter of the sample size.}
+}
+\description{
+Displays a plot of the Hill Estimator against tail sample size.
+}
+\examples{
+# Hill Estimator - Tail Sample Size Plot for random normal dataset
+ Ra <- rnorm(1000)
+ HillPlot(Ra, 180)
+}
+\author{
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measuring Market Risk, Wiley, 2007.
+}
+
Added: pkg/Dowd/man/HillQuantileEstimator.Rd
===================================================================
--- pkg/Dowd/man/HillQuantileEstimator.Rd (rev 0)
+++ pkg/Dowd/man/HillQuantileEstimator.Rd 2015-06-08 21:51:11 UTC (rev 3663)
@@ -0,0 +1,38 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/HillQuantileEstimator.R
+\name{HillQuantileEstimator}
+\alias{HillQuantileEstimator}
+\title{Hill Quantile Estimator}
+\usage{
+HillQuantileEstimator(Ra, tail.index, in.sample.prob, cl)
+}
+\arguments{
+\item{Ra}{A data set}
+
+\item{tail.index}{Assumed tail index}
+
+\item{in.sample.prob}{In-sample probability (used as basis for projection)}
+
+\item{cl}{Confidence level}
+}
+\value{
+Value of Hill Quantile Estimator
+}
+\description{
+Estimates value of Hill Quantile Estimator for a specified data set, tail
+index, in-sample probability and confidence level.
+}
+\examples{
+# Computes estimates value of hill estimator for a specified data set
+ Ra <- rnorm(1000)
+ HillQuantileEstimator(Ra, 40, .5, .9)
+}
+\author{
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measuring Market Risk, Wiley, 2007.
+
+Next reference
+}
+
Added: pkg/Dowd/man/PickandsEstimator.Rd
===================================================================
--- pkg/Dowd/man/PickandsEstimator.Rd (rev 0)
+++ pkg/Dowd/man/PickandsEstimator.Rd 2015-06-08 21:51:11 UTC (rev 3663)
@@ -0,0 +1,35 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/PickandsEstimator.R
+\name{PickandsEstimator}
+\alias{PickandsEstimator}
+\title{Pickands Estimator}
+\usage{
+PickandsEstimator(Ra, tail.size)
+}
+\arguments{
+\item{Ra}{A data set}
+
+\item{tail.size}{Number of observations to be used to estimate the Pickands
+estimator}
+}
+\value{
+Value of Pickands estimator
+}
+\description{
+Estimates the Value of Pickands Estimator for a specified data set
+and chosen tail size. Notes: (1) We estimate the Pickands Estimator by
+looking at the upper tail. (2) The tail size must be less than one quarter
+of the total sample size. (3) The tail size must be a scalar.
+}
+\examples{
+# Computes estimated Pickands estimator for randomly generated data.
+ Ra <- rnorm(1000)
+ PickandsEstimator(Ra, 40)
+}
+\author{
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measuring Market Risk, Wiley, 2007.
+}
+
Added: pkg/Dowd/man/PickandsPlot.Rd
===================================================================
--- pkg/Dowd/man/PickandsPlot.Rd (rev 0)
+++ pkg/Dowd/man/PickandsPlot.Rd 2015-06-08 21:51:11 UTC (rev 3663)
@@ -0,0 +1,29 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/PickandsPlot.R
+\name{PickandsPlot}
+\alias{PickandsPlot}
+\title{Pickand Estimator - Tail Sample Size Plot}
+\usage{
+PickandsPlot(Ra, maximum.tail.size)
+}
+\arguments{
+\item{Ra}{The data set}
+
+\item{maximum.tail.size}{maximum tail size and should be greater than a
+quarter of the sample size.}
+}
+\description{
+Displays a plot of the Pickands Estimator against Tail Sample Size.
+}
+\examples{
+# Pickand - Sample Tail Size Plot for random standard normal data
+ Ra <- rnorm(1000)
+ PickandsPlot(Ra, 40)
+}
+\author{
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measuring Market Risk, Wiley, 2007.
+}
+
More information about the Returnanalytics-commits
mailing list