2020年11月29日 星期日

第13週WORD巨集+表單+TypeText+TypeParagraph+字串

 Exponential指數
 logarithmic對數


Const period As Integer = 4

Const maxerror As Double = 0.0000001

Dim payment(period) As Double '廣域變數 4 維度的陣列

Private Sub CommandButton1_Click()

  Dim a, b, c, f, gap As Double

  Dim loopNumber As Integer

  a = 0

  b = 1

  gap = 10

  loopNumber = 10

  payment(0) = TextBox1.Value

  payment(1) = TextBox2.Value

  payment(2) = TextBox3.Value

  payment(3) = TextBox4.Value

  f = npv(a)

  If f = 0 Then

     Label9.Caption = 0

  ElseIf f < 0 Then

     Label9.Caption = "內部報酬率小於 0."

  Else

     Do While gap > mexerror And Abs(f) > maxerror And loopNumber < 100

       loopNumber = loopNumber + 1

       c = (a + b) / 2

       f = npv(c)

       If Abs(f) > maxerror And gap > maxerror Then

          If f > 0 Then

            a = c

          Else

            b = c

            gap = b - a

          End If

        Else

          Label9.Caption = c

       End If

     Loop

  End If

  Label10.Caption = f

  Label11.Caption = loopNumber

'以下是將結果輸出到WORD文件

  Selection.TypeText ("躉繳:" & TextBox1.Value & "第 1 期:" & TextBox2.Value & "第 2 期:" & TextBox3.Value & "第 3 期:" & TextBox4.Value & "第 4 期:")

  Selection.TypeParagraph

  Selection.TypeText ("內部報酬率:" & c)

  Selection.TypeParagraph

  Selection.TypeText ("淨現值:" & f)

  Selection.TypeParagraph

  Selection.TypeText ("迴圈次數:" & loopNumber)

  Selection.TypeParagraph

End Sub

Private Sub CommandButton2_Click()

  End

End Sub

Function npv(rate) '計算特定折現率rate的淨現值

  Dim y As Double

  Dim j As Integer

  y = -payment(0)

  For j = 1 To period

      y = y + payment(j) / (1 + rate) ^ j

  Next

  npv = y

End Function


2020年11月22日 星期日

第12週 蔣姿如 教你金融計算

躉繳第1期第2期第3期第4期

注意,包含首期躉繳的現金流量都大於0。

報酬率:

淨現值:

迴圈次數:

蔣姿如向劉任昌學習的程式碼

<head> <style> .pmt { width: 80pt; height: 20pt; background-color: coral; color: black; font-weight: bold; text-align: right; } .pig { width: 80pt; height: 20pt; background-color: lightblue; color: black; font-weight: bold; text-align: right; </style> <!--寬度width,高度height,背景珊瑚色background-color: coral,顏色color,文字排列text-align--> </head> <table border="1"> <tbody><tr align="center"><td>躉繳</td><td>第1期</td><td>第2期</td><td>第3期</td><td>第4期</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> <td><input class="pmt" type="number" /></td></tr> </tbody></table><br /> 注意,包含首期躉繳的現金流量都大於0。 <p><input onclick="IRR()" type="button" value="計算內部報酬率" /></p> <!--按下 button 去執行 JavaScript IRR( )--> <p>報酬率: <b class="pig" id="irr"></b></p> <p>淨現值: <b class="pig" id="npv"></b></p> <p>迴圈次數: <b class="pig" id="loopNumber"></b></p> <!--paragragh 輸出計算結果--> <script> const period=5; //pmt class 被array 儲存0,1,2,3,4 constant常數 const maxerror = 0.000001; var payment = new Array(period); function IRR() { var a = 0; var b = 1; var c; 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 ) a = c; else b = c; 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>

2020年11月15日 星期日

蔣姿如第11週CSS+HTML+JavaScript金融計算

躉繳第1期第2期第3期第4期

注意,包含首期躉繳的現金流量都大於0。

報酬率:

淨現值:

迴圈次數:

2020年11月8日 星期日

蔣姿如 第十週陣列

2020年11月1日 星期日

第九週期中考 (蔣姿如)

中央銀行受財政部委託,發行 天期國庫券,
決標貼現率:年息 %。
則每萬元($10,000)新臺幣的發行價格是$ (價格)

影片說明

電子試算表發明人

 1978年,哈佛大學EMBA學生在教室中發明電子試算表(electronic spreadsheet),這個發明永遠改變人們利用電腦在商業應用的方式(forever changed how people use computers in business.)。後來,賈伯斯請比爾...