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)




"DTN feed was the only feed that consistently matched Bloomberg feed for BID/ASK data verification work these past years......DTN feed is a must for my supply & demand based trading using Cumulative Delta" - Comment from Public Forum Post
"There is no doubt that IQFeed is the best data provider. I am very satisfied with your services. And IQFeed is the only one that I would recommend to my friends. Now, most of them are using your product in China." - Comment from Zhezhe
"IQ feed works very well, does not have all of the normal interruptions I have grown used to on *******" - Comment from Mark
"Excellent datafeed !!!" - Comment from Arely
"If you are serious about your trading I would not rely on IB data for serious daytrading. Took me a while to justify the cost of IQ Feed and in the end, it's just a 2 point stop on ES. Better safe than sorry" - Comment from Public Forum
"After all the anxiety I had with my previous data provider it is a relief not to have to worry about data speed and integrity." - Comment from Eamonn
"I had always used ******* but for the past 2 weeks have been trying DTN IQFeed. Customer support has been extraordinary. They call just to make sure your problem hasn't recurred." - Comment from Public Forum
"I ran your IQFeed DDE vs. my broker vs. a level II window for some slow-moving options. I would see the level II quote change, then your feed update instantaneously. My broker's DDE, however, would take as much as 30 seconds to update. I am not chasing milliseconds, but half a minute is unacceptable." - Comment from Rob
"I cannot believe what a difference it makes trading with ProphetX!" - Comment from Bruce in Los Angeles
"Its working FABULOUSLY for me!! Holy cow...there has been so much I've been missing lately, and with this feed and Linnsoft software...I'm in the game now." - Comment from Chris R.
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 423 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 23, 2024 8:56 AM CFBB v1.2.0 8 ms.
© AderSoftware 2002-2003