Problem Valuing Multiple Swaps using the function 'swapbyzero'

조회 수: 1 (최근 30일)
Punar . 2012년 7월 5일
I have 1000 scenarios of interest rate term structres. Each scenario has various 'horizon dates' having a fixed interval between two consecutive dates. On each date I have 6 month forward LIBOR rates for 10 years.
Using these interest rates as an input, I need to value a swap with other inputs fixed on each of these dates. So, I would have 1000 swaps to be valued on each date - one corresponding to each scenario. On the next date only thing that changes is the valuation date.
To do this, I am using the function 'swapbyzero'.
The problem I am facing is that I am unable to value all the swaps in one go(calling the function just once).
s = 1 : NoOfScenarios;
i = 2 : NoOfHD;
Price = swapbyzero(RateSpec, LegRate, Settle, Maturity);
%RateSpec is the matrix of RateSpecs correponding to the horizon dates and the scenarios.
It says all the swaps should have same valuation date. Then I tried to value the 1000 swaps for each date in one go which have all inputs same except the interest rates.
s = 1 : NoOfScenarios;
for i = 2 : NoOfHD
Price(:,i) = swapbyzero(RateSpec(:,i), LegRate, Settle, Maturity);
When I do this, it gives the error: _The first argument must be 1 or 2 term structures created using INTENVSET._
Now I am left with only one option: to create two nested loops and value each swap individually - which takes around a minute for each scenario. It is 100x slower than the correpsonding Excel VBA code.
for s = 1 : NoOfScenarios
for i = 2 : NoOfHD
Price(:,i) = swapbyzero(RateSpec(:,i), LegRate, Settle, Maturity);
Probably I am not using the functions properly. Is there anyway else I can do it? Any other function to value the swaps or another way to use the function? Please help me out!
  댓글 수: 2
Jan 2012년 9월 1일
@Javier, please post this as an answer, such that it can be accepted if it solved the problem. Thanks.

댓글을 달려면 로그인하십시오.

답변 (1개)

Javier 2012년 9월 1일
Hello Punar
There is no need to do a loop. What you have to do is define the RateStructure with your 1000 interest rate structures. Procedure here:
1)Define Rate Structure
EndDates=['02-Jan-2000';'03-Jan-2000';'06-Jan-2000';'10-Jan-2000' ...
;'01-Feb-2000';'01-Mar-2000';'01-Apr-2000';'01-May-2000';'01-Jun-2000';'01-Jul-2000' ...
;'01-Aug-2000';'01-Sep-2000';'01-Oct-2000';'01-Nov-2000';'01-Dec-2000';'01-Jan-2001' ...
2)Swap Structure
settle = '01-Jan-2000';
Maturity = '01-Jan-2003';
Basis = 0;
Principal = [100;50;100]; %three notional amounts
LegRate = [0.06 20]; % [CouponRate Spread]
LegType = [1 0]; % [Fixed Float]
LegReset = [1 1]; % Payments once per year
price = swapbyzero(RateSpec, LegRate, settle, Maturity, LegReset, Basis, Principal, LegType)
Hope it helps. Best Regards


Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by