pub fn pct_change(
beginning_value: Decimal,
ending_value: Decimal,
) -> Option<Decimal>
Expand description
Percentage Change
The percentage change is a measure of the relative change in value between two points in time.
§Arguments
beginning_value
- The initial value or starting pointending_value
- The final value or ending point
§Returns
- The percentage change as an
Option
containing aDecimal
orNone
if there is a division by zero.
§Formula
$$\% \Delta = \frac{\mathrm{Ending\ Value} - \mathrm{Beginning\ Value}}{|\mathrm{Beginning\ Value}|}$$
§Example
- Beginning value of $1000, ending value of $1500
use rust_finprim::rate::pct_change;
use rust_decimal_macros::*;
let beginning_value = dec!(1000);
let ending_value = dec!(1500);
let result = pct_change(beginning_value, ending_value);