www.gusucode.com > fininst 案例源码程序 matlab代码 > fininst/UsethebootstrapMethodtoCreateDualCurvesfortheDiscountandExample.m
%% Use the |bootstrap| Method to Create Dual Curves for the Discount and Projection Curves % Copyright 2015 The MathWorks, Inc. %% % Define the |Settle| date and deposit data. Settle = datenum('13-Dec-2012'); DepositRates = [.001865 .001969 .001951 .001874]'; DepositMat = datenum({'27-Dec-2012','03-Jan-2013','14-Jan-2013',... '13-Feb-2013'}); %% % Defines the forward rate agreement (FRA). FRARates = [.001775 .001274 .001222 .001269 .001565 .001961 .002556 ... .003101]'; FRAStartDate = datenum({'19-Dec-2012','20-Mar-2013','19-Jun-2013',... '18-Sep-2013','18-Dec-2013','19-Mar-2014','18-Jun-2014','17-Sep-2014'}); FRAEndDate = datenum({'19-Mar-2013','20-Jun-2013','19-Sep-2013',... '18-Dec-2013','18-Mar-2014','19-Jun-2014','18-Sep-2014','17-Dec-2014'}); %% % Define the swap data. SwapRates = [.00285 .00437 .00623 .00817 .01 .01171 .01324 .01459 .01692 ... .01933 .02099 .02156 .02186 .022308 .02288 .02367 .024126]'; SwapMat = datenum({'13-Dec-2015','13-Dec-2016','13-Dec-2017',... '13-Dec-2018','13-Dec-2019','13-Dec-2020','13-Dec-2021','13-Dec-2022',... '13-Dec-2024','13-Dec-2027','13-Dec-2032','13-Dec-2037','13-Dec-2042',... '13-Dec-2047','13-Dec-2052','13-Dec-2062','13-Dec-2072'}); %% % Build a forward curve. nDeposits = length(DepositMat); nFRA = length(FRAEndDate); nSwaps = length(SwapMat); InstrumentTypes = [repmat({'deposit'},nDeposits,1); repmat({'fra'},nFRA,1);repmat({'swap'},nSwaps,1)]; InstrumentData = [repmat(Settle,size(InstrumentTypes)) ... [DepositMat;FRAEndDate;SwapMat] ... [DepositRates;FRARates;SwapRates]]; %% % Define the discount curve. DiscountCurveDates = datemnth(Settle,[1 2 3 6 12*([1:5 7 10 15 20 30])],1); DiscountCurveRates = [0.0007 0.0006 0.00053 0.0002 .0001 0.0003 ... 0.0012 0.0027 0.0045 0.0083 0.013 0.018 0.02 0.021]'; DiscountCurve = IRDataCurve('zero',Settle,DiscountCurveDates,DiscountCurveRates) DiscountCurve.Data %% % Define the projection curve. ProjectionCurve = IRDataCurve.bootstrap('zero',Settle,InstrumentTypes,... InstrumentData,'DiscountCurve',DiscountCurve) ProjectionCurve.Data %% % Plot the results. PlottingDates = (Settle+20:30:Settle+365*25)'; TimeToMaturity = yearfrac(Settle,PlottingDates); figure plot(TimeToMaturity,DiscountCurve.getZeroRates(PlottingDates),'b') hold on plot(TimeToMaturity,ProjectionCurve.getZeroRates(PlottingDates),'r') title(['Projection and Discount Curves' datestr(Settle)]) legend({'Discount Curve','Projection Curve'},'location','southeast')