montecarloeuro.m

来自「蒙特卡洛模拟来计算欧式期权的定价」· M 代码 · 共 31 行

M
31
字号
function [P] = MonteCarloEuro(OptionType,So,K,r,T,sigma,NSimulations)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function prices a Vanilla European Call/Put Option Value           %
% using Monte Carlo Simulation.                                           %
% No dividends are assumed in this model                                  %
% Parameters are as follows:                                              %
% OptionType = 1 for a Call or 0 for a Put                                %
% So = initial asset price ; K = strike price ; r = risk free rate        %
% T = time to maturity ;  sigma = volatility ;                            %
% NSimulations = number of simulations                                    %
% This function keeps track of the time required to price the option.     % 
% Note: When pricing using Monte Carlo simulations, you increase accuracy %
% by increasing the number of simulations. At least 5,000,000 simulations %
% seems sufficient for pricing accuracy within one cent.                  %
                                              %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

tic % Keep track of time

% Generate time to maturity simulations
ST = So * exp( (r - 0.5 * sigma^2) * T + sigma * sqrt(T) * randn(NSimulations,1) );

% Price the option
if OptionType == 1
    P = mean( exp(-r * T) * max(0, ST - K) ); % Call pricing
else
    P = mean( exp(-r * T) * max(0, K - ST) ); % Put pricing
end

toc % Keep track of time

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?