Monte Carlo script, Python

Discussion in 'The Cocktail Lounge' started by tbw875, Jun 15, 2018.

  1. tbw875

    tbw875 Active Member

    Joined:
    Mar 19, 2017
    Messages:
    65
    Likes Received:
    25
    Hey all,

    The last few weekends when I had some freetime, I tried my best at gathering and updating some code to run a simple Monte Carlo simulation. I believe it's ready to let others give it a shot, so you can find it here:

    https://github.com/twalsh-wp/montecarlo

    A Monte Carlo simulation takes some statistical properties of the stock price over a given period (in this case, 2006 to the latest market close), and propagates these same properties over 252 trading days (1 year). Multiply this process by 10,000 iterations, and you have a statistical simulation that gives you a normal distribution of possible stock prices 1 year from now. The mean of this distribution is the most likely price 1 year from now, but other information is helpful too, such as the 5% and 95% percentiles.

    Running this script with a ticker as an argument will output:
    • The latest closing price for the given ticker
    • A Describe statement for the simulation. You'll want to pay attention to the Mean here.
    • A matplotlib chart showing all of the simulations over 1 year
    • A histogram showing the final price after 1 year for all iterations
    It runs in python 3, which comes standard in MacOS, and is very easy to install if you don't have it already. I'll spare the details, but ask if you need help. You'll also need a couple relatively standard packages that can be found in the ReadMe.

    Usage
    In terminal or command line:
    python MonteCarlo.py AMZN

    The script should not take any longer than about 1 minute to run. The bulk of the waittime is due to matplotlib plotting the charts, which isnt entirely necessary, but is pretty.

    If you have any questions, let me know. I'll try to upload some pretty pictures and stats tomorrow to entice those of you who aren't able to run it just yet.

    Cheers,
    -T
     
    T0rm3nted likes this.

Share This Page