第18週吳東泰成果

吳東泰期末考

現值
利率
期數
金流
終值

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

對照EXCEL金融計算

程式碼

<style>
h1{border: 30px outset red;  
  background-color: green;  
  color: white;
  text-align: center;}
</style>
<h1>吳東泰期末考</h1>    

<table border="1">
<tbody>
<tr><td>現值</td><td><input id="p" type="number" /></td><td><input onclick="CompP()" type="button" value="計算現值" /></td><td id="p_" width="180"></td></tr>
<tr><td>利率</td><td><input id="y" type="number" value="0.001" /></td></tr>
<tr><td>期數</td><td><input id="n" type="number" value="240" /></td><td><input onclick="CompN()" type="button" value="計算期數" /></td><td id="n_" width="100"></td></tr>
<tr><td>金流</td><td><input id="m" type="number" value="0"/></td><td><input onclick="CompM()" type="button" value="計算金流" /></td><td id="m_"></td></tr>
<tr><td>終值</td><td><input id="f" type="number" value="0"/></td><td><input onclick="CompF()" type="button" value="計算終值" /></td><td id="f_"></td></tr>
</tbody></table>

<h1>對照EXCEL先打開從範圍定義名稱</h1>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3g0vVHXz264T37MOnGBsw_TvovsZ5KImrkCQxRWxObH0AKHLMmwfShXmNWY6q7ZsVXK1BIgrcMDfUrBnwOBhvi4D_sBHcxuaG691p4sTp9K9nh3LFsfBIstJkhV9o_VCL5LiTT8ERR3-U/s752/1.JPG" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="600" data-original-height="564" data-original-width="752" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3g0vVHXz264T37MOnGBsw_TvovsZ5KImrkCQxRWxObH0AKHLMmwfShXmNWY6q7ZsVXK1BIgrcMDfUrBnwOBhvi4D_sBHcxuaG691p4sTp9K9nh3LFsfBIstJkhV9o_VCL5LiTT8ERR3-U/s600/1.JPG"/></a></div>
<h1>對照EXCEL金融計算</h1>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBPdVU7sAUvr-AgQ5qSAvwibCh6zpDR7cW0MwDJ9dbv80KzE9OgXHNx4JGlHlTmvqEdVdOO1Usk34tIYE4BKFnmz1Vp_XsqICZ0THP3K44TJpTj0veY8r2eBge7pL0QiBZRrwAXUWEG6P4/s1072/2.JPG" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="600" data-original-height="380" data-original-width="1072" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBPdVU7sAUvr-AgQ5qSAvwibCh6zpDR7cW0MwDJ9dbv80KzE9OgXHNx4JGlHlTmvqEdVdOO1Usk34tIYE4BKFnmz1Vp_XsqICZ0THP3K44TJpTj0veY8r2eBge7pL0QiBZRrwAXUWEG6P4/s600/2.JPG"/></a></div>

<h1>程式碼</h1>

<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 =fvif ** n;
  var f = p * fvif - m / y *  (fvif - 1);
  document.getElementById("f_").innerHTML = f. toFixed(6);
}  
function CompP(){      //計算現值 p
  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;
}
function CompN(){      //計算期數 n
  var y = document.getElementById("y").value; //從html表格取得 id=y
  var p = document.getElementById("p").value;
  var m = document.getElementById("m").value;
  var f = document.getElementById("f").value;
  var pvif = y;
  pvif++;
  var n = Math.log( (f - m/y )/( p - m/y ) ) / Math.log(pvif);
  document.getElementById("n_").innerHTML = n. toFixed(2);
}
 
function CompM(){      //計算金流 m
  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++;          //pvif = 利率 + 1
  pvif =1/pvif**n;    //pvif = 1/(利率+1)^n
  var m = y * ( p - f * pvif )/( 1 - pvif);
  document.getElementById("m_").innerHTML = m;
}

</script>  

留言

  1. 做得很好,持續加油,讓天下人紀錄你的專業。

    回覆刪除

張貼留言

這個網誌中的熱門文章

吳冠辰:選擇權敏感度

吳冠辰excel工作表群組,Query附加與合併資料表