def test_eurond1d(self): dim = 1 T = 1 domain = DomainNd(np.array([[0, 3]], dtype=np.float64), T) vol_vec, ir, dividend_vec, strike = 0.1*np.ones(dim, dtype=np.float64), 0.03, 0.01*np.ones(dim, dtype=np.float64), 1 payoff_func = lambda x: tf.nn.relu(tf.math.reduce_sum(x, axis=1) - strike) corr_mat = 0.25 * np.ones((dim, dim), dtype=np.float64) np.fill_diagonal(corr_mat, 1) solver = Euro(payoff_func, domain, vol_vec, ir, dividend_vec, corr_mat) solver.run(n_samples=2000, steps_per_sample=1, n_interior=8, n_terminal=8)
def test_euroV3_4d_dirichlet(self): dim = 4 T = 1.0 domain = DomainNd(np.array([[20, 60], [20, 60], [20, 60], [20, 60]], dtype=np.float64), T) vol_vec, ir, dividend_vec, stri = 0.2*np.ones(dim, dtype=np.float64), 0.06, 0.04*np.ones(dim, dtype=np.float64), 40.0 payoff_func = lambda x: tf.nn.relu(tf.pow(tf.math.reduce_prod(x, axis=1), 1/dim) - stri) payoff_func.strike = stri corr_mat = 0.25 * np.ones((dim, dim), dtype=np.float64) np.fill_diagonal(corr_mat, 1.0) solver = EuroV3(payoff_func, domain, vol_vec, ir, dividend_vec, corr_mat) solver.run(n_samples=80000, steps_per_sample=1, saved_name="euroV3_4d_geometric_diri")
def test_euroV2_2d(self): dim = 2 T = 1.0 domain = DomainNd(np.array([[0, 3], [0, 3]], dtype=np.float64), T) vol_vec, ir, dividend_vec, strike = 0.1*np.ones(dim, dtype=np.float64), 0.03, 0.01*np.ones(dim, dtype=np.float64), 1.0 # payoff_func = lambda x: tf.nn.relu(tf.math.reduce_sum(x, axis=1) - strike) payoff_func = lambda x: tf.nn.relu(tf.pow(tf.math.reduce_prod(x, axis=1), 1/dim) - strike) corr_mat = 0.25 * np.ones((dim, dim), dtype=np.float64) np.fill_diagonal(corr_mat, 1.0) solver = EuroV2(payoff_func, domain, vol_vec, ir, dividend_vec, corr_mat) solver.run(n_samples=50000, steps_per_sample=1, saved_name="euroV2_2d_geometric")
def test_euro_restore(self): model_name = "euro2d_geometric" T, dim = 1, 2 domain = DomainNd(np.array([[0, 3], [0, 3]], dtype=np.float64), T) vol_vec, ir, dividend_vec, strike = 0.1 * np.ones( dim, dtype=np.float64), 0.03, 0.01 * np.ones(dim, dtype=np.float32), 1 corr_mat = 0.25 * np.ones((dim, dim), dtype=np.float64) np.fill_diagonal(corr_mat, 1) S = np.array([[1, 1], [2, 2]], dtype=np.float64) t = np.zeros(2, dtype=np.float64).reshape(-1, 1) self.restore_helper_geometric(S, t, model_name, dim, T, domain, vol_vec, ir, dividend_vec, strike, corr_mat)
def test_euroV3_restore(self): model_name = "euroV3_4d_geometric_diri395405_80k" T, dim = 1, 4 domain = DomainNd( np.array([[39.5, 40.5], [39.5, 40.5], [39.5, 40.5], [39.5, 40.5]], dtype=np.float64), T) vol_vec, ir, dividend_vec, strike = 0.1 * np.ones( dim, dtype=np.float64), 0.03, 0.01 * np.ones( dim, dtype=np.float64), 40.0 corr_mat = 0.25 * np.ones((dim, dim), dtype=np.float64) np.fill_diagonal(corr_mat, 1) S = np.array([[40, 40, 40, 40], [40.5, 40.5, 40.5, 40.5], [39.5, 39.5, 39.5, 39.5],\ [40, 40, 40, 40], [40.5, 40.5, 40.5, 40.5], [39.5, 39.5, 39.5, 39.5]], dtype=np.float64) t = np.array([[0], [0], [0], [T], [T], [T]], dtype=np.float64) self.restore_helper_geometricV3(S, t, model_name, dim, T, domain, vol_vec, ir, dividend_vec, strike, corr_mat)