提前还款合不合适

计算代码

class Solution {
public:
    int getSum(int a, int b) {
        double base = 2200000;//2160269.31;
        double ratio = 0.04165;
        int totalMonths = 360;
        double monthlyPayout = base * (ratio/12) * pow((1 + ratio/12), totalMonths) / (pow((1 + ratio/12), totalMonths) - 1);
        double totalPayout = monthlyPayout * totalMonths;
        //cout << monthlyPayout <=0) {
            /*
              计算到第monthIndex个月为止的总支出(查看剩余本金和已经支出的利息):
              1. 假设不提前还款
              (1)到第monthIndex个月为止的总利息 = monthlyPayout * monthIndex;
              2. 在第K个月提前还款X元的总支出 = base - monthlyPayout * (monthIndex - k) - ()
            */
            
            if (monthIndex == indexByAdvance) {
                leftBaseByAdvance = leftBaseByAdvance - x;
            }
            
            if (monthIndex >= indexByAdvance) {
                double cInterest = leftBaseByAdvance * (ratio/12);
                double cBase = monthlyPayout - cInterest;
                leftBaseByAdvance = leftBaseByAdvance - cBase;
                sumInterestByAdvance = sumInterestByAdvance + cInterest;
                flag = true;
                
                // 假设拿x元做投资的回报金额是:
                paybackByInvest = paybackByInvest + (x+paybackByInvest)*(ratioByInvest/12);
                //cout<<"monthIndex: "< (monthlyPayout*333+x - base - sumInterestByAdvance) && (monthIndex >= indexByAdvance) ) {
                cout<<"提前还款在第"< sumInterestByAdvance) {
                cout<<"提前还款在第"<

结论

似乎只要是投资利率高于还款利率就不亏。

你可能感兴趣的:(提前还款合不合适)