Created
April 30, 2013 01:26
-
-
Save tristanwietsma/5486073 to your computer and use it in GitHub Desktop.
CME Eurodollar futures expiration date calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, date, timedelta | |
def EurodollarExpirations(): | |
start = datetime.now().date() | |
n = 20 | |
ex = [date(2008,12,15)] | |
for i in range(120): | |
x = ex[-1] | |
x += timedelta(days=91) | |
if x.day <= 12: x += timedelta(days=7) | |
ex.append(x) | |
ex = [e for e in ex if e >= start] | |
while len(ex) < n: | |
x = ex[-1] | |
x += timedelta(days=91) | |
if x.day <= 12: x += timedelta(days=7) | |
ex.append(x) | |
return ex[:n] | |
def Days360(start, stop): | |
days = 360 * (stop.year - start.year) | |
days += 30 * (stop.month - start.month) | |
sd = start.day | |
td = stop.day | |
feb28 = False | |
if start.month == 2: | |
next = start + timedelta(days=1) | |
if next.month == 3: | |
sd = 30 | |
feb28 = True | |
if stop.month == 2: | |
next = stop + timedelta(days=1) | |
if next.month == 3 and feb28: td = 30 | |
if td == 31 and sd in [30, 31]: td = 30 | |
if sd == 31: sd = 30 | |
days += td-sd | |
return days | |
def Plus90(mark): | |
m = mark + timedelta(days=80) | |
while Days360(mark, m) < 90: | |
m += timedelta(days=1) | |
return m | |
if __name__ == '__main__': | |
ex = EurodollarExpirations() | |
print ' CON EXP TERM DAYS' | |
for i in range(20): | |
x = ex[i] | |
year = x.year | |
month = {3:'H',6:'M',9:'U',12:'Z'}[x.month] | |
term = Plus90(x) | |
actual_days = (term - x).days | |
print str(i+1).ljust(2),\ | |
'GE%s%s'%(month, str(year)[-1]),\ | |
x.strftime('%Y%m%d'),\ | |
term.strftime('%Y%m%d'),\ | |
'',actual_days |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment