This document contains code to calculate the price of a European call/put option using a binomial tree method. It defines two functions:
1) BinTree builds a binomial tree with nodes representing the stock price over discrete time periods to model its evolution, given parameters like the initial stock price, risk-free rate, volatility, and time horizon.
2) BinOptionValue uses the binomial tree generated by BinTree to calculate the option price by working backwards from the terminal nodes to the initial node, taking the average of the option payoffs at each node weighted by the probability of reaching that node.
This document contains code to calculate the price of a European call/put option using a binomial tree method. It defines two functions:
1) BinTree builds a binomial tree with nodes representing the stock price over discrete time periods to model its evolution, given parameters like the initial stock price, risk-free rate, volatility, and time horizon.
2) BinOptionValue uses the binomial tree generated by BinTree to calculate the option price by working backwards from the terminal nodes to the initial node, taking the average of the option payoffs at each node weighted by the probability of reaching that node.
This document contains code to calculate the price of a European call/put option using a binomial tree method. It defines two functions:
1) BinTree builds a binomial tree with nodes representing the stock price over discrete time periods to model its evolution, given parameters like the initial stock price, risk-free rate, volatility, and time horizon.
2) BinOptionValue uses the binomial tree generated by BinTree to calculate the option price by working backwards from the terminal nodes to the initial node, taking the average of the option payoffs at each node weighted by the probability of reaching that node.
% Returns Binomial Shrew Price Tree (imod=0 for JR, 1 for CRR) deltaT = T/N; if imod == 0 rnmut=(r-q-0.5*sigma^2)*deltaT; u=exp(rnmut+sigma*sqrt(deltaT)); d=exp(rnmut-sigma*sqrt(deltaT)); else u=exp(sigma * sqrt(deltaT)); d=1/u; end lattice = ones(N+1,N+1)*S0; for i=2:N+1 lattice(1,i)= 0; end for j=2:1:N+1 for i=1:j-1 lattice(j,i) =u*lattice(j-1,i); end lattice(j,j) =d*lattice(j-1,j-1); for i=j+1:N+1 lattice(j,i) =0; end end imod=0;S0=100;r=0.02;q=0.03;T=1;sigma=0.2;N=9; lattice = BinTree(imod,S0,r,q,T,sigma,N); HW2:
function [price, lattice] =
BinOptionValue(imod,S0,X,r,q,T,sigma,N) deltaT = T/N; if imod == 0 rnmut=(r-q-0.5*sigma^2)*deltaT; u=exp(rnmut+sigma*sqrt(deltaT)); d=exp(rnmut-sigma*sqrt(deltaT)); p=0.5; else u=exp(sigma * sqrt(deltaT)); d=1/u; p=(exp((r-q)*deltaT) - d)/(u-d); end lattice = zeros(N+1,N+1); for j=0:N lattice(N+1,j+1)=max(0 , X-S0*(u^j)*(d^(N-j)) ); end for i=N-1:-1:0 for j=0:i lattice(i+1,j+1) = exp(-r*deltaT) * ... (p * lattice(i+2,j+2) + (1-p) * lattice(i+2,j+1)); end end price = lattice(1,1); [price, lattice]=BinOptionValue(0,100,100,0.02,0.03,1,0.2,10000); [Call,Put] =blsprice(100,100,0.02,1,0.2,0.03);