發表文章

楊雅竹python執行IRR

圖片
維基百科數值分析二分法 pmt = [0,0,0,0] #劉任昌程式設計586設定串列list pmt[0]=float(input('躉繳金額: ')) for nper in range(1,4): pmt[nper] = float(input('第'+str(nper)+'期回收: ')) def npv(rate): y = - pmt[0] for j in range(1,4): y = y + pmt[j]/(1+rate)**j return y a, b, gap, f = 0.0, 1.0, 9.0, 9.0 maxerror = 0.000001 loopNumber = 1 while (gap > maxerror and abs(f) > maxerror and loopNumber < 100): loopNumber+=1 c = (a+b)/2; f = npv(c); if ( abs(f) > maxerror and gap > maxerror): if ( f>0 ): a = c else: b = c gap = b-a; print('報酬率: ', c) print('淨現值: ', f) print('迴圈次數: ', loopNumber)

楊雅竹期末考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."; ...

楊雅竹python自訂函數EXCEL PV和繪圖

圖片
python tkinter create_line利用tkinter繪圖 def pv(r,n,m,f):#楊雅竹函數參數r,n,m,f p = m/r*(1 - 1/(1+r)**n)+f/(1+r)**n return p#執行函數的結果傳回去 n=float(input('期數: '))#要計算轉為實數real nubers m=float(input('收付: '))#浮點點float f=float(input('終值: ')) for i in range(1,10):#迴圈 r = i*0.01 x=pv(r,n,m,f) print('利率 ', r ,'價格 ', x) import tkinter as tk#輸入tkinter繪圖 root = tk.Tk() root.title('楊雅竹python tkinter') root.geometry('600x300')#寬度width改成600 canvas = tk.Canvas(root, width=600, height=300) # 加入 Canvas 畫布 canvas.pack() x, y = 0, 0 canvas.create_line(0, 200, 500, 200, width=3,fill='black') for x in range(1, 200): x1 = x+1 y1 = 200 - pv(x1,n,m,f)*200 canvas.create_line(x, y, x1, y1, width=5,fill='blue') canvas.pack() x = x1 y = y1 root.mainloop()

楊雅竹Javascript與Python數值方法

圖片
PYTHON計算現值PRESENT VALUE程式碼 def computePV(): #python def函數: {} r = float(input('輸入利率: '))#float轉為實數 n = float(input('輸入期數: ')) m = float(input('輸入每期金額: ')) f = float(input('輸入終值: ')) pvif = 1/(1+r)**n pv = (1-pvif)*m/r + f * pvif print('現值等於 ',pv) #前面我們用Javascript這裡python #function: def #{區段} 同一個縮排indent同一個區段 computePV() 我會使用上面的PYTHON也會使用下面的JAVASCRIPT1 利率y(rate) 期數n(nper) 金流m(pmt) 終值f(fv) 參考楊雅竹金融市場講義https://drive.google.com/file/d/17z6UZgN5fC2XCO1L8_BQs57dgQXzbwou/view?usp=sharing 楊雅竹學習HTML+CSS+JavaScript程式碼 <style> h1{border: 30px outset red;     background-color: green;     color: white;   text-align: center;} </style> <script> function computePV(){   var r = document.getElementById("rate").value;   var n = document.getElementById("nper").value;   var m = document.getElementById("pmt").value;   var f = document.getElementById("fv").value;   pvif...

Javascript的輸出字體.font與fillStyle與fillText

圖片
Javascript在網頁就可以執行不需要開啟Spyder sin執行 cos執行 橫軸 以上程式碼 <style>BUTTON{BORDER:GREEN 5PX SOLID;BORDER-RADIUS:30PX;}</style> <h1>Javascript在網頁就可以執行不需要開啟Spyder</h1> <button onclick="LHsin()">sin執行</button> <button onclick="LHcos()">cos執行</button> <button onclick="xLine()">橫軸</button> <canvas height="400" id="my" style="background: black;" width="1200"></canvas> <script> var c = document.getElementById("my"); var cty = c.getContext("2d"); var g = 0.01;//增加一個廣域變數,用在下面的Math.sin(g*x); var h = 195; function LHsin() { var x = 0; var y = 200; cty.beginPath();  cty.lineWidth = 5;  cty.moveTo(x,y); while (x < 1000){   x = x + 1;   y = 200 - h * Math.sin(g*x);   cty.lineTo(x, y);   cty.strokeStyle = "yellow";   cty.stroke();    }; } function LHcos() { var x = 0; var y = 200-h;//上面的sin是y =200這裡要改掉 cty.beginPath();  cty.l...

三個javascript函數sin,cos與canvas,font

Javascript在網頁就可以執行不需要開啟Spyder sin執行 cos執行 橫軸 以上程式碼 <style>BUTTON{BORDER:GREEN 5PX SOLID;BORDER-RADIUS:30PX;}</style> <h1>Javascript在網頁就可以執行不需要開啟Spyder</h1> <button onclick="LHsin()">sin執行</button> <button onclick="LHcos()">cos執行</button> <button onclick="xLine()">橫軸</button> <canvas height="400" id="my" style="background: black;" width="1200"></canvas> <script> var c = document.getElementById("my"); var cty = c.getContext("2d"); var g = 0.01;//增加一個廣域變數,用在下面的Math.sin(g*x); var h = 180; function LHsin() { var x = 0; var y = 200; cty.beginPath();  cty.lineWidth = 5;  cty.moveTo(x,y); while (x < 1000){   x = x + 1;   y = 200 - h * Math.sin(g*x);   cty.lineTo(x, y);   cty.strokeStyle = "yellow";   cty.stroke();    }; } function LHcos() { var x = 0; var y = 200-h;//上面的sin是y =200這裡要改掉 cty.beginPath();  cty.l...

楊雅竹javascript執行三角函數繪圖

執行