From f9747806120fb824ec534e75435861352d60d613 Mon Sep 17 00:00:00 2001 From: benbenbang Date: Mon, 23 Nov 2026 10:33:06 -0500 Subject: [PATCH] docs(examples): move python examples under itofin-py crate This pull request relocates the Python example sources from the top-level `example/python/` directory to `crates/itofin-py/python/examples/`, consolidating them alongside the Python bindings crate. All references are updated to point to the new path. **Example relocation:** * Moved all Python example scripts, configuration files, and `pyproject.toml` from `example/python/` to `crates/itofin-py/python/examples/`. **Documentation updates:** * Updated every reference in `docs/docs/`, `wiki/python.md`, and the root and crate `README.md` files to use the new example path. * Added an "Examples" section to the root `README.md` linking the Rust, Go, and Python example directories. **CI configuration:** * Updated the path filters in `docs.yml` and `pre-commit.yml` workflows to watch `crates/itofin-py/python/examples/**` instead of `example/**`. --- .github/workflows/docs.yml | 2 +- .github/workflows/pre-commit.yml | 2 +- README.md | 6 +++ crates/itofin-py/README.md | 22 +++++----- .../itofin-py/python/examples}/.gitignore | 0 .../itofin-py/python/examples}/.isort.cfg | 0 .../python/examples}/.pre-commit-config.yaml | 0 .../python/examples}/amortizing_fixed_bond.py | 0 .../examples}/amortizing_floating_bond.py | 13 +++++- .../python/examples}/asset_digital.py | 1 + .../python/examples}/bates_option.py | 9 +++- .../python/examples}/benchmark_beta.py | 0 .../python/examples}/bond_coupon_analytics.py | 21 ++++++--- .../python/examples}/bond_price_atm.py | 0 .../python/examples}/cash_digital.py | 9 ++-- .../cash_digital_black_calculator.py | 5 ++- .../itofin-py/python/examples}/chart_adx.py | 0 .../examples}/convergence_statistics.py | 0 .../python/examples}/cpi_base_date.py | 26 ++++++++--- .../python/examples}/cpi_cashflows.py | 22 +++++++--- .../itofin-py/python/examples}/credit_cds.py | 3 +- .../examples}/differential_evolution.py | 0 .../examples}/discrepancy_statistics.py | 0 .../itofin-py/python/examples}/drawdown.py | 0 .../python/examples}/european_option.py | 3 +- .../itofin-py/python/examples}/firefly.py | 0 .../python/examples}/float_float_swap.py | 0 .../itofin-py/python/examples}/gap_option.py | 0 .../python/examples}/geometric_brownian.py | 0 .../python/examples/hw_forward_process.py | 11 +++++ .../examples}/hybrid_simulated_annealing.py | 0 .../python/examples}/inflation_principal.py | 1 + .../python/examples}/inflation_swap.py | 19 ++++++-- .../itofin-py/python/examples}/isda_cds.py | 9 ++-- .../itofin-py/python/examples}/local_vol.py | 2 +- .../python/examples}/mc_variance_swap.py | 0 .../python/examples}/mf_state_process.py | 0 .../itofin-py/python/examples}/monte_carlo.py | 3 +- .../python/examples}/particle_swarm.py | 0 .../python/examples}/payment_inspection.py | 7 ++- .../python/examples}/percentage_strike.py | 1 + .../python/examples}/performance_ratios.py | 0 .../itofin-py/python/examples}/pyproject.toml | 0 .../python/examples}/scalar_payoffs.py | 0 .../python/examples}/sequence_statistics.py | 0 .../itofin-py/python/examples}/swaption.py | 2 +- .../itofin-py/python/examples}/uv.lock | 0 .../python/examples}/vanilla_swap.py | 4 +- .../python/examples}/variance_swap.py | 0 .../itofin-py/python/examples}/xccy_basis.py | 0 .../itofin-py/python/examples}/yield_curve.py | 3 +- .../examples}/yoy_inflation_capfloor.py | 44 ++++++++++++++++--- .../python/examples}/yoy_inflation_swap.py | 38 ++++++++++++++-- docs/docs/amortizing-fixed-bonds.md | 2 +- .../docs/amortizing-floating-bond-bindings.md | 2 +- docs/docs/asset-digital-bindings.md | 2 +- docs/docs/bates.md | 2 +- docs/docs/bond-coupon-analytics.md | 2 +- docs/docs/bond-price-atm-bindings.md | 2 +- docs/docs/cash-digital-bindings.md | 2 +- docs/docs/cash-digital-black-calculator.md | 2 +- docs/docs/chart.md | 2 +- docs/docs/convergence.md | 2 +- docs/docs/cpi-base-date-bindings.md | 2 +- docs/docs/cpi-cashflow-bindings.md | 2 +- docs/docs/discrepancy.md | 2 +- docs/docs/drawdown.md | 4 +- docs/docs/float-float-swaps.md | 2 +- docs/docs/gap-option-bindings.md | 2 +- docs/docs/geometric-brownian.md | 2 +- docs/docs/getting-started.md | 22 +++++----- docs/docs/global-optimization.md | 8 ++-- docs/docs/hw-forward-process-bindings.md | 2 +- docs/docs/index.md | 2 +- docs/docs/inflation-principal-bindings.md | 2 +- docs/docs/mc-variance-swaps.md | 2 +- docs/docs/mf-state-process-bindings.md | 2 +- docs/docs/payment-inspection-bindings.md | 2 +- docs/docs/percentage-strike-bindings.md | 2 +- docs/docs/scalar-payoff-bindings.md | 2 +- docs/docs/statistics.md | 6 +-- docs/docs/variance-swaps.md | 2 +- docs/docs/xccy-basis-bindings.md | 2 +- example/python/hw_forward_process.py | 11 ----- wiki/python.md | 6 +-- 85 files changed, 269 insertions(+), 128 deletions(-) rename {example/python => crates/itofin-py/python/examples}/.gitignore (100%) rename {example/python => crates/itofin-py/python/examples}/.isort.cfg (100%) rename {example/python => crates/itofin-py/python/examples}/.pre-commit-config.yaml (100%) rename {example/python => crates/itofin-py/python/examples}/amortizing_fixed_bond.py (100%) rename {example/python => crates/itofin-py/python/examples}/amortizing_floating_bond.py (89%) rename {example/python => crates/itofin-py/python/examples}/asset_digital.py (92%) rename {example/python => crates/itofin-py/python/examples}/bates_option.py (93%) rename {example/python => crates/itofin-py/python/examples}/benchmark_beta.py (100%) rename {example/python => crates/itofin-py/python/examples}/bond_coupon_analytics.py (56%) rename {example/python => crates/itofin-py/python/examples}/bond_price_atm.py (100%) rename {example/python => crates/itofin-py/python/examples}/cash_digital.py (67%) rename {example/python => crates/itofin-py/python/examples}/cash_digital_black_calculator.py (65%) rename {example/python => crates/itofin-py/python/examples}/chart_adx.py (100%) rename {example/python => crates/itofin-py/python/examples}/convergence_statistics.py (100%) rename {example/python => crates/itofin-py/python/examples}/cpi_base_date.py (62%) rename {example/python => crates/itofin-py/python/examples}/cpi_cashflows.py (72%) rename {example/python => crates/itofin-py/python/examples}/credit_cds.py (97%) rename {example/python => crates/itofin-py/python/examples}/differential_evolution.py (100%) rename {example/python => crates/itofin-py/python/examples}/discrepancy_statistics.py (100%) rename {example/python => crates/itofin-py/python/examples}/drawdown.py (100%) rename {example/python => crates/itofin-py/python/examples}/european_option.py (94%) rename {example/python => crates/itofin-py/python/examples}/firefly.py (100%) rename {example/python => crates/itofin-py/python/examples}/float_float_swap.py (100%) rename {example/python => crates/itofin-py/python/examples}/gap_option.py (100%) rename {example/python => crates/itofin-py/python/examples}/geometric_brownian.py (100%) create mode 100644 crates/itofin-py/python/examples/hw_forward_process.py rename {example/python => crates/itofin-py/python/examples}/hybrid_simulated_annealing.py (100%) rename {example/python => crates/itofin-py/python/examples}/inflation_principal.py (99%) rename {example/python => crates/itofin-py/python/examples}/inflation_swap.py (94%) rename {example/python => crates/itofin-py/python/examples}/isda_cds.py (97%) rename {example/python => crates/itofin-py/python/examples}/local_vol.py (96%) rename {example/python => crates/itofin-py/python/examples}/mc_variance_swap.py (100%) rename {example/python => crates/itofin-py/python/examples}/mf_state_process.py (100%) rename {example/python => crates/itofin-py/python/examples}/monte_carlo.py (97%) rename {example/python => crates/itofin-py/python/examples}/particle_swarm.py (100%) rename {example/python => crates/itofin-py/python/examples}/payment_inspection.py (77%) rename {example/python => crates/itofin-py/python/examples}/percentage_strike.py (92%) rename {example/python => crates/itofin-py/python/examples}/performance_ratios.py (100%) rename {example/python => crates/itofin-py/python/examples}/pyproject.toml (100%) rename {example/python => crates/itofin-py/python/examples}/scalar_payoffs.py (100%) rename {example/python => crates/itofin-py/python/examples}/sequence_statistics.py (100%) rename {example/python => crates/itofin-py/python/examples}/swaption.py (97%) rename {example/python => crates/itofin-py/python/examples}/uv.lock (100%) rename {example/python => crates/itofin-py/python/examples}/vanilla_swap.py (93%) rename {example/python => crates/itofin-py/python/examples}/variance_swap.py (100%) rename {example/python => crates/itofin-py/python/examples}/xccy_basis.py (100%) rename {example/python => crates/itofin-py/python/examples}/yield_curve.py (96%) rename {example/python => crates/itofin-py/python/examples}/yoy_inflation_capfloor.py (94%) rename {example/python => crates/itofin-py/python/examples}/yoy_inflation_swap.py (94%) delete mode 100644 example/python/hw_forward_process.py diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 375f19430..54be17fe9 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -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" diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index a75e340ab..6a395e6a4 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -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 diff --git a/README.md b/README.md index 042304b39..46843672e 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/crates/itofin-py/README.md b/crates/itofin-py/README.md index ab86a8127..db18d9fd8 100644 --- a/crates/itofin-py/README.md +++ b/crates/itofin-py/README.md @@ -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 diff --git a/example/python/.gitignore b/crates/itofin-py/python/examples/.gitignore similarity index 100% rename from example/python/.gitignore rename to crates/itofin-py/python/examples/.gitignore diff --git a/example/python/.isort.cfg b/crates/itofin-py/python/examples/.isort.cfg similarity index 100% rename from example/python/.isort.cfg rename to crates/itofin-py/python/examples/.isort.cfg diff --git a/example/python/.pre-commit-config.yaml b/crates/itofin-py/python/examples/.pre-commit-config.yaml similarity index 100% rename from example/python/.pre-commit-config.yaml rename to crates/itofin-py/python/examples/.pre-commit-config.yaml diff --git a/example/python/amortizing_fixed_bond.py b/crates/itofin-py/python/examples/amortizing_fixed_bond.py similarity index 100% rename from example/python/amortizing_fixed_bond.py rename to crates/itofin-py/python/examples/amortizing_fixed_bond.py diff --git a/example/python/amortizing_floating_bond.py b/crates/itofin-py/python/examples/amortizing_floating_bond.py similarity index 89% rename from example/python/amortizing_floating_bond.py rename to crates/itofin-py/python/examples/amortizing_floating_bond.py index 9a1637319..69ff4e3f2 100644 --- a/example/python/amortizing_floating_bond.py +++ b/crates/itofin-py/python/examples/amortizing_floating_bond.py @@ -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)) diff --git a/example/python/asset_digital.py b/crates/itofin-py/python/examples/asset_digital.py similarity index 92% rename from example/python/asset_digital.py rename to crates/itofin-py/python/examples/asset_digital.py index a47727ed2..dde57a5d0 100644 --- a/example/python/asset_digital.py +++ b/crates/itofin-py/python/examples/asset_digital.py @@ -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) diff --git a/example/python/bates_option.py b/crates/itofin-py/python/examples/bates_option.py similarity index 93% rename from example/python/bates_option.py rename to crates/itofin-py/python/examples/bates_option.py index b1d95e53b..44a06ed3d 100644 --- a/example/python/bates_option.py +++ b/crates/itofin-py/python/examples/bates_option.py @@ -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) diff --git a/example/python/benchmark_beta.py b/crates/itofin-py/python/examples/benchmark_beta.py similarity index 100% rename from example/python/benchmark_beta.py rename to crates/itofin-py/python/examples/benchmark_beta.py diff --git a/example/python/bond_coupon_analytics.py b/crates/itofin-py/python/examples/bond_coupon_analytics.py similarity index 56% rename from example/python/bond_coupon_analytics.py rename to crates/itofin-py/python/examples/bond_coupon_analytics.py index e48526807..728e96d1e 100644 --- a/example/python/bond_coupon_analytics.py +++ b/crates/itofin-py/python/examples/bond_coupon_analytics.py @@ -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 @@ -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)) diff --git a/example/python/bond_price_atm.py b/crates/itofin-py/python/examples/bond_price_atm.py similarity index 100% rename from example/python/bond_price_atm.py rename to crates/itofin-py/python/examples/bond_price_atm.py diff --git a/example/python/cash_digital.py b/crates/itofin-py/python/examples/cash_digital.py similarity index 67% rename from example/python/cash_digital.py rename to crates/itofin-py/python/examples/cash_digital.py index 0f748ebd8..ba721be41 100644 --- a/example/python/cash_digital.py +++ b/crates/itofin-py/python/examples/cash_digital.py @@ -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}") diff --git a/example/python/cash_digital_black_calculator.py b/crates/itofin-py/python/examples/cash_digital_black_calculator.py similarity index 65% rename from example/python/cash_digital_black_calculator.py rename to crates/itofin-py/python/examples/cash_digital_black_calculator.py index 477c883ae..81b7449d6 100644 --- a/example/python/cash_digital_black_calculator.py +++ b/crates/itofin-py/python/examples/cash_digital_black_calculator.py @@ -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}") diff --git a/example/python/chart_adx.py b/crates/itofin-py/python/examples/chart_adx.py similarity index 100% rename from example/python/chart_adx.py rename to crates/itofin-py/python/examples/chart_adx.py diff --git a/example/python/convergence_statistics.py b/crates/itofin-py/python/examples/convergence_statistics.py similarity index 100% rename from example/python/convergence_statistics.py rename to crates/itofin-py/python/examples/convergence_statistics.py diff --git a/example/python/cpi_base_date.py b/crates/itofin-py/python/examples/cpi_base_date.py similarity index 62% rename from example/python/cpi_base_date.py rename to crates/itofin-py/python/examples/cpi_base_date.py index 4aa11843d..ba784b27c 100644 --- a/example/python/cpi_base_date.py +++ b/crates/itofin-py/python/examples/cpi_base_date.py @@ -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 @@ -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)) diff --git a/example/python/cpi_cashflows.py b/crates/itofin-py/python/examples/cpi_cashflows.py similarity index 72% rename from example/python/cpi_cashflows.py rename to crates/itofin-py/python/examples/cpi_cashflows.py index a57105bec..7af80ff50 100644 --- a/example/python/cpi_cashflows.py +++ b/crates/itofin-py/python/examples/cpi_cashflows.py @@ -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 @@ -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) diff --git a/example/python/credit_cds.py b/crates/itofin-py/python/examples/credit_cds.py similarity index 97% rename from example/python/credit_cds.py rename to crates/itofin-py/python/examples/credit_cds.py index cc81f6ca5..6c68058a1 100644 --- a/example/python/credit_cds.py +++ b/crates/itofin-py/python/examples/credit_cds.py @@ -22,7 +22,7 @@ Run it with: - python example/python/credit_cds.py + python crates/itofin-py/python/examples/credit_cds.py """ # plugins @@ -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() diff --git a/example/python/differential_evolution.py b/crates/itofin-py/python/examples/differential_evolution.py similarity index 100% rename from example/python/differential_evolution.py rename to crates/itofin-py/python/examples/differential_evolution.py diff --git a/example/python/discrepancy_statistics.py b/crates/itofin-py/python/examples/discrepancy_statistics.py similarity index 100% rename from example/python/discrepancy_statistics.py rename to crates/itofin-py/python/examples/discrepancy_statistics.py diff --git a/example/python/drawdown.py b/crates/itofin-py/python/examples/drawdown.py similarity index 100% rename from example/python/drawdown.py rename to crates/itofin-py/python/examples/drawdown.py diff --git a/example/python/european_option.py b/crates/itofin-py/python/examples/european_option.py similarity index 94% rename from example/python/european_option.py rename to crates/itofin-py/python/examples/european_option.py index 9514475fe..f345f72cc 100644 --- a/example/python/european_option.py +++ b/crates/itofin-py/python/examples/european_option.py @@ -9,7 +9,7 @@ Run it with: - python example/python/european_option.py + python crates/itofin-py/python/examples/european_option.py """ # plugins @@ -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. diff --git a/example/python/firefly.py b/crates/itofin-py/python/examples/firefly.py similarity index 100% rename from example/python/firefly.py rename to crates/itofin-py/python/examples/firefly.py diff --git a/example/python/float_float_swap.py b/crates/itofin-py/python/examples/float_float_swap.py similarity index 100% rename from example/python/float_float_swap.py rename to crates/itofin-py/python/examples/float_float_swap.py diff --git a/example/python/gap_option.py b/crates/itofin-py/python/examples/gap_option.py similarity index 100% rename from example/python/gap_option.py rename to crates/itofin-py/python/examples/gap_option.py diff --git a/example/python/geometric_brownian.py b/crates/itofin-py/python/examples/geometric_brownian.py similarity index 100% rename from example/python/geometric_brownian.py rename to crates/itofin-py/python/examples/geometric_brownian.py diff --git a/crates/itofin-py/python/examples/hw_forward_process.py b/crates/itofin-py/python/examples/hw_forward_process.py new file mode 100644 index 000000000..e4bf118a6 --- /dev/null +++ b/crates/itofin-py/python/examples/hw_forward_process.py @@ -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)) diff --git a/example/python/hybrid_simulated_annealing.py b/crates/itofin-py/python/examples/hybrid_simulated_annealing.py similarity index 100% rename from example/python/hybrid_simulated_annealing.py rename to crates/itofin-py/python/examples/hybrid_simulated_annealing.py diff --git a/example/python/inflation_principal.py b/crates/itofin-py/python/examples/inflation_principal.py similarity index 99% rename from example/python/inflation_principal.py rename to crates/itofin-py/python/examples/inflation_principal.py index b0dfddf29..16b6d554a 100644 --- a/example/python/inflation_principal.py +++ b/crates/itofin-py/python/examples/inflation_principal.py @@ -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 diff --git a/example/python/inflation_swap.py b/crates/itofin-py/python/examples/inflation_swap.py similarity index 94% rename from example/python/inflation_swap.py rename to crates/itofin-py/python/examples/inflation_swap.py index a077e3e71..fd9f3f506 100644 --- a/example/python/inflation_swap.py +++ b/crates/itofin-py/python/examples/inflation_swap.py @@ -23,7 +23,7 @@ Run it with: - python example/python/inflation_swap.py + python crates/itofin-py/python/examples/inflation_swap.py """ # plugins @@ -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) @@ -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) @@ -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), @@ -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) diff --git a/example/python/isda_cds.py b/crates/itofin-py/python/examples/isda_cds.py similarity index 97% rename from example/python/isda_cds.py rename to crates/itofin-py/python/examples/isda_cds.py index aaff170ba..5cf2476f8 100644 --- a/example/python/isda_cds.py +++ b/crates/itofin-py/python/examples/isda_cds.py @@ -42,7 +42,7 @@ Run it with: - python example/python/isda_cds.py + python crates/itofin-py/python/examples/isda_cds.py """ # plugins @@ -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. @@ -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( @@ -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() diff --git a/example/python/local_vol.py b/crates/itofin-py/python/examples/local_vol.py similarity index 96% rename from example/python/local_vol.py rename to crates/itofin-py/python/examples/local_vol.py index f5f0666e9..13e4e30a8 100644 --- a/example/python/local_vol.py +++ b/crates/itofin-py/python/examples/local_vol.py @@ -5,7 +5,7 @@ Run it with: - python example/python/local_vol.py + python crates/itofin-py/python/examples/local_vol.py """ # standard library diff --git a/example/python/mc_variance_swap.py b/crates/itofin-py/python/examples/mc_variance_swap.py similarity index 100% rename from example/python/mc_variance_swap.py rename to crates/itofin-py/python/examples/mc_variance_swap.py diff --git a/example/python/mf_state_process.py b/crates/itofin-py/python/examples/mf_state_process.py similarity index 100% rename from example/python/mf_state_process.py rename to crates/itofin-py/python/examples/mf_state_process.py diff --git a/example/python/monte_carlo.py b/crates/itofin-py/python/examples/monte_carlo.py similarity index 97% rename from example/python/monte_carlo.py rename to crates/itofin-py/python/examples/monte_carlo.py index d8a5f3a2e..c73e3c37f 100644 --- a/example/python/monte_carlo.py +++ b/crates/itofin-py/python/examples/monte_carlo.py @@ -18,7 +18,7 @@ Run it with: - python example/python/monte_carlo.py + python crates/itofin-py/python/examples/monte_carlo.py """ # plugins @@ -131,6 +131,7 @@ def mc_american() -> None: def main() -> None: + """Run the European, Heston and American Monte Carlo examples.""" mc_european() mc_heston() mc_american() diff --git a/example/python/particle_swarm.py b/crates/itofin-py/python/examples/particle_swarm.py similarity index 100% rename from example/python/particle_swarm.py rename to crates/itofin-py/python/examples/particle_swarm.py diff --git a/example/python/payment_inspection.py b/crates/itofin-py/python/examples/payment_inspection.py similarity index 77% rename from example/python/payment_inspection.py rename to crates/itofin-py/python/examples/payment_inspection.py index 6cc11bbc8..aa22f519e 100644 --- a/example/python/payment_inspection.py +++ b/crates/itofin-py/python/examples/payment_inspection.py @@ -1,4 +1,5 @@ """Inspect actual bond payments without installing a pricing engine.""" + # itofin library from itofin import Settings from itofin.instruments import FixedRateBond @@ -7,8 +8,10 @@ settings = Settings() settings.set_evaluation_date(Date(20, 1, 2026)) calendar = Calendar.null_calendar() -schedule = Schedule(Date(15, 1, 2025), Date(15, 1, 2027), Frequency.Semiannual, calendar, BusinessDayConvention.Unadjusted) -bond = FixedRateBond(2, 1000.0, schedule, [.045], DayCounter.actual365_fixed(), settings) +schedule = Schedule( + Date(15, 1, 2025), Date(15, 1, 2027), Frequency.Semiannual, calendar, BusinessDayConvention.Unadjusted +) +bond = FixedRateBond(2, 1000.0, schedule, [0.045], DayCounter.actual365_fixed(), settings) print("Accrual starts:", bond.start_date()) print("Tradable:", bond.is_tradable()) print("Next payment:", bond.next_cash_flow_date(), bond.next_cash_flow_amount()) diff --git a/example/python/percentage_strike.py b/crates/itofin-py/python/examples/percentage_strike.py similarity index 92% rename from example/python/percentage_strike.py rename to crates/itofin-py/python/examples/percentage_strike.py index 56ecc4a1b..83c410f52 100644 --- a/example/python/percentage_strike.py +++ b/crates/itofin-py/python/examples/percentage_strike.py @@ -9,6 +9,7 @@ def main(): + """Price a percentage-strike call with the finite-difference engine.""" reference = Date(15, 6, 2026) settings = Settings() settings.set_evaluation_date(reference) diff --git a/example/python/performance_ratios.py b/crates/itofin-py/python/examples/performance_ratios.py similarity index 100% rename from example/python/performance_ratios.py rename to crates/itofin-py/python/examples/performance_ratios.py diff --git a/example/python/pyproject.toml b/crates/itofin-py/python/examples/pyproject.toml similarity index 100% rename from example/python/pyproject.toml rename to crates/itofin-py/python/examples/pyproject.toml diff --git a/example/python/scalar_payoffs.py b/crates/itofin-py/python/examples/scalar_payoffs.py similarity index 100% rename from example/python/scalar_payoffs.py rename to crates/itofin-py/python/examples/scalar_payoffs.py diff --git a/example/python/sequence_statistics.py b/crates/itofin-py/python/examples/sequence_statistics.py similarity index 100% rename from example/python/sequence_statistics.py rename to crates/itofin-py/python/examples/sequence_statistics.py diff --git a/example/python/swaption.py b/crates/itofin-py/python/examples/swaption.py similarity index 97% rename from example/python/swaption.py rename to crates/itofin-py/python/examples/swaption.py index 28bbe16f8..38bc90753 100644 --- a/example/python/swaption.py +++ b/crates/itofin-py/python/examples/swaption.py @@ -8,7 +8,7 @@ both checks retain an absolute tolerance of 1e-12. The 4% forwarding curve is equivalent to that fixture's 5% continuous curve plus a -1% zero spread. -Run from the repository root: python example/python/swaption.py +Run from the repository root: python crates/itofin-py/python/examples/swaption.py """ # standard library diff --git a/example/python/uv.lock b/crates/itofin-py/python/examples/uv.lock similarity index 100% rename from example/python/uv.lock rename to crates/itofin-py/python/examples/uv.lock diff --git a/example/python/vanilla_swap.py b/crates/itofin-py/python/examples/vanilla_swap.py similarity index 93% rename from example/python/vanilla_swap.py rename to crates/itofin-py/python/examples/vanilla_swap.py index 84f7f3ae2..832ee94e0 100644 --- a/example/python/vanilla_swap.py +++ b/crates/itofin-py/python/examples/vanilla_swap.py @@ -15,7 +15,7 @@ Run it with: - python example/python/vanilla_swap.py + python crates/itofin-py/python/examples/vanilla_swap.py """ # plugins @@ -32,6 +32,7 @@ def make_market(): + """Build the settings, flat 3% curve and Euribor 6M index shared by the swap examples.""" settings = Settings() settings.set_evaluation_date(REF) # A flat 3% continuous curve for both forwarding and discounting. @@ -92,6 +93,7 @@ def priced_by_hand(): def main() -> None: + """Price a par swap from the builder and a hand-built swap at a 3% coupon.""" par = priced_with_builder() print("MakeVanillaSwap, par 5Y payer (fixed_rate=None):") print(f" fair_rate = {par.fair_rate() * 100:.6f}%") diff --git a/example/python/variance_swap.py b/crates/itofin-py/python/examples/variance_swap.py similarity index 100% rename from example/python/variance_swap.py rename to crates/itofin-py/python/examples/variance_swap.py diff --git a/example/python/xccy_basis.py b/crates/itofin-py/python/examples/xccy_basis.py similarity index 100% rename from example/python/xccy_basis.py rename to crates/itofin-py/python/examples/xccy_basis.py diff --git a/example/python/yield_curve.py b/crates/itofin-py/python/examples/yield_curve.py similarity index 96% rename from example/python/yield_curve.py rename to crates/itofin-py/python/examples/yield_curve.py index a4197c2a1..aa371bcae 100644 --- a/example/python/yield_curve.py +++ b/crates/itofin-py/python/examples/yield_curve.py @@ -11,7 +11,7 @@ Run it with: - python example/python/yield_curve.py + python crates/itofin-py/python/examples/yield_curve.py """ # plugins @@ -45,6 +45,7 @@ def main() -> None: + """Bootstrap a Euribor curve from deposit and swap helpers.""" settings = Settings() calendar = Calendar.target() today = calendar.adjust(Date(15, 6, 2026), BusinessDayConvention.Following) diff --git a/example/python/yoy_inflation_capfloor.py b/crates/itofin-py/python/examples/yoy_inflation_capfloor.py similarity index 94% rename from example/python/yoy_inflation_capfloor.py rename to crates/itofin-py/python/examples/yoy_inflation_capfloor.py index d30d8fbc9..278570931 100644 --- a/example/python/yoy_inflation_capfloor.py +++ b/crates/itofin-py/python/examples/yoy_inflation_capfloor.py @@ -39,7 +39,7 @@ Run it with: - python example/python/yoy_inflation_capfloor.py + python crates/itofin-py/python/examples/yoy_inflation_capfloor.py """ # plugins @@ -73,10 +73,39 @@ # curve's base date from June to 1 August 2007, the origin every number below is # measured from. Dropping them silently moves every optionlet. FIX_DATA = [ - 189.9, 189.9, 189.6, 190.5, 191.6, 192.0, 192.2, 192.2, 192.6, 193.1, - 193.3, 193.6, 194.1, 193.4, 194.2, 195.0, 196.5, 197.7, 198.5, 198.5, - 199.2, 200.1, 200.4, 201.1, 202.7, 201.6, 203.1, 204.4, 205.4, 206.2, - 207.3, -999.0, -999.0, + 189.9, + 189.9, + 189.6, + 190.5, + 191.6, + 192.0, + 192.2, + 192.2, + 192.6, + 193.1, + 193.3, + 193.6, + 194.1, + 193.4, + 194.2, + 195.0, + 196.5, + 197.7, + 198.5, + 198.5, + 199.2, + 200.1, + 200.4, + 201.1, + 202.7, + 201.6, + 203.1, + 204.4, + 205.4, + 206.2, + 207.3, + -999.0, + -999.0, ] # (maturity, quoted year-on-year swap rate in percent). @@ -211,14 +240,14 @@ def priced(settings, index, nominal, cap_floor_type, distribution) -> float: def price_under_each_distribution(settings, index, nominal) -> None: + """Price the year-on-year cap and floor under each distribution and compare with cached values.""" print(f"Two-year year-on-year cap and floor struck at {STRIKE:.2%}, notional {NOMINAL:,.0f}, vol {VOLATILITY:.0%}") for distribution, (cached_cap, cached_floor, tolerance) in CACHED.items(): cap = priced(settings, index, nominal, CapFloorType.Cap, distribution) floor = priced(settings, index, nominal, CapFloorType.Floor, distribution) print(f"\n {distribution}:") print( - f" cap = {cap:10.4f} cached={cached_cap:>9} " - f"|diff|={abs(cap - cached_cap):.4f} (tol {tolerance})" + f" cap = {cap:10.4f} cached={cached_cap:>9} |diff|={abs(cap - cached_cap):.4f} (tol {tolerance})" ) print( f" floor = {floor:10.4f} cached={cached_floor:>9} " @@ -259,6 +288,7 @@ def strike_and_atm_are_exclusive(settings, index, nominal) -> None: def main() -> None: + """Run the year-on-year cap and floor pricing examples.""" settings, index, nominal = build_market() print(f"UK RPI last fixing date (the curve's base) = {index.underlying_index().last_fixing_date()}\n") diff --git a/example/python/yoy_inflation_swap.py b/crates/itofin-py/python/examples/yoy_inflation_swap.py similarity index 94% rename from example/python/yoy_inflation_swap.py rename to crates/itofin-py/python/examples/yoy_inflation_swap.py index eb0916857..06a8d622d 100644 --- a/example/python/yoy_inflation_swap.py +++ b/crates/itofin-py/python/examples/yoy_inflation_swap.py @@ -33,7 +33,7 @@ Run it with: - python example/python/yoy_inflation_swap.py + python crates/itofin-py/python/examples/yoy_inflation_swap.py """ # plugins @@ -59,9 +59,36 @@ # here: the last real figure, 207.3, is the July 2007 period, which is what # makes 1 July 2007 the curve's base date. FIX_DATA = [ - 189.9, 189.9, 189.6, 190.5, 191.6, 192.0, 192.2, 192.2, 192.6, 193.1, - 193.3, 193.6, 194.1, 193.4, 194.2, 195.0, 196.5, 197.7, 198.5, 198.5, - 199.2, 200.1, 200.4, 201.1, 202.7, 201.6, 203.1, 204.4, 205.4, 206.2, + 189.9, + 189.9, + 189.6, + 190.5, + 191.6, + 192.0, + 192.2, + 192.2, + 192.6, + 193.1, + 193.3, + 193.6, + 194.1, + 193.4, + 194.2, + 195.0, + 196.5, + 197.7, + 198.5, + 198.5, + 199.2, + 200.1, + 200.4, + 201.1, + 202.7, + 201.6, + 203.1, + 204.4, + 205.4, + 206.2, 207.3, ] @@ -90,6 +117,7 @@ class Market: calendar and annual schedule every leg and swap below shares.""" def __init__(self): + """Bootstrap the year-on-year curve and index with the RPI fixings they need.""" self.settings = Settings() self.settings.set_evaluation_date(TODAY) self.calendar = Calendar.united_kingdom() @@ -180,6 +208,7 @@ def swap(self, spread: float = 0.0) -> YearOnYearInflationSwap: def price_the_swap(market: Market) -> None: + """Print the NPV, leg values, and fair rate and spread of the 3Y swap.""" swap = market.swap() print(f"3Y year-on-year inflation swap, payer of {FIXED_RATE:.2%} on {NOTIONAL:,.0f}, to {MATURITY}:") print(f" NPV = {swap.npv():14.4f}") @@ -250,6 +279,7 @@ def the_rate_lags_off_the_accrual_end(market: Market) -> None: def main() -> None: + """Run the year-on-year inflation swap examples.""" market = Market() price_the_swap(market) inspect_the_coupons(market) diff --git a/docs/docs/amortizing-fixed-bonds.md b/docs/docs/amortizing-fixed-bonds.md index 830066c6f..b18bfb137 100644 --- a/docs/docs/amortizing-fixed-bonds.md +++ b/docs/docs/amortizing-fixed-bonds.md @@ -65,7 +65,7 @@ this factory does not repair or newly promise economic forward-quote units. ## Examples and oracle -- Python: [`example/python/amortizing_fixed_bond.py`](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/amortizing_fixed_bond.py) +- Python: [`crates/itofin-py/python/examples/amortizing_fixed_bond.py`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/amortizing_fixed_bond.py) - Go: [`sdk/go/examples/amortizing_fixed_bond`](https://github.com/bitbrew-dev/libitofin/tree/main/sdk/go/examples/amortizing_fixed_bond) Native fixtures use independently selected cases: declining/plateau/constant diff --git a/docs/docs/amortizing-floating-bond-bindings.md b/docs/docs/amortizing-floating-bond-bindings.md index 957a5aa20..ba2fb87fe 100644 --- a/docs/docs/amortizing-floating-bond-bindings.md +++ b/docs/docs/amortizing-floating-bond-bindings.md @@ -84,7 +84,7 @@ index wrapper does not change that map. ## Examples -- [Python example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/amortizing_floating_bond.py) +- [Python example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/amortizing_floating_bond.py) - [Go example](https://github.com/bitbrew-dev/libitofin/blob/main/sdk/go/examples/amortizing_floating_bond/main.go) See [bond bindings](bond-bindings.md) for common pricing/lifecycle contracts and diff --git a/docs/docs/asset-digital-bindings.md b/docs/docs/asset-digital-bindings.md index afa9a49b3..5e5a51276 100644 --- a/docs/docs/asset-digital-bindings.md +++ b/docs/docs/asset-digital-bindings.md @@ -81,7 +81,7 @@ this factory does not change the general boundary contract. ## Examples and reference data -- Python: `example/python/asset_digital.py`. +- Python: `crates/itofin-py/python/examples/asset_digital.py`. - Go: `sdk/go/examples/asset_digital/main.go`. - Independent CSV: `crates/itofin-py/tests/fixtures/asset-digital/asset_fd_reference.csv`, with a byte-identical SDK testdata copy. Tracked copies normalize only original diff --git a/docs/docs/bates.md b/docs/docs/bates.md index 209d515db..7004eae5d 100644 --- a/docs/docs/bates.md +++ b/docs/docs/bates.md @@ -41,7 +41,7 @@ are not supported. === "Python" ```python - --8<-- "example/python/bates_option.py" + --8<-- "crates/itofin-py/python/examples/bates_option.py" ``` === "Go" diff --git a/docs/docs/bond-coupon-analytics.md b/docs/docs/bond-coupon-analytics.md index b9e45f436..14442af05 100644 --- a/docs/docs/bond-coupon-analytics.md +++ b/docs/docs/bond-coupon-analytics.md @@ -47,7 +47,7 @@ queries, preserving native behavior. ## Examples -Python: `example/python/bond_coupon_analytics.py`. +Python: `crates/itofin-py/python/examples/bond_coupon_analytics.py`. Go: `sdk/go/examples/bond-coupon-analytics/main.go`. diff --git a/docs/docs/bond-price-atm-bindings.md b/docs/docs/bond-price-atm-bindings.md index fbcc962ef..60c470fa0 100644 --- a/docs/docs/bond-price-atm-bindings.md +++ b/docs/docs/bond-price-atm-bindings.md @@ -52,7 +52,7 @@ calculation; callers retain pointer validity/non-overlap obligations. ## Examples -- Python: `example/python/bond_price_atm.py`. +- Python: `crates/itofin-py/python/examples/bond_price_atm.py`. - Go: `sdk/go/examples/bond-price-atm/main.go`. ## Provenance diff --git a/docs/docs/cash-digital-bindings.md b/docs/docs/cash-digital-bindings.md index c2d77fd3d..46a5b173c 100644 --- a/docs/docs/cash-digital-bindings.md +++ b/docs/docs/cash-digital-bindings.md @@ -60,7 +60,7 @@ QuantLib parity. Existing core behavior, including errors, is retained. ## Examples -Python: [cash digital example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/cash_digital.py). +Python: [cash digital example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/cash_digital.py). Go: [cash digital example](https://github.com/bitbrew-dev/libitofin/blob/main/sdk/go/examples/cash_digital/main.go). Fixtures compare regular positive-volatility prices and Greeks to an independent diff --git a/docs/docs/cash-digital-black-calculator.md b/docs/docs/cash-digital-black-calculator.md index 646f39484..f5380ac26 100644 --- a/docs/docs/cash-digital-black-calculator.md +++ b/docs/docs/cash-digital-black-calculator.md @@ -85,6 +85,6 @@ C++ source reference is `9863b578af0caa4cecabf697196533e84a8308b6`; it is a sepa reference, not a claim that the wheel was built from that source. Runnable examples: -[`example/python/cash_digital_black_calculator.py`](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/cash_digital_black_calculator.py) +[`crates/itofin-py/python/examples/cash_digital_black_calculator.py`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/cash_digital_black_calculator.py) and [`sdk/go/examples/cash_digital_black_calculator/main.go`](https://github.com/bitbrew-dev/libitofin/blob/main/sdk/go/examples/cash_digital_black_calculator/main.go). diff --git a/docs/docs/chart.md b/docs/docs/chart.md index dd7333638..76ea8e907 100644 --- a/docs/docs/chart.md +++ b/docs/docs/chart.md @@ -471,7 +471,7 @@ Use **each channel's** `to_list()`/`NullableValues()` to mask its warmup zeroes. _ = result.ADX.NullableValues() ``` -Runnable examples: `python example/python/chart_adx.py` and, from `sdk/go`, +Runnable examples: `python crates/itofin-py/python/examples/chart_adx.py` and, from `sdk/go`, `go run ./examples/chart_adx`. Rust exposes `math::chart::{Adx, adx, adx_default}`. Python's frozen `Adx` diff --git a/docs/docs/convergence.md b/docs/docs/convergence.md index 833564121..e7edf228d 100644 --- a/docs/docs/convergence.md +++ b/docs/docs/convergence.md @@ -97,7 +97,7 @@ is needed. Executable examples: - [Rust](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/convergence_statistics.rs) -- [Python](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/convergence_statistics.py) +- [Python](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/convergence_statistics.py) - [Go](https://github.com/bitbrew-dev/libitofin/blob/main/sdk/go/examples/convergence-statistics/main.go) - [Pinned oracle and regeneration](https://github.com/bitbrew-dev/libitofin/tree/main/sdk/go/testdata/convergence-statistics) diff --git a/docs/docs/cpi-base-date-bindings.md b/docs/docs/cpi-base-date-bindings.md index 99b7c7d16..141972f7e 100644 --- a/docs/docs/cpi-base-date-bindings.md +++ b/docs/docs/cpi-base-date-bindings.md @@ -72,6 +72,6 @@ independent wheel and records that mixed provenance, not a full-source build. Its entire numerical matrix was also independently reconstructed through SWIG. See the two provenance JSON files under `sdk/go/testdata/cpi-base-date-*`. -- [Python example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/cpi_base_date.py) +- [Python example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/cpi_base_date.py) - [Go example](https://github.com/bitbrew-dev/libitofin/blob/main/sdk/go/examples/cpi_base_date/main.go) - [Existing plain CPI contract](cpi-cashflow-bindings.md) diff --git a/docs/docs/cpi-cashflow-bindings.md b/docs/docs/cpi-cashflow-bindings.md index 29df25ef8..7fc78d6e9 100644 --- a/docs/docs/cpi-cashflow-bindings.md +++ b/docs/docs/cpi-cashflow-bindings.md @@ -64,7 +64,7 @@ Independent fixtures in `sdk/go/testdata/cpi-oracle-*.json` are produced by source is a separate reference, not a claim that it built the Python wheel. Fixture agreement covers the listed scenarios, not full QuantLib parity. -Runnable examples: [`example/python/cpi_cashflows.py`](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/cpi_cashflows.py) +Runnable examples: [`crates/itofin-py/python/examples/cpi_cashflows.py`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/cpi_cashflows.py) and [`sdk/go/examples/cpi_cashflows/main.go`](https://github.com/bitbrew-dev/libitofin/blob/main/sdk/go/examples/cpi_cashflows/main.go). Both use published historical CPI and a nominal discount curve, so no inflation forecast curve is needed for their short maturity. diff --git a/docs/docs/discrepancy.md b/docs/docs/discrepancy.md index 557a51c5e..b4bb63e28 100644 --- a/docs/docs/discrepancy.md +++ b/docs/docs/discrepancy.md @@ -93,7 +93,7 @@ shape/work gate; passing a huge Python sequence still has conversion cost. Executable examples: - [Rust](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/discrepancy_statistics.rs) -- [Python](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/discrepancy_statistics.py) +- [Python](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/discrepancy_statistics.py) - [Go](https://github.com/bitbrew-dev/libitofin/blob/main/sdk/go/examples/discrepancy-statistics/main.go) - [Pinned oracle and regeneration](https://github.com/bitbrew-dev/libitofin/tree/main/sdk/go/testdata/discrepancy-statistics) diff --git a/docs/docs/drawdown.md b/docs/docs/drawdown.md index 495e82731..af285e62b 100644 --- a/docs/docs/drawdown.md +++ b/docs/docs/drawdown.md @@ -32,7 +32,7 @@ from peak index 1 to trough index 2. Later recovery does not erase that loss. === "Python" ```python - --8<-- "example/python/drawdown.py" + --8<-- "crates/itofin-py/python/examples/drawdown.py" ``` === "Go" @@ -41,7 +41,7 @@ from peak index 1 to trough index 2. Later recovery does not erase that loss. --8<-- "sdk/go/examples/drawdown/main.go" ``` -From a native-build checkout, run `python example/python/drawdown.py` or +From a native-build checkout, run `python crates/itofin-py/python/examples/drawdown.py` or `cd sdk/go && go run ./examples/drawdown`. ## Shared APIs and numerical limits diff --git a/docs/docs/float-float-swaps.md b/docs/docs/float-float-swaps.md index 35562f1be..4af979843 100644 --- a/docs/docs/float-float-swaps.md +++ b/docs/docs/float-float-swaps.md @@ -111,4 +111,4 @@ A separately generated QuantLib 1.43 direct-default fixture covers six live reference-date/today inclusion policies with the discount reference on the payment/evaluation date. These tests reuse one cached instrument to verify that silent Settings updates are read without manual invalidation. Runnable examples: -`example/python/float_float_swap.py` and `sdk/go/examples/float-float-swap`. +`crates/itofin-py/python/examples/float_float_swap.py` and `sdk/go/examples/float-float-swap`. diff --git a/docs/docs/gap-option-bindings.md b/docs/docs/gap-option-bindings.md index 0e529d9fe..a0e03beb0 100644 --- a/docs/docs/gap-option-bindings.md +++ b/docs/docs/gap-option-bindings.md @@ -70,7 +70,7 @@ them. Missing/closed/mixed handles and unavailable Greeks report existing errors Python: ```python ---8<-- "example/python/gap_option.py" +--8<-- "crates/itofin-py/python/examples/gap_option.py" ``` Go: diff --git a/docs/docs/geometric-brownian.md b/docs/docs/geometric-brownian.md index 0e3d99e6b..7dd502469 100644 --- a/docs/docs/geometric-brownian.md +++ b/docs/docs/geometric-brownian.md @@ -77,7 +77,7 @@ process's log-price diffusion, not this arithmetic `volatility × x` diffusion. assert process.evolve(0.0, 100.0, 1.0, -6.0) == -15.0 ``` - [Complete Python example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/geometric_brownian.py). + [Complete Python example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/geometric_brownian.py). === "Go" diff --git a/docs/docs/getting-started.md b/docs/docs/getting-started.md index c4773e842..a1871332c 100644 --- a/docs/docs/getting-started.md +++ b/docs/docs/getting-started.md @@ -11,8 +11,8 @@ read the value plus the greeks. === "Python" - ```python title="example/python/european_option.py" - --8<-- "example/python/european_option.py" + ```python title="crates/itofin-py/python/examples/european_option.py" + --8<-- "crates/itofin-py/python/examples/european_option.py" ``` === "Rust" @@ -34,7 +34,7 @@ For an application using the published module, follow [Go installation](go.md#in === "Python" ```bash - python example/python/european_option.py + python crates/itofin-py/python/examples/european_option.py ``` === "Rust" @@ -63,11 +63,11 @@ Rust examples below cover additional products: | Topic | Python | Rust | |-------|--------|------| -| European option | [`european_option.py`](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/european_option.py) | [`european_option.rs`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/european_option.rs) | -| Monte Carlo | [`monte_carlo.py`](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/monte_carlo.py) | [`monte_carlo.rs`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/monte_carlo.rs) | -| Vanilla swap | [`vanilla_swap.py`](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/vanilla_swap.py) | [`vanilla_swap.rs`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/vanilla_swap.rs) | -| Yield curve | [`yield_curve.py`](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/yield_curve.py) | [`yield_curve.rs`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/yield_curve.rs) | -| Credit CDS | [`credit_cds.py`](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/credit_cds.py) | [`credit_cds.rs`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/credit_cds.rs) | -| ISDA CDS | [`isda_cds.py`](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/isda_cds.py) | [`isda_cds.rs`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/isda_cds.rs) | -| Inflation swap | [`inflation_swap.py`](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/inflation_swap.py) | [`inflation_swap.rs`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/inflation_swap.rs) | -| YoY inflation cap/floor | [`yoy_inflation_capfloor.py`](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/yoy_inflation_capfloor.py) | [`yoy_inflation_capfloor.rs`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/yoy_inflation_capfloor.rs) | +| European option | [`european_option.py`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/european_option.py) | [`european_option.rs`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/european_option.rs) | +| Monte Carlo | [`monte_carlo.py`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/monte_carlo.py) | [`monte_carlo.rs`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/monte_carlo.rs) | +| Vanilla swap | [`vanilla_swap.py`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/vanilla_swap.py) | [`vanilla_swap.rs`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/vanilla_swap.rs) | +| Yield curve | [`yield_curve.py`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/yield_curve.py) | [`yield_curve.rs`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/yield_curve.rs) | +| Credit CDS | [`credit_cds.py`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/credit_cds.py) | [`credit_cds.rs`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/credit_cds.rs) | +| ISDA CDS | [`isda_cds.py`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/isda_cds.py) | [`isda_cds.rs`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/isda_cds.rs) | +| Inflation swap | [`inflation_swap.py`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/inflation_swap.py) | [`inflation_swap.rs`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/inflation_swap.rs) | +| YoY inflation cap/floor | [`yoy_inflation_capfloor.py`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/yoy_inflation_capfloor.py) | [`yoy_inflation_capfloor.rs`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/libitofin/examples/yoy_inflation_capfloor.rs) | diff --git a/docs/docs/global-optimization.md b/docs/docs/global-optimization.md index 3db11447a..34d4909d5 100644 --- a/docs/docs/global-optimization.md +++ b/docs/docs/global-optimization.md @@ -267,7 +267,7 @@ checks the calibration cost below `1e-6`, rather than inventing a reference sigm === "Python" ```python - --8<-- "example/python/differential_evolution.py" + --8<-- "crates/itofin-py/python/examples/differential_evolution.py" ``` === "Rust" @@ -292,7 +292,7 @@ The existing root-RSS calibration cost is unchanged. === "Python" ```python - --8<-- "example/python/particle_swarm.py" + --8<-- "crates/itofin-py/python/examples/particle_swarm.py" ``` === "Rust" @@ -319,7 +319,7 @@ or a transformed scalar. === "Python" ```python - --8<-- "example/python/hybrid_simulated_annealing.py" + --8<-- "crates/itofin-py/python/examples/hybrid_simulated_annealing.py" ``` === "Rust" @@ -343,7 +343,7 @@ The calibration scalar remains root-RSS, not the unrooted sum of squares. === "Python" ```python - --8<-- "example/python/firefly.py" + --8<-- "crates/itofin-py/python/examples/firefly.py" ``` === "Rust" diff --git a/docs/docs/hw-forward-process-bindings.md b/docs/docs/hw-forward-process-bindings.md index 5307eecfc..7c8cd3a51 100644 --- a/docs/docs/hw-forward-process-bindings.md +++ b/docs/docs/hw-forward-process-bindings.md @@ -77,5 +77,5 @@ Source reference: QuantLib `9863b578af0caa4cecabf697196533e84a8308b6`, checkout from the separately compiled QuantLib 1.43 wheel and independent high-precision limits. Bindings do not establish full QuantLib/model parity. -[Python example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/hw_forward_process.py) +[Python example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/hw_forward_process.py) and [Go example](https://github.com/bitbrew-dev/libitofin/tree/main/sdk/go/examples/hw_forward_process). diff --git a/docs/docs/index.md b/docs/docs/index.md index 0159c2854..a74e044d3 100644 --- a/docs/docs/index.md +++ b/docs/docs/index.md @@ -63,7 +63,7 @@ links to the language guides and project documentation. | Python API reference | This site (see the **Python API** section) | | Rust API reference | [docs.rs/libitofin](https://docs.rs/libitofin) - see [Rust API](rust.md) | | Go SDK | [Installation, sessions, and examples](go.md), plus [API reference](https://pkg.go.dev/github.com/bitbrew-dev/libitofin/sdk/go) | -| Worked examples | [`example/python`](https://github.com/bitbrew-dev/libitofin/tree/main/example/python), [`sdk/go/examples`](https://github.com/bitbrew-dev/libitofin/tree/main/sdk/go/examples), and [`crates/libitofin/examples`](https://github.com/bitbrew-dev/libitofin/tree/main/crates/libitofin/examples) | +| Worked examples | [`crates/itofin-py/python/examples`](https://github.com/bitbrew-dev/libitofin/tree/main/crates/itofin-py/python/examples), [`sdk/go/examples`](https://github.com/bitbrew-dev/libitofin/tree/main/sdk/go/examples), and [`crates/libitofin/examples`](https://github.com/bitbrew-dev/libitofin/tree/main/crates/libitofin/examples) | ## Reviewed Rust additions diff --git a/docs/docs/inflation-principal-bindings.md b/docs/docs/inflation-principal-bindings.md index 7c548407a..87bc1fd6b 100644 --- a/docs/docs/inflation-principal-bindings.md +++ b/docs/docs/inflation-principal-bindings.md @@ -84,5 +84,5 @@ python scripts/generate_inflation_principal_oracle.py sdk/go/testdata Runnable examples: -- [Python](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/inflation_principal.py) +- [Python](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/inflation_principal.py) - [Go](https://github.com/bitbrew-dev/libitofin/blob/main/sdk/go/examples/inflation_principal/main.go) diff --git a/docs/docs/mc-variance-swaps.md b/docs/docs/mc-variance-swaps.md index b13b1456a..6b7c11ba8 100644 --- a/docs/docs/mc-variance-swaps.md +++ b/docs/docs/mc-variance-swaps.md @@ -105,7 +105,7 @@ is approximately `0.04`, with approximately zero NPV at strike `0.04`. ``` Tolerance mode replaces `samples=1023` with `tolerance=1e-5, max_samples=50000`. - [Complete Python example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/mc_variance_swap.py). + [Complete Python example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/mc_variance_swap.py). === "Go" diff --git a/docs/docs/mf-state-process-bindings.md b/docs/docs/mf-state-process-bindings.md index 20731a33d..f7d7c3a97 100644 --- a/docs/docs/mf-state-process-bindings.md +++ b/docs/docs/mf-state-process-bindings.md @@ -38,7 +38,7 @@ Python objects are unsendable. Existing public constructors are unchanged. ## Examples and evidence -- [Python example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/mf_state_process.py) +- [Python example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/mf_state_process.py) - [Go example](https://github.com/bitbrew-dev/libitofin/blob/main/sdk/go/examples/mf_state_process/main.go) - Fixture provenance: `sdk/go/testdata/mf_state_oracle.md`. diff --git a/docs/docs/payment-inspection-bindings.md b/docs/docs/payment-inspection-bindings.md index 4d35bef0b..b2aad95a8 100644 --- a/docs/docs/payment-inspection-bindings.md +++ b/docs/docs/payment-inspection-bindings.md @@ -71,5 +71,5 @@ aggregation and missing payments. It was produced by The recorded pinned source revision is a separate reference, not evidence that it built that wheel. These cases do not establish complete BondFunctions parity. -Examples: [`example/python/payment_inspection.py`](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/payment_inspection.py) +Examples: [`crates/itofin-py/python/examples/payment_inspection.py`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/payment_inspection.py) and [`sdk/go/examples/payment_inspection/main.go`](https://github.com/bitbrew-dev/libitofin/blob/main/sdk/go/examples/payment_inspection/main.go). diff --git a/docs/docs/percentage-strike-bindings.md b/docs/docs/percentage-strike-bindings.md index b4b0edc72..23320ea62 100644 --- a/docs/docs/percentage-strike-bindings.md +++ b/docs/docs/percentage-strike-bindings.md @@ -66,7 +66,7 @@ explicit Close. Python retains its unsendable native ownership model. ## Examples -- Python: `example/python/percentage_strike.py`. +- Python: `crates/itofin-py/python/examples/percentage_strike.py`. - Go: `sdk/go/examples/percentage_strike/main.go`. This slice is not a complete payoff-object family or CPI pricing implementation. diff --git a/docs/docs/scalar-payoff-bindings.md b/docs/docs/scalar-payoff-bindings.md index 523709f2f..080576a40 100644 --- a/docs/docs/scalar-payoff-bindings.md +++ b/docs/docs/scalar-payoff-bindings.md @@ -76,5 +76,5 @@ agreement does not establish full QuantLib or engine parity. Examples: -- [`example/python/scalar_payoffs.py`](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/scalar_payoffs.py) +- [`crates/itofin-py/python/examples/scalar_payoffs.py`](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/scalar_payoffs.py) - [`sdk/go/examples/scalar_payoffs/main.go`](https://github.com/bitbrew-dev/libitofin/blob/main/sdk/go/examples/scalar_payoffs/main.go) diff --git a/docs/docs/statistics.md b/docs/docs/statistics.md index b96c70390..ca1159007 100644 --- a/docs/docs/statistics.md +++ b/docs/docs/statistics.md @@ -313,7 +313,7 @@ nonnegative, equal-length and have a finite positive sum. _ = beta // approximately 2.0487804878 ``` -Runnable examples: `python example/python/benchmark_beta.py` and, from `sdk/go`, +Runnable examples: `python crates/itofin-py/python/examples/benchmark_beta.py` and, from `sdk/go`, `go run ./examples/benchmark_beta`. Independent fixtures are generated by `scripts/fixtures/generate_benchmark_beta.py` @@ -366,7 +366,7 @@ these stateless APIs retain no handles or session state. === "Python" ```python - --8<-- "example/python/performance_ratios.py" + --8<-- "crates/itofin-py/python/examples/performance_ratios.py" ``` === "Go" @@ -385,7 +385,7 @@ these stateless APIs retain no handles or session state. let sortino = sortino_ratio(&returns, 0.0, 12.0)?; ``` -Run `python example/python/performance_ratios.py` or, from `sdk/go`, +Run `python crates/itofin-py/python/examples/performance_ratios.py` or, from `sdk/go`, `go run ./examples/performance_ratios` after installing the native library. Independent 80-digit Python Decimal definitions and shared binding fixtures live in `scripts/fixtures/performance-ratios/`; regenerate with its `generate.py`. diff --git a/docs/docs/variance-swaps.md b/docs/docs/variance-swaps.md index 70dca030d..4a53bcaa1 100644 --- a/docs/docs/variance-swaps.md +++ b/docs/docs/variance-swaps.md @@ -103,7 +103,7 @@ They inspect a bounded strip, not an asserted exact fair variance of `0.04`. print(swap.variance(), swap.npv(), len(swap.option_weights())) ``` - [Complete Python example](https://github.com/bitbrew-dev/libitofin/blob/main/example/python/variance_swap.py). + [Complete Python example](https://github.com/bitbrew-dev/libitofin/blob/main/crates/itofin-py/python/examples/variance_swap.py). === "Go" diff --git a/docs/docs/xccy-basis-bindings.md b/docs/docs/xccy-basis-bindings.md index 1726df5a4..e725dc89e 100644 --- a/docs/docs/xccy-basis-bindings.md +++ b/docs/docs/xccy-basis-bindings.md @@ -58,7 +58,7 @@ Rebuild the swap when replacing spot or contractual terms. ## Examples and oracle provenance -- Python: `example/python/xccy_basis.py`. +- Python: `crates/itofin-py/python/examples/xccy_basis.py`. - Go: `sdk/go/examples/xccy_basis/main.go`. - Focused fixtures reuse the tracked whole-class native oracle from `crates/libitofin/tests/fixtures/medium3_xccy_basis/`: actual compiled QuantLib diff --git a/example/python/hw_forward_process.py b/example/python/hw_forward_process.py deleted file mode 100644 index c31123b7d..000000000 --- a/example/python/hw_forward_process.py +++ /dev/null @@ -1,11 +0,0 @@ -"""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),.03,DayCounter.actual365_fixed()) -process = HullWhiteForwardProcess(curve,.1,.02) -process.set_forward_measure_time(5.) -print(process.expectation(1.,.03,.8), process.variance(1.,.03,.8)) diff --git a/wiki/python.md b/wiki/python.md index 9a483cf5c..82ce0542b 100644 --- a/wiki/python.md +++ b/wiki/python.md @@ -85,10 +85,10 @@ print(f"{svol.volatility(Period(3, 'Years'), Period(3, 'Years'), 0.03):.4f}") # ## More examples and reference -- [Swaption example](../example/python/swaption.py) (requires current `main`): price vanilla payer and Eonia OIS swaptions, then reprice after a volatility update. +- [Swaption example](../crates/itofin-py/python/examples/swaption.py) (requires current `main`): price vanilla payer and Eonia OIS swaptions, then reprice after a volatility update. - [Getting started](https://bitbrew-dev.github.io/libitofin/getting-started/): runnable Python, Rust, and Go examples. -- [Python example sources](../example/python/): yield curves, swaps, Monte Carlo, credit, and inflation. +- [Python example sources](../crates/itofin-py/python/examples/): yield curves, swaps, Monte Carlo, credit, and inflation. - [Python API reference](https://bitbrew-dev.github.io/libitofin/api/core/): module-by-module signatures and documentation. - [Python bindings source](../crates/itofin-py/): implementation and tests. @@ -96,5 +96,5 @@ print(f"{svol.volatility(Period(3, 'Years'), Period(3, 'Years'), 0.03):.4f}") # ## Global optimization examples -- [Particle swarm](../example/python/particle_swarm.py): seeded signed-scalar minimization, with checked analytic value `-3`. +- [Particle swarm](../crates/itofin-py/python/examples/particle_swarm.py): seeded signed-scalar minimization, with checked analytic value `-3`. - [Shared global-search contract](https://bitbrew-dev.github.io/libitofin/global-optimization/): DE/PSO controls, feasible calibration boxes, budgets and numerical limits.