等额本金计算还款列表的代码来了~
公式
月还本息=(本金/还款月数)+(本金-累计已还本金)×月利率
每月本金=总本金/还款月数
每月利息=(本金-累计已还本金)×月利率
还款总利息=(还款月数+1)×贷款额×月利率/2
还款总额=(还款月数+1)×贷款额×月利率/2+ 贷款额
代码
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class InterestCalculation {
static int DECIMAL_SCALE = 9;
static BigDecimal BIGDECAMAL_100 = new BigDecimal(100);
static BigDecimal BIGDECAMAL_12 = new BigDecimal(12);
static BigDecimal BIGDECAMAL_30 = new BigDecimal(30);
/**
* 等额本金 还款列表计算(自然月)
* @param total 总金额
* @param yearRate 年利率
* @param sumTerm 总期数
* @throws Throwable
*/
public static void calculation_DEBJ_ZRY(BigDecimal total,BigDecimal yearRate,int sumTerm) throws Throwable{
//月利率
BigDecimal monthRate = yearRate.divide(BIGDECAMAL_12,DECIMAL_SCALE, BigDecimal.ROUND_HALF_UP);
//还款总利息
BigDecimal sumInterest = new BigDecimal(sumTerm+1).multiply(total).multiply(monthRate).divide(new BigDecimal(2),2,BigDecimal.ROUND_HALF_UP);
BigDecimal monthPrincipal = total.divide(new BigDecimal(sumTerm),DECIMAL_SCALE,BigDecimal.ROUND_HALF_UP);
BigDecimal remainTotal = total; //剩余本金付初始值为总本金
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
System.out.println("本金:"+total.setScale(2)+"\t年利率:"+yearRate.multiply(BIGDECAMAL_100)+"%\t总期数:"+sumTerm+"\t总利息:"+sumInterest);
System.out.println("期次\t回款本息(元)\t回款利息(元)\t回款本金(元)\t剩余本金(元)\t回款日期");
for(int i=1;i<=sumTerm;i++){
//每月利息=(总本金-累计已还本金)×月利率
BigDecimal interest = remainTotal.multiply(monthRate).setScale(2,BigDecimal.ROUND_HALF_UP);
//月还本息
BigDecimal monthPayTotal = monthPrincipal.add(interest);
remainTotal = remainTotal.subtract(monthPrincipal);
calendar.add(Calendar.MONTH, 1);
System.out.println(i+"\t"+monthPayTotal.setScale(2,BigDecimal.ROUND_HALF_UP)+"\t\t"+interest.setScale(2,BigDecimal.ROUND_HALF_UP)+"\t\t"+monthPrincipal.setScale(2,BigDecimal.ROUND_HALF_UP)+"\t\t"+remainTotal.setScale(2,BigDecimal.ROUND_HALF_UP)+"\t\t"+sdf.format(calendar.getTime()));
}
}
public static void main(String[] args) throws Throwable {
//本金10000元,年利率15%,出借18个月
BigDecimal total = new BigDecimal(10000);
BigDecimal yearRate = BigDecimal.valueOf(0.15);
int sumTerm = 18;
calculation_DEBJ_ZRY(total,yearRate,sumTerm);
}
运行结果
本金:10000.00 年利率:15.00% 总期数:18 总利息:1187.50
期次 回款本息(元) 回款利息(元) 回款本金(元) 剩余本金(元) 回款日期
1 680.56 125.00 555.56 9444.44 2019-06-12
2 673.62 118.06 555.56 8888.89 2019-07-12
3 666.67 111.11 555.56 8333.33 2019-08-12
4 659.73 104.17 555.56 7777.78 2019-09-12
5 652.78 97.22 555.56 7222.22 2019-10-12
6 645.84 90.28 555.56 6666.67 2019-11-12
7 638.89 83.33 555.56 6111.11 2019-12-12
8 631.95 76.39 555.56 5555.56 2020-01-12
9 625.00 69.44 555.56 5000.00 2020-02-12
10 618.06 62.50 555.56 4444.44 2020-03-12
11 611.12 55.56 555.56 3888.89 2020-04-12
12 604.17 48.61 555.56 3333.33 2020-05-12
13 597.23 41.67 555.56 2777.78 2020-06-12
14 590.28 34.72 555.56 2222.22 2020-07-12
15 583.34 27.78 555.56 1666.67 2020-08-12
16 576.39 20.83 555.56 1111.11 2020-09-12
17 569.45 13.89 555.56 555.56 2020-10-12
18 562.50 6.94 555.56 0.00 2020-11-12