Assignment 3 Surya Elements of Computing
Assignment 3 Surya Elements of Computing
Assignment – III(MATLAB)
I Semester
I Year ,AIE
Amrita school of Computing, Chennai
Name : - K.K.SURYESH
Roll no :- Ch.sc.u4aie24036
Case Study 1: Monte Carlo Simulation of European Call Option Pricing
Design a Monte Carlo simulation to price a European call option using the following parameters:
Requirements:
1. Implement a Monte Carlo simulation with at least 10,000 iterations
2. Use the Geometric Brownian Motion model for stock price simulation
3. Calculate the option price using risk-neutral valuation 4. Compute and report:
o Option price
o Standard error
MATLAB CODE :-
% Case Study 1: Monte Carlo Simulation for European Call Option Pricing
% Parameters
S0 = 100; % Initial stock price
K = 100; % Strike price
r = 0.05; % Risk-free interest rate
sigma = 0.2; % Volatility
T = 1; % Time to maturity
N = 10000; % Number of simulations
dt = T; % Time step
% Monte Carlo Simulation
% Geometric Brownian Motion Stock Price Path Simulation
rng(123); % Set random seed for reproducibility
% Simulate stock price paths
Z = randn(N, 1);
ST = S0 * exp((r - 0.5 * sigma^2) * T + sigma * sqrt(T) * Z);
% Option Payoff Calculation
payoff = max(ST - K, 0);
% Option Price Calculation
option_price = exp(-r * T) * mean(payoff);
% Standard Error Calculation
std_error = std(payoff * exp(-r * T)) / sqrt(N);
% Display Results
fprintf('European Call Option Price: $%.2f\n', option_price);
fprintf('Standard Error: $%.4f\n', std_error);
fprintf('95%% Confidence Interval: [%.2f, %.2f]\n', ...
option_price - 1.96*std_error, option_price + 1.96*std_error);
Assignment 2: Monte Carlo Simulation of Project Investment Risk
Develop a Monte Carlo simulation to assess the financial risk of a 5-year investment project with
the following characteristics:
Maximum: $120,000
Cost Range:
Minimum: $40,000
Maximum: $90,000
MATLAB CODE :-
% Case Study 2: Monte Carlo Simulation for Project Investment Risk Assessment
% Parameters
initial_investment = 100000; % Initial project cost
years = 5; % Project duration
num_simulations = 10000; % Number of Monte Carlo simulations
% Probabilistic Input Parameters (Triangular Distribution)
% Revenue Parameters
min_revenue = 50000;
most_likely_revenue = 85000;
max_revenue = 120000;
% Cost Parameters
min_cost = 40000;
most_likely_cost = 60000;
max_cost = 90000;
% Random Seed
rng(456);
% Monte Carlo Simulation
results = zeros(num_simulations, 1);
for i = 1:num_simulations
% Generate random revenues and costs using triangular distribution
revenue = trirnd(min_revenue, most_likely_revenue, max_revenue);
cost = trirnd(min_cost, most_likely_cost, max_cost);
% Calculate Net Present Value (NPV)
annual_cashflow = revenue - cost;
npv = -initial_investment;
% Assume 10% discount rate
for j = 1:years
npv = npv + annual_cashflow / (1 + 0.1)^j;
end
results(i) = npv;
end
% Analysis of Simulation Results
mean_npv = mean(results);
std_npv = std(results);
prob_positive_npv = sum(results > 0) / num_simulations * 100;
% Percentile Calculations
npv_5th_percentile = prctile(results, 5);
npv_95th_percentile = prctile(results, 95);
% Display Results
fprintf('Investment NPV Analysis:\n');
fprintf('Mean NPV: $%.2f\n', mean_npv);
fprintf('NPV Standard Deviation: $%.2f\n', std_npv);
fprintf('Probability of Positive NPV: %.2f%%\n', prob_positive_npv);
fprintf('5th Percentile NPV: $%.2f\n', npv_5th_percentile);
fprintf('95th Percentile NPV: $%.2f\n', npv_95th_percentile);
% Helper function for triangular distribution random number generation
function r = trirnd(a, b, c)
% a: minimum, b: mode, c: maximum
u = rand();
fc = (b - a) / (c - a);
if u < fc
r = a + sqrt(u * (b - a) * (c - a));
else
r = c - sqrt((1 - u) * (c - b) * (c - a));
end
end