Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def mc_bar_call_pv_with_paths(S0, K, B, T, r, sigma, M, I):
- # Simulating I paths with M time steps
- S = np.zeros((M + 1, I))
- S[0] = S0
- isChange = np.ones(I)
- dt = float(T) / M
- for t in range(1, M + 1):
- z = standard_normal(I)
- S_next = S[t - 1] * np.exp((r - 0.5 * sigma ** 2) * dt + sigma * m.sqrt(dt) * z)
- for i in range(I):
- if (S_next[i] >= B) :
- isChange[i] = 0
- for i in range(I):
- if (isChange[i] == 0) :
- S_next[i] = 0;
- S[t] = S_next
- # PV is extected discounted payoff
- C = np.sum(m.exp(-r * T) * np.maximum(S[-1] - K, 0)) / I
- return C, S
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement