fix: payoff chart zoomed to 1.5 SD range instead of 8% flat pad

This commit is contained in:
Manohar 2026-05-27 19:16:30 +05:30
parent ef459facfc
commit b2e6ef940a

View file

@ -582,12 +582,16 @@ async function loadPayoff() {
var mktKey = ul==='SENSEX'?'SENSEX': ul==='NIFTY'?'NIFTY50': ul==='BANKNIFTY'?'BANKNIFTY': null; var mktKey = ul==='SENSEX'?'SENSEX': ul==='NIFTY'?'NIFTY50': ul==='BANKNIFTY'?'BANKNIFTY': null;
var spot = mktKey ? (mktMap[mktKey]||0) : 0; var spot = mktKey ? (mktMap[mktKey]||0) : 0;
// Price range // Price range: ±1.5 SD from spot (uses VIX if available, else 18% ann vol)
// This keeps the chart tight and readable — widens only as much as vol suggests
var vixForRange=(window._mktCache&&window._mktCache['INDIAVIX'])?window._mktCache['INDIAVIX'].price:0;
var sdRange = calcSD(spot||75000, typeof dte==='number'?dte:7, vixForRange);
var rangePad = sdRange.sd1 * 1.5;
var strikes = opts.map(function(p){return p._parsed.strike;}); var strikes = opts.map(function(p){return p._parsed.strike;});
var minS = Math.min.apply(null,strikes), maxS = Math.max.apply(null,strikes); var minS = Math.min.apply(null,strikes), maxS = Math.max.apply(null,strikes);
var pad = Math.max((maxS-minS)*0.6, minS*0.08); // Ensure all strikes are visible even if outside 1.5SD
var lo = Math.floor((Math.min(minS, spot||minS)-pad)/100)*100; var lo = Math.floor((Math.min(minS, spot-rangePad))/100)*100;
var hi = Math.ceil((Math.max(maxS, spot||maxS)+pad)/100)*100; var hi = Math.ceil((Math.max(maxS, spot+rangePad))/100)*100;
var step = Math.max(Math.round((hi-lo)/100/100)*100, 50); var step = Math.max(Math.round((hi-lo)/100/100)*100, 50);
var xs=[], ys=[]; var xs=[], ys=[];