Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

interest

Interest & Time-Value Calculations

Financial functions for DeFi applications.

Functions

  • linear_interpolate - Interpolation between two values
  • exponential_growth - Growth with compound rate
  • decay - Exponential decay
  • compound - Compound interest with frequency
  • simple_interest - Simple interest calculation
  • continuous_compound - Continuous compounding (e^rt)
  • present_value - Discount future value
  • effective_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_interpolateLinear interpolation between two values. Returns start + (end - start) * t
exponential_growthCalculates exponential growth: initial × (1 + rate)^periods
decayCalculates exponential decay: initial × (1 - rate)^periods Requires rate < 1 for meaningful results.
compoundCalculates compound interest with specified frequency. Formula: principal × (1 + rate/n)^(n×t)…
simple_interestCalculates simple interest: principal × (1 + rate × time)
continuous_compoundCalculates continuously compounded interest: principal × e^(rate × time) The theoretical limit of compound interest as compounding frequency → ∞.
present_valueCalculates the present value of a future amount. Formula: FV / (1 + rate)^periods…
effective_annual_rateCalculates the effective annual rate (EAR) from a nominal rate. Formula: (1 + r/n)^n - 1…