%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Octave commands to compute weighted linear regression as in
% Exercise 2.46 of "Binomial Models in Finance" by
% John van der Hoek and Robert J. Elliott
%
% M.V.Wickerhauser, 2019-09-08
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N=5; % how many strike prices
xi=[17.50,18.00, 18.50, 19.00, 19.50]; % strike prices, from Table 2.1
yi=[0.36,0.19,0.12,0.06,0.06]; % C(0) premiums, from Table 2.1
ni=[171, 316, 475, 802, 594]; % open interest, from Table 2.1
n=sum(ni); % total open interest
wi=ni/n; % weights: proportional open interest
% Perform a weighted linear regression to find the best fit line y=m*x+c:
xbar=wi*xi';
ybar=wi*yi';
xybar=wi*(xi.*yi)';
xxbar=wi*(xi.*xi)';
m=(xybar-xbar*ybar)/(xxbar-xbar*xbar); m % best fit slope m = -0.12375
c=ybar-m*xbar; c % best fit y-intercept c = 2.4357
% Use the best fit line to estimate Call premium y=C(0) at strike x=K=17.00
K=17.00; C = m*K+c; C % Call premium estimate is C(0) = 0.33185
% Plot the data points in black and the best-fit line in blue:
plot(xi,yi,"k"); hold on; plot(xi,m*xi+c,"b");
% ...to see that a straight line misrepresents the relationship.
% Use the call-put parity formula C(0)-P(0)=S(0)-K/R
% to estimate P(0) = C(0)+K/R-S(0) from the estimated C(0):
S=16.96; % spot price S(0)
R=1.0042; % risk-free return factor to be used
P=C+K/R-S; P % estimated Put premium is P(0) = 0.30075
% This is very different from the market price P(0) = 0.55
% ...which confirms that the straight line approximation is misleading.
% Compute risk-neutral probability pi (call it pr) from m=-pr/R
pr=-R*m; pr, 1-pr % pr = 0.12427, so 1-pr=0.87573
% Compute up factor u from c=pr*u*S/R
u=c*R/(S*pr); u % up factor u = 1.1605
% Compute down factor d from d=(R-pr*u)/(1-pr)
d=(R-pr*u)/(1-pr); d % down factor d = 0.98202
%%% EXTRA: repeat the estimates of C(0) and P(0) at K=17 using pr,u,d,
% Compute estimated P(0) from the CRR model as in Eq.2.37, p.27:
(1-pr)*(K-d*S)/R % ans = 0.30075
% Compute estimated C(0) from the CRR model as in Eq.2.33, p.26:
pr*(u*S-K)/R % ans = 0.33185