%% Find the Bond Key Rate Duration Given the Zero Curve Using datetime Inputs
% This example shows how to use datetime inputs for Settle and Maturity and also use a table for ZeroData to compute the key rate duration of a bond for key rate times of 2, 5, 10, and 30 years.

ZeroRates = [0.0476 .0466 .0465 .0468 .0473 .0478 ...
.0493 .0539 .0572 .0553 .0530]';

ZeroDates = daysadd('31-Dec-1998',[30 360 360*2 360*3 360*5 ...
360*7 360*10 360*15 360*20 360*25 360*30],1);

ZeroData = table(datetime(ZeroDates,'ConvertFrom','datenum','Locale','en_US'), ZeroRates);

krdur = bndkrdur(ZeroData,.0525,datetime('12/31/1998','Locale','en_US'),...
datetime('11/15/2028','Locale','en_US'),'KeyRates',[2 5 10 30])

% Copyright 2012 The MathWorks, Inc.