Monte Carlo Simulation Language Reference Manual Diego Garcia dg2275 Eita Shuto es2908 Yunling Wang yw2291 Chong Zhai cz2191 MCSL LRM 1 Introduction 5 Overview 5 Goal 5 Sub algorithms 5 Key feature 6 Hybrid Style 6 2 Lexical Conventions 7 Comments 7 Identifiers 7 Keywords 7 Constants 8 Integer constants 8 Floating constants 8 Character constants 8 Strings 8 3 Conversions 9 Floats and integers 9 Random type resolution 9 4 Expressions 10 Objects and lvalues 10 Primary expressions 10 Identifiers 10 Constants 10 Strings 10 Parentheses 10 Functions 10 Arrays 10 Unary Logical Operator 11 operator 11 Arithmetic Operators 11 operator 11 operator 11 operator 11 operator 11 Page 2 of 23 MCSL LRM operator 11 operator 11 Comparison operators 12 operator 12 operator 12 operator 12 operator 12 operator 12 operator 12 Logical operators 12 operator 12 operator 13 5 Declaration 14 Variables 14 Type specifier 14 Declarator list 14 Declarator 14 functions 14 6 Statements 16 Expression statement 16 Statement sequence 16 Declaration statement 16 Branching statement 16 Scoping statement 17 Listing statement 17 Looping statement 17 7 Scope 18 General Rules 18 Scope Classifications 18 File Scope 18 Function Scope 18 Assistant Scope 18 Local Scope 19 8 Compiler Control Lines 20 Page 3 of 23 MCSL LRM File inclusion 20 9 Examples 21 PI calculation 21 Pollard Monte Carlo factorization method 21 10 Appendix 23 Mc aggregate func input time 23 Mc list func input time 23 Page 4 of 23 MCSL LRM 1 Introduction Overview We are studying O Caml when design this general purpose simulation language The language aim to simplify the simulation programming with Monte Carlo method free the programmers to the programming details about the simulation and focus on the model of particular problems The discussion on generality provided the theoretical base for the feasibility of this idea Varieties and derivatives are introduced For example Quasi Monte Carlo method known as the Halton Hammersley Wozniakowski algorithm uses quasirandom numbers also called low discrepancy sequences And it has much faster speed on the evaluation of numerical integrations It was implemented in Mathematica as NIntegrate f Method QuasiMonteCarlo Matlab uses this algorithm when calculate t cumulative distribution function for four or more dimensions mvtcdf uses a quasi Monte Carlo integration algorithm based on methods developed by Genz and Bretz In 1992 a research group in the computer Science Department at Columbia University started testing QMC using improved low discrepancy sequences LDS on a 360 dimensional CMO provided by Goldman Sachs To our surprise QMC always beat MC Their research turned into a patent for an estimation method and system for complex securities using low discrepancy deterministic sequences Goal Since we are not experts on Monte Carlo theory which becomes more and more subtle and is still under development Our goal is not to compare or test the result for different algorithms Beside we are going to provide a language which simplifies the process of generate random numbers or low discrepancy sequences aggregation the simulation results and keeps the track of convergences or variational conditions Due to the scale of this project there would been no GUI or any graphics statistics tools Importing and exporting will be supported so data could be visualized in other mathematical softwares Sub algorithms Generation of random numbers Uniform distribution Mersenne twister It is designed with Monte Carlo simulations and other statistical simulations in mind Researchers primarily want good quality numbers but also benefit from its speed and portability Advantages It was designed to have a period of 219937 1 the creators of the algorithm proved this property In practice there is little reason to use larger ones as most applications do not require 219937 unique combinations 219937 is approximately 4 3 106001 It has a very high order of dimensional equidistribution It passes numerous stringent tests for statistical randomness Arbitrary distribution Most distribution could be generated by using Uniform 0 1 random numbers Algorithms is distribution depended inverse transformation acceptance rejection method composition method and etc Page 5 of 23 MCSL LRM Generation of low discrepancy sequences Sobol type Van der Corput Sequence Halton Sequence and Faure Sequence Key feature Most calculations are based on random or quasi random numbers So we introduce rand as a built in type for our language the only thing programmer has to do is to specify the algorithm to be used and the type of distribution Hybrid Style Most parts of the language follows the style of C language such as naming of keywords comments and functional structures But we also introduced some features from O Caml which we believe are convenient and elegant such as List map List fold left and List iter Page 6 of 23 MCSL LRM 2 Lexical Conventions There are six kinds of tokens identifiers keywords constants strings expression operators and other separators In general blanks tabs newlines and comments as described below are ignored except as they serve to separate tokens At least one of these characters is required to separate otherwise adjacent identifiers constants and certain operator pairs If the input stream has been parsed into tokens up to a given character the next token is taken to include the longest string of characters which could possibly constitute a token Comments The characters introduce a comment which terminates with the characters Identifiers An identifier is a sequence of letters and digits the first character must be alphabetic The underscore counts as alphabetic Upper and lower case letters are considered different Keywords The following identifiers are reserved for use as keywords and may not be used otherwise int float char string bool list array vector if else for rand return continue break Page 7 of 23 MCSL LRM Constants There are several kinds of constants as follows Integer constants An integer constant is a sequence of digits Floating constants A floating constant consists of an integer part a decimal point a fraction part an e and an optionally signed integer exponent The integer and fraction parts both consist of a sequence of digits Either the integer part or the fraction part not both may be missing either the decimal point or the e and the exponent not both may be missing Every floating constant is taken to be double precision In this language some
View Full Document
Unlocking...