提前還款合不合適

計(jì)算代碼

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 <<endl;
        
        int monthIndex = 1;
        // 在第indexByAdvance個(gè)月決定還款
        int indexByAdvance = 24;
        
        bool flag = false;
        
        // 提前還款的額度
        double x = 200000;
        // 假設(shè)當(dāng)前投資別的東西年收益率
        double ratioByInvest = 0.045;
        
        // 不提前還款,到第monthIndex個(gè)月為止的總利息
        double sumInterest = 0;
        
        // 不提前還款,到第monthIndex個(gè)月為止的剩余本金
        double leftBase = base;
        
        // 不提前還款剩余的總利息總和
        double leftInterest = monthlyPayout*totalMonths - base;
        
        // 提前還款剩余的總利息總和
        
        // 提前還款(設(shè)在第K個(gè)月提前還款x元,K<monthIndex),到第monthIndex個(gè)月為止的總利息
        double sumInterestByAdvance = 0;
        
        // 提前還款(設(shè)在第K個(gè)月提前還款x元,K<monthIndex),到第monthIndex個(gè)月為止的剩余本金
        double leftBaseByAdvance = base;
        
        // x元做投資的總回報(bào)
        double paybackByInvest = 0;
        
        
        
        while(monthIndex <= totalMonths && leftBaseByAdvance >=0) {
            /*
              計(jì)算到第monthIndex個(gè)月為止的總支出(查看剩余本金和已經(jīng)支出的利息):
              1. 假設(shè)不提前還款
              (1)到第monthIndex個(gè)月為止的總利息 = monthlyPayout * monthIndex;
              2. 在第K個(gè)月提前還款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;
                
                // 假設(shè)拿x元做投資的回報(bào)金額是:
                paybackByInvest = paybackByInvest + (x+paybackByInvest)*(ratioByInvest/12);
                //cout<<"monthIndex: "<<monthIndex<<", paybackByInvest: "<<paybackByInvest<<endl;
            }
            
            double curInterest = leftBase * (ratio/12);
            double curBase = monthlyPayout - curInterest;
            leftBase = leftBase - curBase;
            sumInterest = sumInterest + curInterest;
            
            if (!flag) {
                sumInterestByAdvance = sumInterest;
                leftBaseByAdvance = leftBase;
            }
            
            
            
            // 作對(duì)比
            
            /*
            if ((totalPayout -base - sumInterest - paybackByInvest) > (monthlyPayout*333+x - base - sumInterestByAdvance) && (monthIndex >= indexByAdvance) ) {
                cout<<"提前還款在第"<<monthIndex<<"個(gè)月開始奏效"<<endl;
            }*/
            
            if ((sumInterest-paybackByInvest) > sumInterestByAdvance) {
                cout<<"提前還款在第"<<monthIndex<<"個(gè)月開始奏效"<<endl;
            }
            
            //cout<<monthlyPayout<<endl;
            //cout<<sumInterest<<endl;
            //cout<<monthIndex<<":"<<leftBaseByAdvance<<":"<<sumInterestByAdvance<<endl;
            //cout<<monthIndex<<":"<<leftBase<<":"<<sumInterest<<endl;
            cout<<"monthIndex: "<<monthIndex<<", sumInterest: "<<sumInterest - paybackByInvest<<", sumInterestByAdvance: "<<sumInterestByAdvance<<endl;
            
            //cout<<"monthIndex: "<<monthIndex<<", paybackByInvest: "<<paybackByInvest<<", leftInterest: "<<totalPayout -base - sumInterest - paybackByInvest<<",leftBase: "<<leftBase<<", leftInterestInAdvance:"<<monthlyPayout*333+x - base - sumInterestByAdvance<<", leftBaseInAdvance: "<<leftBaseByAdvance<<endl;
            
            monthIndex++;
            //cout<<monthIndex<<endl;
            
        }
        
        return 1;
    }
};

結(jié)論

似乎只要是投資利率高于還款利率就不虧。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 著名財(cái)經(jīng)雜志《財(cái)富》對(duì)本書的評(píng)論是:如果你一生只讀一本關(guān)于投資的著作,無疑就是這本《聰明的投資者》。 首先介紹一下...
    惜她閱讀 7,415評(píng)論 0 34
  • 人們常說“守得住鄉(xiāng)愁,變守得住幸?!?它是一個(gè)國家歷史文化的基因,更滲透于每個(gè)人的血液。 就在這個(gè)5月,南京街頭燃...
    jackcool閱讀 445評(píng)論 0 0
  • 今天老師帶我們繼續(xù)學(xué)習(xí)了視圖文檔結(jié)構(gòu)、菜單、背景位圖和工具欄。 文檔視圖結(jié)構(gòu)的應(yīng)用程序框架的實(shí)現(xiàn)過程中,應(yīng)用對(duì)象負(fù)...
    王虹淇閱讀 149評(píng)論 0 0
  • 今天又上了書法課,之前買各種東西花了80多但是還是很值得的! 寫字的時(shí)候,那是一種完全不同的精神狀態(tài)。漢字我們每個(gè)...
    圓寶w閱讀 445評(píng)論 0 1
  • 在我的家鄉(xiāng)淮北,隨處可見的小吃除了燙面便就是面皮了。而我最是偏愛面皮,從小吃到大。 猶記兒時(shí),母親每次趕集前,我總...
    巖書閱讀 935評(píng)論 4 6

友情鏈接更多精彩內(nèi)容