Generating a random variable with specific mean and variance

I am new to Python and I am wondering If I can simulate a process where a variable follow a normal distribution with specific mean and variance

I am working on the Vasicek model and I found the distribution of the stochastic rate as:

enter image description here

Is it possible to generate this with a graph via matplotlib ?

1 answer

  • answered 2017-01-11 14:21 Bathsheba

    The approach that generalises to any distribution is to

    1) draw a uniform random number in the range [0, 1).

    2) Apply the quantile function of your distribution to that random number.

    The result of the quantile function will then have the distribution that you require. Other methods such as Box Muller work well for normal distributions, and can be faster, if a little more fiddly to set up.