Function pct_change

Source
pub fn pct_change<T: FloatLike>(
    beginning_value: T,
    ending_value: T,
) -> Result<T, FinPrimError<T>>
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 point
  • ending_value - The final value or ending point

§Returns

  • The percentage change as a Result containing a FloatLike or DivideByZero error.

§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;

let beginning_value = 1000.0;
let ending_value = 1500.0;

let result = pct_change(beginning_value, ending_value);