Crate br_financial

Crate br_financial 

Source
Expand description

br_financial is a Rust library for calculating real estate financing in Brazil.

It provides tools to calculate and compare financing scenarios using the two main amortization systems in Brazil:

  • SAC (Sistema de Amortização Constante): Characterized by fixed amortization payments, leading to decreasing total payments over time.
  • Price (Sistema Francês de Amortização): Characterized by fixed total payments throughout the financing period.

§Usage

Add br_financial to your Cargo.toml:

[dependencies]
br_financial = "0.1.0"
rust_decimal = "1.39.0"
rust_decimal_macros = "1.39.0"

Then, use the calculate_debt_trajectory function to get the results for both SAC and Price tables:

use br_financial::{calculate_debt_trajectory, DebtCalculationInput};
use rust_decimal_macros::dec;

fn main() {
    let input = DebtCalculationInput {
        total_amount: dec!(360_000),
        interest_per_year: dec!(10.5),
        down_payment_percent: dec!(0),
        total_months: 420,
    };

    match calculate_debt_trajectory(input) {
        Ok(result) => {
            println!("SAC First Payment: {:.2}", result.sac_table.first_payment);
            println!("SAC Last Payment:  {:.2}", result.sac_table.last_payment);
            println!("SAC Total Paid:    {:.2}", result.sac_table.total_paid);

            println!("Price Fixed Payment: {:.2}", result.price_table.fixed_payment);
            println!("Price Total Paid:    {:.2}", result.price_table.total_paid);
        }
        Err(e) => {
            eprintln!("Error calculating debt trajectory: {}", e);
        }
    }
}

Structs§

DebtCalculationInput
Input parameters for debt trajectory calculation.
DebtTrajectoryResult
Contains the comprehensive results for both Price and SAC table calculations.
MonthPayment
Represents the payment details for a single month.
PriceTableResult
Contains the results of a financing calculation using the Price table method.
SacTableResult
Contains the results of a financing calculation using the SAC method.

Functions§

calculate_debt_trajectory
Calculates and compares the debt trajectory for both Price and SAC amortization systems.
calculate_price_table
Calculates the financing trajectory using the Price table (fixed payments).
calculate_sac_table
Calculates the financing trajectory using the SAC (Constant Amortization System).
clean_down_payment
Calculates the down payment amount based on a total amount and a percentage.
normalize_annual_interest_rate
Normalizes an annual interest rate percentage to a monthly decimal factor.