Monte Carlo Simulation - Speed of convergence

Discussion in 'SP6' started by Edwin, Nov 3, 2012.

  1. Edwin

    Edwin Member

    I just performed the simulation exercise to estimate pi, however my simulation is nowhere close to 3.1428.... the average value is around 2! :(

    Surprisingly i used 4177 different values of the (x,y) coordinates since it failed to convergence for the first 100 as suggested by table 20.1 of Hull, 8th edition. I don't know what's wrong since I checked the excel formulas many times.

    On the other hand the simulation I did to price the Option struck at 50 as in table 20.2 converges very quickly to the Black Scholes price of 4.817.

    Could there be a reason why the two converge at varying speeds or why the pi one converges to a wrong value for 4000 diff coordinates?
     
  2. Oxymoron

    Oxymoron Ton up Member

    I actually tried this a couple of years back in MATLAB and faced the same issue - even after 1 billion simulations!

    Code:
    %  Monte Carlo computation of pi.
    
    n = input(' Enter n: ');
    count = 0;
    
    for i=1:n,
      x = 2*rand-1;  y = 2*rand-1;
      if x^2 + y^2 <= 1,  
      count = count + 1;  
      end;
    end;
    
    pi_approx = 4*(count/n);
    I think the difference could be because of the use of pseudo random numbers rather than actually random numbers. I'd be grateful too if someone else can shed more light on this.
     
    Last edited: Nov 4, 2012
  3. Edwin

    Edwin Member

    But even though the author does mention that the speed of convergence is slow for this example, suggesting a value of 3.04 for 100 coordinates is misleading, but that's only if other people faced the difficulty that I and you faced.
     
  4. Edwin

    Edwin Member

    After running your code, I found that the Matlab simulation is more than 150% better than the one I did it excel, in-fact for 1 billion simulations it gave 3.1417, not quite bad, it doesn't converge absolutely but it's not that far away from pi!

    I still wonder why mine is that WAY off??
     
    Last edited by a moderator: Nov 4, 2012
  5. didster

    didster Member

    Something is probably wrong if you run the simulation many times and get pi=2. What are you using as random numbers?

    I got 3.08 for 100 random dots in a square type simulation, but this is by chance. If you run it again it varies (expected as your input is supposed to be a random variable).

    Not sure why you'd expect the two monte carlo simulations to have similar speeds. They are very different in most aspects. You can analyse how fast they converge (variance, estimation error etc) but apples and oranges.

    As for running these things for a billion simluations, that might be a bit spurious. You'd need to make sure you're using a suitable random generator that can generate enough random values. Most generators repeat after a while.
     
    Last edited by a moderator: Nov 6, 2012
  6. Calum

    Calum Member

    For the unit circle estimation method, you should be getting values pretty consistently around three with n=50. It is however a pretty slow technique - it's not even stable to one decimal place at n=10000. I'm never sure why it's such a favourite for introducing Monte Carlo methodology.
     
  7. Edwin

    Edwin Member


    I gave up, I was possibly doing something wrong, still don't know what?
     
  8. Calum

    Calum Member

    Odd, certainly.

    Have you tested the psuedo random values generated? A scatterplot of your x,y values would reveal any obvious problems.

    Excel's RNG is poor quality, especially in <2007 versions, but you don't need high quality randomness for this sort of application.
     

Share This Page