Monte Carlo and Empirical Methods for Stochastic Inference (MASM11/FMSN50)

Similar documents
Monte Carlo and Empirical Methods for Stochastic Inference (MASM11/FMS091)

Monte Carlo and Empirical Methods for Stochastic Inference (MASM11/FMSN50)

Monte Carlo and Empirical Methods for Stochastic Inference (MASM11/FMSN50)

Monte Carlo and Empirical Methods for Stochastic Inference (MASM11/FMSN50)

ELEMENTS OF MONTE CARLO SIMULATION

Financial Risk Forecasting Chapter 7 Simulation methods for VaR for options and bonds

10. Monte Carlo Methods

CPSC 540: Machine Learning

CPSC 540: Machine Learning

Lecture outline. Monte Carlo Methods for Uncertainty Quantification. Importance Sampling. Importance Sampling

UQ, STAT2201, 2017, Lectures 3 and 4 Unit 3 Probability Distributions.

**BEGINNING OF EXAMINATION** A random sample of five observations from a population is:

IEOR E4703: Monte-Carlo Simulation

Probability. An intro for calculus students P= Figure 1: A normal integral

History of Monte Carlo Method

Chapter 7: Point Estimation and Sampling Distributions

The Use of Importance Sampling to Speed Up Stochastic Volatility Simulations

Introduction to Sequential Monte Carlo Methods

Monte Carlo Simulations in the Teaching Process

Math Computational Finance Double barrier option pricing using Quasi Monte Carlo and Brownian Bridge methods

Lecture Slides. Elementary Statistics Tenth Edition. by Mario F. Triola. and the Triola Statistics Series. Slide 1

Chapter 2 Uncertainty Analysis and Sampling Techniques

Computer Exercise 2 Simulation

Monte Carlo Methods for Uncertainty Quantification

Posterior Inference. , where should we start? Consider the following computational procedure: 1. draw samples. 2. convert. 3. compute properties

Math Option pricing using Quasi Monte Carlo simulation

MVE051/MSG Lecture 7

Sublinear Time Algorithms Oct 19, Lecture 1

Point Estimation. Stat 4570/5570 Material from Devore s book (Ed 8), and Cengage

Exam in TFY4275/FY8907 CLASSICAL TRANSPORT THEORY Feb 14, 2014

Financial Risk Management

Statistics 431 Spring 2007 P. Shaman. Preliminaries

Computer Exercise 2 Simulation

Week 1 Quantitative Analysis of Financial Markets Distributions B

A Stochastic Reserving Today (Beyond Bootstrap)

Simulation. Decision Models

Adaptive Experiments for Policy Choice. March 8, 2019

IEOR E4602: Quantitative Risk Management

P VaR0.01 (X) > 2 VaR 0.01 (X). (10 p) Problem 4

Monte Carlo Methods. Matt Davison May University of Verona Italy

Strategies for High Frequency FX Trading

Strategies for Improving the Efficiency of Monte-Carlo Methods

ROM SIMULATION Exact Moment Simulation using Random Orthogonal Matrices

Math489/889 Stochastic Processes and Advanced Mathematical Finance Homework 5

Math Computational Finance Option pricing using Brownian bridge and Stratified samlping

Write legibly. Unreadable answers are worthless.

Risk Measurement in Credit Portfolio Models

Corso di Identificazione dei Modelli e Analisi dei Dati

FREDRIK BAJERS VEJ 7 G 9220 AALBORG ØST Tlf.: URL: Fax: Monte Carlo methods

Introduction Dickey-Fuller Test Option Pricing Bootstrapping. Simulation Methods. Chapter 13 of Chris Brook s Book.

Lecture 6: Chapter 6

STRESS-STRENGTH RELIABILITY ESTIMATION

Chapter 7 presents the beginning of inferential statistics. The two major activities of inferential statistics are

Week 7 Quantitative Analysis of Financial Markets Simulation Methods

Optimal Search for Parameters in Monte Carlo Simulation for Derivative Pricing

Two hours. To be supplied by the Examinations Office: Mathematical Formula Tables and Statistical Tables THE UNIVERSITY OF MANCHESTER

A Markov Chain Monte Carlo Approach to Estimate the Risks of Extremely Large Insurance Claims

Random Variables and Probability Distributions

F19: Introduction to Monte Carlo simulations. Ebrahim Shayesteh

Definition 9.1 A point estimate is any function T (X 1,..., X n ) of a random sample. We often write an estimator of the parameter θ as ˆθ.

2.1 Mathematical Basis: Risk-Neutral Pricing

Limit Theorems for the Empirical Distribution Function of Scaled Increments of Itô Semimartingales at high frequencies

Equity correlations implied by index options: estimation and model uncertainty analysis

A Convenient Way of Generating Normal Random Variables Using Generalized Exponential Distribution

Hand and Spreadsheet Simulations

Statistics for Business and Economics: Random Variables:Continuous

Chapter 7 1. Random Variables

Statistical estimation

Lecture 7: Bayesian approach to MAB - Gittins index

Lecture Quantitative Finance Spring Term 2015

Yao s Minimax Principle

. (i) What is the probability that X is at most 8.75? =.875

Math 416/516: Stochastic Simulation

Chapter 5 Univariate time-series analysis. () Chapter 5 Univariate time-series analysis 1 / 29

Version A. Problem 1. Let X be the continuous random variable defined by the following pdf: 1 x/2 when 0 x 2, f(x) = 0 otherwise.

DRAFT. 1 exercise in state (S, t), π(s, t) = 0 do not exercise in state (S, t) Review of the Risk Neutral Stock Dynamics

Sample Size for Assessing Agreement between Two Methods of Measurement by Bland Altman Method

MATH 3200 Exam 3 Dr. Syring

Central Limit Theorem (CLT) RLS

Exam 2 Spring 2015 Statistics for Applications 4/9/2015

Statistical Methods in Financial Risk Management

Point Estimation. Some General Concepts of Point Estimation. Example. Estimator quality

Introduction to Business Statistics QM 120 Chapter 6

Ch4. Variance Reduction Techniques

Week 2 Quantitative Analysis of Financial Markets Hypothesis Testing and Confidence Intervals

IEOR E4703: Monte-Carlo Simulation

SAQ KONTROLL AB Box 49306, STOCKHOLM, Sweden Tel: ; Fax:

Monte Carlo Methods in Option Pricing. UiO-STK4510 Autumn 2015

- 1 - **** d(lns) = (µ (1/2)σ 2 )dt + σdw t

Construction and behavior of Multinomial Markov random field models

IEOR E4703: Monte-Carlo Simulation

Chapter 7 Sampling Distributions and Point Estimation of Parameters

IEOR E4602: Quantitative Risk Management

GENERATION OF STANDARD NORMAL RANDOM NUMBERS. Naveen Kumar Boiroju and M. Krishna Reddy

Computer labs. May 10, A list of matlab tutorials can be found under

Statistical Computing (36-350)

Homework Problems Stat 479

EVA Tutorial #1 BLOCK MAXIMA APPROACH IN HYDROLOGIC/CLIMATE APPLICATIONS. Rick Katz

4-1. Chapter 4. Commonly Used Distributions by The McGraw-Hill Companies, Inc. All rights reserved.

Chapter 5. Statistical inference for Parametric Models

Transcription:

Monte Carlo and Empirical Methods for Stochastic Inference (MASM11/FMSN50) Magnus Wiktorsson Centre for Mathematical Sciences Lund University, Sweden Lecture 2 Random number generation January 18, 2018 M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (1) 1 / 24

Last time: Principal aim We formulated the main problem of the course, namely to compute some expectation τ = E(φ(X)) = φ(x)f(x) dx, where X is a random variable taking values in A R d (where d N may be very large), f : A R + is the probability density (target density) of X, and φ : A R is a function (objective function) such that the above expectation exists. This framework covers a large set of fundamental problem in statistics and numerical analysis, and we inspected a few examples. A M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (2) 2 / 24

Last time: The MC method in a nutshell Let X 1, X 2,..., X N be independent random variables with density f. Then, by the law of large numbers, as N tends to innity, τ N def. = 1 N N φ(x i ) E(φ(X)). i=1 (a.s.) Inspired by this result, we formulated the basic MC sampler: for i = 1 N do draw X i f end for set τ N N i=1 φ(x i)/n return τ N M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (3) 3 / 24

What do we need to know? OK, so what do we need to master for having practical use of the MC method? We agreed on that, for instance, the following questions should be answered: 1: How do we generate the needed input random variables? 2: How many computer experiments should we do? What can be said about the error? 3: Can we exploit problem structure to speed up the computation M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (4) 4 / 24

Plan of today's lecture 1 MC output analysis Condence bounds The delta method 2 Uniform pseudo-random numbers 3 M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (5) 5 / 24

Condence bounds The delta method Condence bounds Last time we noticed that the central limit theorem (CLT) implies N (τn τ) d. N (0, σ 2 (φ)), as N, where σ 2 (φ) def. = V (φ(x)). Consequently, the two-sided condence interval ( ) σ(φ) σ(φ) I α = τ N λ α/2, τ N + λ α/2, N N where λ p denotes the p-quantile of the standard normal distribution, covers τ with (approximate) probability 1 α. A problem with this approach is that σ 2 (φ) is in general not known. M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (6) 6 / 24

Condence bounds The delta method Condence bounds (cont.) Quick x: σ 2 (φ) is again an expectation that can be estimated using the already generated MC sample (X i ) N i=1! More specically, for large N's, σ 2 (φ) = E ( φ 2 (X) ) E 2 (φ(x)) = E ( φ 2 (X) ) τ 2 ( 1 N φ 2 (X i ) τn 2 = 1 N φ(x i ) 1 N N N i=1 i=1 2 N φ(x l )). l=1 This estimator is not unbiased, and one often uses instead the bias-corrected estimator ( σ 2 N(φ) def. = 1 N 1 N i=1 φ(x i ) 1 N 2 N φ(x l )). In Matlab, this estimator is pre-implemented in the routine var (see also std). M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (7) 7 / 24 l=1

Condence bounds The delta method The delta method For a given estimand τ, one is often interested in estimating ϕ(τ) for some function ϕ : R R. Question: Is it OK to simply estimate ϕ(τ) by ϕ(τ N )? The estimator ϕ(τ N ) is not unbiased; indeed, under suitable assumptions on ϕ it holds that E (ϕ(τ) ϕ(τ N )) = ϕ (τ) V(τ N ) + O ( N 2) 2 = ϕ (τ)σ 2 (φ) + O ( N 2), 2N verifying that ϕ(τ N ) is asymptotically unbiased (consistent). In addition, one may establish the CLT d. N (ϕ(τn ) ϕ(τ)) N (0, ϕ (τ) 2 σ 2 (φ)), as N, which can by used for constructing CBs in the usual manner. M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (8) 8 / 24

Condence bounds The delta method Example: Buon's needle (Simulation without computer) Consider a wooden oor with parallel boards of width d on which we randomly drop a needle with length l, with l d. Let { X = distance from the lower needlepoint to the upper board edge U(0, d) θ = angle between the needle and the board edge normal U( π/2, π/2). Then τ = P (needle intersects board edge) = P(X l cos θ) =... = 2l πd. so we can estimate π as, π = 2l τd. This may not look well suited for computer implementation since the simulation of θ seems to need the value of π. M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (9) 9 / 24

Condence bounds The delta method Example: Buon's needle (cont.) However if U 1, U 2 U(0, 1) then Y = U 1 {U 2 U 2 1 + U2 2 1 + U2 2 1} = d cos(θ). So we can draw U 1 and U 2 and generate Y if U1 2 + U 2 2 1. We will soon talk more about this (rejection sampling). But if we analyse the probability for this event to happen we see that P(U 2 1 + U 2 2 1) = π/4. So this actually suggests a better way to estimate π directly. M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (10) 10 / 24

Condence bounds The delta method Example: Buon's needle (cont.) Since τ = P (needle intersects board edge) = E ( 1 {X l cos θ} ), an MC approximation of π is obtained by using the delta method by rst estimating τ via X = d*rand(1,n); for i=1:n ready=0; while ~ready U=rand(2,1); ready=sum(u.^2)<=1; end costheta(i)=u(1)/sqrt(sum(u.^2)); end tau = mean(x <= L*costheta); and then letting pi_est = 2*L./(tau*d); M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (11) 11 / 24

Condence bounds The delta method Example: Buon's needle (cont.) The delta method provides a 95% condence interval through sigma = std(x <= L*costheta); LB = pi_est norminv(0.975)*2*l/(d*tau^2*sqrt(n))*sigma; UB = pi_est + norminv(0.975)*2*l/(d*tau^2*sqrt(n))*sigma; Executing this code (and the previous) for N = 1:10:1000 yields the following graph: 5 4.5 4 π Estimate 3.5 3 2.5 2 1.5 0 100 200 300 400 500 600 700 800 900 1000 Number of samples N M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (12) 12 / 24

Uniform pseudo-random numbers Pseudo-random numbers = Numbers exhibiting statistical randomness while being generated by a deterministic process. We will discuss how to generate pseudo-random U(0, 1) numbers, inversion and transformation methods, rejection sampling, and conditional methods. M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (13) 13 / 24

Uniform pseudo-random numbers Good pseudo-random numbers Good pseudo-random numbers appear to come from the correct distribution (also in the tails), have long periodicity, are independent and fast to generate. Most standard computing languages have packages or functions that generate either U(0, 1) random numbers or integers on U(0, 2 32 1): rand and unifrnd in matlab rand in C/C++ Random in Java M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (14) 14 / 24

Uniform pseudo-random numbers Linear congruential generator (LCG) The linear congruential generator is a simple, fast, and popular way of generating random numbers: X n = (a X n 1 + c) mod m, where a, c, and m are integers. This recursion generates integer numbers (X n ) in [0, m 1]. These are mapped to (0, 1) through division by m. It turns out that the period of the generator is m if (for c > 0) (i) c and m are relatively prime, (ii) a 1 is divisible by all prime factors of m, and (iii) a 1 is divisible by 4 if m is divisible by 4. This is known as the Hull-Dobell Theorem (1962). Thus with m as a power of 2, as natural on a binary machine, we need only to have c odd and a mod 4 = 1 (Hull-Dobell,1962). M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (15) 15 / 24

Uniform pseudo-random numbers Multiplicative congruential generator (MCG) The multiplicative congruential generator is special case of LCG:s where c = 0: X n = a X n 1 mod m, where a, m are integers. This recursion generates integer numbers (X n ) in [1, m 1]. These are mapped to (0, 1) through division by m. It turns out that the period of the generator is m 1 if (i) The number m is a prime, (ii) The multiplier a is is primitive root of m, and (iii) x 0 [1, m 1]. The number a is a primitive root of m if and only if a mod m 0 and a (m 1)/q mod m 1, for any prime divisor q of m 1. As an example, MATLAB (pre v. 5) uses m = 2 31 1, a = 7 5 = 16807, and c = 0. Now MATLAB uses the Mersenne Twister alogorithm. M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (16) 16 / 24

Uniform pseudo-random numbers We will now assume that we have access to U(0, 1) pseudo-random numbers U and want to generate random numbers X from a univariate distribution with distribution function F. Dene the general inverse F (u) def. = inf{x R : F (x) u} and draw U U(0, 1) set X F (U) return X One may now prove the following. Theorem (Inverse method) The output X has distribution function F. M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (17) 17 / 24

Uniform pseudo-random numbers (cont.) Some remarks: If F is strictly monotone, then F = F 1. The method is limited to cases where we want to generate univariate random numbers and the generalized inverse F is easy to evaluate (which is far from always the case). M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (18) 18 / 24

Uniform pseudo-random numbers Example: exponential distribution F (x) = 1 e x, x R + F (u) = log(1 u), u (0, 1) F_inv = @(y) log(1 y); U = rand(1,20); X = F_inv(U); 1 0.9 Exponential distribution Distribution function 0.8 0.7 0.6 U 0.5 0.4 0.3 0.2 0.1 Density function 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 X M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (19) 19 / 24

Uniform pseudo-random numbers looks promising, but what do we do if, e.g., f(x) exp(cos 2 (x)), x ( π/2, π/2)? Here we cannot nd an inverse and even the normalizing constant is hard to calculate. In the continuous case the following (somewhat magic!) algorithm saves the day. Let f and g be densities on R d for which there exists a constant K < such that f(x) Kg(x) for all x R d ; then repeat draw X g draw U U(0, 1) until U f(x ) Kg(X ) X X return X M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (20) 20 / 24

Uniform pseudo-random numbers (cont.) The following holds true: Theorem () The output X of the rejection sampling algorithm has density function f. Moreover: Theorem The expected number of trials needed before acceptance is K. Consequently, K should be chosen as small as possible. M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (21) 21 / 24

Uniform pseudo-random numbers Example We wish to simulate f(x) = exp(cos 2 (x))/c, x ( π/2, π/2), where c = π/2 π/2 exp(cos2 (z)) dz = πe 1/2 I o (1/2) is the normalizing constant. However, since for all x ( π/2, π/2), f(x) = exp(cos2 (x)) c e c = eπ 1, }{{} c }{{} π K g where g is the density of U( π/2, π/2), we may use rejection sampling where a candidate X U( π/2, π/2) is accepted if U f(x ) Kg(X ) = exp(cos2 (X ))/c = exp(cos 2 (X ) 1). e/c M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (22) 22 / 24

Uniform pseudo-random numbers prob = @(x) exp((cos(x))^2 1); trial = 1; accepted = false; while ~accepted, Xcand = pi/2 + pi*rand; if rand < prob(xcand), accepted = true; X = Xcand; else trial = trial + 1; end end 0.7 0.6 0.5 0.4 0.3 Histogram of accept reject draws f(x) = exp(cos 2 (x))/c 0.2 0.1 0 2 1.5 1 0.5 0 0.5 1 1.5 2 Figure: Plot of a histogram of 20,000 accept-reject draws together with the true density. The average number of trials was 1.5555( K = e 1/2 /I 0 (1/2) 1.5503). M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (23) 23 / 24

Today we have discussed how to construct condence intervals of the MC estimates using the CLT, shown that natural estimator ϕ(τ N ) of ϕ(τ) is asymptotically consistent, shown how to generate pseudo-random numbers using the inversion method (when the general inverse F of F is easily obtained), rejection sampling (when f(x) Kg(x) for some density g and constant K), M. Wiktorsson Monte Carlo and Empirical Methods for Stochastic Inference, L2 (24) 24 / 24