Practical 5
Practical 5
CSPIT-IT 1
MA262-SNTD24IT179
● Option Pricing: Monte Carlo simulations are widely used in financial modeling, particularly in
pricing options (such as European, American, and Asian options). The method can model the
random behavior of asset prices over time and calculate the expected payoff.
● Particle Transport and Radiation: In nuclear physics, the Monte Carlo method is used for
simulating the behavior of particles (like neutrons, photons, or electrons) as they move
through materials, helping in radiation shielding and dosimetry.
3. Machine Learning
● Markov Chain Monte Carlo (MCMC): Used in Bayesian inference, MCMC methods generate
samples from probability distributions and are applied in a wide range of machine learning
tasks, including training probabilistic models and approximate posterior inference.
One of the simplest examples of using the Monte Carlo method is estimating the value
of π. This can be done by simulating random points within a square and counting how
many fall inside a quarter-circle inscribed in that square. The ratio of points inside the
circle to the total number of points is proportional to the area of the circle, which is
related to π.
Why is Monte Carlo Important?
Monte Carlo is important because it provides a simple and flexible approach to problems that
are difficult or impossible to solve analytically. Instead of relying on complex formulas or exact
solutions, Monte Carlo allows for the estimation of answers based on the probability of
random events, making it applicable in a wide range of fields.
Its strengths include:
Code : -
import random
import math
import matplotlib.pyplot as plt
def estimate_pi(sample_size):
inside_circle = 0
CSPIT-IT 2
MA262-SNTD24IT179
for _ in range(sample_size):
x = random.random()
y = random.random()
def run_simulation(sample_sizes):
results = {}
for size in sample_sizes:
pi_estimate = estimate_pi(size)
results[size] = pi_estimate
return results
results = run_simulation(sample_sizes)
Output : -
CSPIT-IT 3
MA262-SNTD24IT179
CSPIT-IT 4
MA262-SNTD24IT179
The program runs the Monte Carlo simulation for three different sample sizes:
10,000, 100,000, and 1,000,000, and estimates π for each. Here's an explanation of
how the results may vary:
● Sample Size: 10,000
With a sample size of 10,000, the estimate of π may not be very close to
the actual value because the number of points is relatively small, and the
randomness can cause deviations.
● Sample Size: 100,000
Increasing the sample size to 100,000 should improve the estimate of π. The
larger number of points better approximates the true ratio of points inside the
quarter-circle to total points, leading to a more accurate estimation.
● Sample Size: 1,000,000
With 1,000,000 points, the estimate of π should be quite close to the actual value
of π (3.14159...), as the larger sample size reduces the impact of random
fluctuations.
CSPIT-IT 5