예제 #1
0
            # 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
            if len(strikes) < 2:
                skipped += 1
                continue
            # Don't fit if strike range does not contain forward
            if not( min(strikes) < implied_forward < max(strikes) ):
                skipped += 1
                continue

            # how should we fit this smile?
            degree = min(4, len(strikes) / 2)

            # fit it
            z = nerdy.moneyness(strikes, implied_forward, 1, years_to_expiration)
            try:
                ATF_vol = nerdy.fit_smile(z, delta_wt_avg_implied_vols, degree=degree)[-1]
                z = z / ATF_vol
                coeffs = list(nerdy.fit_smile(z, delta_wt_avg_implied_vols, degree=degree))
                while not len(coeffs) >= 5:
                    coeffs.insert(0,0)
            except Exception, e:
                fail += 1
                print "Exception:", e
                ipshell("WTF")
                raise Exception, e
            else:
                if DEBUG is True:
                    print
                    print "z:"
예제 #2
0
            strikes, call_ivs, put_ivs, call_delta = nerdy.clip_repeated_wings(
                                         strikes, call_ivs, put_ivs, call_delta)
            wt_avg_implied_vols = call_ivs * (1 - call_delta) + put_ivs * call_delta
            sql = SQL.get_fit_smile % params
            fit_params = execute_query_DF(conn, sql)

            if not fit_params.numrows() == 1:
                print "Error: More than one smile matching supposedly unique criteria."
                ipshell("")
                raise Exception
            vol = fit_params('vol')[0]
            skew = fit_params('skew')[0]
            kurt = fit_params('kurt')[0]
            wave = fit_params('wave')[0]
            wing = fit_params('wing')[0]
            z = nerdy.moneyness(strikes, implied_forward, vol, time_to_expiration)
            # coeffs = [ 10*wing[call_put], 20*wave[call_put], 20*kurt[call_put], 16.75*skew[call_put], vol[call_put] ]
            coeffs = [wing, wave, kurt, skew, vol]
            fit_vols = scipy.polyval(coeffs, z)

#            xmin = min(strikes)
#            xmax = max(strikes)
            time.sleep(.5)
            ATM_marker.remove()
            xmin = int(implied_forward * 1/2)
            xmax = int(implied_forward * 3/2)
            ymin = min(np.hstack((call_ivs, put_ivs)))
            ymax = max(np.hstack((call_ivs, put_ivs)))
            ATM_marker = pyplot.axvline(x=implied_forward, ymin=0, ymax=1, linewidth=10, color="#B0E0E6", zorder=0)
            pyplot.axis([xmin, xmax, ymin, ymax])
            pyplot.title("F: %s, date: %s, exp: %s, points:%s" % (