dimanche 25 avril 2021

Numpy Random Simulation Returns Same Results Every Time

I am currently trying to simulate a stochastic process (to be specific, the Vasicek Model) for my class in fixed income securities. I need to run a simulation multiple times for the same parameters to show different paths that interest rates can take. The code I am currently using is:

import numpy as np
import matplotlib.pyplot as plt

def vasicek(r0, K, theta, sigma, T, N, seed=777):    
    np.random.seed(seed)
    dt = T/float(N)    
    rates = [r0]
    for i in range(N):
        dr = K*(theta-rates[-1])*dt + sigma*np.random.normal()
        rates.append(rates[-1] + dr)
    return range(N+1), rates

My issue is that this function returns the same path when range and rates are plotted. Shouldn't np.random.normal() return different values every time I run this function? How can I change this code to make it do that?




Aucun commentaire:

Enregistrer un commentaire