We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello Lech! Here's a vectorized approach for the short-rate models. Thank you for your lectures & materials!
import typing def f0T(t,P0T): dt = 0.01 return -(np.log(P0T(t+dt))-np.log(P0T(t-dt)))/(2*dt) M: int = 25000 # n_simulations N: int = 252 # n_steps T: float = 40 dt: float = T/N sigma: float = 0.007 Z: np.ndarray = np.random.normal(0.0, 1.0, (M, N)) P0T: typing.Callable = lambda T: np.exp(-0.017*T) x0: float = f0T(0.01, P0T) # r0 Ws: np.ndarray = np.cumsum(np.power(dt, 0.5)*Z, axis=1) Ts: np.ndarray = np.arange(0, T, dt) # np.arange timesteps_vector theta: typing.Callable = lambda t: (f0T(t+dt,P0T)-f0T(t-dt,P0T))/(2.0*dt) + sigma**2.0*t # np.ndarray of (M) short-rates dynamics Xs = np.cumsum(np.concatenate((np.full(shape=(M, 1), fill_value=x0), theta(Ts)[1:] * dt + sigma * np.diff(Ws)), axis=1), axis=1) # np.ndarray of (M) money-savings accounts dynamics Ms = np.cumprod(np.concatenate((np.full(shape=(M, 1), fill_value=1.0), np.exp((Xs[:, 1:] + Xs[:, :-1]) * 0.5 * dt)), axis=1), axis=1) # Here we compare the price of an option on a ZCB from Monte Carlo the Market P_tMC = np.mean(1/Ms, axis=0)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hello Lech!
Here's a vectorized approach for the short-rate models.
Thank you for your lectures & materials!
The text was updated successfully, but these errors were encountered: