diff options
Diffstat (limited to 'python/tests/test_cms_spread.py')
| -rw-r--r-- | python/tests/test_cms_spread.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/python/tests/test_cms_spread.py b/python/tests/test_cms_spread.py index 9ee89bbb..dbf3f218 100644 --- a/python/tests/test_cms_spread.py +++ b/python/tests/test_cms_spread.py @@ -16,7 +16,6 @@ from quantlib.experimental.coupons.cms_spread_coupon import ( CappedFlooredCmsSpreadCoupon) from quantlib.experimental.coupons.lognormal_cmsspread_pricer import ( LognormalCmsSpreadPricer) -from scipy import LowLevelCallable from scipy.special import roots_hermitenorm from scipy.integrate import quad import ctypes @@ -90,13 +89,20 @@ class TestCmsSpread(unittest.TestCase): def test_h1_hcall(self): args = (self.cap, *self.params, self.ρ.value) - h1_fun = _call_integrand.function - + h1_capsule = _call_integrand.function + ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p + ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object, ctypes.c_char_p] + ptr_type = ctypes.CFUNCTYPE(ctypes.c_double, ctypes.c_int, ctypes.POINTER(ctypes.c_double)) + # Get the function pointer from the capsule "capsule_mul" + h1_fun = ptr_type(ctypes.pythonapi.PyCapsule_GetPointer(h1_capsule, b"double (int, double *)")) + x = np.linspace(-5, 5, 11) + b = h_call(x, *args) * np.exp(-0.5* x * x) + i = 0 for x in np.linspace(-5, 5, 11): full_args = np.array((x, *args)) a = h1_fun(9, full_args.ctypes.data_as(ctypes.POINTER(ctypes.c_double))) - b = h_call(x, *args) * math.exp(-0.5 * x * x) - self.assertAlmostEqual(a, b) + self.assertAlmostEqual(a, b[i]) + i+= 1 def test_scipy_integrate(self): x, w = roots_hermitenorm(20) |
