Ejemplo n.º 1
0
def vixExpiration(year, month):
    """
    expriration date of a VX future
    """
    t = datetime(year, month, 1) + datetools.relativedelta(months=1)

    offset = datetools.Week(weekday=4)
    if t.weekday() <> 4:
        t_new = t + 3 * offset
    else:
        t_new = t + 2 * offset

    t_exp = t_new - datetools.relativedelta(days=30)
    return t_exp
delta = today - someDate
print('Delta :', delta)

# calculate difference in dates
delta = dt.timedelta(days=20)
print('Today-delta=', today - delta)

t = dt.datetime(*time.strptime('3/30/2004', "%m/%d/%Y")[0:5])
# the '*' operator unpacks the tuple, producing the argument list.
print(t)

# print every 3d wednesday of the month
for month in range(1, 13):
    t = dt.date(2013, month, 1) + datetools.relativedelta(months=1)

    offset = datetools.Week(weekday=4)
    if t.weekday() != 4:
        t_new = t + 3 * offset
    else:
        t_new = t + 2 * offset

    t_new = t_new - datetools.relativedelta(days=30)
    print(t_new.strftime("%B, %d %Y (%A)"))

# rng = DateRange(t, t+datetools.YearEnd())
# print rng

# create a range of times
start = dt.datetime(2012, 8, 1) + datetools.relativedelta(hours=9, minutes=30)
end = dt.datetime(2012, 8, 1) + datetools.relativedelta(hours=22)