Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def set_numexpr_threads(n=None):
# if we are using numexpr, set the threads to n
# otherwise reset
if _NUMEXPR_INSTALLED and _USE_NUMEXPR:
if n is None:
n = ne.detect_number_of_cores()
ne.set_num_threads(n)
def black_scholes ( nopt, price, strike, t, rate, vol ):
mr = -rate
sig_sig_two = vol * vol * 2
P = price
S = strike
T = t
call = ne.evaluate("P * (0.5 + 0.5 * erf((log(P / S) - T * mr + 0.25 * T * sig_sig_two) * 1/sqrt(T * sig_sig_two))) - S * exp(T * mr) * (0.5 + 0.5 * erf((log(P / S) - T * mr - 0.25 * T * sig_sig_two) * 1/sqrt(T * sig_sig_two))) ")
put = ne.evaluate("call - P + S * exp(T * mr) ")
return call, put
#ne.set_vml_num_threads(ne.detect_number_of_cores())
ne.set_num_threads(ne.detect_number_of_cores())
ne.set_vml_accuracy_mode('high')
base_bs_erf.run("Numexpr-opt", black_scholes)
def set_numexpr_threads(n=None):
# if we are using numexpr, set the threads to n
# otherwise reset
if _NUMEXPR_INSTALLED and _USE_NUMEXPR:
if n is None:
n = ne.detect_number_of_cores()
ne.set_num_threads(n)
def set_numexpr_threads(n=None):
# if we are using numexpr, set the threads to n
# otherwise reset
if _NUMEXPR_INSTALLED and _USE_NUMEXPR:
if n is None:
n = ne.detect_number_of_cores()
ne.set_num_threads(n)
y = ne.evaluate("1/sqrt(z) ")
w1 = ne.evaluate("(a - b + c) * y ")
w2 = ne.evaluate("(a - b - c) * y ")
d1 = ne.evaluate("0.5 + 0.5 * erf(w1) ")
d2 = ne.evaluate("0.5 + 0.5 * erf(w2) ")
Se = ne.evaluate("exp(b) * S ")
call = ne.evaluate("P * d1 - Se * d2 ")
put = ne.evaluate("call - P + Se ")
return call, put
ne.set_num_threads(ne.detect_number_of_cores())
ne.set_vml_accuracy_mode('high')
base_bs_erf.run("Numexpr", black_scholes)