Simulation using Matlab Random Walk Integration Pricing an
Simulation using Matlab Random Walk Integration Pricing an Option
Random Walk % plotting several sample paths of random walks p=0. 4; n=50; num. Processes = 1; for i=1: num. Processes, y=[0 cumsum(2. *(rand(1, n-1)<=p)-1)]; % n steps plot([0: n-1], y, 'm'); hold on end
a=5; b=10; n=10; % number of simulations sum = 0; for i=1: n, x = rand(1); % x is a randon number between 0 and 1 x = x * (b - a); % x is now a random number between 0 and 2 x = x + a; % x is not a random number between 1 and 3 y = x/2; % implement the function for the random number between 1 and 3 sum = sum + y; % accumulate the samples end average = sum/n; % accumulate the samples area = (b - a) * average; % area = width * simulated height average area % print the simulated answer
a=1; b=3; n=100000; % number of simulations sum = 0; for i=1: n, x = rand(1); % x is a randon number between 0 and 1 x = x * (b - a); % x is now a random number between 0 and 2 x = x + a; % x is not a random number between 1 and 3 y = x^2 + 2; % implement the function for the random number between 1 and 3 sum = sum + y; % accumulate the samples end average = sum/n; % accumulate the samples area = (b - a) * average; % area = width * simulated height average area % print the simulated answer
Random Walk Simulation % plotting several sample paths of random walks p=0. 4; n=50; num. Processes = 1; for i=1: num. Processes y=[0 cumsum(2. *(rand(1, n-1)<=p)-1)]; % n steps plot([0: n-1], y, 'm'); hold on end
Simulating a Stock Option clear all; % clear all variables previously set days=365; % days left until option expires year = 365; % number of days in a year S 0 = 100; % stock price present value T=0 Strike = 120; % strike price of the option rate = 0. 05; % annual interest rate volatility = 3; % volatility value sample. Paths = 8; % number of Sample paths (ie simulations) payout = 0; for i=1: sample. Paths, y=[S 0 (S 0 + cumsum(S 0*rate*(1/year) + volatility. *randn(1, days)))]; plot(0: days, y, 'b'); hold on; if (y(days) > Strike) payout = payout + y(days) - Strike; end expected. Payout = payout/sample. Paths; call. Price = expected. Payout/(1 + (rate * days/year)); expected. Payout call. Price
- Slides: 6