def test_correlated_pricing(self): strike = 50 asset_num = 2 init_price_vec = np.array([110, 60]) vol_vec = np.array([0.4, 0.2]) ir = 0.1 dividend_vec = 0 * np.ones(asset_num) corr_mat = np.eye(asset_num) corr_mat[0, 1] = 0.4 corr_mat[1, 0] = 0.4 random_walk = GBM(182 / 365, 400, init_price_vec, ir, vol_vec, dividend_vec, corr_mat) def test_payoff(l): return max(l[0] - l[1] - strike, 0) opt = Euro(test_payoff, random_walk) np.random.seed(1) callV2 = opt.priceV2(1000000) real_call = 12.5583468 assert abs(callV2 - 12.566682253085943) < 0.00000000000001 assert abs(callV2 - real_call) / real_call < 0.00066374 np.random.seed(1) callV3 = opt.priceV3(20000) assert abs(callV3 - 12.586752483453562) < 0.00000000000001 assert abs(callV3 - real_call) / real_call < 0.0022619
def test_correlated_pricing(self): strike = 50 asset_num = 2 init_price_vec = np.array([110, 60]) vol_vec = np.array([0.4, 0.2]) ir = 0.1 dividend_vec = 0 * np.ones(asset_num) corr_mat = np.eye(asset_num) corr_mat[0, 1] = 0.4 corr_mat[1, 0] = 0.4 random_walk = GBM(182 / 365, 400, init_price_vec, ir, vol_vec, dividend_vec, corr_mat) def test_payoff(l): return np.maximum(l[:, 0] - l[:, 1] - strike, np.zeros(len(l))) opt = Euro(test_payoff, random_walk) np.random.seed(1) callV2 = opt.priceV2(1000000) real_call = 12.5583468 assert abs(callV2 - 12.566682253085943) < 0.00000000000001 assert abs(callV2 - real_call) / real_call < 0.00066374 np.random.seed(1) callV3 = opt.priceV3(20000) assert abs(callV3 - 12.586752483453562) < 0.00000000000001 assert abs(callV3 - real_call) / real_call < 0.0022619 """ Test 2: european 2d spread put """ np.random.seed(1) def test_payoff2(l): return np.maximum(-l[:, 0] + l[:, 1] + strike, np.zeros(len(l))) opt = Euro(test_payoff2, random_walk) spreadput2d = opt.priceV2(500000) assert abs(spreadput2d - 10.108531893795202) < 1e-10