SOURCE

function computer () {
  var year = 12,
      firstIn = 20,
      allIn = 0,
      repayment = 0, // 还款总额
      loadAmount = 30,  // 贷款总额
      needPayBack = 38.88,  // 加上利息总还
      mountPrincipal = loadAmount/year/12, //每月待还本金
      lendingRate = 0.049, // 贷款利率
      firstMonthPay = 0.3308, // 首月房贷
      firstYearPay = 3.9132,  // 首年房贷
      yearReduce = 0.012, // 每年房贷下降
      monthReduce = 0.00085,    // 每月房贷下降
      firstMonthRent = 0.2,  // 首年月租金
      firstYearRent = 2.4,  // 首年租金
      rentYearAdd = 0.05,  // 每年租金上涨
      firstYearHouseVaule = 58,     // 首年房子价值
      HouseVaule = 0, //房屋总价值
      houseAdd = 2,    // 平均房价每年上涨幅度
      profit = 0,     //盈利总额
      allProfitRate = 0,  //总收益率
      yearProfitRate = 0,  // 年平均收益率
      allRendAmount = 0, // 总租金
      getMoney = 0,   // 卖房后还了剩余房贷后剩余资金
      thisYearProfitRate = 0,  // 本年收益率
      lastProfit = 0  // 上一年收益

      console.log('年份', '   总投入',  '   总租金', '  房屋总价值', '  卖房后到手资金', '   卖房后收益',  '  总收益率',   '   每年平均收益率',  '   本年收益率')
      for(var i = 1; i <= 12 ; i++) {
        for (var j = 1; j <= 12; j++) {
          var mountRepayment = (loadAmount - ((i -1) * 12 + j - 1) * mountPrincipal) * lendingRate / 12   // 每个月还的总金额
          repayment = repayment + mountRepayment + mountPrincipal
        }
        // 总租金
        allRendAmount += firstYearRent + rentYearAdd * (i - 1)
        // 房屋价值
        HouseVaule = firstYearHouseVaule + houseAdd * (i - 1)
        
        allIn = repayment + firstIn

        getMoney = HouseVaule - (needPayBack - repayment)
        
        profit = HouseVaule + allRendAmount - allIn - (loadAmount - repayment)

        thisYearProfitRate = (profit - lastProfit) / allIn

        lastProfit = profit

        allProfitRate = profit / allIn

        yearProfitRate = allProfitRate / i

      
        console.log('第' + i + '年', '   '+allIn.toFixed(2), '   ' + allRendAmount.toFixed(2), '      ' + HouseVaule.toFixed(2), '     ' + getMoney.toFixed(2),'        ' + profit.toFixed(2), '        ' + allProfitRate.toFixed(2), '        ' + (yearProfitRate * 100).toFixed(2) + '%', '        ' + (thisYearProfitRate * 100).toFixed(2) + '%')

      }
}
computer()
console 命令行工具 X clear

                    
>
console