借呗分期还款模拟
Posted 葫芦一生
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了借呗分期还款模拟相关的知识,希望对你有一定的参考价值。
- /**
- * 阿里借呗计息还款规则说明实现
- *
- * @return
- */
- package jdongtech.jiebaiUtils;
- import java.util.Arrays;
- import java.util.Calendar;
- import java.util.HashMap;
- import java.util.Map;
- import jdongtech.interestUtils.AverageCapitalPlusInterestUtils;
- public class normalRepay {
- public static void main(String[] args) {
- // 需要手动填写
- double invest = 120; // 本金
- int month = 6; // 期数
- double yearRate = 14.4 / 100; // 年利率
- int acctOffsetDay = 15;
- int accountDay = 13; // 账单日,蚂蚁会把账单日设置成借款当日
- // 发起借款当天
- Calendar lendDay = Calendar.getInstance();
- lendDay.set(Calendar.MONTH, 4);
- lendDay.set(Calendar.DAY_OF_MONTH, 13);
- double dateRate = yearRate / 360;
- int[] daysCount = new int[month];
- int IncreaseFlag = 0;
- Calendar lendCalOffset = (Calendar) lendDay.clone();
- lendCalOffset.add(Calendar.DATE, acctOffsetDay);
- Calendar accCal = (Calendar) lendDay.clone();
- accCal.set(Calendar.DAY_OF_MONTH, accountDay);
- Calendar accCalBegin = (Calendar) accCal.clone();
- if (lendCalOffset.before(accCal)) {
- } else {
- accCalBegin.add(Calendar.MONTH, 1);
- IncreaseFlag = 1;
- }
- Calendar accCalEnd = (Calendar) accCal.clone();
- accCalEnd.add(Calendar.MONTH, month-1);
- System.out.println(lendDay.getTime() + "借款日期");
- System.out.println(accCalBegin.getTime() + "开始");
- System.out.println(accCalEnd.getTime() + "结束");
- int daysLending = RepayUtils.daysOffset(lendDay, accCalEnd);
- System.out.println("借款经历" + daysLending + "天");
- Calendar accCalPerEnd = (Calendar) accCalBegin.clone();
- for (int i = 0; i < month; i++) {
- Calendar accCalPerBeg;
- if (i == 0) {
- accCalPerBeg = (Calendar) lendDay.clone();
- } else {
- accCalPerBeg = (Calendar) accCalPerEnd.clone();
- accCalPerBeg.add(Calendar.MONTH, -1);
- }
- int daysPer = RepayUtils.daysOffset(accCalPerBeg, accCalPerEnd);
- daysCount[i] = daysPer;
- accCalPerEnd.add(Calendar.MONTH, 1);
- }
- //dateRate=0.0003;
- getPerMonthPrincipalInterestBig(invest, dateRate, month, daysCount, IncreaseFlag);
- }
- /**
- * 计算实际等额本息每月额度
- *
- * @return
- */
- public static double getPerMonthPrincipalInterestBig(double invest, double dateRate, int totalmonth, int[] daysCount,
- int IncreaseFlag) {
- IncreaseFlag = 1;
- double perMonthStandard = AverageCapitalPlusInterestUtils.getPerMonthPrincipalInterest(invest, dateRate * 360,
- totalmonth);
- double perMonthMax = perMonthStandard * 1.1;
- double[] PRperMonth = new double[totalmonth];
- double[] PperMonth = new double[totalmonth];
- double[] RperMonth = new double[totalmonth];
- double[] PLeftperMonth = new double[totalmonth];
- Map<Double, Double> lastCheckMap = new HashMap<Double, Double>();
- Map<Double, String> PLeftperMonthMap = new HashMap<Double, String>();
- Map<Double, String> PRperMonthMap = new HashMap<Double, String>();
- Map<Double, String> PperMonthMap = new HashMap<Double, String>();
- Map<Double, String> RperMonthMap = new HashMap<Double, String>();
- Map<Double, Double> sumPRMap = new HashMap<Double, Double>();
- Map<Double, Double> sumPMap = new HashMap<Double, Double>();
- Map<Double, Double> sumRMap = new HashMap<Double, Double>();
- if (IncreaseFlag == 1) {
- while (perMonthStandard < perMonthMax) {
- PRperMonth[0] = RepayUtils.num2second(perMonthStandard);
- PLeftperMonth[0] = RepayUtils.num2second(invest);
- RperMonth[0] = RepayUtils.num2secondDown(PLeftperMonth[0] * daysCount[0] * dateRate);
- PperMonth[0] = RepayUtils.num2second(PRperMonth[0] - RperMonth[0]);
- for (int j = 1; j < totalmonth; j++) {
- PRperMonth[j] = RepayUtils.num2second(perMonthStandard);
- PLeftperMonth[j] = RepayUtils.num2second(PLeftperMonth[j - 1] - PperMonth[j - 1]);
- RperMonth[j] = RepayUtils.num2secondDown(PLeftperMonth[j] * dateRate * daysCount[j]);
- PperMonth[j] = RepayUtils.num2second(PRperMonth[j] - RperMonth[j]);
- if (j == totalmonth - 1) {
- PperMonth[j] = RepayUtils.num2second(PLeftperMonth[j]);
- PRperMonth[j] = RepayUtils.num2second(PperMonth[j] + RperMonth[j]);
- }
- }
- double sumP = 0;
- double sumR = 0;
- double sumPR = 0;
- for (int i = 0; i < PLeftperMonth.length; i++) {
- sumP = sumP + PperMonth[i];
- sumR = sumR + RperMonth[i];
- sumPR = sumPR + PRperMonth[i];
- }
- lastCheckMap.put(RepayUtils.num2second(perMonthStandard),
- Math.abs(PRperMonth[totalmonth - 1] - PRperMonth[totalmonth - 2]));
- PLeftperMonthMap.put(RepayUtils.num2second(perMonthStandard), Arrays.toString(PLeftperMonth));
- PRperMonthMap.put(RepayUtils.num2second(perMonthStandard), Arrays.toString(PRperMonth));
- PperMonthMap.put(RepayUtils.num2second(perMonthStandard), Arrays.toString(PperMonth));
- RperMonthMap.put(RepayUtils.num2second(perMonthStandard), Arrays.toString(RperMonth));
- sumPRMap.put(RepayUtils.num2second(perMonthStandard), RepayUtils.num2second(sumPR));
- sumPMap.put(RepayUtils.num2second(perMonthStandard), RepayUtils.num2second(sumP));
- sumRMap.put(RepayUtils.num2second(perMonthStandard), RepayUtils.num2second(sumR));
- perMonthStandard = perMonthStandard + 0.01;
- }
- }
- Double resultKey = RepayUtils.getKeyByMinValue(lastCheckMap);
- System.out.println("等额本息每月还款额:" + resultKey);
- System.out.println("每期经历" + Arrays.toString(daysCount));
- System.out.println("每月余本金:" + PLeftperMonthMap.get(resultKey));
- System.out.println("每月还款额:" + PRperMonthMap.get(resultKey));
- System.out.println("每月还本金:" + PperMonthMap.get(resultKey));
- System.out.println("每月还利息:" + RperMonthMap.get(resultKey));
- System.out.println("总还款额:" + sumPRMap.get(resultKey));
- System.out.println("总还本金:" + sumPMap.get(resultKey));
- System.out.println("总还利息:" + sumRMap.get(resultKey));
- return resultKey;
- }
- }
以上是关于借呗分期还款模拟的主要内容,如果未能解决你的问题,请参考以下文章