2025年12月衍生性金融商品作業

canvas繪圖套件繪製選擇權到期日損益圖

以上程式碼在下面,你們複製、貼上,再去修改

<style>
canvas{border:20px}
option{font-size:24px;background:pink;}
h1{background-image: linear-gradient(orange, blue);text-align:center;padding:10px;color:white;}</style>
<script>
function dashed(){
const c = document.getElementById("Options");
const ctx = c.getContext("2d");
ctx.beginPath();
ctx.moveTo(100,0);
ctx.lineTo(100,500);
ctx.strokeStyle="green";
ctx.setLineDash([10,10]);
ctx.lineWidth=1;
ctx.stroke();
ctx.beginPath();
ctx.moveTo(200,0);
ctx.lineTo(200,500);
ctx.strokeStyle="green";
ctx.setLineDash([10,10]);
ctx.lineWidth=1;
ctx.stroke();
}
function putBear(){
const c = document.getElementById("Options");
const ctx = c.getContext("2d");
ctx.reset();
ctx.beginPath(); //開始繪製
ctx.moveTo(100, 0);
ctx.lineTo(200, 100);
ctx.lineTo(300,100);
ctx.font = "24px Arial";
ctx.fillText("買入履約價120的賣權puts",300,50);
ctx.strokeStyle = "red";
ctx.lineWidth = 5;
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0, 300);
ctx.lineTo(100, 200);
ctx.lineTo(300,200);
ctx.font = "24px Arial";
ctx.fillText("賣出履約價100的賣權puts",300,250);
ctx.strokeStyle = "blue";
ctx.lineWidth = 5;
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0, 400);
ctx.lineTo(100, 400);
ctx.lineTo(200,500);
ctx.lineTo(300,500);
ctx.font = "24px Arial";
ctx.fillText("100至120賣權空頭Put Bear價差",300,450);
ctx.strokeStyle = "black";
ctx.lineWidth = 5;
ctx.stroke();}
  
function callBull(){
const c = document.getElementById("Options");
const ctx = c.getContext("2d");
ctx.reset();
ctx.beginPath();
ctx.moveTo(0, 100);
ctx.lineTo(100, 100);
ctx.lineTo(200,0);
ctx.font = "24px Arial";
ctx.fillText("買入履約價100的買權Call",300,50);
ctx.strokeStyle = "red";
ctx.lineWidth = 5;
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0, 200);
ctx.lineTo(200, 200);
ctx.lineTo(300,300);
ctx.font = "24px Arial";
ctx.fillText("賣出履約價120的買權Call",300,250);
ctx.strokeStyle = "blue";
ctx.lineWidth = 5;
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0, 500);
ctx.lineTo(100, 500);
ctx.lineTo(200,400);
ctx.lineTo(300,400);
ctx.font = "24px Arial";
ctx.fillText("100至120買權多頭Call Bear價差",300,450);
ctx.strokeStyle = "black";
ctx.lineWidth = 5;
ctx.stroke();}
function putBull(){
const c = document.getElementById("Options");
const ctx = c.getContext("2d");
ctx.reset();
ctx.beginPath(); //開始繪製
ctx.moveTo(0, 0);
ctx.lineTo(100, 100);
ctx.lineTo(200,100);
ctx.lineTo(300,100);
ctx.font = "24px Arial";
ctx.fillText("買入履約價100的賣權Put",300,50);
ctx.strokeStyle = "red";
ctx.lineWidth = 5;
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0,300);
ctx.lineTo(100, 300);
ctx.lineTo(200, 200);
ctx.lineTo(300,200);
ctx.font = "24px Arial";
ctx.fillText("賣出履約價120的賣權Put",300,250);
ctx.strokeStyle = "blue";
ctx.lineWidth = 5;
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0, 500);
ctx.lineTo(100, 500);
ctx.lineTo(200,400);
ctx.lineTo(300,400);
ctx.font = "24px Arial";
ctx.fillText("100至120賣權多頭Put Bear價差",300,450);
ctx.strokeStyle = "black";
ctx.lineWidth = 5;
ctx.stroke();}
 
function callBear(){
const c = document.getElementById("Options");
const ctx = c.getContext("2d");
ctx.reset();
ctx.beginPath();
ctx.moveTo(0, 100);
ctx.lineTo(200, 100);
ctx.lineTo(300,0);
ctx.font = "24px Arial";
ctx.fillText("買入履約價120的買權Call",300,50);
ctx.strokeStyle = "red";
ctx.lineWidth = 5;
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0, 300);
ctx.lineTo(100, 200);
ctx.lineTo(300,200);
ctx.font = "24px Arial";
ctx.fillText("賣出履約價100的買權Call",300,250);
ctx.strokeStyle = "blue";
ctx.lineWidth = 5;
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0, 400);
ctx.lineTo(100, 400);
ctx.lineTo(200,500);
ctx.lineTo(300,500);
ctx.font = "24px Arial";
ctx.fillText("100至120買權空頭Call Bear價差",300,450);
ctx.strokeStyle = "black";
ctx.lineWidth = 5;
ctx.stroke();}
function clear()
{const c = document.getElementById("Options");
const ctx = c.getContext("2d")
ctx.reset();}
function Check (reply)
{
const element = document.getElementById('select');
 if ( reply == 'clear' ) clear();
 if ( reply == 'putbear' ){putBear(); dashed();};
 if ( reply == 'callbull' ){callBull();dashed();};
 if ( reply == 'putbull' ){putBull();dashed();};
 if ( reply == 'callbear' ){callBear();dashed();};
}
</script>
<h1>canvas繪圖套件繪製選擇權到期日損益圖</h1>
<label>選擇權價差交易策略</label>
<select id="select" onchange="Check(this.value)">
      <option value="clear">清空</option>
      <option value="putbear">賣權put空頭價差</option>
      <option value="callbull">買權call多頭價差</option>
      <option value="putbull">賣權put多頭價差</option>
      <option value="callbear">買權call空頭價差</option>
</select>
<canvas height="600" id="Options" width="700"></canvas>

留言

  1. 財金系,我一定交網頁相關,尤其是canvas和已開發國家小學用的scrarch,他們都是用網路語言JavaScript寫的。最普遍的工具用在學生的學習,這才有學習效果,過去幾年資管系辦的那些研習,教學用不上,對老師的幫助也沒有。我不去參加這些研習,是不能浪費時間在為學生準備有用的課程,不懂,卻又不能讓人覺得沒在做事,就是在瞎忙!

    回覆刪除
  2. https://lin-cheng-yu.blogspot.com/2025/12/blog-post.html

    回覆刪除
  3. https://whitexd.blogspot.com/2025/12/canvasborder20px-optionfont.html?m=1

    回覆刪除
  4. https://lijiauyn.blogspot.com/2025/12/blog-post.html

    回覆刪除
  5. https://hsiao-yu0711.blogspot.com/2025/12/blog-post_10.html

    回覆刪除
  6. https://s10655075.blogspot.com/2025/12/blog-post.html

    回覆刪除
  7. https://xi07.blogspot.com/2025/12/blog-post.html

    回覆刪除
  8. https://d11217130.blogspot.com/2025/12/d11217130.html?m=1

    回覆刪除
  9. https://yunn-xin.blogspot.com/2025/12/blog-post_10.html

    回覆刪除
  10. https://yuechen613.blogspot.com/2025/12/blog-post.html

    回覆刪除
  11. https://the-most-great-hsing-tsen.blogspot.com/2025/12/canvasborder20px-optionfont.html

    回覆刪除
  12. https://michelle814.blogspot.com/2025/12/blog-post.html

    回覆刪除
  13. https://www.blogger.com/blog/post/edit/preview/1173902976928833486/8816739683597271270

    回覆刪除
  14. https://the-most-great.blogspot.com/2025/12/blog-post.html

    回覆刪除
  15. https://yrye4312311.blogspot.com/2025/12/d11217107.html

    回覆刪除
  16. https://yiminglinn.blogspot.com/2025/12/blog-post.html

    回覆刪除
  17. https://chenyoukai.blogspot.com/2025/12/blog-post.html

    回覆刪除
  18. https://the-most-great-tony11.blogspot.com/2025/12/blog-post.html

    回覆刪除
  19. https://56788888.blogspot.com/2025/12/canvas.html

    回覆刪除
  20. https://xuan0729.blogspot.com/2025/12/blog-post.html

    回覆刪除
  21. https://zhengyuzhe.blogspot.com/2025/12/blog-post.html?m=1

    回覆刪除
  22. https://draft.blogger.com/u/2/blog/post/edit/preview/1538851669311843874/78420916459695192

    回覆刪除
  23. https://ehiwkewh.blogspot.com/2025/12/blog-post_17.html?m=1

    回覆刪除
  24. https://themostgreatteacher.blogspot.com/2025/12/blog-post.html

    回覆刪除
  25. https://rubylinnn.blogspot.com/2025/12/blog-post.html

    回覆刪除
  26. 作者已經移除這則留言。

    回覆刪除
  27. https://www.blogger.com/u/2/blog/post/edit/7887220793710142577/3805035506061689940

    回覆刪除
  28. 陳麗慧https://huilii.blogspot.com/2025/12/canvasborder20px-optionfont.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

金三甲期末考重要題庫與額未加分作業

空頭價差多頭價差跨式勒式