R/RcppExports.R

Defines functions cpp_tier_dp cpp_ecl_paths cpp_cor_matrix cpp_concordance

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Concordance counts between a prediction and an outcome (internal)
#'
#' @param p,r Double vectors of equal length, finite (the caller drops
#'   non-finite pairs).
#' @return A named double vector: `cmd` (concordant minus discordant pairs),
#'   `pairs` (`n(n-1)/2`), `ties_p` and `ties_r` (pairs tied on `p` and on
#'   `r`). Counts are exact up to 2^53.
#' @keywords internal
#' @noRd
cpp_concordance <- function(p, r) {
    .Call(`_scorecraft_cpp_concordance`, p, r)
}

#' Correlation matrix of a list of numeric columns (internal)
#'
#' @param cols List of `p` double vectors of equal length `n`, no missing
#'   values.
#' @param spearman `TRUE` for Spearman (Pearson on mid-ranks), `FALSE` for
#'   Pearson.
#' @param nthreads Threads used to standardize the columns (OpenMP); the
#'   cross-product runs on the BLAS R is linked to.
#' @return A `p x p` matrix; rows and columns of a constant column are `NA`
#'   (the diagonal included).
#' @keywords internal
#' @noRd
cpp_cor_matrix <- function(cols, spearman, nthreads) {
    .Call(`_scorecraft_cpp_cor_matrix`, cols, spearman, nthreads)
}

#' Expected credit loss paths of one scenario (internal)
#'
#' @param h Marginal monthly default hazards (scalar, length `n` or `n x H`).
#' @param L,E LGD and EAD, same shapes.
#' @param P Prepayment hazard (same shapes) or `NULL`.
#' @param r Annual effective interest rate, scalar or length `n`.
#' @param n,H,hz Rows, months in the lifetime, months in the 12-month figure.
#' @param discount Discount at `r` with monthly compounding.
#' @param stage3 Logical of length `n`: credit-impaired rows carry
#'   `LGD_1 * EAD_1`.
#' @param z,pd_mult,lgd_add,ead_mult Scenario shocks, each `NULL`, a scalar or
#'   length `n`.
#' @param rho Asset correlation of the one-factor shock.
#' @param nthreads OpenMP threads over rows.
#' @return A list with `ecl_12m`, `ecl_life` (scenario) and `pd_12m`,
#'   `pd_life` (cumulative PD of the unshocked hazards).
#' @keywords internal
#' @noRd
cpp_ecl_paths <- function(h, L, E, P, r, n, H, hz, discount, stage3, z, pd_mult, lgd_add, ead_mult, rho, nthreads) {
    .Call(`_scorecraft_cpp_ecl_paths`, h, L, E, P, r, n, H, hz, discount, stage3, z, pd_mult, lgd_add, ead_mult, rho, nthreads)
}

#' Optimal tier segmentation over ordered blocks (internal)
#'
#' @param e,n Weighted events and weighted volume with a known outcome per
#'   block (the objective).
#' @param vol Weighted volume per block (the share constraint).
#' @param e_raw,n_raw Unweighted events and rows with a known outcome per
#'   block (the event constraints and the Fisher exact test).
#' @param L Number of segments.
#' @param criterion 0 for the binomial log-likelihood, 1 for the
#'   information value.
#' @param min_share,min_events,alpha The constraints.
#' @return A list: `feasible`, `ends` (1-based end block of every segment,
#'   empty when infeasible) and `objective`.
#' @keywords internal
#' @noRd
cpp_tier_dp <- function(e, n, vol, e_raw, n_raw, L, criterion, min_share, min_events, alpha) {
    .Call(`_scorecraft_cpp_tier_dp`, e, n, vol, e_raw, n_raw, L, criterion, min_share, min_events, alpha)
}

Try the scorecraft package in your browser

Any scripts or data that you put into this service are public.

scorecraft documentation built on Dec. 6, 2026, 1:09 a.m.