Skip to main content

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

#ParametersDataTypeDescription
1TGenericThe generic parameter for TimeZone is used.
2_account_numberStringaccount number for which the EIR is being calculated.
3cashflowsVec of CashflowA vector of struct of Cashflows for the account
4carrying_balancef64The outstanding balance of the account on the carrying date.
5carrying_dateNaiveDateThe date when the carrying balance is measured.

2.1 Cashflow struct

#FieldDataType
1interest_amountf64
2principal_amountf64
3datei64(timestamp)
4unknown_fields:::protobuf::UnknownFields
5cached_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.