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§
- Debt
Calculation Input - Input parameters for debt trajectory calculation.
- Debt
Trajectory Result - Contains the comprehensive results for both Price and SAC table calculations.
- Month
Payment - Represents the payment details for a single month.
- Price
Table Result - Contains the results of a financing calculation using the Price table method.
- SacTable
Result - 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.