Ajout de plusieurs fonctions

This commit is contained in:
François Pelletier 2014-01-04 17:32:36 -05:00
parent bdf752111e
commit 473c634d72
11 changed files with 422 additions and 1 deletions

103
R/cmGAL.R Normal file
View file

@ -0,0 +1,103 @@
# Centered moments of the GAL distribution
# Skewness and (adjusted) kurtosis of the GAL distribution
#
# Author: Francois Pelletier
#
# LGPL 3.0
###############################################################################
#' Centered moments of the GAL distribution
#' @param order Order of raw moment
#' @param param Parameter vector
#' @param type Choose between "mu" or "kappa" parametrization
#' @param log Logical for log-parameters
#' @return A numeric value of the centered moment
#'
#' @author Francois Pelletier
cmGAL <- function(order,param,type="mu",log=FALSE)
{
testparGAL(param,type,log)
if(log)
{
cmGAL(order,exp(param),type,log=FALSE)
}
else
{
if(type=="mu")
{
if(order==2)
{
param[4]*param[2]^2+param[4]*param[3]^2
}
if(order==3)
{
3*param[3]*param[4]*param[2]^2+2*param[3]^3*param[4]
}
if(order==4)
{
(3*param[4]^2+3*param[4])*param[2]^4+(6*param[3]^2*param[4]^2+12*param[3]^2*param[4])*param[2]^2+3*param[3]^4*param[4]^2+6*param[3]^4*param[4]
}
else
stop("order must be 2,3 or 4")
}
if(type=="kappa")
{
if(order==2)
{
(1/2)*param[4]*param[2]^2*(param[3]^4+1)/param[3]^2
}
if(order==3)
{
(1/2)*param[4]*param[2]^3*sqrt(2)*(1-param[3]^6)/param[3]^3
}
if(order==4)
{
(3/4)*param[4]*((param[4]+2)*param[3]^8+2*param[4]*param[3]^4+param[4]+2)*param[2]^4/param[3]^4
}
else
stop("order must be 2,3 or 4")
}
}
}
#' Skewness of the GAL distribution
#' @param param Parameter vector
#' @param type Choose between "mu" or "kappa" parametrization
#' @param log Logical for log-parameters
#' @return A numeric value of the skewness
#'
#' @author Francois Pelletier
skewnessGAL <- function(param,type="mu",log=FALSE)
{
testparGAL(param,type,log)
if(log)
{
skewnessGAL(exp(param),type,log=FALSE)
}
else
{
cmGAL(3,param,type) / (cmGAL(2,param,type)^(3/2))
}
}
#' (Adjusted) kurtosis of the GAL distribution
#' @param param Parameter vector
#' @param type Choose between "mu" or "kappa" parametrization
#' @param log Logical for log-parameters
#' @param adjust Logical to use the adjusted kurtosis
#' @return A numeric value of the kurtosis
#'
#' @author Francois Pelletier
kurtosisGAL <- function(param,type="mu",log=FALSE,adjust=TRUE)
{
testparGAL(param,type,log)
if(log)
{
kurtosisGAL(exp(param),type,log=FALSE)
}
else
{
cmGAL(4,param,type) / (cmGAL(2,param,type)^2) - 3*adjust
}
}

View file

@ -1,4 +1,5 @@
# Moment generating function of GAL distribution
# Cumulant generating function of GAL distribution
#
# Author: Francois Pelletier
#
@ -38,4 +39,39 @@ mgfGAL <- function(u,param,type="mu",log=FALSE)
exp(param[1]*u)*((param[2]^2*u^2)/2+(param[3]*param[2]*u)/sqrt(2)-(param[2]*u)/(sqrt(2)*param[3])+1)^(-param[4])
}
}
}
#' Cumulant generating function of GAL distribution
#' @param u Transform variate
#' @param param Parameter vector
#' @param type Choose between "mu" or "kappa" parametrization
#' @param log Logical for log-parameters
#' @return Cumulant generating function value at point u for given parameter vector
#'
#' @author Francois Pelletier
cgfGAL <- function(u,param,type="mu",log=FALSE)
{
testparGAL(param,type,log)
if(log)
{
if(type=="mu")
{
log(exp(exp(param[1])*u)*(1-(1/2)*exp(param[2])^2*u^2-exp(param[3])*u)^(-exp(param[4])))
}
if(type=="kappa")
{
log(exp(exp(param[1])*u)*((exp(param[2])^2*u^2)/2+(exp(param[3])*exp(param[2])*u)/sqrt(2)-(exp(param[2])*u)/(sqrt(2)*exp(param[3]))+1)^(-exp(param[4])))
}
}
else
{
if(type=="mu")
{
log(exp(param[1]*u)*(1-(1/2)*param[2]^2*u^2-param[3]*u)^(-param[4]))
}
if(type=="kappa")
{
log(exp(param[1]*u)*((param[2]^2*u^2)/2+(param[3]*param[2]*u)/sqrt(2)-(param[2]*u)/(sqrt(2)*param[3])+1)^(-param[4]))
}
}
}

91
R/mGAL.R Normal file
View file

@ -0,0 +1,91 @@
# Raw moments of the GAL distribution
#
# Author: Francois Pelletier
#
# LGPL 3.0
###############################################################################
#' Raw moments of the GAL distribution
#' @param order Order of raw moment
#' @param param Parameter vector
#' @param type Choose between "mu" or "kappa" parametrization
#' @param log Logical for log-parameters
#' @return A numeric value of the raw moment
#'
#' @author Francois Pelletier
mGAL <- function(order,param,type="mu",log=FALSE)
{
testparGAL(param,type,log)
if(log)
{
mGAL(order,exp(param),type,log=FALSE)
}
else
{
if(type=="mu")
{
if(order==1)
{
param[1]+param[4]*param[3]
}
if(order==2)
{
param[1]^2+2*param[1]*param[4]*param[3]+param[4]^2*param[3]^2+
param[4]*param[2]^2+param[4]*param[3]^2
}
if(order==3)
{
3*param[1]*param[4]*param[2]^2+3*param[1]^2*param[4]*param[3]+
3*param[1]*param[4]^2*param[3]^2+param[1]^3+
3*param[1]*param[4]*param[3]^2+param[4]^3*param[3]^3+
3*param[4]^2*param[3]*param[2]^2+3*param[4]^2*param[3]^3+
3*param[4]*param[2]^2*param[3]+2*param[4]*param[3]^3
}
if(order==4)
{
6*param[1]^2*param[4]*param[3]^2+18*param[4]^2*param[3]^2*param[2]^2+
12*param[4]*param[2]^2*param[3]^2+
12*param[1]*param[4]*param[2]^2*param[3]+4*param[1]^3*param[4]*param[3]+
8*param[1]*param[4]*param[3]^3+12*param[1]*param[4]^2*param[3]*param[2]^2+
6*param[1]^2*param[4]^2*param[3]^2+param[1]^4+
6*param[1]^2*param[4]*param[2]^2+param[4]^4*param[3]^4+
6*param[4]^3*param[3]^2*param[2]^2+6*param[4]^3*param[3]^4+
3*param[4]^2*param[2]^4+11*param[4]^2*param[3]^4+
3*param[4]*param[2]^4+6*param[4]*param[3]^4+
12*param[1]*param[4]^2*param[3]^3+4*param[1]*param[4]^3*param[3]^3
}
else
stop("order must be 1,2,3 or 4")
}
if(type=="kappa")
{
if(order==1)
{
(1/2)*(param[4]*param[2]*sqrt(2)-param[4]*param[2]*sqrt(2)*param[2]^2+2*param[1]*param[2])/param[2]
}
if(order==2)
{
(1/2)*(-2*param[1]*param[4]*param[2]*(param[2]+1)*(param[2]-1)*param[2]*sqrt(2)+
param[4]*param[2]^2*(param[4]+1)*param[2]^4+(-2*param[4]^2*param[2]^2+2*param[1]^2)*param[2]^2+
param[4]*param[2]^2*(param[4]+1))/param[2]^2
}
if(order==3)
{
(1/4)*(-(param[2]-1)*param[4]*param[2]*(param[2]+1)*(((-2*param[2]^2+1+param[2]^4)*param[4]+
2*param[2]^2+2*param[2]^4+2)*(param[4]+1)*param[2]^2+
6*param[1]^2*param[2]^2)*sqrt(2)+(6*(param[4]*((-2*param[2]^2+1+param[2]^4)*param[4]+
param[2]^4+1)*param[2]^2+(2/3)*param[1]^2*param[2]^2))*
param[2]*param[1])/param[2]^3
}
if(order==4)
{
1/4*(4*param[1]^4*param[2]^4+param[4]^4*param[2]^4+6*param[4]^3*param[2]^4+11*param[4]^2*param[2]^4+6*param[4]*param[2]^4-24*param[4]^2*param[2]^4*param[1]^2*param[2]^2+12*param[4]^2*param[2]^2*param[1]^2*param[2]^2+12*param[4]^2*param[2]^6*param[1]^2*param[2]^2+12*param[4]*param[2]^6*param[1]^2*param[2]^2-4*param[4]^4*param[2]^4*param[2]^2+6*param[4]^4*param[2]^4*param[2]^4-4*param[4]^4*param[2]^4*param[2]^6+param[4]^4*param[2]^4*param[2]^8-12*param[4]^3*param[2]^4*param[2]^2+12*param[4]^3*param[2]^4*param[2]^4-12*param[4]^3*param[2]^4*param[2]^6+6*param[4]^3*param[2]^4*param[2]^8+11*param[4]^2*param[2]^4*param[2]^8-8*param[4]^2*param[2]^4*param[2]^2+6*param[4]^2*param[2]^4*param[2]^4-8*param[4]^2*param[2]^4*param[2]^6+6*param[4]*param[2]^4*param[2]^8+12*param[4]*param[2]^2*param[1]^2*param[2]^2-12*param[4]^3*param[2]^3*param[2]^3*param[1]*2^(1/2)+4*param[4]^3*param[2]^3*param[2]*param[1]*2^(1/2)+12*param[4]^2*param[2]^3*param[2]*param[1]*2^(1/2)+12*param[4]^3*param[2]^3*param[2]^5*param[1]*2^(1/2)+12*param[4]^2*param[2]^3*param[2]^5*param[1]*2^(1/2)+8*param[4]*param[2]^3*param[2]*param[1]*2^(1/2)+8*param[4]*param[2]*param[2]^3*param[1]^3*2^(1/2)-12*param[4]^2*param[2]^3*param[2]^3*param[1]*2^(1/2)-4*param[4]^3*param[2]^3*param[2]^7*param[1]*2^(1/2)-12*param[4]^2*param[2]^3*param[2]^7*param[1]*2^(1/2)-8*param[4]*param[2]^3*param[2]^7*param[1]*2^(1/2)-8*param[4]*param[2]*param[2]^5*param[1]^3*2^(1/2))/param[2]^4
}
else
stop("order must be 1,2,3 or 4")
}
}
}

36
R/riskneutralparGAL.R Normal file
View file

@ -0,0 +1,36 @@
# Risk neutral conversion of parameters of GAL distirbution
#
# Author: Francois Pelletier
#
# LGPL 3.0
###############################################################################
#' Risk neutral conversion of parameters of GAL distirbution
#' @param param Parameter vector
#' @param riskfree Risk-free rate
#' @param type Choose between "mu" or "kappa" parametrization
#' @param log Logical for log-parameters
#' @return Risk neutral parameter vector
#'
#' @author Francois Pelletier
riskneutralparGAL <- function(param,riskfree,type="mu",log=FALSE)
{
testparGAL(param,type,log)
if(type=="kappa")
{
riskneutralparGAL(changetypeGAL(param,type="kappa",target="mu"),riskfree,type="mu",log)
}
if(type=="mu")
{
if(log)
{
c(log(riskfree+log(1-exp(param[3])-exp(param[2])^2/2)*param[4]),param[2],param[3],param[4])
}
else
{
c(riskfree+log(1-param[3]-param[2]^2/2)*param[4],param[2],param[3],param[4])
}
}
}

View file

@ -9,7 +9,7 @@
#' Check for the validity of a parameter vector. Stop at error.
#' @param param Parameter vector
#' @param type Choose between "mu" or "kappa" parametrization
#' @param log Logical for log-parameters
#' @param log Logical for log-parameters
#' @return logical
#'
#' @author Francois Pelletier

27
man/cgfGAL.Rd Normal file
View file

@ -0,0 +1,27 @@
\name{cgfGAL}
\alias{cgfGAL}
\title{Cumulant generating function of GAL distribution}
\usage{
cgfGAL(u, param, type = "mu", log = FALSE)
}
\arguments{
\item{u}{Transform variate}
\item{param}{Parameter vector}
\item{type}{Choose between "mu" or "kappa"
parametrization}
\item{log}{Logical for log-parameters}
}
\value{
Cumulant generating function value at point u for given
parameter vector
}
\description{
Cumulant generating function of GAL distribution
}
\author{
Francois Pelletier
}

26
man/cmGAL.Rd Normal file
View file

@ -0,0 +1,26 @@
\name{cmGAL}
\alias{cmGAL}
\title{Centered moments of the GAL distribution}
\usage{
cmGAL(order, param, type = "mu", log = FALSE)
}
\arguments{
\item{order}{Order of raw moment}
\item{param}{Parameter vector}
\item{type}{Choose between "mu" or "kappa"
parametrization}
\item{log}{Logical for log-parameters}
}
\value{
A numeric value of the centered moment
}
\description{
Centered moments of the GAL distribution
}
\author{
Francois Pelletier
}

26
man/kurtosisGAL.Rd Normal file
View file

@ -0,0 +1,26 @@
\name{kurtosisGAL}
\alias{kurtosisGAL}
\title{(Adjusted) kurtosis of the GAL distribution}
\usage{
kurtosisGAL(param, type = "mu", log = FALSE, adjust = TRUE)
}
\arguments{
\item{param}{Parameter vector}
\item{type}{Choose between "mu" or "kappa"
parametrization}
\item{log}{Logical for log-parameters}
\item{adjust}{Logical to use the adjusted kurtosis}
}
\value{
A numeric value of the kurtosis
}
\description{
(Adjusted) kurtosis of the GAL distribution
}
\author{
Francois Pelletier
}

26
man/mGAL.Rd Normal file
View file

@ -0,0 +1,26 @@
\name{mGAL}
\alias{mGAL}
\title{Raw moments of the GAL distribution}
\usage{
mGAL(order, param, type = "mu", log = FALSE)
}
\arguments{
\item{order}{Order of raw moment}
\item{param}{Parameter vector}
\item{type}{Choose between "mu" or "kappa"
parametrization}
\item{log}{Logical for log-parameters}
}
\value{
A numeric value of the raw moment
}
\description{
Raw moments of the GAL distribution
}
\author{
Francois Pelletier
}

26
man/riskneutralparGAL.Rd Normal file
View file

@ -0,0 +1,26 @@
\name{riskneutralparGAL}
\alias{riskneutralparGAL}
\title{Risk neutral conversion of parameters of GAL distirbution}
\usage{
riskneutralparGAL(param, riskfree, type = "mu", log = FALSE)
}
\arguments{
\item{param}{Parameter vector}
\item{riskfree}{Risk-free rate}
\item{type}{Choose between "mu" or "kappa"
parametrization}
\item{log}{Logical for log-parameters}
}
\value{
Risk neutral parameter vector
}
\description{
Risk neutral conversion of parameters of GAL distirbution
}
\author{
Francois Pelletier
}

24
man/skewnessGAL.Rd Normal file
View file

@ -0,0 +1,24 @@
\name{skewnessGAL}
\alias{skewnessGAL}
\title{Skewness of the GAL distribution}
\usage{
skewnessGAL(param, type = "mu", log = FALSE)
}
\arguments{
\item{param}{Parameter vector}
\item{type}{Choose between "mu" or "kappa"
parametrization}
\item{log}{Logical for log-parameters}
}
\value{
A numeric value of the skewness
}
\description{
Skewness of the GAL distribution
}
\author{
Francois Pelletier
}