%% Price a Portfolio Containing Two Cash Flow Instruments
% Price a portfolio containing two cash flow instruments paying interest annually over the four-year period from January 1, 2000 to January 1, 2004.
% Load the file deriv.mat, which provides HJMTree. The HJMTree structure contains the time and interest-rate information needed to price the instruments.

load deriv.mat;

%
% The valuation date (settle date) specified in HJMTree is January 1, 2000 (date number 730486).

HJMTree.RateSpec.ValuationDate

%
% Provide values for the other required arguments.

CFlowAmounts =[5 NaN 5.5 105; 5 0 6 105];
CFlowDates = [730852, NaN, 731582, 731947; 
              730852, 731217, 731582, 731947];

%
% Use this information to compute the prices of the two cash flow instruments.

[Price, PriceTree] = cfbyhjm(HJMTree, CFlowAmounts,... 
CFlowDates, HJMTree.RateSpec.ValuationDate)

% You can visualize the prices of the two cash flow instruments with the treeviewer function.
% Copyright 2012 The MathWorks, Inc.