157 lines
5.1 KiB
TypeScript
157 lines
5.1 KiB
TypeScript
// ─── Property Type ───────────────────────────────────────────────────────────
|
|
|
|
export type PropertyType = 'neuf' | 'ancien';
|
|
|
|
// ─── Loan Input ──────────────────────────────────────────────────────────────
|
|
|
|
export interface LoanInput {
|
|
id: string;
|
|
name: string;
|
|
amount: number;
|
|
rate: number; // Annual rate as decimal (3.25% → 0.0325)
|
|
duration: number; // Years
|
|
deferral: number; // Deferred period in years
|
|
insuranceRate: number; // Annual rate on initial capital (0.3% → 0.003)
|
|
isMainLoan: boolean; // If true, amount = totalCredit - sum(others)
|
|
enabled: boolean;
|
|
}
|
|
|
|
// ─── Simulation State (all inputs) ──────────────────────────────────────────
|
|
|
|
export interface SimulationState {
|
|
// Project
|
|
propertyType: PropertyType;
|
|
propertyPrice: number;
|
|
notaryFeesRate: number;
|
|
guaranteeRate: number;
|
|
bankFees: number;
|
|
worksCost: number;
|
|
downPayment: number;
|
|
|
|
// Current costs (tenant)
|
|
currentRent: number;
|
|
rentEvolutionRate: number; // Annual evolution (1.2% → 0.012)
|
|
currentUtilities: number; // EDF / fibre / eau
|
|
currentCharges: number;
|
|
currentHomeInsurance: number;
|
|
|
|
// Projected costs (owner)
|
|
projectedCharges: number; // Copropriété
|
|
propertyTax: number; // Taxe foncière (monthly)
|
|
projectedUtilities: number; // EDF / fibre / eau
|
|
projectedHomeInsurance: number;
|
|
|
|
// Loans
|
|
loans: LoanInput[];
|
|
|
|
// Resale parameters
|
|
firstYearDepreciation: number; // e.g., -0.05 (5% loss first year)
|
|
annualAppreciation: number; // e.g., 0.01 (1% per year)
|
|
saleFees: number; // e.g., 0.07 (7% agency + notary)
|
|
}
|
|
|
|
// ─── Monthly Amortization (per loan) ────────────────────────────────────────
|
|
|
|
export interface MonthlyRow {
|
|
month: number; // 1-based global month
|
|
monthInYear: number; // 1-12
|
|
year: number; // 1-based year
|
|
interest: number;
|
|
principal: number;
|
|
insurance: number;
|
|
remaining: number;
|
|
payment: number; // interest + principal + insurance
|
|
}
|
|
|
|
// ─── Yearly Amortization (per loan) ─────────────────────────────────────────
|
|
|
|
export interface YearlyRow {
|
|
year: number;
|
|
interest: number;
|
|
principal: number;
|
|
insurance: number;
|
|
remaining: number;
|
|
payment: number;
|
|
}
|
|
|
|
// ─── Loan Computation Result ────────────────────────────────────────────────
|
|
|
|
export interface LoanResult {
|
|
loan: LoanInput;
|
|
effectiveAmount: number; // Actual amount (auto-calculated for main)
|
|
monthlyPayment: number; // Monthly principal + interest (excl. insurance)
|
|
monthlyInsurance: number;
|
|
monthly: MonthlyRow[];
|
|
yearly: YearlyRow[];
|
|
totalInterest: number;
|
|
totalInsurance: number;
|
|
totalCost: number; // amount + totalInterest + totalInsurance
|
|
}
|
|
|
|
// ─── Yearly Summary (aggregated across all loans) ───────────────────────────
|
|
|
|
export interface YearlySummary {
|
|
year: number;
|
|
|
|
// Credits aggregated
|
|
totalInterest: number;
|
|
totalPrincipal: number;
|
|
totalInsurance: number;
|
|
totalRemaining: number;
|
|
totalPayment: number;
|
|
|
|
// Projected monthly costs (as owner)
|
|
monthlyInterest: number;
|
|
monthlyPrincipal: number;
|
|
monthlyCharges: number; // charges + tax + utilities + home insurance
|
|
monthlyLoanInsurance: number;
|
|
monthlyTotal: number;
|
|
capitalRatio: number; // Part of payment building equity
|
|
yearlyTotal: number;
|
|
|
|
// Current monthly costs (as tenant)
|
|
currentRent: number;
|
|
currentCharges: number; // utilities + charges + insurance
|
|
currentMonthlyTotal: number;
|
|
currentYearlyTotal: number;
|
|
|
|
// Comparison
|
|
difference: number; // projected - current (negative = savings)
|
|
|
|
// Resale projection
|
|
resalePrice: number;
|
|
netResale: number; // After fees - remaining debt - down payment
|
|
}
|
|
|
|
// ─── Final Simulation Results ───────────────────────────────────────────────
|
|
|
|
export interface SimulationResults {
|
|
// Financing
|
|
notaryFees: number;
|
|
guaranteeFees: number;
|
|
totalFinancing: number;
|
|
totalCredit: number;
|
|
mainLoanAmount: number;
|
|
|
|
// Per-loan results
|
|
loanResults: LoanResult[];
|
|
|
|
// Yearly summaries (up to 30 years)
|
|
yearlySummaries: YearlySummary[];
|
|
|
|
// Global totals
|
|
totalCapital: number;
|
|
totalInterest: number;
|
|
totalInsurance: number;
|
|
grandTotal: number;
|
|
|
|
// Year 1 monthly snapshot
|
|
monthlyPaymentYear1: number;
|
|
projectedMonthlyCharges: number;
|
|
projectedMonthlyTotal: number;
|
|
currentMonthlyTotal: number;
|
|
|
|
// Max duration across all loans
|
|
maxDuration: number;
|
|
}
|