SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def mc_bar_call_pv_with_paths(S0, K, B, T, r, sigma, M, I):
  2.     # Simulating I paths with M time steps
  3.     S = np.zeros((M + 1, I))
  4.     S[0] = S0
  5.     isChange = np.ones(I)
  6.     dt = float(T) / M
  7.     for t in range(1, M + 1):
  8.         z = standard_normal(I)
  9.        
  10.         S_next = S[t - 1] * np.exp((r - 0.5 * sigma ** 2) * dt + sigma * m.sqrt(dt) * z)
  11.         for i in range(I):
  12.             if (S_next[i] >= B) :
  13.                 isChange[i] = 0
  14.         for i in range(I):
  15.             if (isChange[i] == 0) :
  16.                 S_next[i] = 0;
  17.         S[t] = S_next
  18.  
  19.     # PV is extected discounted payoff
  20.     C = np.sum(m.exp(-r * T) * np.maximum(S[-1] - K, 0)) / I
  21.     return C, S
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top