Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions examples/scripts/rates/example_inflation_swap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# ============================================================================
# FINANCEPY EXAMPLES - InflationSwap
# ============================================================================
#
# Copyright (C) 2018-2026 Dominic O'Kane
#
# This example demonstrates the valuation of Zero-Coupon Inflation Swaps
# (ZCIS) and Year-on-Year Inflation Swaps (YYIS) against a DiscountCurve and
# an InflationIndexCurve.
#
# ============================================================================

from financepy.utils.date import Date
from financepy.utils.day_count import DayCountTypes
from financepy.utils.frequency import FrequencyTypes
from financepy.utils.global_types import SwapTypes
from financepy.market.curves.flat_discount_curve import FlatDiscountCurve
from financepy.market.curves.inflation_index_curve import InflationIndexCurve
from financepy.products.rates.inflation_swap import (
InflationSwap,
InflationSwapTypes,
)

value_dt = Date(15, 1, 2025)
effective_dt = Date(15, 1, 2025)

discount_curve = FlatDiscountCurve(value_dt, 0.04)

# Build a 3-month lagged CPI curve with 2.5% annualised inflation
index_dts = [value_dt.add_months(m) for m in range(-4, 65)]
index_vals = [100.0 * (1.025 ** ((dt - value_dt) / 365.0)) for dt in index_dts]
infl_curve = InflationIndexCurve(index_dts, index_vals, lag_in_months=3)

# 1. Zero-Coupon Inflation Swap (5Y)
zcis = InflationSwap(
effective_dt,
"5Y",
SwapTypes.PAY,
0.02,
swap_type=InflationSwapTypes.ZERO_COUPON,
dc_type=DayCountTypes.ACT_365F,
notional=1_000_000.0,
)
zcis_par = zcis.fair_rate(value_dt, discount_curve, infl_curve)
zcis_pv = zcis.value(value_dt, discount_curve, infl_curve)
print(f"5Y ZCIS Par Rate : {zcis_par * 100:.4f}% | MtM PV (K=2.0%): {zcis_pv:,.2f}")

# 2. Year-on-Year Inflation Swap (5Y, Annual)
yyis = InflationSwap(
effective_dt,
"5Y",
SwapTypes.PAY,
0.02,
swap_type=InflationSwapTypes.YEAR_ON_YEAR,
freq_type=FrequencyTypes.ANNUAL,
dc_type=DayCountTypes.ACT_365F,
notional=1_000_000.0,
)
yyis_par = yyis.fair_rate(value_dt, discount_curve, infl_curve)
yyis_pv = yyis.value(value_dt, discount_curve, infl_curve)
print(f"5Y YYIS Par Rate : {yyis_par * 100:.4f}% | MtM PV (K=2.0%): {yyis_pv:,.2f}")
1 change: 1 addition & 0 deletions financepy/products/rates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .ibor_conventions import *
from .ibor_swap import *
from .ibor_swaption import *
from .inflation_swap import *
from .ois_basis_swap import *
from .ois_curve import *
from .ois import *
Expand Down
Loading