Skip to content

Commit ee2335a

Browse files
authored
fix the expiration mismatch between futures and options
1 parent 31131d2 commit ee2335a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

CME3.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_expiration_data(expiration_json,options_id):
4343

4444
expiration_dict=expiration_json[str(options_id)]['expirations']
4545

46-
return [expiration_dict[i]['expiration'] for i in expiration_dict]
46+
return [(expiration_dict[i]['expiration'],expiration_dict[i]['label']) for i in expiration_dict]
4747

4848

4949
# In[4]:
@@ -153,7 +153,7 @@ def main():
153153
target_exp_id=get_expiration_data(response_expiration.json())
154154

155155
#get option data
156-
for expiration_id in target_exp_id:
156+
for expiration_id,expiration_date in target_exp_id:
157157

158158
option_url=f'https://www.cmegroup.com/CmeWS/mvc/Quotes/Option/{option_id}/G/{expiration_id}/ALL?optionProductId={option_id}&strikeRange=ALL'
159159
response_option=scrape(option_url)
@@ -200,6 +200,11 @@ def main():
200200

201201
df=df[target]
202202

203+
#fix the expiration mismatch between futures and options
204+
#or you can use cme rule based month coding system
205+
# https://www.cmegroup.com/month-codes.html
206+
df['futures-expirationDate']=pd.to_datetime(expiration_date)
207+
203208
df.to_csv(f'corn option {expiration_id}.csv',index=False)
204209

205210
except ValueError:

0 commit comments

Comments
 (0)