I've written the following function which should simulate realizations of a CIR process:
def cir_simulations(alpha: float, mu: float, sigma: float, delta_t: float, num_steps: int, num_sims: int):
sims_shape = (num_steps, num_sims)
sims = np.empty(sims_shape)
std_norm_rand = np.random.standard_normal(sims_shape)
prev_r = mu
for r_t, rnd in zip(sims, std_norm_rand):
delta_r = alpha * (mu - prev_r) * delta_t + sigma * np.sqrt(prev_r) * np.sqrt(delta_t) * rnd[:]
r_t[:] = prev_r = prev_r + delta_r
return sims
Can anyone confirm that my code will correctly simulate a CIR process?
As a secondary question, are there any improvements you'd make to this code?