%% Stripping Caplet Volatilities from Caps Using the Shifted Black Model
% Compute the zero curve for discounting and projecting forward rates.

ValuationDate = datenum('1-Mar-2016');
ZeroRates = [-0.38 -0.25 -0.21 -0.12 0.01 0.2]/100;
CurveDates = datemnth(ValuationDate, [0.25 0.5 1 2 3 5]*12);
ZeroCurve = IRDataCurve('Zero',ValuationDate,CurveDates,ZeroRates)

%
% Define the cap volatility (Shifted Black) data.

CapSettle = datenum('1-Mar-2016');
CapMaturity = datenum({'1-Mar-2017';'1-Mar-2018';'1-Mar-2019'; ...
    '2-Mar-2020';'1-Mar-2021'});
CapVolatility = [0.35;0.40;0.37;0.34;0.32]; % Shifted Black volatilities
Shift = 0.01; % 1 percent shift.
CapStrike = -0.001; % -0.1 percent strike.

%
% Strip caplet volatilities from caps using the Shifted Black Model.

[CapletVols, CapletPaymentDates, CapStrikes] = capvolstrip(ZeroCurve, ...
CapSettle,CapMaturity,CapVolatility,'Strike',CapStrike,'Shift',Shift);

PaymentDates = string(datestr(CapletPaymentDates));
format;
table(PaymentDates,CapletVols,CapStrikes)

% Copyright 2012 The MathWorks, Inc.