程式設計期末考

劉庭安2021年1月期末考

現值
利率
期數
金流
終值

對照EXCEL先打開從範圍定義名稱

對照EXCEL金融計算

程式碼

<script>
function CompF(){
  var y = document.getElementById("y").value; //輸入
  var m = document.getElementById("m").value;
  var p = document.getElementById("p").value;
  var n = document.getElementById("n").value;
  var fvif = y;
  fvif++;          // pvif = 1+y
  pvif = fvif ** n ; //pvif = 1/(1+y)^n
  var f = p * fvif - m / y * (fvif - 1) ;
  document.getElementById("f_").innerHTML = f.toFixed(6);
}
function CompN(){    //輸入y, m, p, f 計算 n 
  var y = document.getElementById("y").value;
  var m = document.getElementById("m").value;
  var p = document.getElementById("p").value;
  var f = document.getElementById("f").value;
  var pvif = y;
  pvif++;        // pvif = 1+y
  var n = Math.log( ( f - m/y )/( p - m/y ) )/Math.log( pvif ) ;
  document.getElementById("n_").innerHTML = n.toFixed(2);
}
function CompM(){
  var y = document.getElementById("y").value;
  var n = document.getElementById("n").value;
  var p = document.getElementById("p").value;
  var f = document.getElementById("f").value;
  var pvif = y;
  pvif++;
  pvif =1/pvif**n;
  var m = y*( p - f * pvif )/( 1 - pvif ) ;
  document.getElementById("m_").innerHTML = m.toFixed(2);
}
function CompP(){
  var y = document.getElementById("y").value;
  var n = document.getElementById("n").value;
  var m = document.getElementById("m").value;
  var f = document.getElementById("f").value;
  var pvif = y;
  pvif++;
  pvif =1/pvif**n;
  var p = (1-pvif)*m/y + f * pvif;
  document.getElementById("p_").innerHTML = p.toFixed(2);
}

</script>

留言

留言

張貼留言

這個網誌中的熱門文章

劉庭安德國股市,樞紐分析,週末效應

第六週進度

第七週程式設計學習進度