Example 2

The below scripts use the functions getFeasibleOptionFlags and getMidPriceQReg to clean the list of options given in spoptions.txt and return the Q distribution.

In the following script:

  • sp_np represents the spot prices in 4 different states of the world

  • bid_np represents the bid prices of different options

  • ask_np represents the ask prices of different options

  • strike_np represents the strike prices of different options

  • pFlag_np indicates whether an option si a call or a put option

  • fw is the forward price

import dbbpy
import numpy as np 

fw_data = np.loadtxt("forward1.txt", delimiter='\t')
data = np.loadtxt("spopt1.txt", delimiter='\t')

strike_list = data[:, 0]
pFlag_list = data[:, 1]
bid_list = data[:, 2]
ask_list = data[:, 3]

min_strike = int(np.min(strike_list))
max_strike = int(np.max(strike_list))

sp = list(range(0, min_strike, 10)) + list(range(min_strike, max_strike, 5)) + list(range(max_strike, 4440, 10))

sp_np = np.array(sp)
bid_np = np.array(bid_list)
ask_np = np.array(ask_list)
strike_np = np.array(strike_list)
pFlag_np = np.array(pFlag_list, dtype=bool)
fw = fw_data[0]

feasible_options = dbbpy.getFeasibleOptionFlags(sp_np, bid_np, ask_np, strike_np, pFlag_np, fw, fw-0.02, fw+0.02)
q = dbbpy.getMidPriceQReg(sp_np, bid_np[feasible_options], ask_np[feasible_options], strike_np[feasible_options], pFlag_np[feasible_options],  fw, fw-0.02, fw+0.02)
print(q)
File including options data
File including the forward price

Last updated