swapbycir
Price swap instrument from Cox-Ingersoll-Ross interest-rate tree
Syntax
Description
[
prices a swap instrument from a Cox-Ingersoll-Ross (CIR) interest-rate tree.
Price
,PriceTree
,SwapRate
]
= swapbycir(CIRTree
,LegRate
,Settle
,Maturity
)swapbycir
computes prices of vanilla swaps, amortizing swaps, and
forward swaps using a CIR++ model with the Nawalka-Beliaeva (NB) approach.
Note
Alternatively, you can use the Swap
object to price a swap
instrument. For more information, see Get Started with Workflows Using Object-Based Framework for Pricing Financial Instruments.
[
adds additional name-value pair arguments.Price
,PriceTree
,SwapRate
]
= swapbycir(___,Name,Value
)
Examples
Price an Interest-Rate Swap Using a CIR Interest-Rate Tree
Define an interest-rate swap with a fixed receiving leg and a floating paying leg. Payments are made once a year and the notional principal amount is $100.
Basis = 0; Principal = 100; LegRate = [0.06 20]; % [CouponRate Spread] LegType = [1 0]; % [Fixed Float] LegReset = [1 1]; % Payments once per year
Create a RateSpec
using the intenvset
function.
Rates = [0.035; 0.042147; 0.047345; 0.052707]; Dates = [datetime(2017,1,1) ; datetime(2018,1,1) ; datetime(2019,1,1) ; datetime(2020,1,1) ; datetime(2021,1,1)]; ValuationDate = datetime(2017,1,1); EndDates = Dates(2:end)'; Compounding = 1; RateSpec = intenvset('ValuationDate', ValuationDate, 'StartDates', ValuationDate, 'EndDates',EndDates,'Rates', Rates, 'Compounding', Compounding);
Create a CIR
tree.
NumPeriods = 5; Alpha = 0.03; Theta = 0.02; Sigma = 0.1; Settle = datetime(2017,1,1); Maturity = datetime(2022,1,1); CIRTimeSpec = cirtimespec(ValuationDate, Maturity, NumPeriods); CIRVolSpec = cirvolspec(Sigma, Alpha, Theta); CIRT = cirtree(CIRVolSpec, RateSpec, CIRTimeSpec)
CIRT = struct with fields:
FinObj: 'CIRFwdTree'
VolSpec: [1x1 struct]
TimeSpec: [1x1 struct]
RateSpec: [1x1 struct]
tObs: [0 1 2 3 4]
dObs: [736696 737061 737426 737791 738156]
FwdTree: {[1.0350] [1.0790 1.0500 1.0298] [1.1275 1.0887 1.0594 1.0390 1.0270] [1.1905 1.1406 1.1014 1.0718 1.0512 1.0390 1.0350] [1.2349 1.1740 1.1248 1.0861 1.0570 1.0366 1.0246 1.0206]}
Connect: {[3x1 double] [3x3 double] [3x5 double] [3x7 double]}
Probs: {[3x1 double] [3x3 double] [3x5 double] [3x7 double]}
Price the interest-rate swap.
[Price,PriceTree] = swapbycir(CIRT,LegRate,Settle,Maturity,'LegReset',LegReset,'Basis',3,'Principal',100,'LegType',LegType)
Price = 2.5522
PriceTree = struct with fields:
FinObj: 'CIRPriceTree'
tObs: [0 1 2 3 4 5]
PTree: {[2.5522] [-9.0229 -0.0249 6.9681] [-16.5229 -8.1674 -1.0761 4.3321 7.7223] [-19.1049 -12.2245 -6.1556 -1.1426 2.6034 4.9197 5.7042] [-14.3229 -9.8801 -5.9413 -2.5909 0.0972 2.0626 3.2603 3.6626] [0 0 0 0 0 0 0 0]}
Connect: {[3x1 double] [3x3 double] [3x5 double] [3x7 double]}
Input Arguments
CIRTree
— Interest-rate structure
structure
Interest-rate tree structure, created by cirtree
Data Types: struct
LegRate
— Leg rate
matrix
Leg rate, specified as a NINST
-by-2
matrix,
with each row defined as one of the following:
[CouponRate Spread]
(fixed-float)[Spread CouponRate]
(float-fixed)[CouponRate CouponRate]
(fixed-fixed)[Spread Spread]
(float-float)
CouponRate
is the decimal annual rate.
Spread
is the number of basis points over the reference rate. The
first column represents the receiving leg, while the second column represents the
paying leg.
Data Types: double
Settle
— Settlement date
datetime array | string array | date character vector
Settlement date, specified either as a scalar or
NINST
-by-1
vector using a datetime array, string
array, or date character vectors.
To support existing code, swapbycir
also
accepts serial date numbers as inputs, but they are not recommended.
The Settle
date for every swap is set to the
ValuationDate
of the CIR tree. The swap argument
Settle
is ignored.
Maturity
— Maturity date
datetime array | string array | date character vector
Maturity date, specified as a NINST
-by-1
vector using a datetime array, string array, or date character vectors representing the
maturity date for each swap.
To support existing code, swapbycir
also
accepts serial date numbers as inputs, but they are not recommended.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: [Price,PriceTree,SwapRate] =
swapbycir(CIRTree,LegRate,Settle,Maturity,LegReset,Basis,Principal,LegType)
LegReset
— Reset frequency per year for each swap
[1 1]
(default) | vector
Reset frequency per year for each swap, specified as the comma-separated pair
consisting of 'LegReset'
and a
NINST
-by-2
vector.
Data Types: double
Basis
— Day-count basis representing the basis for each leg
0
(actual/actual) (default) | integer from 0
to 13
Day-count basis representing the basis for each leg, specified as the
comma-separated pair consisting of 'Basis'
and a
NINST
-by-1
array (or
NINST
-by-2
if Basis
is
different for each leg).
0 = actual/actual
1 = 30/360 (SIA)
2 = actual/360
3 = actual/365
4 = 30/360 (PSA)
5 = 30/360 (ISDA)
6 = 30/360 (European)
7 = actual/365 (Japanese)
8 = actual/actual (ICMA)
9 = actual/360 (ICMA)
10 = actual/365 (ICMA)
11 = 30/360E (ICMA)
12 = actual/365 (ISDA)
13 = BUS/252
For more information, see Basis.
Data Types: double
Principal
— Notional principal amounts or principal value schedules
100
(default) | vector or cell array
Notional principal amounts or principal value schedules, specified as the
comma-separated pair consisting of 'Principal'
and a vector or cell
array.
Principal
accepts a
NINST
-by-1
vector or
NINST
-by-1
cell array (or
NINST
-by-2
if Principal
is different for each leg) of the notional principal amounts or principal value
schedules. For schedules, each element of the cell array is a
NumDates
-by-2
array where the first column
is dates and the second column is its associated notional principal value. The date
indicates the last day that the principal value is valid.
Data Types: cell
| double
LegType
— Leg type
[1 0]
for each instrument (default) | matrix with values [1 1]
(fixed-fixed), [1 0]
(fixed-float), [0 1]
(float-fixed), or [0 0]
(float-float)
Leg type, specified as the comma-separated pair consisting of
'LegType'
and a NINST
-by-2
matrix with values:
[1 1]
(fixed-fixed) swap[1 0]
(fixed-float) swap[0 1]
(float-fixed) swap[0 0]
(float-float) swap
Each row represents an instrument. Each column indicates if the corresponding leg
is fixed (1
) or floating (0
). This matrix
defines the interpretation of the values entered in LegRate
.
Data Types: double
EndMonthRule
— End-of-month rule flag for generating dates when Maturity
is end-of-month date for month having 30 or fewer days
1
(in effect) (default) | nonnegative integer [0,1]
End-of-month rule flag for generating dates when Maturity
is
an end-of-month date for a month having 30 or fewer days, specified as the
comma-separated pair consisting of 'EndMonthRule'
and a nonnegative
integer [0
, 1
] using a
NINST
-by-1
(or
NINST
-by-2
if EndMonthRule
is different for each leg).
0
= Ignore rule, meaning that a payment date is always the same numerical day of the month.1
= Set rule on, meaning that a payment date is always the last actual day of the month.
Data Types: logical
AdjustCashFlowsBasis
— Flag to adjust cash flows based on actual period day count
false
(default) | value of 0
(false) or 1
(true)
Flag to adjust cash flows based on actual period day count, specified as the
comma-separated pair consisting of 'AdjustCashFlowsBasis'
and a
NINST
-by-1
(or
NINST
-by-2
if
AdjustCashFlowsBasis
is different for each leg) of logicals with
values of 0
(false) or 1
(true).
Data Types: logical
BusinessDayConvention
— Business day conventions
actual
(default) | character vector | cell array of character vectors
Business day conventions, specified as the comma-separated pair consisting of
'BusinessDayConvention'
and a character vector or a
N
-by-1
(or
NINST
-by-2
if
BusinessDayConvention
is different for each leg) cell array of
character vectors of business day conventions. The selection for business day
convention determines how nonbusiness days are treated. Nonbusiness days are defined
as weekends plus any other date that businesses are not open (e.g. statutory
holidays). Values are:
actual
— Nonbusiness days are effectively ignored. Cash flows that fall on nonbusiness days are assumed to be distributed on the actual date.follow
— Cash flows that fall on a non-business day are assumed to be distributed on the following business day.modifiedfollow
— Cash flows that fall on a non-business day are assumed to be distributed on the following business day. However if the following business day is in a different month, the previous business day is adopted instead.previous
— Cash flows that fall on a non-business day are assumed to be distributed on the previous business day.modifiedprevious
— Cash flows that fall on a non-business day are assumed to be distributed on the previous business day. However if the previous business day is in a different month, the following business day is adopted instead.
Data Types: char
| cell
Holidays
— Holidays used in computing business days
if not specified, the default is to use holidays.m
(default) | MATLAB® dates
Holidays used in computing business days, specified as the comma-separated pair
consisting of 'Holidays'
and MATLAB dates using a NHolidays
-by-1
vector.
Data Types: datetime
StartDate
— Date swap actually starts
Settle
date (default) | datetime array | string array | date character vector
Date swap actually starts, specified as the comma-separated pair consisting of
'StartDate'
and a
NINST
-by-1
vector of dates using a datetime
array, string array, or date character vectors.
To support existing code, swapbycir
also
accepts serial date numbers as inputs, but they are not recommended.
Use this argument to price forward swaps, that is, swaps that start in a future date
Output Arguments
Price
— Expected swap prices at time 0
vector
Expected swap prices at time 0, returned as a
NINST
-by-1
vector.
PriceTree
— Tree structure of instrument prices
structure
Tree structure of instrument prices, returned as a MATLAB structure of trees containing vectors of swaption instrument prices and
a vector of observation times for each node. Within PriceTree
:
PriceTree.tObs
contains the observation times.PriceTree.PTree
contains the clean prices.
SwapRate
— Rates applicable to fixed leg
matrix
Rates applicable to the fixed leg, returned as a
NINST
-by-1
vector of rates applicable to the
fixed leg such that the swaps’ values are zero at time 0. This rate is used in
calculating the swaps’ prices when the rate specified for the fixed leg in
LegRate
is NaN
. The
SwapRate
output is padded with NaN
for those
instruments in which CouponRate
is not set to
NaN
.
More About
Amortizing Swap
In an amortizing swap, the notional principal decreases periodically because it is tied to an underlying financial instrument with a declining (amortizing) principal balance, such as a mortgage.
Forward Swap
Agreement to enter into an interest-rate swap arrangement on a fixed date in future.
References
[1] Cox, J., Ingersoll, J., and S. Ross. "A Theory of the Term Structure of Interest Rates." Econometrica. Vol. 53, 1985.
[2] Brigo, D. and F. Mercurio. Interest Rate Models - Theory and Practice. Springer Finance, 2006.
[3] Hirsa, A. Computational Methods in Finance. CRC Press, 2012.
[4] Nawalka, S., Soto, G., and N. Beliaeva. Dynamic Term Structure Modeling. Wiley, 2007.
[5] Nelson, D. and K. Ramaswamy. "Simple Binomial Processes as Diffusion Approximations in Financial Models." The Review of Financial Studies. Vol 3. 1990, pp. 393–430.
Version History
Introduced in R2018aR2022b: Serial date numbers not recommended
Although swapbycir
supports serial date numbers,
datetime
values are recommended instead. The
datetime
data type provides flexible date and time
formats, storage out to nanosecond precision, and properties to account for time
zones and daylight saving time.
To convert serial date numbers or text to datetime
values, use the datetime
function. For example:
t = datetime(738427.656845093,"ConvertFrom","datenum"); y = year(t)
y = 2021
There are no plans to remove support for serial date number inputs.
See Also
bondbycir
| capbycir
| cfbycir
| fixedbycir
| floatbycir
| floorbycir
| oasbycir
| optbndbycir
| optfloatbycir
| optembndbycir
| optemfloatbycir
| rangefloatbycir
| swaptionbycir
| instswap
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)