Question: Your task is to extend this function to also price European options. Ensure that you do not alter the structure of the input arguments to
Your task is to extend this function to also price European options. Ensure that you do not alter the structure of the input arguments to maintain backwards compatibility with the original version.
function price binomialpricerS K r sigma, T type, NumSteps, varargin
Values American Options, both calls and puts, accommodating different
types of dividends
INPUTS
S : Initial Stock Price
K : Strike Price
r : Riskfree Rate
sigma : Stock volatility
T : Term to Maturity
type : Option type Call C or Put P
NumSteps : Number of steps in binomial tree
varargin : variable number of other input arguments.
No dividend: enter no extra input argument.
Continuous dividend yield
y : extra input which is the yield.
Discrete dividends
D : the dividend vector
xdate : time to exdividend date vector in years
OUTPUT
price : option value
compute tree parameters
dt TNumSteps; length of each time step, in years
u expsigmasqrtdt;
d u;
q expr dt du d; risk neutral prob of up state
df exprdt; discount factor
Forward propagation to construct the underlying price tree
First, preallocation
St zerosNumSteps NumSteps ; matrix to hold underlying prices
ft zerosNumSteps NumSteps ; matrix to hold option prices
Construct price tree
Go through different scenarios of dividend based on the number of
variable input arguments
n lengthvarargin;
switch n
case No dividend
Populate the tree with prices
St S;
for j :NumSteps
for i :j
Stij Sti ju;
end
Stij Sti jd;
end
case dividend yield
y varargin;
Recalculate q
q expr ydt du d;
Populate the tree with prices
St S;
for j :NumSteps
for i :j
Stij Sti ju;
end
Stij Sti jd;
end
case Scenario : discrete dividend
load input variables for this scenario
D varargin; dividend amount
xdate varargin; dividend timing
Remove NPV of dividends from initial price
pvD npvD xdate, r;
St SpvD;
Construct price tree that excludes the dividend
for j :NumSteps
for i :j
Stij Sti ju;
end
Stij Sti jd;
end
Then add back dividend for nodes that occur before ex div date
tau; Track time through tree steps
for j :NumSteps
check if current time step is before the dividend
timetoxdate xdate tau;
idx findtimetoxdate;
if ~isemptyidx
timetoxdate timetoxdateidx;
div Didx;
divtoaddback npvdiv timetoxdate, r; pv of relevant future dividends
St:jSt:jdivtoaddback;
end
taudt; Increase by timestep
end
end
Compute option prices at terminal nodes and perform backward induction to complete the option price tree
if type C
ft: end maxSt: end K;
Backward induction
for j NumSteps ::
for i :j
CV df qfti jqfti j;
IV Stij K;
ftij maxCV IV;
end
end
elseif type P
ft: end max K St: end;
Backward induction
for j NumSteps ::
for i :j
CV df qfti jqfti j;
IV K Stij;
ftij maxCV IV;
end
end
else
errorbinomialpricer Option type must be C or P;
end
price ft;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
