美文网首页
纯商贷等额本息、等额本金房贷月供计算(js)

纯商贷等额本息、等额本金房贷月供计算(js)

作者: 阿西Enzo | 来源:发表于2019-08-12 23:02 被阅读0次

/**
 * 纯商贷 等额本息 月供 贷款利息计算
 * @param {*} rate 国家规定银行贷款基准利率 默认0.049
 * @param {*} floatRate 贷款银行利率上浮率 0.2
 * @param {*} year 贷款年限
 * @param {*} cost 本金
 */
function payWayOne(rate, floatRate, year, cost){
    let realYearRate = rate * ( 1 + floatRate);
    console.info('实际年利率', realYearRate);
    let monthRate = realYearRate / 12;
    console.info('实际月利率', monthRate);
    let monthPay = ( cost * monthRate * Math.pow(1 + monthRate, year * 12) )/( Math.pow( 1 + monthRate , year * 12) - 1);
    console.info('月供', monthPay);
    let totalPay = monthPay * year * 12;
    console.info('总计支付', totalPay);
    let totalInterest = totalPay - cost;
    console.info('额外支付', totalInterest);
    result = { cost, year, rate, floatRate, monthRate, monthPay, totalPay, totalInterest};
    return result;
}

/**
 * 纯商贷 等额本金 月供 贷款利息计算
 * @param {*} rate 国家规定银行贷款基准利率 默认0.049
 * @param {*} floatRate 贷款银行利率上浮率 0.2
 * @param {*} year 贷款年限
 * @param {*} cost 本金
 * @param {*} payMonth 已付款月数
 */
function payWayTwo(rate, floatRate, year, cost, payMonth){
    let realYearRate = rate * ( 1 + floatRate);
    // console.info('实际年利率', realYearRate);
    let monthRate = realYearRate / 12;
    // console.info('实际月利率', monthRate);
    let monthCost = cost / year / 12;
    // 累计已支付本金(等额本金--每月本金不变)
    let payTotal = 0.0
    let payCost = monthCost * 0;
    let historyPayCost = 0.0;
    let historyPayTotal = 0.0;
    let month = 1;
    let monthPayDetail = [];
    while(month <= (year * 12)){
        let preMonthPay = (cost / (year * 12)) + ( cost - payCost ) * monthRate;
        if(month <= payMonth){
            historyPayCost += monthCost; 
            historyPayTotal += preMonthPay;
            if(month === payMonth){
                console.info('当前累计支付', historyPayTotal);
                console.info('当前累计支付本金', historyPayCost);
            }
        }
        payCost += monthCost;// 已支付本金
        payTotal += preMonthPay;// 累计支付
        monthPayDetail.push({ month, monthCost, payCost, payTotal, pay: preMonthPay, interest: (preMonthPay - monthCost), accInterest: (payTotal - payCost) });
        month++;
    }
    console.info('累计支付', payTotal);
    console.info('累计支付本金', payCost);
    let totalInterest = payTotal - payCost;
    console.info('总计支付利息', totalInterest);
    return { cost, realYearRate, monthRate, monthCost, historyPayCost, historyPayTotal, 
            payMonth, historyInterest: (historyPayTotal - historyPayCost), 
            payCost, payTotal, totalInterest,
            detail: monthPayDetail};    
}

相关文章

网友评论

      本文标题:纯商贷等额本息、等额本金房贷月供计算(js)

      本文链接:https://www.haomeiwen.com/subject/eqqmjctx.html