calc_eir
1. Description
The calc_eir function calculates the Effective Interest Rate (EIR) based on a series of cashflows and their corresponding dates. The EIR represents the discount rate that equates the net present value (NPV) of cashflows to the carrying balance of an account. It relies on iterative numerical methods to approximate the result.
2 Input
# | Parameters | DataType | Description |
---|---|---|---|
1 | T | Generic | The generic parameter for TimeZone is used. |
2 | _account_number | String | account number for which the EIR is being calculated. |
3 | cashflows | Vec of Cashflow | A vector of struct of Cashflows for the account |
4 | carrying_balance | f64 | The outstanding balance of the account on the carrying date. |
5 | carrying_date | NaiveDate | The date when the carrying balance is measured. |
2.1 Cashflow struct
# | Field | DataType |
---|---|---|
1 | interest_amount | f64 |
2 | principal_amount | f64 |
3 | date | i64(timestamp) |
4 | unknown_fields: | ::protobuf::UnknownFields |
5 | cached_size: | ::protobuf::CachedSize |
3. Output
This function returns Result: Ok(f64): The calculated EIR as a decimal (e.g., 0.05 for 5%) or Err(&'static str): An error message if the calculation fails.