劉任昌期末考Javascript與Python計算內部報酬率IRR
躉繳 | 第1期 | 第2期 | 第3期 |
注意,包含首期躉繳的現金流量都大於0。
輸出:
報酬率:
淨現值:
迴圈次數:
劉任昌向項柏綱學習程式設計程式碼如下
<STYLE>H1{margin: 0; padding: 20px 0; color: #000000; text-shadow: 2PX 2PX yellow;}
.Takming{border: 20px outset red;background-color: green;color: white;}
.pmt{width: 60pt; height: 20pt;background-color: GRAY;color: white;}
</STYLE>
<SCRIPT>//註解分享過程重點,貢獻,註解給人看,註解維護MAINTAIN程式碼
const period=4;//給定期數四期
const maxerror = 0.000000001; //要求的精確度
var payment = new Array(period);
function IRR()
{
var a = 0;//TRY報酬率是否=0
var b = 1;//TRY報酬率是否=1
var c;//如果不是上面的a,b,就測試c=(a+b)/2
var f;
var gap=10;
var loopNumber = 0;
for (var i=0; i<period; i++)
payment[i]=document.getElementsByClassName("pmt")[i].value;
f = npv(a);
if ( f==0 )
document.getElementById("irr").innerHTML = "內部報酬率等於0.";
else if ( f<0 )
document.getElementById("irr").innerHTML = "內部報酬率小於0.";
else
{ while ( gap > maxerror && Math.abs(f) > maxerror && loopNumber < 100)
{
loopNumber++;
c = (a+b)/2;//二分法求內部報酬率
f = npv(c);
if ( Math.abs(f) > maxerror && gap > maxerror)
{ if ( f>0 )//如果淨現值f>0使用c取代下限a
a = c;
else
b = c;//else否怎,淨現值f<0使用c取代上限b
gap = b-a;
}
} //迴圈while結束
}
document.getElementById("irr").innerHTML= c;
document.getElementById("npv").innerHTML= f;
document.getElementById("loopNumber").innerHTML = loopNumber;
}
var npv=function(rate){var y= -payment[0];for (var j=1; j<period; j++)y=y+payment[j]/(1+rate)**j;return y;}
</SCRIPT>
<table border="1">
<tr align="center"><td>躉繳</td><td>第1期</td><td>第2期</td><td>第3期</td></tr>
<tr><td><input class="pmt" type="number" /></td>
<td><input class="pmt" type="number" /></td>
<td><input class="pmt" type="number" /></td>
<td><input class="pmt" type="number" /></td></tr>
</table><br />
注意,包含首期躉繳的現金流量都大於0。
<p><input onclick="IRR()" type="button" value="計算內部報酬率" />輸出:</p> <!-- 按下 button 去執行 JavaScript IRR( )-->
<p>報酬率:<b id="irr"></b></p>
<p>淨現值:<b id="npv"></b></p>
<p>迴圈次數:<b id="loopNumber"></b></p>
維基百科數值分析二分法
數值分析NUMERICAL ANALYSIS應用數學系,資訊工程或資訊科學數值方法NUMERICAL METHOD必修課,學程式設計求解。
P=PARAGRAPH, B=BOLD, H=HEADER, SRC=SOURCE
https://acdhdwstzws.blogspot.com/2025/06/h1-margin-0-padding-20px-0-color-000000.html
回覆刪除沒有放EXCEL的結果
刪除https://lin-yujing.blogspot.com/2025/06/blog-post_16.html
回覆刪除https://gbsddik.blogspot.com/2025/06/blog-post.html
回覆刪除https://chiuerya0515.blogspot.com/2025/06/javascriptpythonirr.html
回覆刪除https://danny0976790127.blogspot.com/2025/06/blog-post.html
回覆刪除https://lu-cheng-yin-2024.blogspot.com/2025/06/617.html
回覆刪除https://chenyenhsun.blogspot.com/2025/06/irr.html
回覆刪除https://huuiiiiman.blogspot.com/2025/06/javascriptpythonirr.html
回覆刪除https://tzuchenchu.blogspot.com/2025/06/javascriptpythonirr-6-16-2025.html
回覆刪除https://yuweiiiiiiiiiiii.blogspot.com/2025/06/javascriptpythonirr.html
回覆刪除嵌入維基百科優秀https://yuweiiiiiiiiiiii.blogspot.com/2025/06/javascriptpythonirr.html
刪除610.spider截圖,但沒有放程式碼。截圖太大,沒有重點。https://yuweiiiiiiiiiiii.blogspot.com/2025/06/pythonexcel-pv.html
https://chuyuchi.blogspot.com/2025/06/javascriptpythonirr.html
回覆刪除還欠影片作業。https://chuyuchi.blogspot.com/2025/06/javascriptpythonirr.html
刪除https://jiachiangkuo.blogspot.com/2025/06/617.html
回覆刪除https://www.youtube.com/watch?v=MGB5tUfIg08
刪除https://takuto20050803.blogspot.com/2025/06/takutojavascriptpythonirr.html
回覆刪除https://koala111222.blogspot.com/2025/06/javascriptpythonirr.html
回覆刪除應付!https://koala111222.blogspot.com/2025/04/blog-post.html
刪除https://sccabout.blogspot.com/2025/06/h1margin-0-padding-20px-0-color-000000.html
回覆刪除https://huutingyu.blogspot.com/2025/06/h1-margin-0-padding-20px-0-color-000000.html
回覆刪除準時交但沒有Excel截圖https://huutingyu.blogspot.com/2025/06/h1-margin-0-padding-20px-0-color-000000.html
刪除610python自定函數計算很完美https://huutingyu.blogspot.com/2025/06/pythonexcel-pv.html
603.https://huutingyu.blogspot.com/2025/06/h1border-30px-outset-red-background.html
https://yangyami.blogspot.com/2025/06/h1-margin-0-padding-20px-0-color-000000.html
回覆刪除完美呈現維基百科與程式碼https://yangyami.blogspot.com/2025/06/h1-margin-0-padding-20px-0-color-000000.html
刪除完美呈現影片與Spyder.https://yangyami.blogspot.com/2025/06/def-pvrnmfrnmf-p-mr1-11rnf1rn-return-p.html
https://sincewayne.blogspot.com/2025/06/h1-margin-0-padding-20px-0-color-000000.html
回覆刪除https://winnielee0311.blogspot.com/2025/06/javascriptirr.html
回覆刪除https://pagestjing.blogspot.com/2025/06/javascriptpythonirr.html
回覆刪除520.https://pagestjing.blogspot.com/2025/05/javascriptsincoscanvasfont.html
刪除513.https://pagestjing.blogspot.com/2025/05/javascript_12.html
507.https://pagestjing.blogspot.com/2025/05/javascript.html
422.https://pagestjing.blogspot.com/2025/04/htmlbuttononclick.html
318.https://pagestjing.blogspot.com/2025/03/javascriptpython.html
311.https://pagestjing.blogspot.com/2025/03/pythonlistarraytuplesetdict.html
304.https://pagestjing.blogspot.com/2025/03/w3schoolspython.html
225.https://pagestjing.blogspot.com/2025/02/chatgpt.html
https://mumeng-ru.blogspot.com/2025/06/h1-margin-0-padding-20px-0-color-000000.html
回覆刪除一影片
刪除https://zhuo-1005.blogspot.com/2025/06/blog-post.html
回覆刪除https://zhang-1108.blogspot.com/2025/06/javascriptpythonirr.html
回覆刪除地表上最帥的男人就是張東煌https://youtu.be/YnH5gFiLzK8?si=jiz-i7eIItAVvo2s
刪除https://kiannc1201.blogspot.com/2025/06/javascriptpythonirr.html
回覆刪除https://www.youtube.com/watch?v=Y_8VaLcky7s&t=1s
刪除https://chinenkohana.blogspot.com/2025/06/javascriptsincoscanvasfont.html
回覆刪除nice video made by you.https://chinenkohana.blogspot.com/2025/05/javascriptsincoscanvasfont.html
刪除https://xu-bing-wei-0804.blogspot.com/2025/06/h1-margin-0-padding-20px-0-color-000000.html
回覆刪除沒有影片
刪除https://pei940922.blogspot.com/2025/06/h1margin-0-padding-20px-0-color-000000.html
回覆刪除sin cos.https://pei940922.blogspot.com/2025/05/javascriptfontfillstylefilltext.html
刪除https://slu804387.blogspot.com/2025/06/h1margin-0-padding-20px-0-color-000000.html
回覆刪除沒有EXCEL對照https://slu804387.blogspot.com/2025/06/h1margin-0-padding-20px-0-color-000000.html
刪除https://xuan-ang.blogspot.com/2025/06/blog-post.html
回覆刪除沒有使用Excel對照https://ting100000.blogspot.com/2025/06/h1-margin-0-padding-20px-0-color-000000.html
回覆刪除https://yangyoyo0125.blogspot.com/2025/06/javascriptpythonirr.html
回覆刪除拷貝老師的截圖自己沒有做https://yangyoyo0125.blogspot.com/2025/06/pythonexcel-pv.html
刪除https://d11117242.blogspot.com/2025/06/javascriptpythonirr.html
回覆刪除只有貼上https://d11117242.blogspot.com/2025/06/javascriptpython.html
刪除https://d11117315111.blogspot.com/2025/06/javascriptpythonirr.html
回覆刪除