def _put_zerofunc(sigma, S0, K, T, r, p): return bsprices(S0, K, T, r, sigma)[1] - p
def _call_zerofunc(sigma, S0, K, T, r, c): return bsprices(S0, K, T, r, sigma)[0] - c
put_pay_off.mean()*discount) if __name__ == "__main__": S0 = 40 # $40 current price K = 42 # $46 strike price T = 3/12.0 # 3 months in units of years r = 0.01 # annual risk-free rate of return sigma = 0.30 # volatility per annum msg = "Call price: %4.2f; Put price: %4.2f" c1, p1 = mcprices(S0, K, T, r, sigma, N=10000) print msg % (c1, p1) c1, p1 = mcprices2(S0, K, T, r, sigma, N=10000) print msg % (c1, p1) # FIXME: this is not a new-student-friendly technique # Get black scholes equation from other directory # import os, sys fullpath = os.path.abspath(__file__) direc = os.sep.join([os.path.split(os.path.split(fullpath)[0])[0], 'black_scholes']) sys.path.insert(0, direc) from black_scholes_solution import bsprices c1, p1 = bsprices(S0, K, T, r, sigma) print msg % (c1, p1) sys.path.pop()