Interest rate swap
Value to the fixed payer and receiver, par swap rate and annuity factor of a fixed-for-floating swap, from discount factors or a zero curve.
- Model id
derivatives.interest_rate_swap, version 1- Domain
- Derivatives
- Evidence
- standard
- Cost class
- instant: A closed-form calculation; a hosted run may take up to 2 seconds.
Formula
Where
- Annuity factor: the value of 1 paid on the fixed leg's accruals
annuity_factor - Accrual fraction of fixed period i, in years
accruals - Discount factor at fixed payment i
discount_factors - Discount factor at the swap's start
start_discount_factor - Discount factor at the last payment
- Notional
notional - Fixed rate of the swap
fixed_rate - Value of the floating leg
floating_leg_value - Value of the fixed leg
fixed_leg_value - Par swap rate: the fixed rate that makes the swap worth nothing
par_swap_rate - Value to the payer of the fixed rate
payer_value - Value to the receiver of the fixed rate
receiver_value
Each symbol's field is named beside it; the inputs and outputs, with their units and bounds, are under Variables, and the citations give each formula's source.
Variables
Rates, returns and yields are decimals: 0.05 is five percent. Bounds in brackets include their end; in parentheses they exclude it.
Inputs
Swap value from discount factors (discount_factors): 6 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Notionalnotionalmoney · [0, 1e+12] | money | [0, 1e+12] | Notional principal |
Fixed ratefixed_raterate · [-0.1, 1] | rate | [-0.1, 1] | Fixed rate per year of the fixed leg |
Calculationcalculationtext | text | Swap value from discount factors | |
Accrualsaccrualsyears (array) · length min 1, max 600; each (0, 1] | years (array) | length min 1, max 600; each (0, 1] | Accrual fraction of each fixed period, in years |
Discount factorsdiscount_factorsratio (array) · length min 1, max 600; each (0, 10] | ratio (array) | length min 1, max 600; each (0, 10] | Discount factor at each payment date |
Start discount factorstart_discount_factorratio · (0, 10] | ratio | (0, 10] | Discount factor at the start date: 1 for a swap starting now |
Swap value from a zero curve (zero_curve): 9 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Curve tenorscurve_tenorsyears (array) · length min 1, max 200; each (0, 100] | years (array) | length min 1, max 200; each (0, 100] | Tenors of the zero curve's nodes in years, increasing |
Curve ratescurve_ratesrate (array) · length min 1, max 200; each [-0.1, 1] | rate (array) | length min 1, max 200; each [-0.1, 1] | Zero rate at each node: linear between nodes, flat outside |
Compoundingcompoundingtext | text | How the zero rates compound | |
Frequencyfrequencytext | text | Compounding frequency of periodic zero rates | |
Notionalnotionalmoney · [0, 1e+12] | money | [0, 1e+12] | Notional principal |
Fixed ratefixed_raterate · [-0.1, 1] | rate | [-0.1, 1] | Fixed rate per year of the fixed leg |
Calculationcalculationtext | text | Swap value from a zero curve | |
Accrualsaccrualsyears (array) · length min 1, max 600; each (0, 1] | years (array) | length min 1, max 600; each (0, 1] | Accrual fraction of each fixed period, in years |
Start yearsstart_yearsyears · [0, 100] | years | [0, 100] | Years until the swap starts: 0 for now |
Swap value from payment dates and a zero curve (dated): 11 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Curve tenorscurve_tenorsyears (array) · length min 1, max 200; each (0, 100] | years (array) | length min 1, max 200; each (0, 100] | Tenors of the zero curve's nodes in years, increasing |
Curve ratescurve_ratesrate (array) · length min 1, max 200; each [-0.1, 1] | rate (array) | length min 1, max 200; each [-0.1, 1] | Zero rate at each node: linear between nodes, flat outside |
Compoundingcompoundingtext | text | How the zero rates compound | |
Frequencyfrequencytext | text | Compounding frequency of periodic zero rates | |
Notionalnotionalmoney · [0, 1e+12] | money | [0, 1e+12] | Notional principal |
Fixed ratefixed_raterate · [-0.1, 1] | rate | [-0.1, 1] | Fixed rate per year of the fixed leg |
Calculationcalculationtext | text | Swap value from payment dates and a zero curve | |
Valuation datevaluation_datedate | date | Date the swap is valued on | |
Start datestart_datedate | date | Date the first period starts accruing | |
Payment datespayment_datesdate (array) · length min 1, max 600 | date (array) | length min 1, max 600 | Fixed payment dates, increasing, the last at maturity |
Day countday_counttext | text | Day count of the fixed leg's accruals |
Outputs
Swap value from discount factors (discount_factors): 7 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Annuity factorannuity_factoryears · [0, 1e+06] | years | [0, 1e+06] | Sum of accrual fraction times discount factor over payments |
Par swap ratepar_swap_raterate · [-0.99, 10] | rate | [-0.99, 10] | Fixed rate at which the swap is worth zero |
Fixed leg valuefixed_leg_valuemoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | Value of the fixed leg: c N A |
Floating leg valuefloating_leg_valuemoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | Value of the floating leg: N (d_0 - d_n) |
Payer valuepayer_valuemoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | Value to the fixed payer: floating less fixed |
Receiver valuereceiver_valuemoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | Value to the fixed receiver: fixed less floating |
Calculationcalculationtext | text | Swap value from discount factors |
Swap value from a zero curve (zero_curve): 7 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Annuity factorannuity_factoryears · [0, 1e+06] | years | [0, 1e+06] | Sum of accrual fraction times discount factor over payments |
Par swap ratepar_swap_raterate · [-0.99, 10] | rate | [-0.99, 10] | Fixed rate at which the swap is worth zero |
Fixed leg valuefixed_leg_valuemoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | Value of the fixed leg: c N A |
Floating leg valuefloating_leg_valuemoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | Value of the floating leg: N (d_0 - d_n) |
Payer valuepayer_valuemoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | Value to the fixed payer: floating less fixed |
Receiver valuereceiver_valuemoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | Value to the fixed receiver: fixed less floating |
Calculationcalculationtext | text | Swap value from a zero curve |
Swap value from payment dates and a zero curve (dated): 7 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Annuity factorannuity_factoryears · [0, 1e+06] | years | [0, 1e+06] | Sum of accrual fraction times discount factor over payments |
Par swap ratepar_swap_raterate · [-0.99, 10] | rate | [-0.99, 10] | Fixed rate at which the swap is worth zero |
Fixed leg valuefixed_leg_valuemoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | Value of the fixed leg: c N A |
Floating leg valuefloating_leg_valuemoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | Value of the floating leg: N (d_0 - d_n) |
Payer valuepayer_valuemoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | Value to the fixed payer: floating less fixed |
Receiver valuereceiver_valuemoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | Value to the fixed receiver: fixed less floating |
Calculationcalculationtext | text | Swap value from payment dates and a zero curve |
Calculator
Run the model on your own inputs, starting from its example. Rates are decimals: 0.05 is five percent. The run goes to the pyeconomics API on this site: your values travel only in the request, and nothing is stored.
Loading the calculator…
Worked example
Example two_year_semiannual. Inputs:
{
"accruals": [0.5, 0.5, 0.5, 0.5],
"calculation": "zero_curve",
"compounding": "continuous",
"curve_rates": [0.05, 0.058, 0.064, 0.068],
"curve_tenors": [0.5, 1, 1.5, 2],
"fixed_rate": 0.065,
"frequency": "annual",
"notional": 100000000,
"start_years": 0
}Outputs:
{
"annuity_factor": 1.8501332540112783,
"calculation": "zero_curve",
"fixed_leg_value": 12025866.151073309,
"floating_leg_value": 12715736.75112807,
"par_swap_rate": 0.06872876169086227,
"payer_value": 689870.6000547614,
"receiver_value": -689870.6000547614
}Assumptions
- One curve both projects the floating rates and discounts every cash flow, and the floating leg pays the rate for its own accrual period with no spread, so it is worth the notional at the start less the notional at the end.
- The swap starts on or after the valuation date: no floating coupon has been fixed.
- Zero rates are interpolated linearly between the curve's nodes and held flat outside them; in the dated calculation they are read at ACT/365 (Fixed) years from the valuation date.
Limitations
- Results are the formulas' outputs for the inputs given, not a valuation of a traded swap or trading advice.
- Separate projection and discounting curves, a floating spread, business-day adjustment and seasoned swaps with a fixed coupon outstanding are out of scope.
- A par rate outside [-0.99, 10], an annuity factor of zero (periods that accrue nothing on their day count, or an underflow) or above 1e6, a leg worth more than 1e15, or a simple-interest curve with no positive growth, raises DomainError.
Evidence
Status: standard. Textbook consensus, such as bond duration or the CAPM formula.
Every model declares one status: standard (textbook consensus), practitioner (a widely used convention), contested (under active debate), rejected (failed out of sample) or historical (a superseded methodology).
Syllabus
The 2027 CFA® Program's topic areas this model relates to, as factual tags. Each links to CFA Institute's page for its level; pyeconomics holds none of the curriculum's text.
Citations
- Hull, J. C. (2018). Options, Futures, and Other Derivatives, 10th ed. Pearson. https://openlibrary.org/isbn/9780134472089 (Chapters 4 and 7 (par yields; interest rate swaps and their valuation in terms of bonds)). ISBN 9780134472089
- International Swaps and Derivatives Association (2006). 2006 ISDA Definitions. ISDA. https://www.isda.org/a/smMDE/Blackline-2000-v-2006-ISDA-Definitions.pdf (Section 4.16, Day Count Fraction)
Changelog
- Version 1: First version.
Use it elsewhere
- Documentation
- The model's reference page
- REST API
GET or POST /v1/models/derivatives.interest_rate_swap/run- MCP tool
run_modelwith the model's id,derivatives.interest_rate_swap. Connect an assistant- Command line
pyeconomics models run derivatives.interest_rate_swap --help
The worked example, from Python and from the command line:
import pyeconomics
inputs = {
"accruals": [0.5, 0.5, 0.5, 0.5],
"calculation": "zero_curve",
"compounding": "continuous",
"curve_rates": [0.05, 0.058, 0.064, 0.068],
"curve_tenors": [0.5, 1, 1.5, 2],
"fixed_rate": 0.065,
"frequency": "annual",
"notional": 100000000,
"start_years": 0,
}
result = pyeconomics.run("derivatives.interest_rate_swap", inputs)
print(result.to_json())
pyeconomics models run derivatives.interest_rate_swap --inputs - <<'JSON'
{
"accruals": [0.5, 0.5, 0.5, 0.5],
"calculation": "zero_curve",
"compounding": "continuous",
"curve_rates": [0.05, 0.058, 0.064, 0.068],
"curve_tenors": [0.5, 1, 1.5, 2],
"fixed_rate": 0.065,
"frequency": "annual",
"notional": 100000000,
"start_years": 0
}
JSON