Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- "docs/**"
- "crates/itofin-py/python/**"
- "crates/libitofin/examples/**"
- "example/**"
- "crates/itofin-py/python/examples/**"
- "sdk/go/examples/**"
- ".github/workflows/docs.yml"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
- docs/**
- crates/itofin-py/python/**
- crates/libitofin/examples/**
- example/**
- crates/itofin-py/python/examples/**
- sdk/go/examples/**
- .github/workflows/*.yml

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ go get github.com/bitbrew-dev/libitofin/sdk/go@v0.24.0
Use `-tags itofin_external` for builds, runs, tests, and vet outside this checkout.
[Go guide and examples](wiki/go.md) · [API reference](https://pkg.go.dev/github.com/bitbrew-dev/libitofin/sdk/go)

## Examples

- [Rust](crates/libitofin/examples)
- [Go](sdk/go/examples)
- [Python](crates/itofin-py/python/examples)

## Documentation

| Topic | Start here |
Expand Down
22 changes: 11 additions & 11 deletions crates/itofin-py/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ bindings expose forward-measure transitions, not a fitted GSR model.

| Scope | Guide | Example |
| --- | --- | --- |
| Ordinary bond coupon helpers | [BPS and ATM rate](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/bond-coupon-analytics.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/bond_coupon_analytics.py) |
| Price-fed bond ATM | [Price-fed ATM](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/bond-price-atm-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/bond_price_atm.py) |
| European asset-or-nothing FD pricing | [Asset digitals](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/asset-digital-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/asset_digital.py) |
| European signed gap FD pricing | [Gap options](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/gap-option-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/gap_option.py) |
| European percentage-strike FD pricing | [Percentage-strike options](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/percentage-strike-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/percentage_strike.py) |
| Amortizing fixed-rate bonds | [Fixed amortization](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/amortizing-fixed-bonds.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/amortizing_fixed_bond.py) |
| Amortizing plain-Ibor bonds | [Ibor amortization](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/amortizing-floating-bond-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/amortizing_floating_bond.py) |
| European analytic cash digitals | [Cash-or-nothing](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/cash-digital-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/cash_digital.py) |
| Standalone Gaussian state process | [MF state](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/mf-state-process-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/mf_state_process.py) |
| Standalone live-curve forward process | [Hull-White forward](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/hw-forward-process-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/hw_forward_process.py) |
| Constant-notional Ibor cross-currency swaps | [Xccy basis](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/xccy-basis-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/xccy_basis.py) |
| Ordinary bond coupon helpers | [BPS and ATM rate](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/bond-coupon-analytics.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/bond_coupon_analytics.py) |
| Price-fed bond ATM | [Price-fed ATM](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/bond-price-atm-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/bond_price_atm.py) |
| European asset-or-nothing FD pricing | [Asset digitals](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/asset-digital-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/asset_digital.py) |
| European signed gap FD pricing | [Gap options](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/gap-option-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/gap_option.py) |
| European percentage-strike FD pricing | [Percentage-strike options](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/percentage-strike-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/percentage_strike.py) |
| Amortizing fixed-rate bonds | [Fixed amortization](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/amortizing-fixed-bonds.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/amortizing_fixed_bond.py) |
| Amortizing plain-Ibor bonds | [Ibor amortization](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/amortizing-floating-bond-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/amortizing_floating_bond.py) |
| European analytic cash digitals | [Cash-or-nothing](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/cash-digital-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/cash_digital.py) |
| Standalone Gaussian state process | [MF state](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/mf-state-process-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/mf_state_process.py) |
| Standalone live-curve forward process | [Hull-White forward](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/hw-forward-process-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/hw_forward_process.py) |
| Constant-notional Ibor cross-currency swaps | [Xccy basis](https://github.com/bitbrew-dev/libitofin/blob/main/docs/docs/xccy-basis-bindings.md) | [Example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/xccy_basis.py) |

These helpers do not complete the wider `BondFunctions` overload set. The
process facades are not fitted models; cash digitals cover European analytic
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@
rate = SimpleQuote(0.04)
forward = FlatForward.from_quote(today, rate, counter)
discount = FlatForward(today, 0.025, counter)
index = IborIndex("AmortizingExample", Period(6, "Months"), 2, Currency.eur(), calendar, BDC.Following, False, counter, forward, settings)
index = IborIndex(
"AmortizingExample",
Period(6, "Months"),
2,
Currency.eur(),
calendar,
BDC.Following,
False,
counter,
forward,
settings,
)
schedule = Schedule(Date(5, 10, 2026), Date(5, 10, 2027), Frequency.Quarterly, calendar, BDC.Unadjusted)
bond = AmortizingFloatingRateBond(0, [1000.0, 800.0, 800.0, 500.0], schedule, index, counter, settings, spreads=[0.001])
bond.set_engine(DiscountingBondEngine(discount, settings))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


def main():
"""Price an asset-or-nothing call with the finite-difference engine."""
reference = Date(15, 6, 2026)
settings = Settings()
settings.set_evaluation_date(reference)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
spot,
FlatForward.from_quote(today, rate, dc),
FlatForward.from_quote(today, dividend, dc),
0.04, 1.5, 0.04, 0.3, -0.5, 0.7, -0.12, 0.18,
0.04,
1.5,
0.04,
0.3,
-0.5,
0.7,
-0.12,
0.18,
)
model = BatesModel(process)
engine = BatesEngine(model, integration_order=144)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Price-independent coupon BPS per100 and own-NPV ATM rate."""

# itofin library
from itofin import Settings
from itofin.instruments import FixedRateBond
Expand All @@ -17,11 +18,19 @@
settings = Settings()
settlement = Date(26, 6, 2026)
calendar, counter = Calendar.null_calendar(), DayCounter.actual360()
schedule = Schedule(Date(24, 3, 2026), Date(24, 3, 2028), Frequency.Semiannual,
calendar, BusinessDayConvention.Unadjusted, DateGeneration.Backward)
bond = FixedRateBond(5, 375.0, schedule, [.047, .058], counter, settings)
curve = FlatForward(Date(1, 6, 2026), .032, DayCounter.actual365_fixed())
schedule = Schedule(
Date(24, 3, 2026),
Date(24, 3, 2028),
Frequency.Semiannual,
calendar,
BusinessDayConvention.Unadjusted,
DateGeneration.Backward,
)
bond = FixedRateBond(5, 375.0, schedule, [0.047, 0.058], counter, settings)
curve = FlatForward(Date(1, 6, 2026), 0.032, DayCounter.actual365_fixed())
print("Coupon BPS per100:", bond.bps_from_curve(curve, settlement=settlement))
print("Yield-discounted coupon BPS:", bond.bps_from_yield(.052, counter, Compounding.Continuous,
Frequency.Annual, settlement=settlement))
print(
"Yield-discounted coupon BPS:",
bond.bps_from_yield(0.052, counter, Compounding.Continuous, Frequency.Annual, settlement=settlement),
)
print("Own-NPV ATM coupon rate:", bond.atm_rate_from_curve(curve, settlement=settlement))
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@


def main():
"""Price a cash-or-nothing call and report its delta."""
reference = Date(15, 6, 2026)
settings = Settings()
settings.set_evaluation_date(reference)
process = BlackScholesProcess(
100.0, 0.05, 0.02, 0.2, reference, DayCounter.actual360()
)
option = VanillaOption.cash_or_nothing(
OptionType.Call, 105.0, 12.0, reference + 360, settings
)
process = BlackScholesProcess(100.0, 0.05, 0.02, 0.2, reference, DayCounter.actual360())
option = VanillaOption.cash_or_nothing(OptionType.Call, 105.0, 12.0, reference + 360, settings)
print(f"Digital NPV: {option.price(process):.10f}")
print(f"Digital delta: {option.delta():.10f}")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Standalone cash-digital Black value and Greeks, without an instrument graph."""

# itofin library
from itofin.instruments import OptionType
from itofin.pricingengines import BlackCalculator

calculator = BlackCalculator.cash_digital(OptionType.Call, 100., 7., 110., .3, .94)
calculator = BlackCalculator.cash_digital(OptionType.Call, 100.0, 7.0, 110.0, 0.3, 0.94)
print(f"value: {calculator.value():.8f}")
print(f"forward delta: {calculator.delta_forward():.8f}")
print(f"vega (two-year expiry): {calculator.vega(2.):.8f}")
print(f"vega (two-year expiry): {calculator.vega(2.0):.8f}")
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Lazy base-date CPI coupon and leg with historical observations."""

# itofin library
from itofin import Settings
from itofin.cashflows import CPICoupon, CPICouponPricer, CPILeg, npv
Expand All @@ -13,16 +14,27 @@
index.add_fixing(Date(1, 4, 2025), 100.8)
dc = DayCounter.actual365_fixed()
lag = Period(3, "Months")
coupon = CPICoupon.from_base_date(Date(15, 10, 2024), Date(15, 7, 2025), 100000.0,
Date(15, 1, 2025), Date(15, 7, 2025), index, lag,
CpiInterpolationType.Flat, dc, 0.02)
coupon = CPICoupon.from_base_date(
Date(15, 10, 2024),
Date(15, 7, 2025),
100000.0,
Date(15, 1, 2025),
Date(15, 7, 2025),
index,
lag,
CpiInterpolationType.Flat,
dc,
0.02,
)
coupon.set_pricer(CPICouponPricer())
print("Effective base CPI", coupon.base_fixing())
print("Coupon amount", coupon.amount())
calendar = Calendar.null_calendar()
schedule = Schedule(Date(15, 1, 2025), Date(15, 7, 2025), Frequency.Semiannual,
calendar, BusinessDayConvention.Unadjusted)
leg = CPILeg.from_base_date(schedule, index, lag, [100000.0], [0.02], dc, calendar,
BusinessDayConvention.Unadjusted, growth_only=False).build()
schedule = Schedule(
Date(15, 1, 2025), Date(15, 7, 2025), Frequency.Semiannual, calendar, BusinessDayConvention.Unadjusted
)
leg = CPILeg.from_base_date(
schedule, index, lag, [100000.0], [0.02], dc, calendar, BusinessDayConvention.Unadjusted, growth_only=False
).build()
discount = FlatForward(Date(15, 6, 2025), 0.04, dc)
print("NPV", npv(leg, discount, settings))
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Price a plain explicit-base CPI leg with an indexed terminal payment."""

# itofin library
from itofin import Settings
from itofin.cashflows import CPILeg, npv
Expand All @@ -14,13 +15,24 @@
day_counter = DayCounter.actual365_fixed()
calendar = Calendar.null_calendar()
schedule = Schedule(
Date(15, 1, 2025), Date(15, 7, 2025), Frequency.Semiannual,
calendar, BusinessDayConvention.Unadjusted,
Date(15, 1, 2025),
Date(15, 7, 2025),
Frequency.Semiannual,
calendar,
BusinessDayConvention.Unadjusted,
)
builder = CPILeg(
schedule, index, 100.0, Period(3, "Months"), [100000.0], [0.02],
day_counter, calendar, BusinessDayConvention.Unadjusted,
CpiInterpolationType.Flat, False,
schedule,
index,
100.0,
Period(3, "Months"),
[100000.0],
[0.02],
day_counter,
calendar,
BusinessDayConvention.Unadjusted,
CpiInterpolationType.Flat,
False,
)
leg = builder.build()
discount = FlatForward(today, 0.04, day_counter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

Run it with:

python example/python/credit_cds.py
python crates/itofin-py/python/examples/credit_cds.py
"""

# plugins
Expand Down Expand Up @@ -161,6 +161,7 @@ def bootstrap_default_curve() -> None:


def main() -> None:
"""Run the single-name CDS pricing and hazard-rate bootstrap examples."""
price_single_cds()
bootstrap_default_curve()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Run it with:

python example/python/european_option.py
python crates/itofin-py/python/examples/european_option.py
"""

# plugins
Expand All @@ -21,6 +21,7 @@


def main() -> None:
"""Price a European call with the analytic Black-Scholes engine."""
# D5: one Settings object holds the evaluation date and is threaded into
# every instrument. There is no global "today"; an unset date is an error,
# not a silent fall back to the system clock.
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions crates/itofin-py/python/examples/hw_forward_process.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Standalone forward-measure process, not a calibrated Hull-White model."""

# itofin library
from itofin.processes import HullWhiteForwardProcess
from itofin.termstructures import FlatForward
from itofin.time import Date, DayCounter

curve = FlatForward(Date(23, 10, 2026), 0.03, DayCounter.actual365_fixed())
process = HullWhiteForwardProcess(curve, 0.1, 0.02)
process.set_forward_measure_time(5.0)
print(process.expectation(1.0, 0.03, 0.8), process.variance(1.0, 0.03, 0.8))
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Compare fixed and live CPI denominators and value their one-flow legs."""

# itofin library
from itofin import Settings
from itofin.cashflows import CPICashFlow, ZeroInflationCashFlow, npv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

Run it with:

python example/python/inflation_swap.py
python crates/itofin-py/python/examples/inflation_swap.py
"""

# plugins
Expand Down Expand Up @@ -105,8 +105,18 @@
# January of the year the curve's base period ends in. They are stationary, so
# the lookup wrapping modulo twelve reuses them for every later year.
SEASONALITY_FACTORS = [
1.003245, 1.000000, 0.999715, 1.000495, 1.000929, 0.998687,
0.995949, 0.994682, 0.995949, 1.000519, 1.003705, 1.004186,
1.003245,
1.000000,
0.999715,
1.000495,
1.000929,
0.998687,
0.995949,
0.994682,
0.995949,
1.000519,
1.003705,
1.004186,
]
SEASONALITY_ANCHOR = Date(31, 1, 2007)
SEASONALITY_PROBE = Date(1, 8, 2012)
Expand All @@ -119,6 +129,7 @@ def _fixing_date(i: int) -> Date:


def build_index(settings: Settings) -> ZeroInflationIndex:
"""Build a UK RPI zero-inflation index loaded with the monthly fixings."""
index = ZeroInflationIndex.uk_rpi(settings)
for i, fixing in enumerate(FIX_DATA):
index.add_fixing(_fixing_date(i), fixing)
Expand All @@ -131,6 +142,7 @@ def nominal_curve() -> FlatForward:


def build_helpers(settings, index):
"""Build the zero-coupon inflation swap helpers that bootstrap the curve."""
return [
ZeroCouponInflationSwapHelper(
SimpleQuote(rate / 100.0),
Expand Down Expand Up @@ -210,6 +222,7 @@ def apply_seasonality(settings, index, curve) -> None:


def main() -> None:
"""Bootstrap the UK zero-inflation curve and price a zero-coupon inflation swap."""
# D5: one Settings threaded through index, helpers, swaps and engines.
settings = Settings()
settings.set_evaluation_date(TODAY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

Run it with:

python example/python/isda_cds.py
python crates/itofin-py/python/examples/isda_cds.py
"""

# plugins
Expand Down Expand Up @@ -175,12 +175,11 @@ def isda_curve(reference, deposits, swaps, float_tenor, fixed_frequency, currenc
def grid_cases():
"""The 20 (term date, spread, recovery) triples, in the loop order the
Markit values are indexed by."""
return [
(term_date, spread, recovery) for term_date in TERM_DATES for spread in SPREADS for recovery in RECOVERIES
]
return [(term_date, spread, recovery) for term_date in TERM_DATES for spread in SPREADS for recovery in RECOVERIES]


def markit_grid() -> None:
"""Reproduce the Markit upfront grid against the ISDA USD curve."""
settings = Settings()
# The evaluation date goes in before any helper is built: the helpers date
# off it, and MakeCreditDefaultSwap derives its trade date from it.
Expand Down Expand Up @@ -282,6 +281,7 @@ def trade(term_date, running_spread):


def eur_reconciliation() -> None:
"""Reconcile an EUR CDS valuation with Markit's reference values."""
settings = Settings()
settings.set_evaluation_date(VALUE_DATE)
discount = isda_curve(
Expand Down Expand Up @@ -355,6 +355,7 @@ def trade(running_spread, trade_date=None):


def main() -> None:
"""Run the ISDA CDS examples: the USD upfront grid and EUR reconciliation."""
markit_grid()
eur_reconciliation()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Run it with:

python example/python/local_vol.py
python crates/itofin-py/python/examples/local_vol.py
"""

# standard library
Expand Down
Loading
Loading