for expiration_date in expiration_dates: smile_count += 1 params['expiration_date'] = expiration_date # Get the necessary data sql = SQL.get_implied_forwards % params forward = execute_query_DF(conn, sql) synthetic_bids = forward('synthetic_bid') synthetic_offers = forward('synthetic_offer') days_to_expiration = (float(expiration_date) - float(t_date)) / seconds_per_day years_to_expiration = days_to_expiration / 365. print str(days_to_expiration).rjust(15), try: implied_forward = nerdy.find_implied_forward(synthetic_bids, synthetic_offers) except Exception, e: print "Exception: %s" % e ipshell("problem with IF") implied_rate = np.log(implied_forward / spot_closing_price) / years_to_expiration sql = SQL.get_strike_and_cvol_and_pvol_and_call_delta % params data = execute_query_DF(conn, sql) strikes = data('strike') call_ivs = data('call_iv') put_ivs = data('put_iv') call_delta = data('call_delta') strikes, call_ivs, put_ivs, call_delta = nerdy.clip_repeated_wings( strikes, call_ivs, put_ivs, call_delta) delta_wt_avg_implied_vols = call_ivs * (1 - call_delta) + put_ivs * call_delta # print "degree: %s, len(strikes): %s, t_date: %s, expiration_date: %s" % (degree, len(strikes), t_date, expiration_date) # Don't fit 0 or 1 points
from dataframe import * from sqlite3tools import * import sqlite3 DBNAME = "Levered_Financial_ETF_Option_and_Stock_DB.sqlite3" conn = sqlite3.connect(DBNAME) start_date = date(2009, 6, 1) SQL = """SELECT AlphaCurve.*, StockPrice.price_close AS spot, StockPrice.t_date AS stock_date FROM AlphaCurve JOIN StockPrice ON AlphaCurve.t_date=StockPrice.t_date AND AlphaCurve.symbol=StockPrice.symbol WHERE AlphaCurve.symbol='FAS' AND AlphaCurve.t_date > %s """ % datetime2epoch(start_date) results = execute_query_DF(conn, SQL) pivot_vol_yields = np.diff(np.log(results('pivot_vol'))) mean_vol_yields = np.diff(np.log(results('mean_vol'))) spot_yields = np.diff(np.log(results('spot'))) pyplot.plot(spot_yields, pivot_vol_yields, 'k*') pyplot.xlabel("spot yields") pyplot.ylabel("pivot vol yields") pyplot.show() ipshell("")