Docsity

Generating Random Numbers - Banking - Lecture Slides, Slides of Banking and Finance

Partial preview of the text

Download Generating Random Numbers - Banking - Lecture Slides and more Slides Banking and Finance in PDF only on Docsity!

Generating Random

Numbers

Simulation with Arena — Further Statistical Issues (^) C11/

What We’ll Do ...

  • Random-number generation
  • Generating random variates
  • Non-stationary Poisson processes
  • Variance reduction

Simulation with Arena — Further Statistical Issues (^) C11/

Pseudo Random Numbers

  • Random numbers generated by a computer are not really random
  • They just behave like random numbers
  • For a large enough sample, the generated values will pass all tests for a uniform distribution - If you look at a histogram of a large number, it will look uniform - Pass chi-square test - Pass Kolmogorov-Smirnov Test
  • The stream of random numbers will pass all the tests for randomness - Runs test - Autocorrelation test

Simulation with Arena — Further Statistical Issues (^) C11/

Linear Congruential Generators

(LCGs)

  • The most common of several different methods
  • Generate a sequence of integers Z 1 , Z 2 , Z 3 , … via the recursion Zi = (a Zi–1 + c) (mod m)
  • a, c, and m are carefully chosen constants
  • Specify a seed, Z 0 to start off
  • “mod m” means take the remainder of dividing by m as the next Z (^) i
  • All the Z (^) i’s are between 0 and m – 1
  • Return the ith “random number” as U (^) i = Zi / m

Simulation with Arena — Further Statistical Issues (^) C11/

Issues with LCGs

  • Cycle length
    • Typically, m = 2.1 billion (= 2 31 – 1) or more
    • Other parameters chosen so that cycle length = m or m – 1
  • Statistical properties
    • Uniformity, independence
    • There are many tests of RNGs
      • Empirical tests
      • Theoretical tests — “lattice” structure (next slide …)
  • Speed, storage — both are usually fine
  • Must be carefully, cleverly coded — BIG integers
  • Reproducibility — streams (long internal subsequences) with fixed seeds

Simulation with Arena — Further Statistical Issues (^) C11/

Plot of Ui vs. i Plot of^ U^ i vs.^ U^ i -1 “Random Numbers Fall Mainly in the Planes” — Marsaglia

Issues with LCGs (cont’d.)

  • “Regularity” of LCGs (and other kinds of RNGs): For the earlier “toy” LCG …
  • “Design” RNGs: dense lattice in high dimensions
  • Other kinds of RNGs — longer memory in recursion, combination of several RNGs

Simulation with Arena — Further Statistical Issues (^) C11/

Generating Random Variates

  • Have: Desired input distribution for model (fitted or specified in some way), and RNG (UNIF (0, 1))
  • Want: Transform UNIF (0, 1) random numbers into “draws” from the desired input distribution
  • Method: Mathematical transformations of random numbers to “deform” them to the desired distribution - Specific transform depends on desired distribution - Details in online Help about methods for all distributions
  • Do discrete, continuous distributions separately

Simulation with Arena — Further Statistical Issues (^) C11/

Generating from Discrete

Distributions

  • Example: probability mass function
  • Divide [0, 1] into subintervals of length 0.1, 0.5, 0.4; generate U ~ UNIF (0, 1); see which subinterval it’s in; return X = corresponding value

–2 0 3

0.1 0.5 0. U : 0.0 0.1 0.6 1. X = –2 X = 0 X = 3

0.1 0.5 0. U : 0.0 0.1 0.6 1. X = –2 X = 0 X = 3

Simulation with Arena — Further Statistical Issues (^) C11/

Generating from Continuous

Distributions

  • Example: EXPO (5) distribution

Density (PDF)

Distribution (CDF)

  • General algorithm (can be rigorously justified): 1. Generate a random number U ~ UNIF(0, 1) 2. Set U = F ( X ) and solve for X = F –1( U ) - Solving for X may or may not be simple - Sometimes use numerical approximation to “solve”

Simulation with Arena — Further Statistical Issues (^) C11/

Intuition: More U ’s will hit F ( x ) where it’s steep This is where the density f ( x ) is tallest, and we want a denser distribution of X ’s

Generating from Continuous

Distributions (cont’d.)

  • Solution for EXPO (5) case:

Set U = F(X) = 1 – e–X/ e–X/5 = 1 – U –X/5 = ln (1 – U) X = – 5 ln (1 – U)

  • Picture (inverting the CDF, as in discrete case):

Simulation with Arena — Further Statistical Issues (^) C11/

  • Usual model: nonstationary Poisson process:
    • Have a rate function l(t)
    • Number of events in [t1, t2] ~ Poisson with mean
  • Issues:
    • How to estimate rate function?
    • Given an estimate, how to generate during simulation?

λ( t )

t

2 1

( 1 , 2 ) ( )

t

t

t t λ t dt

Non-stationary Poisson Processes

(cont’d.)

Simulation with Arena — Further Statistical Issues (^) C11/

  • Estimation of the rate function
    • Probably the most practical method is piecewise constant
      • Decide on a time interval within which rate is fixed
      • Estimate from data the (constant) rate during each interval
      • Be careful to get the units right: arrivals per time unit being used throughout the model, which may not be the time interval for the estimate rate function
    • Other methods exist in the literature

t

λ^ ^ ( ) t

Nonstationary Poisson Processes

(cont’d.)

Simulation with Arena — Further Statistical Issues (^) C11/

Rejection Sampling

  • For the non-homogeneous Poisson process
    • we sampled from a process with the maximum rate
    • then we rejected enough to thin the process down to the correct rate
  • This is an example of rejection sampling
  • Rejection sampling can also be used for sampling from univariate distributions where F -1(x) does not exist or cannot be easily approximate
  • Basic Idea
    • Sample from another distribution that is easy to sample from
    • Reject those that are drawn from area where the target distribution has low density

Simulation with Arena — Further Statistical Issues (^) C11/

Rejection Sampling

  • Thus
    • g(x) is not a probability density function
    • But g(x)/c is a probability density function
    • Must choose g(x) so that sampling from g(x)/c is easy

∞ −∞

∞ −∞

c g x dx f x dx

g ( x )≥ f ( x ), ∀ x ∈[−∞,∞ ]

f(x)

g(x)

Want to sample from this distribution

This function dominates f(x)