option 2

add_shortcode(‘advanced_nse_option_chain’, function($atts){

$symbol = isset($atts[‘symbol’]) ? strtoupper($atts[‘symbol’]) : ‘NIFTY’;
$url = “https://www.nseindia.com/api/option-chain-indices?symbol=”.$symbol;

$response = wp_remote_get($url, [
‘headers’=>[
‘User-Agent’=>’Mozilla/5.0’,
‘Accept’=>’application/json’
],
‘timeout’=>20
]);

if(is_wp_error($response)) return “NSE Fetch Error”;

$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);

if(!$data || !isset($data[‘records’])) return “No Data”;

$records = $data[‘records’][‘data’];
$expiry_list = $data[‘records’][‘expiryDates’];
$spot = $data[‘records’][‘underlyingValue’];

// ——– Black Scholes Functions ——–
function n_cdf($x){ return 0.5*(1+erf($x/sqrt(2))); }
function n_pdf($x){ return (1/sqrt(2*pi()))*exp(-0.5*$x*$x); }

function greeks($type,$S,$K,$T,$r,$sigma){
if($T<=0 || $sigma<=0) return ['delta'=>0,’gamma’=>0,’theta’=>0,’vega’=>0];
$d1=(log($S/$K)+($r+0.5*$sigma*$sigma)*$T)/($sigma*sqrt($T));
$d2=$d1-$sigma*sqrt($T);
$delta = ($type==’CE’)? n_cdf($d1) : n_cdf($d1)-1;
$gamma = n_pdf($d1)/($S*$sigma*sqrt($T));
$vega = $S*n_pdf($d1)*sqrt($T)/100;
$theta = -($S*n_pdf($d1)*$sigma)/(2*sqrt($T));
return compact(‘delta’,’gamma’,’theta’,’vega’);
}

ob_start();
?>

Option Chain | Spot:



0 ? round($totalPE_OI/$totalCE_OI,2):0;
?>

PCR:
Total CE OI:
Total PE OI:

0,’gamma’=>0,’vega’=>0];
$peGreeks=[‘delta’=>0,’gamma’=>0,’vega’=>0];

if($ce && isset($ce[‘impliedVolatility’])){
$ceGreeks=greeks(‘CE’,$spot,$strike,$T,$r,$ce[‘impliedVolatility’]/100);
}
if($pe && isset($pe[‘impliedVolatility’])){
$peGreeks=greeks(‘PE’,$spot,$strike,$T,$r,$pe[‘impliedVolatility’]/100);
}

$atmClass = abs($strike-$spot)<50 ? 'atm':''; echo "

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;

echo “

“;

echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
}
?>

CALLS STRIKE PUTS
OI ChgOI LTP IV Delta Gamma Vega Delta Gamma Vega IV LTP ChgOI OI
“.($ce[‘openInterest’]??’-‘).” “.($ce[‘changeinOpenInterest’]??’-‘).” “.($ce[‘lastPrice’]??’-‘).” “.($ce[‘impliedVolatility’]??’-‘).” “.round($ceGreeks[‘delta’],3).” “.round($ceGreeks[‘gamma’],5).” “.round($ceGreeks[‘vega’],3).” $strike “.round($peGreeks[‘delta’],3).” “.round($peGreeks[‘gamma’],5).” “.round($peGreeks[‘vega’],3).” “.($pe[‘impliedVolatility’]??’-‘).” “.($pe[‘lastPrice’]??’-‘).” “.($pe[‘changeinOpenInterest’]??’-‘).” “.($pe[‘openInterest’]??’-‘).”

Scroll to Top