+ Reply to Thread
Results 1 to 10 of 10

Monte Carlo simulation

  1. #1
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Monte Carlo simulation

    Hello everyone,

    I have written a Monte Carlo simulation to see how different variables in the profile of a trading system play out in real life.

    For every simulation I run 3 trades X 80 days = 240 simulations.

    What I would like is to run this simulation 100 or even 1000 times and count the result for every single simulation and thus getting an average, maximum and minimum value.

    It is primarily the value in cell B13 and secondarily B14 I am interested in.

    I was thinking to maybe perform 100 simulations and record each result manually, but I could not copy and paste those cells for some reason.

    Any ideas?

    I attached the sheet.

    Thanks in advance!

    Best regards,

    Elijah
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Monte Carlo simulation

    No ideas?

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,755

    Re: Monte Carlo simulation

    Attached is a simple VBA solution. Make sure you allow macros to run when opening.

    Press the button and then enter the number of iterations when prompted. Results are saved in the new worksheet "Runs".

    You might want to think about building a histogram of the results instead of just min, avg, and max. Just a suggestion.
    Attached Files Attached Files
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Monte Carlo simulation

    Quote Originally Posted by 6StringJazzer View Post
    Attached is a simple VBA solution. Make sure you allow macros to run when opening.

    Press the button and then enter the number of iterations when prompted. Results are saved in the new worksheet "Runs".

    You might want to think about building a histogram of the results instead of just min, avg, and max. Just a suggestion.
    6StringJazzer,

    I LOVE you!

    That was truly beautiful. I just ran 1000 iterations and it was wonderful to sit back and enjoy what was unfolding in front of me

    How advanced is it to make a macro like that?

    I am clueless since I have never done any programming work, but I STRONGLY dislike getting stuff handed on a silver platter and not do it myself or at least be able to reproduce it.

    Very good suggestion regarding presenting it as a histogram.

    Thank you very much!

    Best regards,

    Elijah

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,755

    Re: Monte Carlo simulation

    If you press ALT+F11 you will get the development environment for VBA and can see the code. If you want a breakdown of how it works I can post a walkthrough.

  6. #6
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Monte Carlo simulation

    Quote Originally Posted by 6StringJazzer View Post
    If you press ALT+F11 you will get the development environment for VBA and can see the code. If you want a breakdown of how it works I can post a walkthrough.
    If you have the time to do so, I would highly appreciate it, even though I`m leaning towards being content with my understanding as it is since I got a lot on my plate these days.

    I have however run into a little discrepancy in the sheet you sent me, which is more important if you have the time.

    The thing is that the formula I entered in cell B14 (Account balance after 28% taxes) is wrong. I should only pay taxes on capital gains and not the whole account. Thus, the correct formula should be something like this:

    B14 = B13-((B13-B1)*0,28)

    In the second sheet, "Runs", the values in column A and and column B does not seem to be related.

    Is that because the code is not updated? Or is a simulation run independently for both these columns so that column B is not a function of column A as in the original sheet?

    I hope that made sense. My eyes are barely open right now and my cognitive abilites seems clouded

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,755

    Re: Monte Carlo simulation

    I did not anticipate the recalculation of RAND. RAND is being recalculated every time a value is saved to the "Runs" sheet. This occurs after it saves the value of B13 but before it saves the value in B14. This causes B14 to be updated before it is saved and it no longer correlates to B13.

    I corrected this problem, and also included your formula update. Here is a code walkthrough:

    Code in the module for worksheet MonteCarlo:
    Please Login or Register  to view this content.
    Code for module for worksheet Runs:
    Please Login or Register  to view this content.
    formRunning has no code.
    Attached Files Attached Files

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,755

    Re: Monte Carlo simulation

    Here is an upgrade that includes a histogram.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Monte Carlo simulation

    Thank you once again, 6StringJazzer!

    The sheet looks great. You are a saint!

    I really appreciate the code, but at the moment I think it is a bit over my head and I should probably get an introductory textbook on the subject to start with.

    Do you happen to know of any good material for getting started? Perhaps online?

    Best regards,

    Elijah

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,755

    Re: Monte Carlo simulation

    I don't know of an online tutorial but www.ozgrid.com has some great reference material. I learned a few years ago using a book by John Walkenbach. I highly recommend any of his stuff.

+ 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