File tree 1 file changed +7
-2
lines changed
1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ def get_expiration_data(expiration_json,options_id):
43
43
44
44
expiration_dict = expiration_json [str (options_id )]['expirations' ]
45
45
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 ]
47
47
48
48
49
49
# In[4]:
@@ -153,7 +153,7 @@ def main():
153
153
target_exp_id = get_expiration_data (response_expiration .json ())
154
154
155
155
#get option data
156
- for expiration_id in target_exp_id :
156
+ for expiration_id , expiration_date in target_exp_id :
157
157
158
158
option_url = f'https://www.cmegroup.com/CmeWS/mvc/Quotes/Option/{ option_id } /G/{ expiration_id } /ALL?optionProductId={ option_id } &strikeRange=ALL'
159
159
response_option = scrape (option_url )
@@ -200,6 +200,11 @@ def main():
200
200
201
201
df = df [target ]
202
202
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
+
203
208
df .to_csv (f'corn option { expiration_id } .csv' ,index = False )
204
209
205
210
except ValueError :
You can’t perform that action at this time.
0 commit comments