Search code examples
excelrandommontecarloprobability-densityprobability-distribution

Given a exponential probability density function, how to generate random values using the random generator in Excel?


Based on a set of experiments, a probability density function (PDF) for an exponentially distributed variable was generated. Now the goal is to use this function in a Monte carlo simulation. I am vaguely familiar with PDF's and random generator, especially for normal and log-normal distributions. However, I am not quite able to figure this out. Would be great if someone can help.

Here's the function:

f = γ/2R * exp⁡(-γl/2R) (1-exp⁡(-γ) )^(-1) H (2R-l)

  • f is the probability density function,
  • 1/γ is the mean of the distribution,
  • R is a known fixed variable,
  • H is the heaviside step function,
  • l is the variable that is exponentially distributed

Solution

  • Well. I don't know how to do it in Excel, but using inverse method it is easy to get the answer (assuming there is RANDOM() function which returns uniform numbers in the [0...1] range)

    l = -(2R/γ)*LOG(1 - RANDOM()*(1-EXP(-γ)))

    Easy to check boundary values

    if RANDOM()=0, then l = 0

    if RANDOM()=1, then l = 2R

    UPDATE

    So there is a PDF

    PDF(l|R,γ) = γ/2R * exp⁡(-lγ/2R)/(1-exp⁡(-γ)), l in the range [0...2R]

    First, check that it is normalized

    ∫ PDF(l|R,γ) dl from 0 to 2R = 1

    Ok, it is normalized

    Then compute CDF(l|R,γ)

    CDF(l|R,γ) = ∫ PDF(l|R,γ) dl from 0 to l = (1 - exp⁡(-lγ/2R))/(1-exp⁡(-γ))

    Check again, CDF(l=2R|R,γ) = 1, good.

    Now set CDF(l|R,γ)=RANDOM(), solve it wrt l and get your sampling expression. Check it at the RANDOM() returning 0 or RANDOM() returning 1, you should get end points of l interval.