science:social:economics:finance:option-simulator

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
science:social:economics:finance:option-simulator [2025/10/04 14:02] falsycatscience:social:economics:finance:option-simulator [2025/10/04 15:56] (current) falsycat
Line 1: Line 1:
-====== Option Price Simulator ======+====== Option PnL Simulator ======
  
-<WRAP TODO>WIP</WRAP>+[[black-scholes-equation]]に基づいて、オプションの損益をシミュレーションするためのツールです。 
 +テキストエリアに建玉を入力してCalcボタンを押すと、縦軸を原資産価格、横軸を満期までの日数とした損益のヒートマップを生成することができます。 
 +建玉の入力記法については[[#how-to-use]]を参照してください。
  
 <html> <html>
Line 7: Line 9:
  
 <div id="heatmap_param"> <div id="heatmap_param">
-  <div><textarea class="script">LC@45000#5$100</textarea></div> +  <div><textarea class="script" style="height: 16rem">SC@22000#5$130 
-  <div style="width: 32rem">+LC@21750#5$250x2 
 +SC@21500#5$390</textarea></div> 
 +  <div style="width: 40rem">
     <table>     <table>
       <tr><td>IV</td><td><input class="iv" type="number" value="0.2" /></td><td>1=100%</td></tr>       <tr><td>IV</td><td><input class="iv" type="number" value="0.2" /></td><td>1=100%</td></tr>
Line 62: Line 66:
   const priceMin = Math.min(...pos.map(x => x.strike))*0.8;   const priceMin = Math.min(...pos.map(x => x.strike))*0.8;
   const priceMax = Math.max(...pos.map(x => x.strike))*1.2;   const priceMax = Math.max(...pos.map(x => x.strike))*1.2;
-  const priceStep = (priceMax - priceMin)/50;+  const priceStep = (priceMax - priceMin)/100;
   let prices = [];   let prices = [];
   for (let S = priceMin; S <= priceMax; S+=priceStep) {   for (let S = priceMin; S <= priceMax; S+=priceStep) {
Line 81: Line 85:
       for (const p of pos) {       for (const p of pos) {
         if (p.open_at >= T) {         if (p.open_at >= T) {
-            const open_vol = p.open_price * p.count;+            const open_vol = p.open_price;
             const curr_vol = blackScholes(S, p.strike, T/252, r, p.iv, p.type);             const curr_vol = blackScholes(S, p.strike, T/252, r, p.iv, p.type);
             pnl += p.count*(p.side === "short"?             pnl += p.count*(p.side === "short"?
Line 149: Line 153:
     z: z,     z: z,
     zmid: 0,     zmid: 0,
-    type: 'heatmap'+    colorscale: [ 
 +      [0.0, 'blue'], 
 +      [0.49, 'lightblue'], 
 +      [0.5, 'black'], 
 +      [0.51, 'pink'], 
 +      [1.0, 'red'], 
 +    ], 
 +    type: 'heatmap'
 +     
 +    hovertemplate: 'Days Left: %{x}<br>Underlying Price: %{y}<br>Option PnL: %{z}<extra></extra>',
   }], {   }], {
-    xaxis: { autorange: 'reversed},+    title: {text: "Option PnL simulation"}, 
 +    xaxis: { 
 +      title: {text: "Days Left"}, 
 +      autorange: "reversed", 
 +      fixedrange: true, 
 +    }
 +    yaxis: { 
 +      title: {text: "Underlying Price"}, 
 +      fixedrange: true, 
 +    }, 
 +    dragmode: false,
   });   });
 }; };
Line 171: Line 194:
 ===== How To Use ===== ===== How To Use =====
  
 +単体の建玉は以下の記法で記述できます。
 +単体の建玉記述を1行ずつ記述することで、複数の建玉を記述することができます。
 +
 +<code>
 +(S/L)(C/P)@strike#open_at$open_price
 +  S/L: Short or Long
 +  C/P: Call or Put
 +  strike    : strike price
 +  open_at   : days left at open
 +  open_price: price at open
 +</code>
 +
 +==== 例 ====
 +
 +オプション戦略については[[option-strategy]]を参照。
 +
 +=== Short Iron Butterfly ===
 +
 +<code>
 +SC@21000#30$990
 +LC@20000#30$590
 +LP@20000#30$620
 +SP@19000#30$120
 +</code>
  • Last modified: 11 hours ago
  • by falsycat