Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- paths = 30000000; %paths
- [ NumWorkers, NumBlocks, NumIter] = ChoiceParam( paths )%Choice of the number of workers
- delete(gcp('nocreate')) %Delete the current parallel pool
- parpool(NumWorkers) %Start a parallel pool to define the number of workers
- %Start a stopwatch to measure performance
- tic
- averPayoff = 0; %average call payoffs
- averPayoff_int = 0; %temporary average call payoffs
- parfor i = 1:NumBlocks;
- S_1 = 863.00 * ones(1,NumIter); %underlying spot price
- sigma1 = 0.20 * ones(1,NumIter); %volatility of 20.00%
- r1 = 0.0118 * ones(1,NumIter); %risk free rate of 1.18%
- T1 = 100/365.0 * ones(1,NumIter);%maturity in 100 days
- K1 = 860.00 * ones(1,NumIter); %strike
- zero1 = zeros(1,NumIter);
- % generate asset price
- M=S_1.*exp((r1 -0.5 * sigma1.^2) .* T1 + sigma1 .* sqrt(T1) .* normrnd(0.0,1.0,1,NumIter));
- % call payoffs
- payoff_i = max(M - K1, zero1);
- averPayoff_int = averPayoff_int + sum(payoff_i)/NumIter;
- end
- averPayoff = averPayoff_int / NumBlocks; %average call payoffs
- toc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement