Skip to content

Commit 2e087a1

Browse files
mingjie-intelDiptorup Deb
authored andcommitted
Updated blackscholes example to use dpnp.erf.
1 parent cfb105b commit 2e087a1

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

numba_dpex/examples/blacksholes_njit.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ def blackscholes(sptprice, strike, timev, rate, volatility):
2727
generate a single SYCL kernel. The kernel is automatically offloaded to
2828
the device specified where the function is invoked.
2929
"""
30-
NofXd1 = dpnp.empty_like(sptprice)
31-
NofXd2 = dpnp.empty_like(sptprice)
3230

3331
a = dpnp.log(sptprice / strike)
3432
b = timev * -rate
@@ -38,9 +36,8 @@ def blackscholes(sptprice, strike, timev, rate, volatility):
3836
w1 = (a - b + c) * y
3937
w2 = (a - b - c) * y
4038

41-
for idx in numba.prange(sptprice.shape[0]):
42-
NofXd1[idx] = 0.5 + 0.5 * math.erf(w1[idx])
43-
NofXd2[idx] = 0.5 + 0.5 * math.erf(w2[idx])
39+
NofXd1 = 0.5 + 0.5 * dpnp.erf(w1)
40+
NofXd2 = 0.5 + 0.5 * dpnp.erf(w2)
4441

4542
futureValue = strike * dpnp.exp(b)
4643
call = sptprice * NofXd1 - futureValue * NofXd2
@@ -71,7 +68,8 @@ def run(iterations):
7168
t1 = time.time()
7269
put = blackscholes(sptprice, initStrike, rate, volatility, timev)
7370
t = time.time() - t1
74-
print("checksum: ", sum(put))
71+
# print("checksum: ", sum(put))
72+
print(put)
7573
print("SELFTIMED ", t)
7674

7775

0 commit comments

Comments
 (0)