Search
Code Directory
 ASP
 ASP.NET
 C/C++
 CFML
 CGI/PERL
 Delphi
 Development
 Flash
 HTML
 Java
 JavaScript
 Pascal
 PHP
 Python
 SQL
 Tools
 Visual Basic & VB.NET
 XML
New Code
Vue Injector 3.3
Spectrum Analyzer pro Live 2019
Devart Excel Add-in for HubSpot 2.1
RentALLScript - Airbnb clone 2.2
SuiteCRM Theme Customization 7.11.6
iScripts NetMenus 3.1
iScripts EasyIndex 2.2
iScripts EasySnaps 2.0
Australia MyPost shipping For Magento 2 1.0.0
Australia Post eParcel For Magento 1.1.1
Source Control for SQL Server 2.0
Answers phpSoftPro 3.12
Exlcart 2.0
School College ERP 1.3.2
White-label Grocery Delivery App Solution 2.0
Top Code
IcrediBB Bulletin Board System 1.0
iScripts EasySnaps 1
iScripts EasyIndex 1
iScripts NetMenus 2.0
Azizi search engine script PHP 4.1.10
White-label Grocery Delivery App Solution 2.0
MP3 Player (GUI) (Sripts) 1.0
Vue Injector 3.3
JAT JADE Agent Testing framework 1.0.0
CamStudio 2.0
Faculty Evaluation System 1.1
inout Music Ultimate
Tradebit Download and Affiliate Shop 3.0.0
Readymade MLM Products 2.01
Classic HangMan Game 1.0
Top Rated
phpEnter 5.1.
Quick Maps For Dynamics CRM 3.1
Single Leg MLM 1.2.1
Azizi search engine script PHP 4.1.10
Paste phpSoftPro 1.4.1
Extreme Injector 3.7
Deals and Discounts Website Script 1.0.2
Solid File System OS edition 5.1
Classified Ad Lister 1.0
Aglowsoft SQL Query Tools 8.2
Invoice Manager by PHPJabbers 3.0
ICPennyBid Penny Auction Script 4.0
PHP Review Script 1.0
ATN Resume Finder 2.0
ATN Site Builder 3.0
Calculate Pi using Monte Carlo Simulations in Python (Vectorized) 
File ID: 64473






Calculate Pi using Monte Carlo Simulations in Python (Vectorized) 
Download Calculate Pi using Monte Carlo Simulations in Python (Vectorized) http://code.activestate.com/recipes/577578-calculate-pi-using-monte-carlo-simulations-in-pyth/?in=lang-pythonReport Error Link
License: Freeware
Downloads: 148
User Rating:3 Stars  (1 rating)
Submit Rating:
Calculate Pi using Monte Carlo Simulations in Python (Vectorized)  Description
Description: 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.

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.

It might be useful for visualization to plot the occurrence of data points, and observe the randomness

License: Freeware

Related: Calculate, carlo, monte, pi, Python

O/S:Windows

Downloads: 148



More Similar Code

An example to price an Arithmetic Average fixed strike Call option in the Black-Scholes framework using Monte Carlo Control Variate



This set of files show some of the principles of Monte Carlo simulations, applied in the financial industry. this is the content of the web seminar called "Simulations de Monte Carlo en MATLAB".

The slides are in French and a...



Numerical Integration using Monte Carlo method.



Calculating area under the curve using Monte Carlo method
for any given function.



Monte Carlo methods have long been used in computational finance to solve problems where analytical solutions are not feasible or are difficult to formulate. However, these methods are computationally intensive making it challenging to implement...



Function for pricing basket option using Monte Carlo Simulation. You can specify if you want an American option. For American options, it follows LMS algorithm. You can choose to specify Averaging date, Average Price, Average type etc.



Calculate pi using the Gaussian-Legendre algorithm. The function PIGL.M produces an ASCII file containing the number of decimals requested. The maximum number depends on free disk space and the RAM available.



SPSens is a complete software package written in C that estimates parameter sensitivities for stochastic models of chemical and biochemical reaction networks using Monte Carlo (MC) stochastic simulations. It is possible to estimate sensitivities...



Simulation model to accompany the article, "Monte-Carlo Simulation in MATLAB Using Copulas" in the November 2003 issue of MATLAB News&Notes. The function METAPOP runs the metapopulation simulation model described in the article.



The solution of the nearest correlation matrix applies the hypershpere or spectral decomposition methods as outlined in Monte Carlo methods in Finance by Peter Jackel, Chapter 6.

Use CorrelationExample.m that applies a simple example...

User Review for Calculate Pi using Monte Carlo Simulations in Python (Vectorized)
- required fields
     

Please enter text on the image