+ Reply to Thread
Results 1 to 5 of 5

Possible to speed up a Monte Carlo Simulation?

  1. #1
    Forum Contributor
    Join Date
    03-13-2009
    Location
    New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    136

    Possible to speed up a Monte Carlo Simulation?

    I wrote a program to run the simulation 6 times. Each simulation runs through 10,000 possible scenarios with each scenario stretching out yearly for 30 years. I timed it and it takes just over an hour to run through it all. Is this typical for vba or have I just managed to write the most inefficient code of all time? I am a complete amateur so it is possible and don't be afraid to tell me because I would love to know a better way.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Possible to speed up a Monte Carlo Simulation?

    See if this is faster:
    Please Login or Register  to view this content.
    Runs in a fraction of a second...

    Do you expect an answer based on the information provided?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Possible to speed up a Monte Carlo Simulation?

    One thing you're doing (from your other thread) is using WorksheetFunction.NormInv to generate random numbers with normal distribution. That's very slow; this runs about 100 times faster:
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    03-13-2009
    Location
    New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: Possible to speed up a Monte Carlo Simulation?

    Ahhh...I had a breakthrough. A combination of Shg (thank you very much), and a quick read on how to use arrays. What was slowing me down was that I was writing the value to each cell as I was calculating it. This time I run all of the calculations and then write them all at once to the cells. 10 minutes is now down to about 5 seconds.

    This stuff is so much fun!

    Please Login or Register  to view this content.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Possible to speed up a Monte Carlo Simulation?

    That's very good.

    If you replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    ... you should get significant additional speed.

    Also
    Please Login or Register  to view this content.
    should be just
    Please Login or Register  to view this content.
    Last edited by shg; 11-11-2009 at 12:59 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1