www.gusucode.com > fininst 案例源码程序 matlab代码 > fininst/ComputethePriceofaPortfolioofInstrumentsExample.m
%% Compute the Price of a Portfolio of Instruments %% % The data for the interest-rate term structure is as follows: Rates = [0.035; 0.042147; 0.047345; 0.052707]; ValuationDate = 'Jan-1-2011'; StartDates = ValuationDate; EndDates = {'Jan-1-2012'; 'Jan-1-2013'; 'Jan-1-2014'; 'Jan-1-2015'}; Compounding = 1; %% % Create a |RateSpec|. RS = intenvset('ValuationDate', ValuationDate, 'StartDates',... StartDates, 'EndDates', EndDates,'Rates', Rates, 'Compounding', Compounding) %% % Create an instrument portfolio with two range notes and a floating rate % note with the following data and display the results: Spread = 200; Settle = 'Jan-1-2011'; Maturity = 'Jan-1-2014'; % First Range Note RateSched(1).Dates = {'Jan-1-2012'; 'Jan-1-2013' ; 'Jan-1-2014'}; RateSched(1).Rates = [0.045 0.055; 0.0525 0.0675; 0.06 0.08]; % Second Range Note RateSched(2).Dates = {'Jan-1-2012'; 'Jan-1-2013' ; 'Jan-1-2014'}; RateSched(2).Rates = [0.048 0.059; 0.055 0.068 ; 0.07 0.09]; % Create an InstSet InstSet = instadd('RangeFloat', Spread, Settle, Maturity, RateSched); % Add a floating-rate note InstSet = instadd(InstSet, 'Float', Spread, Settle, Maturity); % Display the portfolio instrument instdisp(InstSet) %% % The data to build the tree is as follows: Volatility = [.2; .19; .18; .17]; CurveTerm = [ 1; 2; 3; 4]; MaTree = {'Jan-1-2012'; 'Jan-1-2013'; 'Jan-1-2014'; 'Jan-1-2015'}; HJMTS = hjmtimespec(ValuationDate, MaTree); HJMVS = hjmvolspec('Proportional', Volatility, CurveTerm, 1e6); HJMT = hjmtree(HJMVS, RS, HJMTS) %% % Price the portfolio. Price = hjmprice(HJMT, InstSet)