The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
This package provides an implementation of the elastic net penalty for Gamma and exponentially distributed response variables.
You can install the stable version on R CRAN.
install.packages("RPEGLMEN", dependencies = TRUE)
You can install the development version from GitHub.
library(devtools)
::install_github("AnthonyChristidis/RPEGLMEN") devtools
This package is designed to provide the user to fit an Exponential or Gamma distribution to the response variable with an elastic net penalty on the predictors. This package is of particular use in combination with the RPEIF and RPESE packages, in which the influence function of a time series of returns is used to compute the standard error of a risk and performance measure. See Chen and Martin (2018) for more details.
For the computational details to fit a Gamma distribution on data with an elastic net penalty, see Chen, Arakvin and Martin (2018).
# Sample Code
# Load the package
library(RPEGLMEN)
# Function to return the periodogram of data series
<- function (data, max.freq = 0.5, twosided = FALSE, keep = 1){
myperiodogram <- fft(data)
data.fft <- length(data)
N <- Mod(data.fft[2:floor(N/2)])^2/N
tmp <- sapply(tmp, function(x) max(1e-05, x))
tmp <- ((1:(floor(N/2) - 1))/N)
freq <- tmp[1:floor(length(tmp) * keep)]
tmp <- freq[1:floor(length(freq) * keep)]
freq if (twosided) {
<- c(rev(tmp), tmp)
tmp <- c(-rev(freq), freq)
freq
}return(list(spec <- tmp, freq <- freq))
}
# Function to compute the standard error based the periodogram of the influence functions time series
<- function(data, d = 7, alpha = 0.5, keep = 1, exponential.dist = TRUE){
SE.Gamma <-length(data)
N# Compute the periodograms
<- myperiodogram(data)
my.periodogram <- my.periodogram$freq
my.freq <- my.periodogram$spec
my.periodogram # Remove values of frequency 0 as it does not contain information about the variance
<- my.freq[-1]
my.freq <- my.periodogram[-1]
my.periodogram # Implement cut-off
<- length(my.freq)
nfreq <- my.freq[1:floor(nfreq*keep)]
my.freq <- my.periodogram[1:floor(nfreq*keep)]
my.periodogram # GLM with BFGS optimization
# Create 1, x, x^2, ..., x^d
<- rep(1,length(my.freq))
x.mat for(col.iter in 1:d){
<- cbind(x.mat,my.freq^col.iter)
x.mat
}# Fit the Exponential or Gamma model
if(exponential.dist)
<- glmnet_exp(x.mat, my.periodogram, alpha.EN = alpha) else
res <- fit.glmGammaNet(x.mat, my.periodogram, alpha.EN = alpha)
res # Return the estimated variance
return(sqrt(exp(res[1])/N))
}
# Loading hedge fund data from PA
data(edhec, package <- "PerformanceAnalytics")
colnames(edhec)
# Computing the expected shortfall for the time series of returns
library(RPEIF)
<- apply(edhec, 2, IF.ES)
test.mat <- apply(test.mat, 2, as.numeric)
test.mat
# Returning the standard errors from the Exponential distribution fit
apply(test.mat, 2, SE.Gamma, exponential.dist = TRUE)
This package is free and open source software, licensed under GPL (>= 2).
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.