Geometric Brownian Motion
From ThetaWiki
Contents |
[edit] Overview
Geometric Brownian motion is the underlying assumption for Black-Scholes Option Pricing. It dictates that future stock prices are not predictable and evolve as
- dSt = μStdt + σStdWt
where μ is the drift rate, σ the volatility of S and dWt the increment of a Wiener process.
[edit] Process simulation
[edit] Implementation as Theta.m
[edit] 1-Dimensional
function state = Theta(dt, state) if nargin == 0 state.S.comment = 'Stock price'; state.EUR.comment = 'Numeraire'; state.sigma.comment = 'Volatility'; state.r.comment = 'Risk-free rate'; else % risk-free rate r = state.r(1); % excess return mu = r; % volatility sigma = state.sigma(1); state.S = state.S .* exp( (mu-0.5*sigma^2)*dt + sqrt(dt)*sigma*randn(size(state.S))); state.EUR = state.EUR* exp(-r*dt); end
[edit] N-Dimensional
function state = Theta(dt, state) if nargin == 0 state.S.comment = 'Stock price'; state.EUR.comment = 'Numeraire'; state.rho.comment = 'Correlation'; state.sigma.comment= 'Volatility'; else r = 0.05; mu = r; rho=mean(state.rho); sigma = ones(1,size(state.S,2))*mean(state.sigma); Z=zeros(length(sigma),length(sigma)); for i=1:length(sigma) for k=1:length(sigma) if i==k Z(i,i)=sigma(i)^2; else Z(i,k)=rho*sigma(i)*sigma(k); end end end A=(chol(Z))'; B=randn(size(state.S')); for i = 1:length(sigma) state.S(:,i) = state.S(:,i) .* exp( (mu-0.5*sigma(i)^2)*dt + sqrt(dt)*(A(i,:)*B)'); end state.EUR = state.EUR*exp(-r*dt); end end
[edit] Implementation in ThetaScript
Model BS %Black Scholes model import So "Initial Stock Price" import EURo "Initial value of Numeraire" import r "Risk free rate" import vola "volatility" export S "Stock Price" export EUR "Numeraire" S=So EUR=EURo fork loop inf theta $dt S=S*exp(-0.5*vola^2*$dt+vola*sqrt($dt)*randn()) EUR=EUR*exp(-r*$dt) end end end
[edit] Analytic pricing
The price of European puts and calls can be obtained by calling theta_bls()
function result = theta_bls(S, K, sigma, r, T, call, greek) %function result = theta_bls(S, K, sigma, r, T, call, greek) % % returns option characteristics European Put and Call options with % % S : asset price % K : strike % sigma: volatility % r : risk-free rate % T : maturity time % call: true for call, otherwise put % greek: "value", "delta" or "gamma" if T<=0 if call V = max(S-K,0); else V = max(K-S,0); end return end d1 = ( log(S./K) + (r + (sigma.^2)/2)*T ) ./ (sigma * sqrt(T)); d2 = d1 - sigma*sqrt(T); switch call case true switch greek case 'value' result = S.*normcdf(d1,0,1) - K .* exp(-r.*T).*normcdf(d2); case 'delta' result = normcdf(d1,0,1)'; case 'gamma' result = (normpdf(d1,0,1)./(S.*sigma.*sqrt(T)))'; end otherwise switch greek case 'value' result = -S.*normcdf(-d1,0,1) + K .* exp(-r.*T).*normcdf(-d2); case 'delta' result = normcdf(d1,0,1)'-1; case 'gamma' result = (normpdf(d1,0,1)./(S.*sigma.*sqrt(T)))'; end end
