Skip to content

Commit

Permalink
[cran] [v.1.1.2-8] Fix Wmissing-template-arg-list-after-template-kw e…
Browse files Browse the repository at this point in the history
…rror (clang-19)
  • Loading branch information
vissarion committed Oct 7, 2024
1 parent 033d7b5 commit 920d5f8
Show file tree
Hide file tree
Showing 26 changed files with 152 additions and 148 deletions.
6 changes: 3 additions & 3 deletions R-proj/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ Description: Provides an R interface for 'volesti' C++ package. 'volesti' comput
for sampling, rounding and rotating polytopes. Moreover, 'volesti' provides algorithms for
estimating copulas useful in computational finance. Methods implemented in 'volesti' are described
in A. Chalkis and V. Fisikopoulos (2022) <doi:10.32614/RJ-2021-077> and references therein.
Version: 1.1.2-7
Date: 2023-10-18
Version: 1.1.2-8
Date: 2024-10-7
Maintainer: Vissarion Fisikopoulos <vissarion.fisikopoulos@gmail.com>
Depends: Rcpp (>= 0.12.17)
Imports: methods, stats
LinkingTo: Rcpp, RcppEigen, BH
Suggests: testthat
Encoding: UTF-8
RoxygenNote: 7.1.1
RoxygenNote: 7.2.1
BugReports: https://github.com/GeomScale/volesti/issues
8 changes: 4 additions & 4 deletions R-proj/R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ copula <- function(r1, r2 = NULL, sigma = NULL, m = NULL, n = NULL, seed = NULL)
#' The \eqn{d}-dimensional unit simplex is the set of points \eqn{\vec{x}\in \R^d}, s.t.: \eqn{\sum_i x_i\leq 1}, \eqn{x_i\geq 0}. The \eqn{d}-dimensional canonical simplex is the set of points \eqn{\vec{x}\in \R^d}, s.t.: \eqn{\sum_i x_i = 1}, \eqn{x_i\geq 0}.
#'
#' @param body A list to request exact uniform sampling from special well known convex bodies through the following input parameters:
#' \itemize{
#' \describe{
#' \item{\code{type} }{ A string that declares the type of the body for the exact sampling: a) \code{'unit_simplex'} for the unit simplex, b) \code{'canonical_simplex'} for the canonical simplex, c) \code{'hypersphere'} for the boundary of a hypersphere centered at the origin, d) \code{'ball'} for the interior of a hypersphere centered at the origin.}
#' \item{\code{dimension} }{ An integer that declares the dimension when exact sampling is enabled for a simplex or a hypersphere.}
#' \item{\code{radius} }{ The radius of the \eqn{d}-dimensional hypersphere. The default value is \eqn{1}.}
Expand Down Expand Up @@ -202,7 +202,7 @@ rounding <- function(P, settings = NULL, seed = NULL) {
#' @param P A convex polytope. It is an object from class (a) Hpolytope or (b) Vpolytope or (c) Zonotope or (d) VpolytopeIntersection.
#' @param n The number of points that the function is going to sample from the convex polytope.
#' @param random_walk Optional. A list that declares the random walk and some related parameters as follows:
#' \itemize{
#' \describe{
#' \item{\code{walk} }{ A string to declare the random walk: i) \code{'CDHR'} for Coordinate Directions Hit-and-Run, ii) \code{'RDHR'} for Random Directions Hit-and-Run, iii) \code{'BaW'} for Ball Walk, iv) \code{'BiW'} for Billiard walk, v) \code{'BCDHR'} boundary sampling by keeping the extreme points of CDHR or vi) \code{'BRDHR'} boundary sampling by keeping the extreme points of RDHR. The default walk is \code{'BiW'} for the uniform distribution or \code{'CDHR'} for the Gaussian distribution.}
#' \item{\code{walk_length} }{ The number of the steps per generated point for the random walk. The default value is 1.}
#' \item{\code{nburns} }{ The number of points to burn before start sampling.}
Expand All @@ -212,7 +212,7 @@ rounding <- function(P, settings = NULL, seed = NULL) {
#' \item{\code{seed} }{ A fixed seed for the number generator.}
#' }
#' @param distribution Optional. A list that declares the target density and some related parameters as follows:
#' \itemize{
#' \describe{
#' \item{\code{density} }{ A string: (a) \code{'uniform'} for the uniform distribution or b) \code{'gaussian'} for the multidimensional spherical distribution. The default target distribution is uniform.}
#' \item{\code{variance} }{ The variance of the multidimensional spherical gaussian. The default value is 1.}
#' \item{\code{mode} }{ A \eqn{d}-dimensional numerical vector that declares the mode of the Gaussian distribution. The default choice is the center of the as that one computed by the function \code{inner_ball()}.}
Expand Down Expand Up @@ -245,7 +245,7 @@ sample_points <- function(P, n, random_walk = NULL, distribution = NULL) {
#'
#' @param P A convex polytope. It is an object from class a) Hpolytope or b) Vpolytope or c) Zonotope or d) VpolytopeIntersection.
#' @param settings Optional. A list that declares which algorithm, random walk and values of parameters to use, as follows:
#' \itemize{
#' \describe{
#' \item{\code{algorithm} }{ A string to set the algorithm to use: a) \code{'CB'} for CB algorithm, b) \code{'SoB'} for SOB algorithm or b) \code{'CG'} for CG algorithm. The defalut algorithm is \code{'CB'}.}
#' \item{\code{error} }{ A numeric value to set the upper bound for the approximation error. The default value is \eqn{1} for SOB algorithm and \eqn{0.1} otherwise.}
#' \item{\code{random_walk} }{ A string that declares the random walk method: a) \code{'CDHR'} for Coordinate Directions Hit-and-Run, b) \code{'RDHR'} for Random Directions Hit-and-Run, c) \code{'BaW'} for Ball Walk, or \code{'BiW'} for Billiard walk. For CB and SOB algorithms the default walk is \code{'CDHR'} for H-polytopes and \code{'BiW'} for the other representations. For CG algorithm the default walk is \code{'CDHR'} for H-polytopes and \code{'RDHR'} for the other representations.}
Expand Down
40 changes: 20 additions & 20 deletions R-proj/R/compute_indicators.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#' Compute an indicator for each time period that describes the state of a market.
#'
#' Given a matrix that contains row-wise the assets' returns and a sliding window \code{win_length}, this function computes an approximation of the joint distribution (copula, e.g. see \url{https://en.wikipedia.org/wiki/Copula_(probability_theory)}) between portfolios' return and volatility in each time period defined by \code{win_len}.
#' For each copula it computes an indicator: If the indicator is large it corresponds to a crisis period and if it is small it corresponds to a normal period.
#' Given a matrix that contains row-wise the assets' returns and a sliding window \code{win_length}, this function computes an approximation of the joint distribution (copula, e.g. see \url{https://en.wikipedia.org/wiki/Copula_(probability_theory)}) between portfolios' return and volatility in each time period defined by \code{win_len}.
#' For each copula it computes an indicator: If the indicator is large it corresponds to a crisis period and if it is small it corresponds to a normal period.
#' In particular, the periods over which the indicator is greater than 1 for more than 60 consecutive sliding windows are warnings and for more than 100 are crisis. The sliding window is shifted by one day.
#'
#' @param returns A \eqn{d}-dimensional vector that describes the direction of the first family of parallel hyperplanes.
#' @param parameters A list to set a parameterization.
#' \itemize{
#' \item{win_length }{ The length of the sliding window. The default value is 60.}
#' \item{m } { The number of slices for the copula. The default value is 100.}
#' \item{n }{ The number of points to sample. The default value is \eqn{5\cdot 10^5}.}
#' \item{nwarning }{ The number of consecutive indicators larger than 1 required to declare a warning period. The default value is 60.}
#' \item{ncrisis }{ The number of consecutive indicators larger than 1 required to declare a crisis period. The default value is 100.}
#' \item{seed }{ A fixed seed for the number generator.}
#' \describe{
#' \item{win_length}{The length of the sliding window. The default value is 60.}
#' \item{m}{The number of slices for the copula. The default value is 100.}
#' \item{n}{The number of points to sample. The default value is \eqn{5\cdot 10^5}.}
#' \item{nwarning}{The number of consecutive indicators larger than 1 required to declare a warning period. The default value is 60.}
#' \item{ncrisis}{The number of consecutive indicators larger than 1 required to declare a crisis period. The default value is 100.}
#' \item{seed}{A fixed seed for the number generator.}
#' }
#'
#' @references \cite{L. Cales, A. Chalkis, I.Z. Emiris, V. Fisikopoulos,
#' \dQuote{Practical volume computation of structured convex bodies, and an application to modeling portfolio dependencies and financial crises,} \emph{Proc. of Symposium on Computational Geometry, Budapest, Hungary,} 2018.}
#'
#' @return A list that contains the indicators and the corresponding vector that label each time period with respect to the market state: a) normal, b) crisis, c) warning.
#'
#' @examples
#' @examples
#' # simple example on random asset returns
#' asset_returns = replicate(10, rnorm(14))
#' market_states_and_indicators = compute_indicators(asset_returns,
Expand All @@ -34,7 +34,7 @@
#' @importFrom "stats" "cov"
#' @importFrom "methods" "new"
compute_indicators <- function(returns, parameters = list("win_length" = 60, "m" = 100, "n" = 500000, "nwarning" = 60, "ncrisis" = 100)) {

win_length = 60
if (!is.null(parameters$win_length)) {
win_length = parameters$win_length
Expand All @@ -59,29 +59,29 @@ compute_indicators <- function(returns, parameters = list("win_length" = 60, "m"
if (!is.null(parameters$seed)) {
seed = parameters$seed
}

nrows = dim(returns)[1]
nassets = dim(returns)[2]
wl = win_length-1

indicators = c()
for (i in 1:(nrows-wl)) {

Win=i:(i+wl)
E = cov(returns[Win,])

compRet = rep(1,nassets)
for (j in 1:nassets) {
for (k in Win) {
compRet[j] = compRet[j] * (1 + returns[k, j])
}
compRet[j] = compRet[j] - 1
}

cop = copula(r1 = compRet, sigma = E, m = m, n = n, seed = seed)
blue_mass = 0
red_mass = 0

for (row in 1:m) {
for (col in 1:m) {
if (row-col<=0.2*m && row-col>=-0.2*m) {
Expand All @@ -105,7 +105,7 @@ compute_indicators <- function(returns, parameters = list("win_length" = 60, "m"
col = rep("normal", N)

for (i in 1:N) {

if(indicators[i]>1 && !set_index){
index = i
set_index = TRUE
Expand All @@ -127,7 +127,7 @@ compute_indicators <- function(returns, parameters = list("win_length" = 60, "m"
col[index:i] = "crisis"
}
}

return(list("indicators" = indicators, market_states = col))

}
22 changes: 11 additions & 11 deletions R-proj/R/gen_rand_hpoly.R
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#' Generator function for random H-polytopes
#'
#'
#' This function generates a \eqn{d}-dimensional polytope in H-representation with \eqn{m} facets. We pick \eqn{m} random hyperplanes tangent on the \eqn{d}-dimensional unit hypersphere as facets.
#'
#'
#' @param dimension The dimension of the convex polytope.
#' @param nfacets The number of the facets.
#' @param generator A list that could contain two elements.
#' \itemize{
#' \describe{
#' \item{constants }{ To declare how to set the constants \eqn{b_i} for each facets: (i) 'sphere', each hyperplane is tangent to the hypersphere of radius 10, (ii) 'uniform' for each \eqn{b_i} the generator picks a uniform number from \eqn{(0,1)}. The defalut value is 'sphere'.}
#' \item{seed }{ Optional. A fixed seed for the number generator.}
#' }
#'
#'
#' @return A polytope class representing a H-polytope.
#' @examples
#' @examples
#' # generate a 10-dimensional polytope with 50 facets
#' P = gen_rand_hpoly(10, 50)
#' @export
gen_rand_hpoly <- function(dimension, nfacets, generator = list('constants' = 'sphere')) {

seed = NULL
if (!is.null(generator$seed)) {
seed = generator$seed
}

if (is.null(generator$constants)) {
kind_gen = 6
} else if (generator$constants == 'sphere'){
Expand All @@ -32,14 +32,14 @@ gen_rand_hpoly <- function(dimension, nfacets, generator = list('constants' = 's
stop("Wrong generator!")
}
Vpoly_gen = FALSE

Mat = poly_gen(kind_gen, Vpoly_gen, FALSE, dimension, nfacets, seed)

# first column is the vector b
b = Mat[, 1]
Mat = Mat[, -c(1), drop = FALSE]

P = Hpolytope(A = Mat, b = b)

return(P)
}
20 changes: 10 additions & 10 deletions R-proj/R/gen_rand_vpoly.R
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#' Generator function for random V-polytopes
#'
#'
#' This function generates a \eqn{d}-dimensional polytope in V-representation with \eqn{m} vertices. We pick \eqn{m} random points from the boundary of the \eqn{d}-dimensional unit hypersphere as vertices.
#'
#'
#' @param dimension The dimension of the convex polytope.
#' @param nvertices The number of the vertices.
#' @param generator A list that could contain two elements.
#' \itemize{
#' \describe{
#' \item{body }{ the body that the generator samples uniformly the vertices from: (i) 'cube' or (ii) 'sphere', the default value is 'sphere'.}
#' \item{seed }{ Optional. A fixed seed for the number generator.}
#' }
#'
#'
#' @return A polytope class representing a V-polytope.
#' @examples
#' @examples
#' # generate a 10-dimensional polytope defined as the convex hull of 25 random vertices
#' P = gen_rand_vpoly(10, 25)
#' @export
gen_rand_vpoly <- function(dimension, nvertices, generator = list('body' = 'sphere')) {

seed = NULL
if (!is.null(generator$seed)) {
seed = generator$seed
}

if (is.null(generator$body)) {
kind_gen = 4
} else if (generator$body == 'cube'){
Expand All @@ -31,14 +31,14 @@ gen_rand_vpoly <- function(dimension, nvertices, generator = list('body' = 'sphe
} else {
stop("Wrong generator!")
}

Mat = poly_gen(kind_gen, TRUE, FALSE, dimension, nvertices, seed)

# first column is the vector b
b = Mat[, 1]
Mat = Mat[, -c(1), drop = FALSE]

P = Vpolytope(V = Mat)

return(P)
}
24 changes: 12 additions & 12 deletions R-proj/R/gen_rand_zonotope.R
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
#' Generator function for zonotopes
#'
#'
#' This function generates a random \eqn{d}-dimensional zonotope defined by the Minkowski sum of \eqn{m} \eqn{d}-dimensional segments.
#' The function considers \eqn{m} random directions in \eqn{R^d}. There are three strategies to pick the length of each segment: a) it is uniformly sampled from \eqn{[0,100]}, b) it is random from \eqn{\mathcal{N}(50,(50/3)^2)} truncated to \eqn{[0,100]}, c) it is random from \eqn{Exp(1/30)} truncated to \eqn{[0,100]}.
#'
#'
#' @param dimension The dimension of the zonotope.
#' @param nsegments The number of segments that generate the zonotope.
#' @param generator A list that could contain two elements.
#' \itemize{
#' \item{distribution }{ the distribution to pick the length of each segment from \eqn{[0,100]}: (i) 'uniform', (ii) 'gaussian' or (iii) 'exponential', the default value is 'uniform.}
#' \item {seed }{ Optional. A fixed seed for the number generator.}
#' \describe{
#' \item{distribution}{The distribution to pick the length of each segment from \eqn{[0,100]}: (i) 'uniform', (ii) 'gaussian' or (iii) 'exponential', the default value is 'uniform.}
#' \item{seed}{Optional. A fixed seed for the number generator.}
#' }
#'
#'
#' @return A polytope class representing a zonotope.
#'
#' @examples
#' @examples
#' # generate a 10-dimensional zonotope defined by the Minkowski sum of 20 segments
#' P = gen_rand_zonotope(10, 20)
#' @export
gen_rand_zonotope <- function(dimension, nsegments, generator = list('distribution' = 'uniform')) {

seed = NULL
if (!is.null(generator$seed)) {
seed = generator$seed
}

if (is.null(generator$distribution)) {
kind_gen = 1
} else if (generator$distribution == 'gaussian') {
Expand All @@ -35,13 +35,13 @@ gen_rand_zonotope <- function(dimension, nsegments, generator = list('distributi
} else {
stop("Wrong generator!")
}

Mat = poly_gen(kind_gen, FALSE, TRUE, dimension, nsegments, seed)

# first column is the vector b
b = Mat[, 1]
Mat = Mat[, -c(1), drop = FALSE]

P = Zonotope(G = Mat)

return(P)
Expand Down
Loading

0 comments on commit 920d5f8

Please sign in to comment.