Most viewed recipes tagged "monte"http://code.activestate.com/recipes/tags/monte/views/2014-04-27T17:25:25-07:00ActiveState Code RecipesCalculate Pi using Monte Carlo Simulations in Python (Vectorized) (Python) 2011-02-17T22:35:46-08:00Zach Pacehttp://code.activestate.com/recipes/users/4177048/http://code.activestate.com/recipes/577578-calculate-pi-using-monte-carlo-simulations-in-pyth/ <p style="color: grey"> Python recipe 577578 by <a href="/recipes/users/4177048/">Zach Pace</a> (<a href="/recipes/tags/calculate/">calculate</a>, <a href="/recipes/tags/carlo/">carlo</a>, <a href="/recipes/tags/monte/">monte</a>, <a href="/recipes/tags/pi/">pi</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>I saw something like this in C++ as an introduction to Monte Carlo, so I decided to make something similar in Python. My original code used for loops, but I vectorized it with no small amount of effort, and it now runs orders of magnitude faster. For example, I can calculate pi to .002% error with 100,000,000 randomized coordinates in approximately 15 seconds. Careful to start small, because memory fills up quickly, and the computer will run slow if you overstep your RAM. I'm able to go up to a bit more than 150 million without compromising speed and functionality in other tasks.</p> <p>For those who are curious, vectorization is a technique whereby numpy (or similar) arrays replace things like loops. They're a bit tricky to write (at least for me), but they work beautifully.</p> <p>It might be useful for visualization to plot the occurrence of data points, and observe the randomness</p> Monte Carlo Engine : Simple Head Tail Model (Python) 2014-04-27T17:25:25-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578868-monte-carlo-engine-simple-head-tail-model/ <p style="color: grey"> Python recipe 578868 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/carlo/">carlo</a>, <a href="/recipes/tags/monte/">monte</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/strategy/">strategy</a>). Revision 2. </p> <p>Wanted to implement something that shows how the simple framework can be used to investigate a basic heads and tail game. The betting strategy can be varied simply by changing the logic in the ontrail() method. This currently tests the double or quits strategy. Run it to see how many </p> Monte Carlo Engine : Stochastic Interest Rate Predictor (Python) 2014-04-27T16:42:29-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578867-monte-carlo-engine-stochastic-interest-rate-predic/ <p style="color: grey"> Python recipe 578867 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/carlo/">carlo</a>, <a href="/recipes/tags/interest/">interest</a>, <a href="/recipes/tags/model/">model</a>, <a href="/recipes/tags/monte/">monte</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/rate/">rate</a>). Revision 2. </p> <p>This is a simple Monte Carlo Engine model, based on some ideas from the Quantopian folks. The idea is that the model and the engine are separate. I have integrated a simple example from an earlier post. The idea was to try and build some game theory simulations using simple models that were separate from the Engine. </p>