Expand description
§br_financial
A Rust library for calculating real estate financing in Brazil.
§Amortization Systems
- SAC (Sistema de Amortização Constante): Fixed amortization payments with decreasing total payments over time.
- Price (Sistema Francês de Amortização): Fixed total payments throughout the financing period (PMT calculated once upfront).
§Additional Features
- Insurance: Monthly cost composed of a normalized rate applied to the
outstanding balance plus a fixed fee (
insurance_cost = balance * rate + fee). - Administration fee: Fixed monthly amount added to each installment.
- Monetary correction: Variable monthly rate applied to the current balance
before amortization. Rates are provided as a
BTreeMap<NaiveDate, Decimal>, looked up by the most recent issue date on or before the installment due date. - Date-based installments: Each payment has a due date computed from
start_date,due_day(1–28), and month offset. - Internationalization: Error messages localized via
rust-i18n(EN and PT-BR).
§Example
use std::collections::BTreeMap;
use br_financial::{calculate_debt_trajectory, DebtCalculationInput, DebtCalculationType, Locale};
use rust_decimal_macros::dec;
use chrono::NaiveDate;
let input = DebtCalculationInput {
total_amount: dec!(360_000),
interest_per_year: dec!(10.5),
down_payment_percent: dec!(5),
total_months: 420,
debt_type: DebtCalculationType::Sac,
insurance_rate: dec!(0.0003),
insurance_fee: dec!(25),
admin_fee: dec!(30),
due_day: 15,
start_date: NaiveDate::from_ymd_opt(2026, 1, 1).unwrap(),
monthly_correction_rates: BTreeMap::new(),
locale: Locale::En,
};
match calculate_debt_trajectory(input) {
Ok(result) => {
println!("Financed: {:.2}", result.financed_amount);
println!("Total Paid: {:.2}", result.table.total_paid);
println!("Total Insurance: {:.2}", result.table.total_insurance);
println!("Total Admin Fees: {:.2}", result.table.total_admin_fees);
println!("Total Monetary Correction: {:.2}", result.table.total_monetary_correction);
}
Err(e) => eprintln!("Error: {}", e),
}Re-exports§
pub use debt_calculator::DebtCalculationInput;pub use debt_calculator::DebtCalculationType;pub use debt_calculator::MonthPayment;pub use debt_calculator::TableResult;pub use debt_calculator::calculate_table;pub use locale::Locale;
Modules§
Structs§
- Debt
Trajectory Result - Contains the comprehensive results for a financing calculation.
Functions§
- calculate_
debt_ trajectory - Calculates the debt trajectory for the selected amortization system.