Join the 80,000 other DTN customers who enjoy the fastest, most reliable data available. There is no better value than DTN!

(Move your cursor to this area to pause scrolling)




"You are either overstaffed or people just don't have problems with your feed because customer support always answers the phone quickly." - Comment from Jay via Email
"Just a thank you for the very helpful and prompt assistance and services. You provided me with noticeably superior service in my setup compared to a couple of other options I had looked at." - Comment from John
"You have an excellent feed. Very few spikes for Spot Forex." - Comment from Public Forum Post
"I am a hedge fund manager here. It’s funny, I have a Bloomberg terminal and a Bridge feed, but I still like having my DTN feed!" - Comment from Feras
"I used to have *******, but they are way more money for the same thing. I have had no probs with data from DTN since switching over." - Comment from Public Forum Post
"I "bracket trade" all major news releases and I have not found one lag or glitch with DTN.IQ feed. I am very comfortable with their feed under all typical news conditions (Fed releases, employment numbers, etc)." - Comment from Public Forum
"I just wanted to let you know how fast and easy I found it to integrate IQFeed into our existing Java code using your JNI client. In my experience, such things almost never go so smoothly - great job!" - Comment from Nate
"Thank you so much - awesome feed, awesome service!" - Comment from Greg via Email
"Everything is working great ! Very impressive client. The news refreshes better and is more pertinent than the ******* feed I paid $ 100/month for. I Also like the charts a lot." - Comment from Leon
"I just wanted to let u know that your data feed/service is by far the best!!! Your unfiltered tick data is excellent for reading order flow and none of your competitors delivers this quality of data!" - Comment from Peter via Email
Home  Search  Register  Login  Recent Posts

Information on DTN's Industries:
DTN Oil & Gas | DTN Trading | DTN Agriculture | DTN Weather
Follow DTNMarkets on Twitter
DTN.IQ/IQFeed on Twitter
DTN News and Analysis on Twitter
»Forums Index »NEW IQFEED FORUMS »New IQFeed Forum »Futures Option Chain prices
Author Topic: Futures Option Chain prices (5 messages, Page 1 of 1)

emp
-Interested User-
Posts: 32
Joined: Aug 10, 2011


Posted: Apr 20, 2023 12:18 AM          Msg. 1 of 5
I opened a new thread for 1 question because my previous thread got cluttered with too many questions.

When I open the "IQFeed option chain" App, select "Futures Options" then type in the Futures symbols @ES and in the "Chains criteria" chose the month June and the year 2023 I almost instantly get a table with Open Interest numbers for all the options in the chain, see attached PDF.

When I however use my code below to access the Open Interest for all the option symbols in the chain it takes forever.

My question: is there a better way to access the open interest numbers. Maybe some automated way to save the data from the "IQFeed Option Chain" App to CSV files? How does IQFeed do this internally? I guess IQFeed stores these numbers somewhere where they can be accessed instantly in a table form?

thank you


 
# filesname: charpHistoricalDataTest.py
# To run code IQFeed should be launched already
# To run code type in the CMD window (path to python should be known)
# python charpHistoricalDataTest.py

# Dynamically add IQFeed.CSharpApiClient DLL
# for instructions see: https://github.com/mathpaquette/IQFeed.CSharpApiClient/blob/master/docs/USING-WITH-PYTHON.md
import sys
import clr
assembly_path = r'C:/Program Files/AmiBroker/IQFeedCSharpApiClient'
sys.path.append(assembly_path)
clr.AddReference("IQFeed.CSharpApiClient")
from System import DateTime
from datetime import datetime, timedelta
from IQFeed.CSharpApiClient.Lookup import LookupClientFactory
from IQFeed.CSharpApiClient.Lookup.Chains import OptionSideFilterType
import pandas as pd
import matplotlib.pyplot as plt

lookupClient = LookupClientFactory.CreateNew()
lookupClient.Connect()

def total_loss_at_strike(chainC, chainP, expiry_price):
"""Calculate loss at strike price"""
# All call options with strike price below the expiry price will result in loss for option writers
in_money_calls = chainC[chainC['Strike'] < expiry_price][["OpenInterest", "Strike"]]
in_money_calls["CE loss"] = (expiry_price - in_money_calls['Strike'])*in_money_calls["OpenInterest"]

# All put options with strike price above the expiry price will result in loss for option writers
in_money_puts = chainP[chainP['Strike'] > expiry_price][["OpenInterest", "Strike"]]
in_money_puts["PE loss"] = (in_money_puts['Strike'] - expiry_price)*in_money_puts["OpenInterest"]
total_loss = in_money_calls["CE loss"].sum() + in_money_puts["PE loss"].sum()

return total_loss

def createListofSymbolPlusStrikePrice(f_symbol, o_month, o_year, o_side):
f_symbol = str(f_symbol)
o_month = str(o_month)
o_year = str(o_year)

if( o_side == 1):
side = OptionSideFilterType.C
if( o_side == 2):
side = OptionSideFilterType.P

try:
ticks = lookupClient.Chains.GetChainFutureOption( f_symbol, side, o_month, o_year )
symbollist = '
strikepricelist = '
for tt in ticks:
symbollist += str(tt.Symbol)
symbollist += ','
strikepricelist += str(tt.StrikePrice)
#print(tt.StrikePrice)
strikepricelist += ','

# remove last comma
symbollist = symbollist[:len(symbollist)-1]
except Exception as err:
print(f"Unexpected {err=}, {type(err)=}")

return symbollist,strikepricelist

def getOpenInterestdata( sym, d1, d2 ):
sym = str(sym)
#ticks = lookupClient.Historical.GetHistoryDailyDatapoints(sym, 1)
ticks = lookupClient.Historical.GetHistoryDailyTimeframe(sym, d1, d2)

for tick in ticks:
s = str(tick)
datalist = s.split(',')
#print(int(str(datalist[6]).replace(' OpenInterest: ',')))
oi = int(str(datalist[6]).replace(' OpenInterest: ','))

return oi

def main():
##################
# input parameters
''
Month codes:
January: F
February: G
March: H
April: J
May: K
June: M
July: N
August: Q
September: U
October: V
November: X
December: Z
''
f_symbol = '@ES'
o_month = 'M'
o_year = '23'
##################

yesterday = datetime.now() - timedelta(1)
d1 = DateTime(yesterday.year,yesterday.month,yesterday.day)
d2 = DateTime(yesterday.year,yesterday.month,yesterday.day)

# Calls
symbollist,strikepricelist = createListofSymbolPlusStrikePrice(f_symbol, o_month, o_year, 1)
list1 = symbollist.split(',')
list2 = strikepricelist.split(',')
df_calls = pd.DataFrame(list(zip(list1, list2)), columns =['Symbols', 'Strike'])
df_calls = df_calls.astype({'Strike':'float'})
df_calls = df_calls.sort_values(by=['Strike'])
df_calls['OpenInterest'] = 0

idx = 0
for index, row in df_calls.iterrows():
sym = row['Symbols']
oi = getOpenInterestdata( sym, d1, d2 )
df_calls.iloc[idx, 2] = oi
print(idx,row['Strike'],row['Symbols'],oi)
idx += 1

print(df_calls)

# Puts
symbollist,strikepricelist = createListofSymbolPlusStrikePrice(f_symbol, o_month, o_year, 2)
list1 = symbollist.split(',')
list2 = strikepricelist.split(',')
df_puts = pd.DataFrame(list(zip(list1, list2)), columns =['Symbols', 'Strike'])
df_puts = df_puts.astype({'Strike':'float'})
df_puts = df_puts.sort_values(by=['Strike'])
df_puts['OpenInterest'] = 0

idx = 0
for index, row in df_puts.iterrows():
sym = row['Symbols']
oi = getOpenInterestdata( sym, d1, d2 )
df_puts.iloc[idx, 2] = oi
print(idx,row['Strike'],row['Symbols'],oi)
idx += 1

print(df_puts)

strikes = list(df_calls['Strike'])
losses = [total_loss_at_strike(df_calls, df_puts, strike)/1000000 for strike in strikes]

m = losses.index(min(losses))
print("Max pain > {}".format(strikes[m]))

plt.plot(strikes, losses)
plt.ylabel('Total loss in (Millon)')
plt.show()

if __name__ == "__main__":
main()



File Attached: optionschain.pdf (downloaded 434 times)

pawantanwar
-Interested User-
Posts: 1
Joined: Jul 19, 2023


Posted: Jul 19, 2023 05:29 AM          Msg. 2 of 5
The reason your code takes a long time to access open interest numbers for all the option symbols is likely due to the way it queries the data one by one, which can be time-consuming.

A better approach would be to directly access the data in bulk from IQFeed, if it provides such functionality. For example, you could check if IQFeed has an API method that allows you to retrieve the entire option chain's open interest data in one request, rather than making individual requests for each option symbol.

If such bulk data access is not available through IQFeed's API, another option could be to automate the process of exporting the data from the "IQFeed Option Chain" App into CSV files. This way, you can save the data locally and then read it into your code for analysis, which should be much faster than querying the data live each time.

As for how IQFeed internally handles and stores the data, it's proprietary information, and the exact implementation details are not publicly disclosed. However, most financial data providers optimize their data storage and retrieval systems to ensure fast and efficient access to data, especially for frequently requested information like option chain data.

To summarize, check if IQFeed has bulk data access through its API. If not, consider automating the export of data to CSV files for quicker access in your code. This way, you can improve the speed of accessing open interest numbers for your analysis.

emp
-Interested User-
Posts: 32
Joined: Aug 10, 2011


Posted: Jul 19, 2023 05:37 AM          Msg. 3 of 5
hi, thanks. Yes that is what I did. I exported the data to a CSV file and then processed that file with Python code. But I lost interest in the chains because I used them to do Max Pain calculations and I watched it for a while but it is basically pretty useless. It does not give predictions that are anywhere near accurate.

DTN_Gary_Stephen
-DTN Guru-
Posts: 394
Joined: Jul 3, 2019


Posted: Jul 20, 2023 09:55 AM          Msg. 4 of 5
Other than the FDS and EDS reports, there's no way to get a statistic in bulk for all symbols in an exchange. Whether a Level 1 watch or historical lookup, it has to retrieve the data symbol-by-symbol. The Options Chains command can filter for the option symbols you want, but you still have to retrieve the data for each. The Options Chains IQFeed client app does this to display Price, Open Interest, and other stats for each options symbol.

Sincerely,
Gary Stephen
DTN IQFeed Implementation Support Specialist

emp
-Interested User-
Posts: 32
Joined: Aug 10, 2011


Posted: Jul 21, 2023 04:59 AM          Msg. 5 of 5
thanks. Exporting from the options chains app worked fine for me. Gave the same result when I used the more time consuming method. But I have lost interest in option chains for the moment. At least this "Maximum Pain" method appears to be useless. It does not give accurate longer term predictions.
 

 

Time: Tue April 30, 2024 10:41 AM CFBB v1.2.0 19 ms.
© AderSoftware 2002-2003