pub fn apply_pct_change(value: Decimal, pct_change: Decimal) -> Decimal
Expand description
Apply Percentage Change
This function applies the percentage change to a given value and returns the new value.
§Arguments
value
- The initial value or starting pointpct_change
- The percentage change to apply
§Returns
- The new value after applying the percentage change.
§Formula
$$\mathrm{New\ Value} = |\mathrm{Value}| \times \% \Delta + \mathrm{Value}$$
Fluctuations between pos and neg values are handled properly by using the absolute value as derived by the proper percentage change formula.
The more common formula for applying the percentage change is:
$$\mathrm{New\ Value} = \mathrm{Value} \times (1 + \% \Delta)$$
However, this does not handle the cases where the value is negative and the percentage change is positive, its a simplification for when it can be assumed that the value is always positive.
For example, if EBITDA is -$1000 and EBITDA increased to -$500, the percentage change should/would be a pos. 50% but the latter formula would return -$1500 while the former would properly return -$500.
§Example
- Value of $1000, percentage change of 50%
use rust_finprim::rate::apply_pct_change;
use rust_decimal_macros::*;
let value = dec!(1000);
let pct_change = dec!(0.5); // 50%
let result = apply_pct_change(value, pct_change);