Option Trading strategies in Python: Intermediate

Is there any way to get the following fields, using NSEPY :

 

fut_near_month_close,  fut_far_month_close,  strike_price,  near_month_expiry,  LTP_near_month,  far_month_expiry,  LTP_far_month, 

This is being used in  Volatility Trading Strategies -  Unit 2: Strategy using Forward Volatility in the mentioned course of QUANTRA

You have to create the Nifty.csv from multiple futures contracts. You won't get that CSV directly from NSE India or NSEPy. 



To construct the Nifty.csv, you have to download the data for two futures contract for example Jan-2015 (near month) and Feb-2015 (far month). Then you need to combine the data of these two futures contract. The detail steps of these are mentioned below.



Step 1: Download the data for the near month contract.



nifty_fut_near_month = get_history(symbol="NIFTY",

                        start=date(2015,1,1),

                        end=date(2015,1,10),

                        index=True,

                        futures=True,

                        expiry_date=date(2015,1,29))




Step 2: Download the data for far month contract. Note, everything is the same except the expiry date.



nifty_fut_far_month = get_history(symbol="NIFTY",

                        start=date(2015,1,1),

                        end=date(2015,1,10),

                        index=True,

                        futures=True,

                        expiry_date=date(2015,2,26))




Step 3: Combine nifty_fut_near_month and nifty_fut_far_month dataframe and create a new dataframe. You can use pandas merge function here or can download the data in CSV with to_csv method and then can merge it in excel. The mappings of columns of Nifty.csv and the nifty contract is shown below.

 

nifty_fut_near_month nifty_fut_far_month
symbol Symbol Symbol
date date date
fut_near_month_close Close  
fut_far_month_close   Close
strike_price strike_price  
near_month_expiry Expiry  
LTP_near_month Last  
far_month_expiry   Expiry
LTP_far_month   Last

Thanks.
 

Where can i get strike price

Hi Anil,



As you know, the strike price is related to the options and can be retrieved through the NSE website or any of the authorised data vendors of NSE. You can check Section 2 unit 4 for the list of authorised data vendors. 



Hope this helps.

In the sample dataset provided. The strike price is constant what does it mean? I am not sure which strike price i need to include



symbol,date,fut_near_month_close,fut_far_month_close,strike_price,near_month_expiry,LTP_near_month,far_month_expiry,LTP_far_month

NIFTY,28-Aug-17,9950.8,9980.65,9800,28-Sep-17,226.45,26-Oct-17,293.6

NIFTY,29-Aug-17,9829.4,9860.15,9800,28-Sep-17,150.8,26-Oct-17,219.7

NIFTY,30-Aug-17,9912.45,9939.75,9800,28-Sep-17,191.2,26-Oct-17,259.7

NIFTY,31-Aug-17,9937.2,9963.35,9800,28-Sep-17,201.85,26-Oct-17,266.2



I want to implement this in live market . Here strike price LTP is mentioned is it CE or PE ?

What to short and what to buy ?



I am confused.Please help.

Hi Anil,



The strategy notebook uses NIFTY call options data. Usually the option which is at the money is chosen.



The strategy logic is mentioned in section 10 unit 1 where you calculate the forward volatility of the far month, or Option B and if the forward volatility of the far month (Option B) is more than the implied volatility of the near month (Option A), then you will go long on the near month (Option A) and go short on the far month (Option B).



Hope this clarifies.