Problem Valuing Multiple Swaps using the function 'swapbyzero'

1 visualización (últimos 30 días)
Punar
Punar el 5 de Jul. de 2012
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);
end
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);
end
end
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 comentarios
Javier
Javier el 1 de Sept. de 2012
Editada: Jan el 1 de Sept. de 2012
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
StartDate='01-Jan-2000';
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' ...
;'01-Jan-2002';'01-Jan-2003';'01-Jan-2004';'01-Jan-2005'];
Rates=[0.0208;0.0208;0.0208;0.0209;0.0209;0.021;ones(10,1)*0.0215;0.0227;0.02441;0.02608;0.02764];
SimulRates=randn(20,1000)/1000;
SimulRates=SimulRates+Rates*ones(1,1000);
RateSpec=intenvset('Rates',SimulRates,'StartDates',StartDate,'EndDates',EndDates,'Compounding',1);
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
3)Pricing
>> price = swapbyzero(RateSpec, LegRate, settle, Maturity, LegReset, Basis, Principal, LegType)
Hope it helps. Best Regards
Javier
[EDITED, Code formatted, Jan]
Jan
Jan el 1 de Sept. de 2012
@Javier, please post this as an answer, such that it can be accepted if it solved the problem. Thanks.

Iniciar sesión para comentar.

Respuestas (1)

Javier
Javier el 1 de Sept. de 2012
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
StartDate='01-Jan-2000';
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' ...
;'01-Jan-2002';'01-Jan-2003';'01-Jan-2004';'01-Jan-2005'];
Rates=[0.0208;0.0208;0.0208;0.0209;0.0209;0.021;ones(10,1)*0.0215;0.0227;0.02441;0.02608;0.02764];
SimulRates=randn(20,1000)/1000;
SimulRates=SimulRates+Rates*ones(1,1000);
RateSpec=intenvset('Rates',SimulRates,'StartDates',StartDate,'EndDates',EndDates,'Compounding',1);
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
3)Pricing
price = swapbyzero(RateSpec, LegRate, settle, Maturity, LegReset, Basis, Principal, LegType)
Hope it helps. Best Regards
Javier

Categorías

Más información sobre Price and Analyze Financial Instruments en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by