Computes the annualized rate of change from paired start and end values over a given time interval, annualizing according to the specified unit.
Usage
annualize_change(
start_values,
end_values,
time_elapsed,
time_unit = c("daily", "weekly", "monthly", "quarterly", "annually"),
year_length = 365.2425
)
Arguments
- start_values
Numeric scalar or vector of positive start values.
- end_values
Numeric scalar or vector of positive end values. If any of
start_values
,end_values
, ortime_elapsed
is a scalar, it is recycled to the common length; otherwise, lengths must be compatible.- time_elapsed
Numeric scalar or vector of elapsed time in
time_unit
between start and end. If scalar, it is recycled.- time_unit
One of "daily", "weekly", "monthly", "quarterly", "annually".
- year_length
Days per year used when
time_unit
is "daily" (and to derive weeks/year whentime_unit
is "weekly"). Defaults to 365.2425 (Gregorian average year).
Examples
# Scalar (monthly): from 100 to 103 over 1 month -> annualized rate
annualize_change(100, 103, time_elapsed = 1, time_unit = "monthly")
#> [1] 0.4257609
# Vectorized (quarterly): scalar start recycled to match end/time vectors
annualize_change(
start_values = 100,
end_values = c(101, 98, 120),
time_elapsed = c(1, 2, 3),
time_unit = "quarterly"
)
#> [1] 0.04060401 -0.03960000 0.27519028
# Weekly with exact 52-week convention (52 * 7 = 364 days)
annualize_change(
start_values = 100,
end_values = 102,
time_elapsed = 4,
time_unit = "weekly",
year_length = 364
)
#> [1] 0.2936066