THE REINSURANCE ACTUARY
  • Blog
  • Project Euler
  • Category Theory
  • Disclaimer

Monte Carlo Integration

20/11/2016

 

I blogged a while ago about using Monte Carlo methods to estimate the value of $\pi$.

We used random sampling inside a unit square and then counted the proportion of sample points that landed inside a unit circle. We knew what the area of the unit circle was - $\pi$ - and we could therefore relate the area we had calculated using random sampling with the known area of the circle.

It got my thinking that there is actually another way to think about what we did - we numerically integrated the unit circle and then compared this to the known value of the integral using analytical methods. But why can't we use this method to numerically integrate other shapes and curves? It turns out we can!

Lets set up some problems and look at how it works in practice.

Problem 1 - y = x

Integrate y = x from x = 0 to x = 1.

I first sampled 1000 points in the unit square and put them in a chart along with the line we are trying to integrate. This is just to help visualise what we are trying to do.
Picture

​Since we are interested in the area under the curve I coloured all these points in a different colour.
Picture
Since we have sampled randomly from the square, we would expect the proportion of points falling below the line will approach the proportion of the area below and above the line.

If we examine this ratio we get a value of $ 492 / 1000 $ which is very close to the value of $1/2$ we would expect from analytical methods.

Problem 2 - y = x ^ 2

Let's try again on a harder problem. What is the integral of $y = x^2$ between $0$ and $3$?

Let's create another graph of this problem:
​
Picture

When we look at the results we see that the ratio now is 0.3326, which once again we can see is converging to the answer we expect of 0.3333.

I had to bump the number of simulations up to 5000 in this example to get a reasonable fit.

​Problem 3 - e^(x^2)

You might be thinking to yourself at this point - all this is quite interesting but is there any benefit it doing things this way? All we've done so far is check the solutions to intergrals that we already know how to solve!

The integral for this problem however is known to have no elementary closed solution. That means that we can't just use A-level maths to calculate the integral.

The graph of the function isn't too complicated and looks like this:
Picture

I had to bump up the number of simulations here again to 50,000, but the analysis gave us a figure of 1.46 for the value of the integral.

So why does this particular problem matter again? It means that this method is not just an interesting curiosity. But that it actually allows solutions to be calculated for integrals which standard A-level integration techniques don't work for.

    Author

    ​​I work as an actuary and underwriter at a global reinsurer in London.

    I mainly write about Maths, Finance, and Technology.
    ​
    If you would like to get in touch, then feel free to send me an email at:

    ​LewisWalshActuary@gmail.com

      Sign up to get updates when new posts are added​

    Subscribe

    RSS Feed

    Categories

    All
    Actuarial Careers/Exams
    Actuarial Modelling
    Bitcoin/Blockchain
    Book Reviews
    Economics
    Finance
    Forecasting
    Insurance
    Law
    Machine Learning
    Maths
    Misc
    Physics/Chemistry
    Poker
    Puzzles/Problems
    Statistics
    VBA

    Archives

    March 2023
    February 2023
    October 2022
    July 2022
    June 2022
    May 2022
    April 2022
    March 2022
    October 2021
    September 2021
    August 2021
    July 2021
    April 2021
    March 2021
    February 2021
    January 2021
    December 2020
    November 2020
    October 2020
    September 2020
    August 2020
    May 2020
    March 2020
    February 2020
    January 2020
    December 2019
    November 2019
    October 2019
    September 2019
    April 2019
    March 2019
    August 2018
    July 2018
    June 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017
    September 2017
    June 2017
    May 2017
    April 2017
    March 2017
    February 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    April 2016
    January 2016

  • Blog
  • Project Euler
  • Category Theory
  • Disclaimer