How to get latest weekly expiry date from NSEPython?

How to get latest weekly expiry date from this module as well as from Aliceblue?

Unsure of Aliceblue.

For weekly expiry, You just need to see the first expiry of any banknifty options.
For monthly expiry, You just need to see the first expiry of any banknifty futures.

Futures are monthly. Options are weekly.

Quick Workaround is Reliance Future’s latest expiry will be BankNIFTY’s monthly expiry.

Use this function expiry_list() -

print(expiry_list('BANKNIFTY'))

Output -

           Date
0   03-Jun-2021
1   10-Jun-2021
2   17-Jun-2021
3   24-Jun-2021
4   01-Jul-2021
5   08-Jul-2021
6   15-Jul-2021
7   22-Jul-2021
8   29-Jul-2021
9   26-Aug-2021
10  30-Sep-2021
11  30-Dec-2021

Alternatively, here is another quick hack -

Usage:

payload=nse_optionchain_scrapper('BANKNIFTY')
currentExpiry,dte=nse_expirydetails(payload,1)
print(currentExpiry)
print(dte)

As inp is 1 here, It is showing PCR of next expiry!

Output:

2021-06-10
11

So for the current weekly expiry, it will be -

payload=nse_optionchain_scrapper('BANKNIFTY')
currentExpiry,dte=nse_expirydetails(payload,0)
print(currentExpiry)
print(dte)
2021-06-03
4
1 Like

How can i get nearest expiry based on date for past dates??

Just get it from any dude who does backtesting. It will be small number of rows.

PS - NSE does not give such data; So the API does not cover it.