You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#' Rescale min-max scaling output between two numbers.
131
+
#' Rescale a vector using either min-max scaling or risk-neutral adjustment.
132
132
#'
133
-
#' @param x vector of data.
134
-
#' @param a numeric; lower limit.
135
-
#' @param b numeric; upper limit.
136
-
#' @return Returns a rescaled distribution within provided limits.
133
+
#' @param x numeric vector; data to rescale (e.g., terminal prices for risk-neutral method).
134
+
#' @param a numeric; defines the scaling target:
135
+
#' - For \code{method = "minmax"}: the lower limit of the output range (e.g., 5 to scale to [5, b]).
136
+
#' - For \code{method = "riskneutral"}: the initial price \( S_0 \) (must be positive, e.g., 100), used to set the target mean.
137
+
#' @param b numeric; defines the scaling range or rate:
138
+
#' - For \code{method = "minmax"}: the upper limit of the output range (e.g., 10 to scale to [a, 10]).
139
+
#' - For \code{method = "riskneutral"}: the risk-free rate \( r \) (e.g., 0.05), used with \( T \) to adjust the mean.
140
+
#' @param method character; scaling method: \code{"minmax"} (default) for min-max scaling, or \code{"riskneutral"} for risk-neutral adjustment.
141
+
#' @param T numeric; time to maturity in years (required for \code{method = "riskneutral"}, ignored otherwise; e.g., 1). Default is NULL.
142
+
#' @param type character; for \code{method = "riskneutral"}: \code{"Terminal"} (default, mean = \( S_0 e^{r T} \)) or \code{"Discounted"} (mean = \( S_0 \)).
143
+
#' @return Returns a rescaled distribution:
144
+
#' - For \code{"minmax"}: values scaled linearly to the range \code{[a, b]}.
145
+
#' - For \code{"riskneutral"}: values scaled multiplicatively to a risk-neutral mean (\( S_0 e^{r T} \) if \code{type = "Terminal"}, or \( S_0 \) if \code{type = "Discounted"}).
137
146
#' @author Fred Viole, OVVO Financial Systems
138
147
#' @examples
139
148
#' \dontrun{
140
149
#' set.seed(123)
150
+
#' # Min-max scaling: a = lower limit, b = upper limit
141
151
#' x <- rnorm(100)
142
-
#' NNS.rescale(x, 5, 10)
152
+
#' NNS.rescale(x, a = 5, b = 10, method = "minmax") # Scales to [5, 10]
153
+
#'
154
+
#' # Risk-neutral scaling (Terminal): a = S_0, b = r # Mean ≈ 105.13
0 commit comments