等额本息法:每月的还款额相同,从本质上来说是本金所占比例逐月递增,利息所占比例逐月递减,月还款数不变,即在月供“本金与利息”的分配比例中,前半段时期所还的利息比例大、本金比例小,还款期限过半后逐步转为本金比例大、利息比例小。
/**
* 等额本息还款法
* @param _loanAmount 贷款金额(元)
* @param _loanYears 贷款年数
* @param _annualInterestRate 贷款年利率(%)
*/
private static void averageCapitalPlusInterest(double _loanAmount, int _loanYears, double _annualInterestRate){
BigDecimal digit_0 = new BigDecimal(0); //数字0
BigDecimal digit_1 = new BigDecimal(1); //数字1
BigDecimal digit_100 = new BigDecimal(100); //数字100
BigDecimal monthsOfYear = new BigDecimal(12); //一年的月数
int scale = 10; //精度
BigDecimal loanTotal = new BigDecimal(_loanAmount); //贷款总额,元为单位
BigDecimal loanYears = new BigDecimal(_loanYears); //贷款年数
BigDecimal annualInterestRate = new BigDecimal(_annualInterestRate).divide(digit_100); //年利率
//还款月数
int loanMonths = loanYears.multiply(monthsOfYear).intValue();
System.out.println("还款月数:" + loanMonths);
//月利率 = 年利率 /12。一般以千分之表示
BigDecimal monthlyInterestRate = annualInterestRate.divide(monthsOfYear, scale, BigDecimal.ROUND_HALF_UP);
System.out.println("月利率:" + toFixed(monthlyInterestRate.multiply(new BigDecimal(1000)), 3));
//每月还款额 = [贷款本金×月利率×(1+月利率)^还款月数] ÷ [(1+月利率)^还款月数 - 1]
BigDecimal bx1 = loanTotal.multiply(monthlyInterestRate).multiply(digit_1.add(monthlyInterestRate).pow(loanMonths));
BigDecimal bx2 = digit_1.add(monthlyInterestRate).pow(loanMonths).subtract(digit_1);
BigDecimal monthlyRepaymentAmount = bx1.divide(bx2, scale, BigDecimal.ROUND_HALF_UP);
System.out.println("每月还款额:" + toFixed(monthlyRepaymentAmount, 2));
//总利息
BigDecimal totalInterest = digit_0;
//剩余本金
BigDecimal remainingPrincipal = loanTotal;
System.out.println("\n期数,还款本息(元),还款利息(元),还款本金(元),剩余本金(元)");
for(int n=1; n<=loanMonths; n++){
//每月还贷本金 B = a*i*(1+i)^(n-1) / [(1+i)^N-1]
//B=等额本息月还本金,a=贷款总金额, i=贷款月利率,n=第n期还贷数,N=还贷总月数
BigDecimal bj = loanTotal.multiply(monthlyInterestRate).multiply(digit_1.add(monthlyInterestRate).pow(n-1));
bj = bj.divide(digit_1.add(monthlyInterestRate).pow(loanMonths).subtract(digit_1), scale, BigDecimal.ROUND_HALF_UP);
//利息 = 剩余本金 * 月利率
BigDecimal lx = remainingPrincipal.multiply(monthlyInterestRate);
//剩余本金
remainingPrincipal = remainingPrincipal.subtract(bj);
//总利息
totalInterest = totalInterest.add(lx);
System.out.println( n + "," + toFixed(monthlyRepaymentAmount, 2) + "," + toFixed(lx, 2) + "," + toFixed(bj, 2) + "," + toFixed(remainingPrincipal,2) );
}
System.out.println("总利息:" + toFixed(totalInterest, 2));
System.out.println("还款总金额:" + toFixed(loanTotal.add(totalInterest), 2));
}
/**
* 四舍五入
* @param value 数值
* @param scale 精度:保留几位小数点
*/
private static BigDecimal toFixed(BigDecimal value, int scale){
return value.divide(new BigDecimal(1), scale, BigDecimal.ROUND_HALF_UP);
}