Nanyi-Introduction to Monte Carlo method

Source: Internet
Author: User

This article is reproduced from the Nanyi-Monte Carlo method primer

In this paper, the Monte Carlo method is introduced by five examples.

I. Overview

Monte Carlo method is a computational method. The principle is to understand a system by a large number of random samples, and then get the value to be computed.

It is very powerful and flexible, and quite simple to understand and easy to implement. For many problems, it is often the simplest method of calculation, and sometimes even the only feasible method.

It was born in the 40 's American "Manhattan Project", the name from the city of Monte Carlo, symbolic probability.

Ii. Calculation of π

The first example is how to calculate pi π by Monte Carlo method.

There is a tangent circle inside the square, and the ratio of their area is Π/4.

Now, within this square, randomly generate 10,000 points (i.e., 10,000 coordinate pairs (x, y)) and calculate their distance from the center point to determine if they fall within the circle.

If these points are evenly distributed, then the points within the circle should occupy the π/4 of all points, so multiply this ratio by 4, which is the value of π. The R language script randomly simulates 30,000 points, and the estimated value of π differs from the real value by 0.07%.

Three, the calculation of the integral

The above method can be generalized to calculate the value of any one integral.

For example, calculating the function y = x2 the integral in the [0, 1] interval is to find the area of the red part.

This function has a value of 1 at the () point, so the entire red area is inside a square with an area of 1. Within the square, a large number of random points are generated, and you can calculate how many points fall in the red area (judging condition y < x2). This proportion is the required integral value.

Using MATLAB to simulate 1 million random points, the result is 0.3328.

Iv. Traffic jams

The Monte Carlo method can be used not only for calculation, but also for simulating stochastic motion inside the system. The following example simulates a single-lane traffic jam.

According to the Nagel-schreckenberg model, the vehicle's motion satisfies the following rules.

  • The current speed is v.
  • If there is no car in front, it will increase to V + 1 in the next second, until the specified maximum speed limit is reached.
  • If there is a car in front, the distance is D, and D < V, then it slows down to d-1 in the next second.
  • In addition, the driver will slow down randomly with probability p, reducing the speed of the next second to V-1.

In a straight line, randomly generate 100 points, representing 100 vehicles on the road, and the probability p is 0.3.

, the horizontal axis represents the distance (from left to right), and the vertical axes represent time (top to bottom), so each line represents the next second of the road condition.

As you can see, the model randomly generates traffic jams (the black-gathered part of the graph). This proves that a single lane can cause traffic jams even for no reason.

Five, product thickness

A product is made up of eight parts stacked. In other words, the total thickness of the eight parts is equal to the thickness of the product.

It is known that the thickness of the product must be controlled within 27mm, but each part has a certain probability, the thickness will exceed the error. How much probability is there, the product thickness will exceed 27mm?

Take 100,000 random samples, each with 8 values, corresponding to the respective thickness of the 8 parts. The calculation found that the passing rate of the product is 99.9979%, that is, the probability of 21, the thickness will exceed 27mm.

VI. Securities Markets

Stock markets are sometimes brisk trading and sometimes trading is deserted. Here is your forecast for the market.

    • If the deal is deserted, you will sell 50,000 shares at an average price of 11 yuan.
    • If trading is active, you will sell 100,000 shares at an average price of 8 yuan.
    • If the deal is moderate, you will sell 75,000 shares at an average price of 10 yuan.

Your cost is known to be between $5.5 and $7.5 per share, with an average of 6.5 yuan. What is your net profit for the next transaction?

Take 1000 random samples, each with two values: one is the cost of the security (5.5 yuan to 7.5 yuan evenly distributed), the other is the current market state (deserted, active, moderate, one-third possible).

The average net profit for the simulation was 92, $427.

Seven, reference link
    • Introduction to Monte Carlo methods,by Alex Woods
    • Monte Carlo Simulation Tutorial
    • Monte Carlo method Introduction, by Wang Xiaoyong
    • An application example of Monte Carlo simulation

(ext.) Nanyi-Introduction to Monte Carlo method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.