单日复利,单月复利计算java实现

/**
	 * 单日复利计算方式
	 */
	@Test
	public void testSDCI() {
		double prin = 1375;
		double rate = 0.001;
		double over = 0.00;
		String startDate = "2017/12/10";
		String endDate = "2018/12/08";
		int days = DateHelper.getDays(startDate, endDate);
		for(int i = 0 ;i < days;i++) {
			double sumAmt = Arith.add(prin, over);
//			System.out.println("sumAmt:" + sumAmt);
			if(i > 1) {
				over = Arith.mul(sumAmt, Arith.mul(i - 1, rate, 8));
			}
			System.out.println("逾期天数" + (i+1)+ ",overFee:" + over);
		}
		System.out.println(over);
		
	}
	
	/**
	 * 单月复利方式计息
	 * @throws ParseException 
	 */
	@Test
	public void testSMCI() throws ParseException {
		String startDate = "2017/11/15";//账单起始日
		String endDate = "2019/01/15";//最新逾期日
		double prinAmt = 462;//本金
		int manaFee = 5;//逾期管理费
		double plentyFeeRate = 0.001;//逾期滞纳金费率
		double months = DateHelper.getMonths(startDate, endDate);//逾期月数
		int sumManaFee = 0;
		double sumPeriodOverduelatefeedayfee = 0.00d;
		System.out.println("逾期月数为:" + months);
		for(int i = 0 ;i < months;i++) {
			String lastDate = DateHelper.addMonth(startDate,i);
			String nextDate = DateHelper.addMonth(startDate,i+1);
			int overdays = DateHelper.getDays(lastDate, nextDate);
            if(DateUtils.compareDate(endDate, nextDate) > 0) {
                overdays = DateHelper.getDays(lastDate, nextDate);
            } else {
                overdays =  DateHelper.getDays(lastDate, endDate);
            }
			
			sumManaFee = (i+1)*manaFee;
			double overDueFee = (prinAmt + sumManaFee + sumPeriodOverduelatefeedayfee) * plentyFeeRate * overdays;
			
			sumPeriodOverduelatefeedayfee += overDueFee;
			System.out.println("逾期天数="+  overdays + "逾期" + (i+1)+ "月,overDueFee=" + overDueFee + ",sumPeriodOverduelatefeedayfee=" + sumPeriodOverduelatefeedayfee );
		}
		
		
		
		
	}

 

你可能感兴趣的:(java,互联网金融,信贷核算,计息)