Exemplo 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
Exemplo n.º 2
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
Exemplo n.º 3
0
def monthCode(month):
    codes = ('F','G','H','J','K','M','N','Q','U','V','X','Z')
    if isinstance(month,int):
        return codes[month-1]
    elif isinstance(month,str):
        return codes.index(month)+1
    else:
        raise ValueError('Function accepts int or str')
    
    
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

def getHistoricData(symbol):
    ''' get historic data from CBOE
        symbol: VIX or VXV
        return dataframe
# time deltas
someDate = dt.date(2011, 8, 1)
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)
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 xrange(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