ids = np.isclose(spots[trims], H.spot) idv = np.isclose(vars[trimv], H.variance.value) dss = np.hstack((np.nan, np.diff(spots))) dvs = np.hstack((np.nan, np.diff(vars))) BADANALYTICAL = False bs = BlackScholesOption(spot=spots[:, np.newaxis], strike=H.strike, interest_rate=H.interest_rate.value, variance=vars[np.newaxis, :], tenor=H.tenor).analytical utils.tic("Heston Analytical:") hs = hs_call_vector(spots, H.strike, H.interest_rate.value, np.sqrt(vars), H.tenor, H.mean_reversion, H.mean_variance, H.vol_of_variance, H.correlation) utils.toc() hs = np.nan_to_num(hs) if max(hs.flat) > spots[-1] * 2: BADANALYTICAL = True print "Warning: Analytical solution looks like trash." if len(sys.argv) > 1: if sys.argv[1] == '0': print "Bail out with arg 0." sys.exit() def mu_s(t, *dim): return H.interest_rate.value * dim[0] def gamma2_s(t, *dim): return 0.5 * dim[1] * dim[0]**2
V_init = init(spots, nvols, k) V = np.copy(V_init) # bs, delta = [x for x in bs_call_delta(spots[:, newaxis], k, r, # np.sqrt(vars)[newaxis, :], t)] bs = BlackScholesOption(spot=spots[:, np.newaxis], strike=k, interest_rate=r, variance=vars[np.newaxis, :], tenor=t).analytical utils.tic("Heston Analytical:") # hss = array([hs_call(spots, k, r, np.sqrt(vars), # dt*i, kappa, theta, sigma, rho) for i in range(int(t/dt)+1)]) # hs = hss[-1] hs = hs_call_vector(spots, k, r, np.sqrt(vars), t, kappa, theta, sigma, rho) utils.toc() hs[isnan(hs)] = 0.0 if max(hs.flat) > spots[-1] * 2: BADANALYTICAL = True print "Warning: Analytical solution looks like trash." if len(sys.argv) > 1: if sys.argv[1] == '0': print "Bail out with arg 0." sys.exit() L1_ = [] R1_ = [] utils.tic("Building As(s):") print "(Up/Down)wind from:", flip_idx_spot