How to Price a Swap Using the API

Use the /swap_pricer endpoint to price interest rate swaps with full cashflow analysis, MTM valuation, and support for amortizing schedules.

This guide walks you through pricing interest rate swaps using the BlueGamma API. Whether you need a simple mid-market rate or detailed cashflow analysis for an amortizing loan hedge, we offer multiple approaches.

This example uses SOFR swaps with semi-annual payments.


Before You Start

To follow this guide, make sure you have:

  • An active BlueGamma API key

  • Python 3.x with the requests library installed

If you don't have an API key yet, see Authentication or contact support@bluegamma.ioenvelope.


Overview: Mid Swap Rate vs Mark-to-Market

When pricing a swap, there are two key values you'll typically need:

Mid Swap Rate (Fair Rate)

The mid swap rate (also called the par rate or fair rate) is the fixed rate that makes the present value of the fixed leg equal to the present value of the floating leg — i.e., NPV = 0.

Mid Swap Rate=i=1n(Fi×DFi×τi×Ni)i=1n(DFi×τi×Ni)\text{Mid Swap Rate} = \frac{\sum_{i=1}^{n} (F_i \times DF_i \times \tau_i \times N_i)}{\sum_{i=1}^{n} (DF_i \times \tau_i \times N_i)}

Where:

  • Fi = Forward rate for period i

  • DFi = Discount factor to payment date i

  • τi = Day count fraction for period i

  • Ni = Notional for period i

Mark-to-Market (MTM)

The mark-to-market value represents the current market value of an existing swap. It's calculated as the difference between the present value of the floating leg and the fixed leg at the contracted rate.

  • MTM > 0: The swap is an asset (in your favor)

  • MTM < 0: The swap is a liability (against you)


The /swap_pricer endpoint provides comprehensive swap valuation in a single API call:

  • Fair swap rate calculation

  • Mark-to-market valuation

  • PV01 (dollar value of a basis point)

  • Detailed cashflow schedules for both fixed and floating legs

This is the recommended approach for loan hedging and amortizing swaps.

Request Format

Request Parameters

Field
Required
Description

index

Yes

Reference rate index (e.g., "SOFR", "SONIA", "3M EURIBOR")

start_date

Yes

Swap start date (YYYY-MM-DD or tenor like "0D")

maturity_date

Yes

Swap maturity date (YYYY-MM-DD or tenor like "5Y")

fixed_leg_frequency

Yes

Payment frequency (e.g., "6M", "3M", "1Y")

fixed_notionals

Yes

Notional amount(s) as a number or array

fixed_rate

No

Fixed rate as percentage (e.g., 4.25 for 4.25%). If omitted, MTM = 0

fixed_leg_first_payment_date

No

First payment date (YYYY-MM-DD). Defaults to start_date + fixed_leg_frequency adjusted for business days.

fixed_leg_day_count

No

Day count convention for fixed leg (defaults to currency-specific)

valuation_time

No

Valuation timestamp (ISO 8601). Defaults to current time.

For a full list of supported indices, see Available Indices.

Response Fields

Field
Description

fair_rate

The mid-market par swap rate (percentage)

mtm

Mark-to-market value (0 if no fixed_rate provided)

pv01

Dollar value of 1 basis point move

fixed_rate

The fixed rate used (input or fair_rate if not provided)

fixed_cashflows

Array of fixed leg cashflow details

floating_cashflows

Array of floating leg cashflow details


Example 1: Get the Mid Swap Rate

To get the current mid-market swap rate, simply omit the fixed_rate parameter. The API will return the fair rate, and MTM will be zero.

Example Response:

Key Points:

  • The fair_rate is 3.844% — this is your mid swap rate

  • The mtm is 0.0 because the swap is priced at fair value

  • The pv01 of -$8,419 means a 1bp increase in rates decreases the swap value by ~$8.4k

circle-check

Example 2: Get Mark-to-Market for an Existing Swap

If you have an existing swap with a contracted fixed rate, provide the fixed_rate parameter to calculate the MTM.

Example Response:

Interpretation:

  • Your fixed rate (4.25%) is higher than the current fair rate (3.848%)

  • If you're paying fixed, you're paying more than market — the swap is a liability

  • MTM is negative — you would need to pay this to exit the swap

circle-info

Pro Tip: The MTM can be approximated as: MTM ≈ (Fair Rate - Fixed Rate) × PV01 × 100

Example: (3.848% - 4.25%) × (-8,417) × 100 ≈ $33,836 (close to actual MTM)

circle-check

For ongoing MTM tracking of existing swaps, also see Swap Mark-to-Market.


Example 3: Price an Amortizing Swap

For loan hedging, you often need to match your swap notional to your loan's amortization schedule. Pass an array of notionals to fixed_notionals.

Example Response:

Key Points:

  • The amortizing swap rate (3.46%) is lower than a bullet swap rate because more weight is placed on near-term periods where forward rates are lower

  • MTM is calculated correctly based on the amortizing schedule

  • PV01 is smaller because the average outstanding notional is lower than a bullet swap


Example 4: Custom First Payment Date

When hedging a loan, your first interest payment date often doesn't fall exactly one period from the start date. Use fixed_leg_first_payment_date to align your swap to your loan schedule.

This creates a swap where the first period runs from 2026-01-15 to 2026-03-31 (a short stub), then regular 6M periods thereafter.


Understanding the Cashflow Response

Each cashflow in the response contains detailed period information:

Field
Description

period_start

Accrual start date

period_end

Accrual end date (payment date)

notional

Notional amount for this period

day_count_fraction

Year fraction based on day count convention

rate

Interest rate (fixed rate for fixed leg, forward rate for floating leg)

cashflow

Undiscounted cashflow: Notional × Rate × DCF

discount_factor

Discount factor to payment date

present_value

Discounted cashflow value

For more on discount factors, see Getting Discount Factors.


Method 2: Use the /swap_rate Endpoint (Quick)

For a quick par rate without cashflows, use the GET /swap_rate endpoint:

Example Response:

For more details, see Fetching a Swap Rate.


Method 3: Build the Cashflow Schedule (Full Control)

For complete control — such as custom date schedules or integrating into your own pricing models — you can build the cashflow schedule yourself using the Getting Forward Rates and Getting Discount Factors endpoints.


Comparing with the BlueGamma Web App

You can validate your API results against the BlueGamma web application.

Step 1: Open the Swap Pricer

Go to app.bluegamma.io/swap-pricerarrow-up-right and click Add Swap.

Step 2: Enter the Same Swap Parameters

Configure the swap with the same parameters used in your API call:

  • Currency: USD (for SOFR)

  • Start Date: 26/01/2026

  • First Interest Payment Date: 26/07/2026

  • End Date: 26/01/2036 (10 years)

  • Payment Frequency: 6M

  • Notional: 10,000,000

BlueGamma Swap Pricer form showing USD currency selection with 10-year tenor and 6M payment frequency
Enter swap details matching your API parameters

Step 3: Compare the Results

The app displays the Mid Swap Rate: 3.844% and BPV: 8,419, which matches our API result.

BlueGamma Swap Pricer showing Mid Swap Rate of 3.844% and BPV of 8,419 for a 10-year USD SOFR swap
The web app shows 3.844% and BPV 8,419 — matching the API result

The results match because both the API and web app use the same underlying curve data and calculation methodology.

circle-info

Tip: If you see small differences, check that your day count convention and payment frequency match exactly. The API defaults to currency-standard conventions.


Day Count Conventions

The API supports the following day count conventions:

Convention
Description

Actual360

Actual days / 360 (standard for SOFR, EURIBOR)

Actual365Fixed

Actual days / 365 (standard for GBP SONIA)

Thirty360BondBasis

30/360 US convention

Thirty360EuroBondBasis

30/360 European convention

Business252

Business days / 252 (used for BRL CDI)

When using the /swap_pricer endpoint, you can specify the convention:


Error Handling

Always handle potential API errors. For rate limit details, see Rate Limits & Best Practices.


Summary: Mid Rate vs MTM

Scenario

fixed_rate Parameter

What You Get

Get Mid Rate

Omit

fair_rate = mid swap rate, mtm = 0

Get MTM

Provide contracted rate

fair_rate = current mid, mtm = swap value


API Endpoint Reference

Endpoint
Method
Use Case

/swap_pricer

POST

Full swap pricing with cashflows (recommended)

/swap_rate

GET

Quick par rate calculation (no cashflows)

/forward_rate

GET

Forward rate between any two dates

/discount_factor

GET

Discount factor to any specific date

For the complete API specification, see API Reference.



Need help? 📩 support@bluegamma.ioenvelope | 📅 Book a callarrow-up-right

Last updated

Was this helpful?