Dispersion Trading Strategy


Dispersion Trading Strategy:  As per your guide, output shows in error.

Hello Shanmuga,



Thanks for writing to us. Can you tell us where in which course, section and unit this error is in? Also, any error log our output that you can share with us. 

Course:  Options Trading Strategies In Python: Advanced

Section 2- Dispersion Trading Strategy.


Data manipulation

import numpy as np

import pandas as pd

import datetime


To calculate Greeks

import mibian


For Plotting

import matplotlib.pyplot as plt



import warnings

warnings.simplefilter("ignore")





HDFCBANK_Wt = 0.3258

HDFCBANK_Lot_Size = 500



ICICIBANK_Wt = 0.1966

ICICIBANK_Lot_Size = 1375



KOTAKBANK_Wt = 0.1499

KOTAKBANK_Lot_Size = 400



AXISBANK_Wt = 0.1272

AXISBANK_Lot_Size = 1200



SBIN_Wt = 0.1020

SBIN_Lot_Size = 3000



BankNifty_Wt = 1.0

BankNifty_Lot_Size = 20



def read_data(inst_name):

    opt = pd.read_csv(inst_name  + ".csv")   

    fut = pd.read_csv("Banknifty_data.csv")

    opt = opt[opt['Open Int'] != 0]    

    opt = opt[['Symbol','Date','Expiry','Option Type','Strike Price','Close','futures_price']]                 

    return opt



BankNifty_Opt = read_data('Banknifty_data')

BankNifty_Opt = BankNifty_Opt[(BankNifty_Opt.Symbol=='BANKNIFTY')]

BankNifty_Opt.head()



def time_to_expiry(opt):

    opt.Expiry = pd.to_datetime(opt.Expiry)

    opt.Date = pd.to_datetime(opt.Date)

    opt['time_to_expiry']= (opt.Expiry - opt.Date).dt.days              

    return opt



BankNifty_Opt = time_to_expiry(BankNifty_Opt)  

BankNifty_Opt.head()    



def atm_strike_price(opt):

    opt['strike_distance'] = np.abs(opt.futures_price - opt['Strike Price'])  

    df = opt.groupby(['Date'])['strike_distance'].min().to_frame()

    df.index.column = 0

    opt = pd.merge(opt, df)    

    opt = opt[(np.abs(opt.futures_price - opt['Strike Price'])==opt.strike_distance)]    

    opt = opt.drop('strike_distance',1)

    opt = opt.drop_duplicates(subset=['Date','Expiry','Option Type'])

    return opt



full_BankNifty_opt = BankNifty_Opt

BankNifty_Opt = atm_strike_price(BankNifty_Opt)  

BankNifty_Opt.tail()





Result: TypeError: unsupported operand type(s) for -: 'str' and 'str'

Hello Shamuga,



I wasn't able to reproduce this error even with the parameter values you have set over here (which are different from the original notebook). Can you retrace your steps while you're customising the notebook? If the error persists please share the error screenshot.