def linear_interpolation_for_synthetic_maturity_future(days, trade_date, expiration_dates, prices): """Linearly interpolate. Will break if it can't find a future on each side of the requested maturity. Moving the garbage to another function so the real function can be properly implemented at a later date. TODO: For now, this will just linearly interpolate between the nearest 2 surrounding futures. Should rewrite. This will serve initial purpose though for only a 90 day interpolated price for hist vol studies. """ dte = [i.days for i in (expiration_dates - trade_date)] if not all(np.diff(dte) >= 0): print "DATES NOT ORDERED WELL" print expiration_dates print prices ipshell() try: synth_fut = np.interp(days, dte, prices) # print "-" *20 # print "synth fut, days: %s, %s" % (synth_fut, days) # print "dte: %s" % dte # print "pxs: %s" % prices # ipshell() except: print "-" *20 print "dte: %s" % dte print "pxs: %s" % prices ipshell() return synth_fut
line, = pyplot.plot(0, 0, "bo") dot, = pyplot.plot(0, 0, "ro") interval = 0.0 ylim_window = 12 synth_maturities = [100, 200, 300] synth_fut_dict = dict((synth_maturity, []) for synth_maturity in synth_maturities) DEBUG = False for trade_date in trade_dates: if DEBUG: if trade_date in freeze_dates: print expiration_dates print settles print closes ipshell() df = execute_query_DF(conn, SQL_get_futures_for_trade_date % trade_date) closes = df("px_close") settles = df("px_settle") prices = settles expiration_dates = df("exp_date") # if abs( (trade_date - datetime.date(1991, 4, 11)).days ) <= 1: # pass # # weird day. # ipshell() # bad_prints = (prices > 8000) + (prices < 10) if any(bad_prints):