← back to StudentLoanTracker
src/lib/calculators/icr-calculator.ts
85 lines
/**
* ICR Plan Calculator (Income-Contingent Repayment)
*
* Key rules:
* - Payment is the LESSER of:
* a) 20% of discretionary income (AGI - 100% of poverty guideline)
* b) Fixed 12-year payment adjusted by income percentage factor
* - 25-year forgiveness (300 months)
* - Only IDR plan available for Parent PLUS (after consolidation)
* - Interest capitalizes if payment doesn't cover it
* - No payment cap relative to Standard plan
*/
import { LoanInputs, PlanResult, MonthlySnapshot } from './types';
import { getDiscretionaryIncome, getPovertyGuideline, POVERTY_MULTIPLIERS } from './poverty-guidelines';
const ICR_PAYMENT_RATE = 0.20;
const FORGIVENESS_MONTHS = 300; // 25 years
export function calculateICR(inputs: LoanInputs): PlanResult {
const { totalBalance, weightedRate, agi, familySize, state } = inputs;
const povertyGuideline = getPovertyGuideline(familySize, state);
const discretionaryIncome = getDiscretionaryIncome(
agi, familySize, state, POVERTY_MULTIPLIERS.ICR
);
// Option A: 20% of discretionary income / 12
const optionA = Math.max(0, (discretionaryIncome * ICR_PAYMENT_RATE) / 12);
// Option B: 12-year fixed payment (amortized over 12 years × income percentage factor)
// Simplified: use standard 12-year amortization
const monthlyRate = weightedRate / 12;
const optionB =
monthlyRate > 0
? (totalBalance * monthlyRate) / (1 - Math.pow(1 + monthlyRate, -144))
: totalBalance / 144;
// ICR payment = lesser of the two options
const monthlyPayment = Math.min(optionA, optionB);
let balance = totalBalance;
let totalPaid = 0;
let totalInterest = 0;
const schedule: MonthlySnapshot[] = [];
for (let month = 1; month <= FORGIVENESS_MONTHS; month++) {
const interestThisMonth = balance * monthlyRate;
const payment = Math.min(monthlyPayment, balance + interestThisMonth);
const principalPaid = payment - interestThisMonth;
totalPaid += payment;
totalInterest += interestThisMonth;
if (principalPaid >= 0) {
balance = Math.max(0, balance - principalPaid);
} else {
balance += Math.abs(principalPaid);
}
schedule.push({
month,
payment: Math.round(payment * 100) / 100,
principal: Math.round(Math.max(0, principalPaid) * 100) / 100,
interest: Math.round(interestThisMonth * 100) / 100,
balance: Math.round(balance * 100) / 100,
});
if (balance <= 0) break;
}
return {
planName: 'ICR',
monthlyPayment: Math.round(monthlyPayment * 100) / 100,
totalPaid: Math.round(totalPaid * 100) / 100,
totalInterest: Math.round(totalInterest * 100) / 100,
forgivenessAmount: Math.round(Math.max(0, balance) * 100) / 100,
forgivenessMonths: FORGIVENESS_MONTHS,
repaymentMonths: schedule.length,
discretionaryIncome: Math.round(discretionaryIncome * 100) / 100,
povertyGuideline,
paymentSchedule: schedule,
};
}