%% Price a Cap Using capbynormal and Compare to capbyblk
% Define the RateSpec.

Settle = datenum('20-Jan-2016');
ZeroTimes = [.5 1 2 3 4 5 7 10 20 30]';
ZeroRates = [0.0052 0.0055 0.0061 0.0073 0.0094 0.0119 0.0168 0.0222 0.0293 0.0307]';
ZeroDates = datemnth(Settle,12*ZeroTimes);
RateSpec = intenvset('StartDate',Settle,'EndDates',ZeroDates,'Rates',ZeroRates)

%
% Define the cap instrument and price with capbyblk.

ExerciseDate = datenum('20-Jan-2026');

[~,ParSwapRate] = swapbyzero(RateSpec,[NaN 0],Settle,ExerciseDate)

Strike = .01;
BlackVol = .3;
NormalVol = BlackVol*ParSwapRate;

Price = capbyblk(RateSpec,Strike,Settle,ExerciseDate,BlackVol)

%
% Price the cap instrument using capbynormal.

Price_Normal = capbynormal(RateSpec,Strike,Settle,ExerciseDate,NormalVol)

%
% Price the cap instrument using capbynormal for a negative strike.

 Price_Normal = capbynormal(RateSpec,-.005,Settle,ExerciseDate,NormalVol)

% Copyright 2012 The MathWorks, Inc.