interest
Interest & Time-Value Calculations
Financial functions for DeFi applications.
Functions
linear_interpolate- Interpolation between two valuesexponential_growth- Growth with compound ratedecay- Exponential decaycompound- Compound interest with frequencysimple_interest- Simple interest calculationcontinuous_compound- Continuous compounding (e^rt)present_value- Discount future valueeffective_annual_rate- Convert nominal to effective rate
Example
use cairo_fp::f128::math::interest::{compound, simple_interest};
// $1000 at 10% for 1 year, compounded monthly
let principal = FixedTrait::new_unscaled(1000, false);
let rate = FixedTrait::new(1844674407370955162, false); // 0.1
let n = FixedTrait::new_unscaled(12, false);
let t = FixedTrait::ONE();
let result = compound(principal, rate, n, t); // ~$1104.71
Fully qualified path: cairo_fp::f128::math::interest
Free functions
| linear_interpolate | Linear interpolation between two values. Returns start + (end - start) * t… |
| exponential_growth | Calculates exponential growth: initial × (1 + rate)^periods |
| decay | Calculates exponential decay: initial × (1 - rate)^periods Requires rate < 1 for meaningful results. |
| compound | Calculates compound interest with specified frequency. Formula: principal × (1 + rate/n)^(n×t)… |
| simple_interest | Calculates simple interest: principal × (1 + rate × time) |
| continuous_compound | Calculates continuously compounded interest: principal × e^(rate × time) The theoretical limit of compound interest as compounding frequency → ∞. |
| present_value | Calculates the present value of a future amount. Formula: FV / (1 + rate)^periods… |
| effective_annual_rate | Calculates the effective annual rate (EAR) from a nominal rate. Formula: (1 + r/n)^n - 1… |