From 1cc6a94c6e055141a66f0519bc928cf971504d85 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Mon, 2 Jun 2025 23:54:02 -0400 Subject: [PATCH 1/7] move shared_ptr and the like to quantlib.ext --- quantlib/_cashflow.pxd | 2 +- quantlib/_instrument.pxd | 2 +- quantlib/_observable.pxd | 2 +- quantlib/_option.pxd | 2 +- quantlib/_settings.pxd | 3 +- quantlib/cashflow.pxd | 2 +- quantlib/cashflow.pyx | 2 +- quantlib/cashflows/_cap_floored_coupon.pxd | 2 +- quantlib/cashflows/_cms_coupon.pxd | 2 +- quantlib/cashflows/_coupon_pricer.pxd | 4 ++- quantlib/cashflows/_dividend.pxd | 2 +- quantlib/cashflows/_floating_rate_coupon.pxd | 2 +- quantlib/cashflows/_ibor_coupon.pxd | 2 +- .../cashflows/_inflation_coupon_pricer.pxd | 3 +- .../cashflows/_overnight_indexed_coupon.pxd | 2 +- quantlib/cashflows/cap_floored_coupon.pyx | 2 +- quantlib/cashflows/cms_coupon.pyx | 4 +-- quantlib/cashflows/coupon.pyx | 2 +- quantlib/cashflows/coupon_pricer.pxd | 2 +- quantlib/cashflows/fixed_rate_coupon.pyx | 2 +- quantlib/cashflows/floating_rate_coupon.pyx | 2 +- quantlib/cashflows/ibor_coupon.pyx | 2 +- .../cashflows/inflation_coupon_pricer.pxd | 2 +- .../cashflows/overnight_indexed_coupon.pyx | 2 +- quantlib/exercise.pxd | 2 +- quantlib/exercise.pyx | 2 +- .../coupons/_cms_spread_coupon.pxd | 3 +- .../coupons/_lognormal_cmsspread_pricer.pxd | 3 +- .../coupons/_swap_spread_index.pxd | 2 +- .../coupons/cms_spread_coupon.pyx | 2 +- .../coupons/lognormal_cmsspread_pricer.pyx | 2 +- .../coupons/swap_spread_index.pyx | 2 +- .../_crosscurrencyratehelpers.pxd | 3 +- .../crosscurrencyratehelpers.pyx | 2 +- quantlib/{handle.pxd => ext.pxd} | 16 ---------- quantlib/handle.pxd.in | 24 ++++++++++++++ quantlib/handle.pyx.in | 25 +++++++++++++++ quantlib/index.pxd | 2 +- quantlib/indexes/_ibor_index.pxd | 3 +- quantlib/indexes/_inflation_index.pxd | 2 +- quantlib/indexes/_swap_index.pxd | 7 ++-- quantlib/indexes/ibor/_sofr.pxd | 2 +- quantlib/indexes/ibor/_usdlibor.pxd | 2 +- quantlib/indexes/ibor_index.pyx | 2 +- quantlib/indexes/inflation_index.pyx | 1 - quantlib/indexes/interest_rate_index.pyx | 1 - quantlib/indexes/swap_index.pyx | 2 +- quantlib/instrument.pxd | 2 +- quantlib/instrument.pyx | 2 +- quantlib/instruments/_asian_options.pxd | 2 +- quantlib/instruments/_assetswap.pxd | 2 +- quantlib/instruments/_bondforward.pxd | 3 +- quantlib/instruments/_credit_default_swap.pxd | 3 +- quantlib/instruments/_dividendschedule.pxd | 2 +- quantlib/instruments/_europeanoption.pxd | 2 +- quantlib/instruments/_fixedvsfloatingswap.pxd | 2 +- quantlib/instruments/_implied_volatility.pxd | 4 +-- quantlib/instruments/_make_cds.pxd | 3 +- quantlib/instruments/_make_cms.pxd | 2 +- quantlib/instruments/_make_ois.pxd | 3 +- quantlib/instruments/_make_swaption.pxd | 2 +- quantlib/instruments/_make_vanilla_swap.pxd | 3 +- quantlib/instruments/_oneassetoption.pxd | 2 +- .../instruments/_overnightindexedswap.pxd | 2 +- .../instruments/_overnightindexfuture.pxd | 3 +- quantlib/instruments/_swaption.pxd | 6 ++-- quantlib/instruments/_vanillaoption.pxd | 2 +- quantlib/instruments/_vanillaswap.pxd | 2 +- quantlib/instruments/_zerocouponswap.pxd | 2 +- quantlib/instruments/asian_options.pyx | 2 +- quantlib/instruments/assetswap.pyx | 2 +- quantlib/instruments/bondforward.pyx | 2 +- .../bonds/_amortizingfloatingratebond.pxd | 2 +- quantlib/instruments/bonds/_cpibond.pxd | 2 +- .../instruments/bonds/_floatingratebond.pxd | 2 +- .../bonds/amortizingfloatingratebond.pyx | 2 +- quantlib/instruments/bonds/cpibond.pyx | 2 +- .../instruments/bonds/floatingratebond.pyx | 2 +- quantlib/instruments/credit_default_swap.pyx | 2 +- quantlib/instruments/dividendschedule.pxd | 2 +- quantlib/instruments/europeanoption.pxd | 1 + quantlib/instruments/europeanoption.pyx | 2 +- quantlib/instruments/implied_volatility.pyx | 2 +- quantlib/instruments/make_cds.pyx | 2 +- quantlib/instruments/make_cms.pyx | 2 +- quantlib/instruments/make_ois.pyx | 2 +- quantlib/instruments/make_swaption.pyx | 2 +- quantlib/instruments/make_vanilla_swap.pyx | 2 +- quantlib/instruments/oneassetoption.pyx | 1 + quantlib/instruments/overnightindexedswap.pyx | 2 +- quantlib/instruments/overnightindexfuture.pyx | 2 +- quantlib/instruments/swaption.pyx | 2 +- quantlib/instruments/vanillaoption.pyx | 2 +- quantlib/instruments/vanillaswap.pyx | 2 +- quantlib/instruments/zerocouponswap.pyx | 2 +- .../math/_hestonhwcorrelationconstraint.pxd | 11 +++---- .../math/hestonhwcorrelationconstraint.pyx | 7 ++-- quantlib/math/optimization.pxd | 2 +- quantlib/math/optimization.pyx | 2 +- .../solvers/fdmbackwardsolver.pyx | 1 - .../montecarlo/_multipathgenerator.pxd | 2 +- quantlib/models/_calibration_helper.pxd | 3 +- quantlib/models/_model.pxd | 3 +- quantlib/models/calibration_helper.pxd | 2 +- quantlib/models/calibration_helper.pyx | 2 +- quantlib/models/equity/_bates_model.pxd | 2 +- quantlib/models/equity/_heston_model.pxd | 3 +- quantlib/models/equity/bates_model.pxd | 3 -- quantlib/models/equity/bates_model.pyx | 2 +- quantlib/models/equity/heston_model.pxd | 2 +- quantlib/models/equity/heston_model.pyx | 2 +- .../marketmodels/_brownian_generator.pxd | 2 +- .../marketmodels/brownian_generator.pxd | 2 +- .../_mt_brownian_generator.pxd | 2 +- quantlib/models/model.pxd | 2 +- quantlib/models/model.pyx | 2 +- .../models/shortrate/_onefactor_model.pxd | 2 +- .../models/shortrate/_twofactor_model.pxd | 2 +- .../calibrationhelpers/_swaption_helper.pxd | 3 +- .../calibrationhelpers/swaption_helper.pxd | 1 - .../calibrationhelpers/swaption_helper.pyx | 2 +- quantlib/models/shortrate/onefactor_model.pxd | 2 +- quantlib/models/shortrate/onefactor_model.pyx | 2 +- .../onefactormodels/_blackkarasinski.pxd | 2 +- .../onefactormodels/_gaussian1dmodel.pxd | 3 +- .../onefactormodels/blackkarasinski.pyx | 4 +-- .../shortrate/onefactormodels/hullwhite.pyx | 2 +- .../shortrate/onefactormodels/vasicek.pxd | 1 - .../shortrate/onefactormodels/vasicek.pyx | 2 +- quantlib/models/shortrate/twofactor_model.pxd | 2 +- quantlib/models/shortrate/twofactor_model.pyx | 2 +- quantlib/observable.pxd | 2 +- quantlib/payoffs.pxd | 2 +- quantlib/pricingengines/_swap.pxd | 5 +-- .../asian/_analyticcontgeomavprice.pxd | 2 +- .../asian/analyticcontgeomavprice.pyx | 2 +- .../asian/analyticdiscrgeomavprice.pyx | 5 ++- .../pricingengines/bond/_bondfunctions.pxd | 2 +- .../bond/_discountingbondengine.pxd | 3 +- .../pricingengines/bond/bondfunctions.pyx | 2 +- .../credit/_isda_cds_engine.pxd | 3 +- .../credit/_midpoint_cds_engine.pxd | 3 +- .../pricingengines/credit/isda_cds_engine.pyx | 2 +- .../credit/midpoint_cds_engine.pyx | 2 +- quantlib/pricingengines/engine.pxd | 2 +- .../forward/_mc_variance_swap_engine.pxd | 2 +- .../_replicating_variance_swap_engine.pxd | 2 +- .../forward/mc_variance_swap_engine.pyx | 6 ++-- .../replicating_variance_swap_engine.pyx | 2 +- quantlib/pricingengines/swap.pyx | 4 +-- .../swaption/_fdg2_swaption_engine.pxd | 2 +- .../swaption/_fdhullwhite_swaption_engine.pxd | 2 +- .../swaption/_g2_swaption_engine.pxd | 2 +- .../swaption/_jamshidian_swaption_engine.pxd | 3 +- .../swaption/_tree_swaption_engine.pxd | 3 +- .../swaption/fdhullwhite_swaption_engine.pyx | 2 +- .../swaption/tree_swaption_engine.pyx | 2 +- .../vanilla/_analytic_heston_engine.pxd | 2 +- .../vanilla/_fdblackscholesvanillaengine.pxd | 2 +- .../vanilla/_mceuropeanhestonengine.pxd | 2 +- .../vanilla/_mchestonhullwhiteengine.pxd | 2 +- .../vanilla/_mcvanillaengine.pxd | 2 +- quantlib/pricingengines/vanilla/_vanilla.pxd | 2 +- .../vanilla/fdblackscholesvanillaengine.pyx | 2 +- .../vanilla/mceuropeanhestonengine.pyx | 2 +- .../vanilla/mchestonhullwhiteengine.pyx | 2 +- quantlib/pricingengines/vanilla/vanilla.pyx | 2 +- quantlib/processes/_black_scholes_process.pxd | 4 +-- quantlib/processes/_heston_process.pxd | 3 +- .../_hybrid_heston_hullwhite_process.pxd | 2 +- quantlib/processes/bates_process.pyx | 2 +- .../hybrid_heston_hullwhite_process.pyx | 2 +- quantlib/quote.pxd | 3 +- quantlib/quote.pyx | 2 +- .../quotes/_futuresconvadjustmentquote.pxd | 3 +- .../quotes/futuresconvadjustmentquote.pyx | 2 +- quantlib/settings.pyx | 2 +- quantlib/sim/simulate.pyx | 2 +- quantlib/stochastic_process.pxd | 2 +- quantlib/termstructure.pxd | 2 +- quantlib/termstructure.pyx | 2 +- .../_inflation_term_structure.pxd | 3 +- .../termstructures/_yield_term_structure.pxd | 1 - .../termstructures/credit/_credit_helpers.pxd | 3 +- .../credit/_piecewise_default_curve.pxd | 2 +- .../credit/default_probability_helpers.pxd | 2 +- .../credit/default_probability_helpers.pyx | 4 +-- .../credit/flat_hazard_rate.pyx | 10 +++--- .../credit/interpolated_hazardrate_curve.pyx | 2 +- .../credit/piecewise_default_curve.pyx | 2 +- .../termstructures/default_term_structure.pyx | 2 +- .../inflation/_inflation_helpers.pxd | 3 +- .../_interpolated_zero_inflation_curve.pxd | 2 +- .../_piecewise_zero_inflation_curve.pxd | 2 +- .../inflation/inflation_helpers.pxd | 2 +- .../inflation/inflation_helpers.pyx | 2 +- .../piecewise_zero_inflation_curve.pyx | 2 +- .../termstructures/inflation/seasonality.pxd | 2 +- .../termstructures/inflation/seasonality.pyx | 2 +- .../inflation_term_structure.pyx | 2 +- .../termstructures/vol_term_structure.pxd | 2 +- .../_sabr_interpolated_smilesection.pxd | 3 +- .../equityfx/black_constant_vol.pyx | 1 - .../equityfx/black_variance_curve.pyx | 2 +- .../equityfx/black_variance_surface.pyx | 1 - .../volatility/equityfx/local_vol_surface.pyx | 2 +- .../optionlet_volatility_structure.pxd | 3 +- .../sabr_interpolated_smilesection.pyx | 3 +- .../volatility/smilesection.pxd | 2 +- .../_sabr_swaption_volatility_cube.pxd | 3 +- .../swaption/_swaption_vol_cube.pxd | 3 +- .../swaption/_swaption_vol_matrix.pxd | 2 +- .../swaption/_swaption_vol_structure.pxd | 2 +- .../sabr_swaption_volatility_cube.pyx | 10 +++--- .../swaption/spreaded_swaption_vol.pxd | 1 - .../swaption/spreaded_swaption_vol.pyx | 13 ++++---- .../swaption/swaption_constant_vol.pyx | 12 +++---- .../volatility/swaption/swaption_vol_cube.pyx | 2 +- .../swaption/swaption_vol_matrix.pyx | 13 ++++---- .../swaption/swaption_vol_structure.pxd | 9 +----- .../swaption/swaption_vol_structure.pyx | 32 ++----------------- .../termstructures/yields/_bond_helpers.pxd | 4 +-- .../termstructures/yields/_flat_forward.pxd | 2 +- .../_forward_spreaded_term_structure.pxd | 2 +- .../yields/_ois_rate_helper.pxd | 3 +- .../_overnightindexfutureratehelper.pxd | 3 +- .../yields/_piecewise_yield_curve.pxd | 2 +- .../termstructures/yields/_rate_helpers.pxd | 3 +- .../termstructures/yields/bond_helpers.pyx | 2 +- .../yields/discount_curve.pyx.in | 1 - .../yields/forward_curve.pyx.in | 1 - .../termstructures/yields/ois_rate_helper.pyx | 3 +- .../yields/overnightindexfutureratehelper.pyx | 2 +- .../yields/piecewise_yield_curve.pyx.in | 2 +- .../termstructures/yields/rate_helpers.pxd | 2 +- .../termstructures/yields/rate_helpers.pyx | 3 +- .../termstructures/yields/zero_curve.pyx.in | 2 +- quantlib/time/_schedule.pxd | 2 +- quantlib/time/date.pxd | 2 +- quantlib/time/schedule.pyx | 2 +- 240 files changed, 357 insertions(+), 342 deletions(-) rename quantlib/{handle.pxd => ext.pxd} (62%) create mode 100644 quantlib/handle.pxd.in create mode 100644 quantlib/handle.pyx.in diff --git a/quantlib/_cashflow.pxd b/quantlib/_cashflow.pxd index d8a6ef165..0ad23d281 100644 --- a/quantlib/_cashflow.pxd +++ b/quantlib/_cashflow.pxd @@ -2,7 +2,7 @@ from quantlib.types cimport Real from libcpp cimport bool from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr, optional +from quantlib.ext cimport shared_ptr, optional from quantlib.time._date cimport Date cdef extern from 'ql/event.hpp' namespace 'QuantLib' nogil: diff --git a/quantlib/_instrument.pxd b/quantlib/_instrument.pxd index d28985071..316a377ff 100644 --- a/quantlib/_instrument.pxd +++ b/quantlib/_instrument.pxd @@ -1,6 +1,6 @@ from quantlib.types cimport Real -from quantlib.handle cimport shared_ptr +from .ext cimport shared_ptr from quantlib.pricingengines._pricing_engine cimport PricingEngine from quantlib.time._date cimport Date from libcpp.string cimport string diff --git a/quantlib/_observable.pxd b/quantlib/_observable.pxd index b1481fb18..390a92aba 100644 --- a/quantlib/_observable.pxd +++ b/quantlib/_observable.pxd @@ -1,4 +1,4 @@ -from .handle cimport shared_ptr +from .ext cimport shared_ptr from .types cimport Size cdef extern from 'ql/patterns/observable.hpp' namespace 'QuantLib' nogil: diff --git a/quantlib/_option.pxd b/quantlib/_option.pxd index 3aee447a5..8dfa09019 100644 --- a/quantlib/_option.pxd +++ b/quantlib/_option.pxd @@ -1,7 +1,7 @@ from ._instrument cimport Instrument from ._exercise cimport Exercise from ._payoffs cimport Payoff -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cdef extern from 'ql/option.hpp' namespace 'QuantLib' nogil: diff --git a/quantlib/_settings.pxd b/quantlib/_settings.pxd index 121f21f14..8594f603f 100644 --- a/quantlib/_settings.pxd +++ b/quantlib/_settings.pxd @@ -1,8 +1,7 @@ -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport optional, shared_ptr from quantlib._observable cimport Observable from quantlib.time._date cimport Date from libcpp cimport bool -from .handle cimport optional cdef extern from "ql/settings.hpp" namespace "QuantLib" nogil: cdef cppclass Settings: diff --git a/quantlib/cashflow.pxd b/quantlib/cashflow.pxd index 1ca7dc0f4..b253f0f7d 100644 --- a/quantlib/cashflow.pxd +++ b/quantlib/cashflow.pxd @@ -1,6 +1,6 @@ cimport quantlib._cashflow as _cf -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from libcpp.vector cimport vector cdef class CashFlow: diff --git a/quantlib/cashflow.pyx b/quantlib/cashflow.pyx index e90f1e57a..11d41ea5f 100644 --- a/quantlib/cashflow.pyx +++ b/quantlib/cashflow.pyx @@ -15,7 +15,7 @@ from libcpp.vector cimport vector from libcpp cimport bool from cpython.datetime cimport date, import_datetime from cython.operator cimport dereference as deref, preincrement as preinc -from quantlib.handle cimport shared_ptr, optional +from quantlib.ext cimport shared_ptr, optional import_datetime() diff --git a/quantlib/cashflows/_cap_floored_coupon.pxd b/quantlib/cashflows/_cap_floored_coupon.pxd index f8f7b0091..559d058a0 100644 --- a/quantlib/cashflows/_cap_floored_coupon.pxd +++ b/quantlib/cashflows/_cap_floored_coupon.pxd @@ -1,6 +1,6 @@ include '../types.pxi' from libcpp cimport bool -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.indexes._ibor_index cimport IborIndex from quantlib.indexes._swap_index cimport SwapIndex from quantlib.time._date cimport Date diff --git a/quantlib/cashflows/_cms_coupon.pxd b/quantlib/cashflows/_cms_coupon.pxd index 9761829b6..ea2482e03 100644 --- a/quantlib/cashflows/_cms_coupon.pxd +++ b/quantlib/cashflows/_cms_coupon.pxd @@ -1,7 +1,7 @@ include '../types.pxi' from libcpp cimport bool -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time._date cimport Date from quantlib.time._daycounter cimport DayCounter from quantlib.indexes._swap_index cimport SwapIndex diff --git a/quantlib/cashflows/_coupon_pricer.pxd b/quantlib/cashflows/_coupon_pricer.pxd index 9a0106b6a..65ba32bd9 100644 --- a/quantlib/cashflows/_coupon_pricer.pxd +++ b/quantlib/cashflows/_coupon_pricer.pxd @@ -1,6 +1,8 @@ +from libcpp cimport bool from quantlib.types cimport Rate, Real -from quantlib.handle cimport shared_ptr, Handle +from quantlib.ext cimport shared_ptr, optional +from quantlib.handle cimport Handle from quantlib.termstructures.volatility.optionlet._optionlet_volatility_structure cimport OptionletVolatilityStructure from quantlib.termstructures.volatility.swaption._swaption_vol_structure cimport SwaptionVolatilityStructure from quantlib._cashflow cimport Leg diff --git a/quantlib/cashflows/_dividend.pxd b/quantlib/cashflows/_dividend.pxd index 759b9420e..42f4df394 100644 --- a/quantlib/cashflows/_dividend.pxd +++ b/quantlib/cashflows/_dividend.pxd @@ -1,5 +1,5 @@ from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.types cimport Real from quantlib.time._date cimport Date diff --git a/quantlib/cashflows/_floating_rate_coupon.pxd b/quantlib/cashflows/_floating_rate_coupon.pxd index edb4773d5..ed1402694 100644 --- a/quantlib/cashflows/_floating_rate_coupon.pxd +++ b/quantlib/cashflows/_floating_rate_coupon.pxd @@ -1,6 +1,6 @@ from quantlib.types cimport Natural, Rate, Real, Spread from libcpp cimport bool -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time._date cimport Date from quantlib.time._daycounter cimport DayCounter from quantlib._cashflow cimport CashFlow diff --git a/quantlib/cashflows/_ibor_coupon.pxd b/quantlib/cashflows/_ibor_coupon.pxd index a335c89a8..14c4de7be 100644 --- a/quantlib/cashflows/_ibor_coupon.pxd +++ b/quantlib/cashflows/_ibor_coupon.pxd @@ -1,7 +1,7 @@ include '../types.pxi' from libcpp cimport bool -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time._date cimport Date from quantlib.time._daycounter cimport DayCounter from quantlib._cashflow cimport CashFlow diff --git a/quantlib/cashflows/_inflation_coupon_pricer.pxd b/quantlib/cashflows/_inflation_coupon_pricer.pxd index 5e2a35011..549d6d1a1 100644 --- a/quantlib/cashflows/_inflation_coupon_pricer.pxd +++ b/quantlib/cashflows/_inflation_coupon_pricer.pxd @@ -1,4 +1,5 @@ -from quantlib.handle cimport shared_ptr, Handle +from quantlib.handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib.termstructures._yield_term_structure cimport YieldTermStructure from quantlib._cashflow cimport Leg cdef extern from 'ql/cashflows/inflationcouponpricer.hpp' namespace 'QuantLib': diff --git a/quantlib/cashflows/_overnight_indexed_coupon.pxd b/quantlib/cashflows/_overnight_indexed_coupon.pxd index 3b8b0a8cd..91d226cff 100644 --- a/quantlib/cashflows/_overnight_indexed_coupon.pxd +++ b/quantlib/cashflows/_overnight_indexed_coupon.pxd @@ -2,7 +2,7 @@ from quantlib.types cimport Integer, Natural, Rate, Real, Spread, Time from libcpp cimport bool from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time._date cimport Date from quantlib.time._daycounter cimport DayCounter from quantlib.time._schedule cimport Schedule diff --git a/quantlib/cashflows/cap_floored_coupon.pyx b/quantlib/cashflows/cap_floored_coupon.pyx index 3f80e929a..48cd4126c 100644 --- a/quantlib/cashflows/cap_floored_coupon.pyx +++ b/quantlib/cashflows/cap_floored_coupon.pyx @@ -2,7 +2,7 @@ include '../types.pxi' from libcpp cimport bool from cython.operator cimport dereference as deref from quantlib.utilities.null cimport Null -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast from quantlib.cashflows.coupon_pricer cimport FloatingRateCouponPricer from quantlib.indexes.ibor_index cimport IborIndex from quantlib.indexes.swap_index cimport SwapIndex diff --git a/quantlib/cashflows/cms_coupon.pyx b/quantlib/cashflows/cms_coupon.pyx index 9bb296aca..5e411250b 100644 --- a/quantlib/cashflows/cms_coupon.pyx +++ b/quantlib/cashflows/cms_coupon.pyx @@ -1,7 +1,7 @@ -include '../types.pxi' +from quantlib.types cimport Natural, Real from libcpp cimport bool from cython.operator cimport dereference as deref -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast from quantlib.time.date cimport Date from quantlib.time.daycounter cimport DayCounter from quantlib.indexes.swap_index cimport SwapIndex diff --git a/quantlib/cashflows/coupon.pyx b/quantlib/cashflows/coupon.pyx index a67350897..7b53e7601 100644 --- a/quantlib/cashflows/coupon.pyx +++ b/quantlib/cashflows/coupon.pyx @@ -1,5 +1,5 @@ from cython.operator cimport dereference as deref -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time.date cimport Date, date_from_qldate cimport quantlib.time._date as _date from quantlib.time.daycounter cimport DayCounter diff --git a/quantlib/cashflows/coupon_pricer.pxd b/quantlib/cashflows/coupon_pricer.pxd index ae9e0f03f..d6ade99e8 100644 --- a/quantlib/cashflows/coupon_pricer.pxd +++ b/quantlib/cashflows/coupon_pricer.pxd @@ -1,4 +1,4 @@ -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from . cimport _coupon_pricer as _cp cdef class FloatingRateCouponPricer: diff --git a/quantlib/cashflows/fixed_rate_coupon.pyx b/quantlib/cashflows/fixed_rate_coupon.pyx index f1d8a114e..47639fc57 100644 --- a/quantlib/cashflows/fixed_rate_coupon.pyx +++ b/quantlib/cashflows/fixed_rate_coupon.pyx @@ -3,7 +3,7 @@ from cython.operator cimport dereference as deref, preincrement as preinc from libcpp.vector cimport vector from libcpp.utility cimport move from quantlib.compounding cimport Compounding -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time.businessdayconvention cimport BusinessDayConvention from quantlib.time.calendar cimport Calendar from quantlib.time.date cimport Date diff --git a/quantlib/cashflows/floating_rate_coupon.pyx b/quantlib/cashflows/floating_rate_coupon.pyx index 1e8033eea..9ec4a397f 100644 --- a/quantlib/cashflows/floating_rate_coupon.pyx +++ b/quantlib/cashflows/floating_rate_coupon.pyx @@ -1,7 +1,7 @@ from quantlib.types cimport Natural, Real, Spread from libcpp cimport bool from cython.operator cimport dereference as deref -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast from quantlib.time.date cimport Date, date_from_qldate from quantlib.time.daycounter cimport DayCounter from .coupon_pricer cimport FloatingRateCouponPricer diff --git a/quantlib/cashflows/ibor_coupon.pyx b/quantlib/cashflows/ibor_coupon.pyx index 0cc05d43a..c242c565c 100644 --- a/quantlib/cashflows/ibor_coupon.pyx +++ b/quantlib/cashflows/ibor_coupon.pyx @@ -2,7 +2,7 @@ include '../types.pxi' from libcpp cimport bool from cython.operator cimport dereference as deref -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast from quantlib.time.date cimport Date from quantlib.time.daycounter cimport DayCounter cimport quantlib.cashflows._ibor_coupon as _ic diff --git a/quantlib/cashflows/inflation_coupon_pricer.pxd b/quantlib/cashflows/inflation_coupon_pricer.pxd index 74f66294f..2c6d64466 100644 --- a/quantlib/cashflows/inflation_coupon_pricer.pxd +++ b/quantlib/cashflows/inflation_coupon_pricer.pxd @@ -1,4 +1,4 @@ -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from . cimport _inflation_coupon_pricer as _icp cdef class InflationCouponPricer: diff --git a/quantlib/cashflows/overnight_indexed_coupon.pyx b/quantlib/cashflows/overnight_indexed_coupon.pyx index 5c427d4c1..27ced848e 100644 --- a/quantlib/cashflows/overnight_indexed_coupon.pyx +++ b/quantlib/cashflows/overnight_indexed_coupon.pyx @@ -4,7 +4,7 @@ from libcpp cimport bool from libcpp.vector cimport vector from libcpp.utility cimport move from cython.operator cimport dereference as deref, preincrement as preinc -from quantlib.handle cimport make_shared, shared_ptr, static_pointer_cast +from quantlib.ext cimport make_shared, shared_ptr, static_pointer_cast from quantlib.time.businessdayconvention cimport BusinessDayConvention from quantlib.time.date cimport Date, date_from_qldate from quantlib.time._date cimport Date as QlDate diff --git a/quantlib/exercise.pxd b/quantlib/exercise.pxd index 24b63f6af..4793947ce 100644 --- a/quantlib/exercise.pxd +++ b/quantlib/exercise.pxd @@ -1,4 +1,4 @@ -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from . cimport _exercise cdef extern from 'ql/exercise.hpp' namespace 'QuantLib::Exercise' nogil: diff --git a/quantlib/exercise.pyx b/quantlib/exercise.pyx index 6f4c81977..66a8202b5 100644 --- a/quantlib/exercise.pyx +++ b/quantlib/exercise.pyx @@ -1,7 +1,7 @@ from cython.operator cimport dereference as deref, preincrement as preinc from libcpp cimport bool from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time.date cimport Date, _pydate_from_qldate from quantlib.time._date cimport Date as QlDate diff --git a/quantlib/experimental/coupons/_cms_spread_coupon.pxd b/quantlib/experimental/coupons/_cms_spread_coupon.pxd index 579beed68..d06757fe3 100644 --- a/quantlib/experimental/coupons/_cms_spread_coupon.pxd +++ b/quantlib/experimental/coupons/_cms_spread_coupon.pxd @@ -1,7 +1,8 @@ include '../../types.pxi' from libcpp cimport bool from libcpp.string cimport string -from quantlib.handle cimport shared_ptr, Handle +from quantlib.ext cimport shared_ptr +from quantlib.handle cimport Handle from quantlib.cashflows._floating_rate_coupon cimport FloatingRateCoupon from quantlib.cashflows._coupon_pricer cimport FloatingRateCouponPricer from quantlib.cashflows._cap_floored_coupon cimport CappedFlooredCoupon diff --git a/quantlib/experimental/coupons/_lognormal_cmsspread_pricer.pxd b/quantlib/experimental/coupons/_lognormal_cmsspread_pricer.pxd index 92d92e2ca..7a610db97 100644 --- a/quantlib/experimental/coupons/_lognormal_cmsspread_pricer.pxd +++ b/quantlib/experimental/coupons/_lognormal_cmsspread_pricer.pxd @@ -1,6 +1,7 @@ include '../../types.pxi' from libcpp.string cimport string -from quantlib.handle cimport shared_ptr, Handle, optional +from quantlib.handle cimport Handle +from quantlib.ext cimport optional, shared_ptr from ._cms_spread_coupon cimport CmsSpreadCouponPricer from quantlib.cashflows._coupon_pricer cimport CmsCouponPricer from quantlib._quote cimport Quote diff --git a/quantlib/experimental/coupons/_swap_spread_index.pxd b/quantlib/experimental/coupons/_swap_spread_index.pxd index 4fab06b02..d0411700c 100644 --- a/quantlib/experimental/coupons/_swap_spread_index.pxd +++ b/quantlib/experimental/coupons/_swap_spread_index.pxd @@ -1,6 +1,6 @@ include '../../types.pxi' from libcpp.string cimport string -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.indexes._interest_rate_index cimport InterestRateIndex from quantlib.indexes._swap_index cimport SwapIndex diff --git a/quantlib/experimental/coupons/cms_spread_coupon.pyx b/quantlib/experimental/coupons/cms_spread_coupon.pyx index 5d3104739..05dd88459 100644 --- a/quantlib/experimental/coupons/cms_spread_coupon.pyx +++ b/quantlib/experimental/coupons/cms_spread_coupon.pyx @@ -3,7 +3,7 @@ from libcpp cimport bool from cython.operator cimport dereference as deref from quantlib.utilities.null cimport Null -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast from quantlib.time.date cimport Date from quantlib.time.daycounter cimport DayCounter from .swap_spread_index cimport SwapSpreadIndex diff --git a/quantlib/experimental/coupons/lognormal_cmsspread_pricer.pyx b/quantlib/experimental/coupons/lognormal_cmsspread_pricer.pyx index e1a1beb72..beb87b59a 100644 --- a/quantlib/experimental/coupons/lognormal_cmsspread_pricer.pyx +++ b/quantlib/experimental/coupons/lognormal_cmsspread_pricer.pyx @@ -1,6 +1,6 @@ include '../../types.pxi' -from quantlib.handle cimport Handle, optional, shared_ptr, static_pointer_cast +from quantlib.ext cimport optional, shared_ptr, static_pointer_cast from .cms_spread_coupon cimport CmsSpreadCouponPricer from quantlib.cashflows.coupon_pricer cimport CmsCouponPricer diff --git a/quantlib/experimental/coupons/swap_spread_index.pyx b/quantlib/experimental/coupons/swap_spread_index.pyx index 19b600c93..8b030352c 100644 --- a/quantlib/experimental/coupons/swap_spread_index.pyx +++ b/quantlib/experimental/coupons/swap_spread_index.pyx @@ -7,7 +7,7 @@ from quantlib.indexes.swap_index cimport SwapIndex cimport quantlib._index as _in cimport quantlib.indexes._swap_index as _si cimport quantlib.experimental.coupons._swap_spread_index as _ssi -from quantlib.handle cimport shared_ptr, static_pointer_cast, dynamic_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast, dynamic_pointer_cast @cython.final cdef class SwapSpreadIndex(InterestRateIndex): diff --git a/quantlib/experimental/termstructures/_crosscurrencyratehelpers.pxd b/quantlib/experimental/termstructures/_crosscurrencyratehelpers.pxd index c3d35c67b..c5d0b1c02 100644 --- a/quantlib/experimental/termstructures/_crosscurrencyratehelpers.pxd +++ b/quantlib/experimental/termstructures/_crosscurrencyratehelpers.pxd @@ -1,6 +1,7 @@ from quantlib.types cimport Natural from libcpp cimport bool -from quantlib.handle cimport Handle, shared_ptr +from quantlib._handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib._quote cimport Quote from quantlib.time.businessdayconvention cimport BusinessDayConvention from quantlib.time._calendar cimport Calendar diff --git a/quantlib/experimental/termstructures/crosscurrencyratehelpers.pyx b/quantlib/experimental/termstructures/crosscurrencyratehelpers.pyx index 8dca0fe22..dca109299 100644 --- a/quantlib/experimental/termstructures/crosscurrencyratehelpers.pyx +++ b/quantlib/experimental/termstructures/crosscurrencyratehelpers.pyx @@ -1,7 +1,7 @@ from quantlib.types cimport Natural from cython.operator cimport dereference as deref from libcpp cimport bool -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast from quantlib.time.businessdayconvention cimport BusinessDayConvention from quantlib.time.date cimport Period from quantlib.time.calendar cimport Calendar diff --git a/quantlib/handle.pxd b/quantlib/ext.pxd similarity index 62% rename from quantlib/handle.pxd rename to quantlib/ext.pxd index aace488c9..5de844ed7 100644 --- a/quantlib/handle.pxd +++ b/quantlib/ext.pxd @@ -33,19 +33,3 @@ cdef extern from 'ql/optional.hpp' namespace 'QuantLib::ext' nogil: optional& operator=(optional&) optional[T] make_optional[T](...) except + - -cdef extern from 'ql/handle.hpp' namespace 'QuantLib' nogil: - cdef cppclass Handle[T]: - Handle() - Handle(shared_ptr[T]&) - Handle(shared_ptr[T]&, bool registerAsObserver) - shared_ptr[T]& currentLink() - bool empty() - - cdef cppclass RelinkableHandle[T](Handle): - RelinkableHandle() - RelinkableHandle(T*) - RelinkableHandle(shared_ptr[T]&) - RelinkableHandle(shared_ptr[T]&, bool registerAsObserver) - void linkTo(shared_ptr[T]&) - void linkTo(shared_ptr[T]&, bool registerAsObserver) diff --git a/quantlib/handle.pxd.in b/quantlib/handle.pxd.in new file mode 100644 index 000000000..26e1551f4 --- /dev/null +++ b/quantlib/handle.pxd.in @@ -0,0 +1,24 @@ +from libcpp cimport bool +cdef extern from 'ql/handle.hpp' namespace 'QuantLib' nogil: + cdef cppclass Handle[T]: + Handle() + Handle(shared_ptr[T]&) + Handle(shared_ptr[T]&, bool registerAsObserver) + shared_ptr[T]& currentLink() + bool empty() + + cdef cppclass RelinkableHandle[T](Handle): + RelinkableHandle() + RelinkableHandle(T*) + RelinkableHandle(shared_ptr[T]&) + RelinkableHandle(shared_ptr[T]&, bool registerAsObserver) + void linkTo(shared_ptr[T]&) + void linkTo(shared_ptr[T]&, bool registerAsObserver) + +from quantlib.termstructures._yield_term_structure cimport YieldTermStructure as QlYieldTermStructure +from quantlib.termstructures.volatility.optionlet._optionlet_volatility_structure cimport OptionletVolatilityStructure as QlOptionletVolatilityStructure + +{{for T in ("YieldTermStructure", "OptionletVolatilityStructure")}} +cdef class Handle{{T}}: + cdef RelinkableHandler[{{T}}] handle +{{endfor}} diff --git a/quantlib/handle.pyx.in b/quantlib/handle.pyx.in new file mode 100644 index 000000000..2310e60cf --- /dev/null +++ b/quantlib/handle.pyx.in @@ -0,0 +1,25 @@ +from quantlib.termstructures.yield_term_structure cimport YieldTermStructure +from quantlib.termstructures.volatility.optionlet.optionlet_volatility_structure cimport OptionletVolatilityStructure + +{{for T in ("YieldTermStructure", "VolatilityTermStructure")}} +cdef class Handle{{T}}: +def __init__(self, {{T}} t=None, bool register_as_observer=True): + if t is not None: + self.handle = RelinkableHandle[Ql{{T}}]( + static_pointer_cast[Ql{{T}}](t._thisptr), + register_as_observer) + + @property + def current_link(self): + cdef instance = {{T}}.__new__({{T}}) + if self.handle.empty(): + raise ValueError("empty handle") + instance._thisptr = self.handle.currentLink() + return instance + + def link_to(self, {{T}} t, bool register_as_observer=True): + self.handle.linkTo(static_pointer_cast[Ql{{T}}](t._thisptr), register_as_observer) + + def __bool__(self): + return not self.handle.empty() +{{endfor}} diff --git a/quantlib/index.pxd b/quantlib/index.pxd index 427fdc689..3a28837e2 100644 --- a/quantlib/index.pxd +++ b/quantlib/index.pxd @@ -8,7 +8,7 @@ """ cimport quantlib._index as _in -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cdef class Index: cdef shared_ptr[_in.Index] _thisptr diff --git a/quantlib/indexes/_ibor_index.pxd b/quantlib/indexes/_ibor_index.pxd index 805ce511b..30de09544 100644 --- a/quantlib/indexes/_ibor_index.pxd +++ b/quantlib/indexes/_ibor_index.pxd @@ -10,7 +10,8 @@ include '../types.pxi' from libcpp cimport bool from libcpp.string cimport string -from quantlib.handle cimport shared_ptr, Handle +from quantlib.ext cimport shared_ptr +from quantlib.handle cimport Handle from quantlib.time._date cimport Date from quantlib.time._period cimport Period diff --git a/quantlib/indexes/_inflation_index.pxd b/quantlib/indexes/_inflation_index.pxd index 342ef4feb..f78be87da 100644 --- a/quantlib/indexes/_inflation_index.pxd +++ b/quantlib/indexes/_inflation_index.pxd @@ -13,7 +13,7 @@ from libcpp.string cimport string from quantlib._index cimport Index from quantlib.currency._currency cimport Currency from quantlib.indexes._region cimport Region -from quantlib.handle cimport shared_ptr, Handle +from quantlib._handle cimport Handle from quantlib.time._period cimport Period, Frequency from quantlib.time._date cimport Date diff --git a/quantlib/indexes/_swap_index.pxd b/quantlib/indexes/_swap_index.pxd index d591be1a4..691056380 100644 --- a/quantlib/indexes/_swap_index.pxd +++ b/quantlib/indexes/_swap_index.pxd @@ -12,7 +12,8 @@ from libcpp cimport bool from libcpp.string cimport string from quantlib.currency._currency cimport Currency -from quantlib.handle cimport shared_ptr, Handle +from quantlib.handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib.indexes._interest_rate_index cimport InterestRateIndex from quantlib.indexes._ibor_index cimport IborIndex, OvernightIndex from quantlib.instruments._vanillaswap cimport VanillaSwap @@ -49,8 +50,8 @@ cdef extern from 'ql/indexes/swapindex.hpp' namespace 'QuantLib' nogil: const Handle[YieldTermStructure]& discountingTermStructure) shared_ptr[VanillaSwap] underlyingSwap(const Date& fixingDate) shared_ptr[IborIndex] iborIndex() - Handle[YieldTermStructure] forwardingTermStructure() except + - Handle[YieldTermStructure] discountingTermStructure() except + + Handle[YieldTermStructure] forwardingTermStructure() + Handle[YieldTermStructure] discountingTermStructure() cdef cppclass OvernightIndexedSwapIndex(SwapIndex): OvernightIndexedSwapIndex(string& familyName, diff --git a/quantlib/indexes/ibor/_sofr.pxd b/quantlib/indexes/ibor/_sofr.pxd index c394f4f5d..f6381db0c 100644 --- a/quantlib/indexes/ibor/_sofr.pxd +++ b/quantlib/indexes/ibor/_sofr.pxd @@ -1,4 +1,4 @@ -from quantlib.handle cimport Handle +from quantlib._handle cimport Handle from quantlib.termstructures._yield_term_structure cimport YieldTermStructure from quantlib.indexes._ibor_index cimport OvernightIndex diff --git a/quantlib/indexes/ibor/_usdlibor.pxd b/quantlib/indexes/ibor/_usdlibor.pxd index ba2a37aee..c12f5ebd9 100644 --- a/quantlib/indexes/ibor/_usdlibor.pxd +++ b/quantlib/indexes/ibor/_usdlibor.pxd @@ -1,4 +1,4 @@ -from quantlib.handle cimport Handle +from quantlib._handle cimport Handle cimport quantlib.termstructures._yield_term_structure as _yts from quantlib.indexes.ibor._libor cimport Libor from quantlib.time._period cimport Period diff --git a/quantlib/indexes/ibor_index.pyx b/quantlib/indexes/ibor_index.pyx index 14b1f6cdf..8d098c942 100644 --- a/quantlib/indexes/ibor_index.pyx +++ b/quantlib/indexes/ibor_index.pyx @@ -3,7 +3,7 @@ from cython.operator cimport dereference as deref from libcpp.string cimport string from libcpp cimport bool -from quantlib.handle cimport shared_ptr, Handle +from quantlib.ext cimport shared_ptr from quantlib.time.date cimport Period from quantlib.time.daycounter cimport DayCounter from quantlib.currency.currency cimport Currency diff --git a/quantlib/indexes/inflation_index.pyx b/quantlib/indexes/inflation_index.pyx index 2c86a7c3e..4748b745e 100644 --- a/quantlib/indexes/inflation_index.pyx +++ b/quantlib/indexes/inflation_index.pyx @@ -8,7 +8,6 @@ include '../types.pxi' from cython.operator cimport dereference as deref -from quantlib.handle cimport Handle, shared_ptr, static_pointer_cast from libcpp cimport bool from libcpp.string cimport string diff --git a/quantlib/indexes/interest_rate_index.pyx b/quantlib/indexes/interest_rate_index.pyx index 99d8957d4..971b129da 100644 --- a/quantlib/indexes/interest_rate_index.pyx +++ b/quantlib/indexes/interest_rate_index.pyx @@ -11,7 +11,6 @@ from libcpp cimport bool from libcpp.string cimport string from quantlib.index cimport Index -from quantlib.handle cimport shared_ptr from quantlib.time.date cimport Period from quantlib.time.daycounter cimport DayCounter from quantlib.currency.currency cimport Currency diff --git a/quantlib/indexes/swap_index.pyx b/quantlib/indexes/swap_index.pyx index 179da9ca8..81ea59d6b 100644 --- a/quantlib/indexes/swap_index.pyx +++ b/quantlib/indexes/swap_index.pyx @@ -18,7 +18,7 @@ from quantlib.indexes.interest_rate_index cimport InterestRateIndex from quantlib.instruments.vanillaswap cimport VanillaSwap from quantlib.instruments.overnightindexedswap cimport OvernightIndexedSwap from quantlib.indexes.ibor_index cimport IborIndex, OvernightIndex -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast from quantlib.time.date cimport Period from quantlib.time.daycounter cimport DayCounter from quantlib.currency.currency cimport Currency diff --git a/quantlib/instrument.pxd b/quantlib/instrument.pxd index a7e5c8eab..8d1ff6677 100644 --- a/quantlib/instrument.pxd +++ b/quantlib/instrument.pxd @@ -1,4 +1,4 @@ -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.observable cimport Observable from . cimport _instrument diff --git a/quantlib/instrument.pyx b/quantlib/instrument.pyx index 43d2a124b..456fb2757 100644 --- a/quantlib/instrument.pyx +++ b/quantlib/instrument.pyx @@ -1,7 +1,7 @@ """Abstract instrument class""" from quantlib.time.date cimport date_from_qldate from quantlib.pricingengines.engine cimport PricingEngine -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast from quantlib._observable cimport Observable as QlObservable cdef class Instrument(Observable): diff --git a/quantlib/instruments/_asian_options.pxd b/quantlib/instruments/_asian_options.pxd index 0eedb2199..f86a5740b 100644 --- a/quantlib/instruments/_asian_options.pxd +++ b/quantlib/instruments/_asian_options.pxd @@ -1,7 +1,7 @@ from quantlib.types cimport Real, Size from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time._date cimport Date from quantlib._exercise cimport Exercise diff --git a/quantlib/instruments/_assetswap.pxd b/quantlib/instruments/_assetswap.pxd index 6cc66d635..674624092 100644 --- a/quantlib/instruments/_assetswap.pxd +++ b/quantlib/instruments/_assetswap.pxd @@ -2,7 +2,7 @@ from libcpp cimport bool from quantlib.types cimport Real, Spread from quantlib.time._schedule cimport Schedule from ._bond cimport Bond -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time._date cimport Date from quantlib.time._daycounter cimport DayCounter from .._cashflow cimport Leg diff --git a/quantlib/instruments/_bondforward.pxd b/quantlib/instruments/_bondforward.pxd index 077934081..d38a252d8 100644 --- a/quantlib/instruments/_bondforward.pxd +++ b/quantlib/instruments/_bondforward.pxd @@ -7,7 +7,8 @@ from quantlib.time.businessdayconvention cimport BusinessDayConvention from quantlib.termstructures._yield_term_structure cimport YieldTermStructure from ._bond cimport Bond from ._forward cimport Forward -from quantlib.handle cimport shared_ptr, Handle +from quantlib.ext cimport shared_ptr +from quantlib.handle cimport Handle from quantlib.position cimport Position cdef extern from "ql/instruments/bondforward.hpp" namespace "QuantLib" nogil: diff --git a/quantlib/instruments/_credit_default_swap.pxd b/quantlib/instruments/_credit_default_swap.pxd index 2948b217d..424f39d2f 100644 --- a/quantlib/instruments/_credit_default_swap.pxd +++ b/quantlib/instruments/_credit_default_swap.pxd @@ -1,7 +1,8 @@ from quantlib.types cimport Natural, Rate, Real from libcpp cimport bool -from quantlib.handle cimport optional, Handle, shared_ptr +from quantlib.ext cimport optional, shared_ptr +from quantlib.handle cimport Handle from quantlib.termstructures._yield_term_structure cimport YieldTermStructure from .._instrument cimport Instrument from quantlib._cashflow cimport CashFlow, Leg diff --git a/quantlib/instruments/_dividendschedule.pxd b/quantlib/instruments/_dividendschedule.pxd index 98bb87ea5..b98b1d316 100644 --- a/quantlib/instruments/_dividendschedule.pxd +++ b/quantlib/instruments/_dividendschedule.pxd @@ -1,5 +1,5 @@ from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.cashflows._dividend cimport Dividend cdef extern from 'ql/instruments/dividendschedule.hpp' namespace 'QuantLib' nogil: diff --git a/quantlib/instruments/_europeanoption.pxd b/quantlib/instruments/_europeanoption.pxd index 3decf83e8..77e95ee00 100644 --- a/quantlib/instruments/_europeanoption.pxd +++ b/quantlib/instruments/_europeanoption.pxd @@ -1,7 +1,7 @@ from .._payoffs cimport Payoff, StrikedTypePayoff from ._vanillaoption cimport VanillaOption from .._exercise cimport Exercise -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cdef extern from 'ql/instruments/europeanoption.hpp' namespace 'QuantLib' nogil: diff --git a/quantlib/instruments/_fixedvsfloatingswap.pxd b/quantlib/instruments/_fixedvsfloatingswap.pxd index 83e742b85..a53248414 100644 --- a/quantlib/instruments/_fixedvsfloatingswap.pxd +++ b/quantlib/instruments/_fixedvsfloatingswap.pxd @@ -1,7 +1,7 @@ from libcpp.vector cimport vector from quantlib.types cimport Natural, Rate, Real, Spread -from quantlib.handle cimport shared_ptr, optional +from quantlib.ext cimport shared_ptr, optional from quantlib.time._calendar cimport BusinessDayConvention, Calendar from quantlib.time._date cimport Date from quantlib.time._daycounter cimport DayCounter diff --git a/quantlib/instruments/_implied_volatility.pxd b/quantlib/instruments/_implied_volatility.pxd index 672d95155..ecfa119e3 100644 --- a/quantlib/instruments/_implied_volatility.pxd +++ b/quantlib/instruments/_implied_volatility.pxd @@ -8,9 +8,7 @@ """ from quantlib.types cimport Natural, Real, Volatility -from quantlib.handle cimport Handle, shared_ptr -cimport quantlib.termstructures._yield_term_structure as _yts -cimport quantlib.time._daycounter as _dc +from quantlib.ext cimport shared_ptr from quantlib.quotes._simplequote cimport SimpleQuote cimport quantlib._instrument as _ins cimport quantlib.pricingengines._pricing_engine as _pe diff --git a/quantlib/instruments/_make_cds.pxd b/quantlib/instruments/_make_cds.pxd index 815f28e38..548ba9f37 100644 --- a/quantlib/instruments/_make_cds.pxd +++ b/quantlib/instruments/_make_cds.pxd @@ -1,7 +1,8 @@ from quantlib.types cimport Real, Natural from libcpp cimport bool from quantlib.default cimport Protection -from quantlib.handle cimport shared_ptr, Handle +from quantlib.ext cimport shared_ptr +from quantlib.handle cimport Handle from quantlib.pricingengines._pricing_engine cimport PricingEngine from quantlib.time._calendar cimport Calendar from quantlib.time._daycounter cimport DayCounter diff --git a/quantlib/instruments/_make_cms.pxd b/quantlib/instruments/_make_cms.pxd index 253d6ef53..248015dce 100644 --- a/quantlib/instruments/_make_cms.pxd +++ b/quantlib/instruments/_make_cms.pxd @@ -1,6 +1,6 @@ from quantlib.types cimport Real, Spread from libcpp cimport bool -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.indexes._swap_index cimport SwapIndex from quantlib.indexes._ibor_index cimport IborIndex from quantlib.instruments._swap cimport Swap diff --git a/quantlib/instruments/_make_ois.pxd b/quantlib/instruments/_make_ois.pxd index 61d7a3c1a..f3490872d 100644 --- a/quantlib/instruments/_make_ois.pxd +++ b/quantlib/instruments/_make_ois.pxd @@ -1,5 +1,6 @@ from quantlib.types cimport Natural, Real, Rate, Spread -from quantlib.handle cimport shared_ptr, Handle +from quantlib.ext cimport shared_ptr +from quantlib.handle cimport Handle from libcpp cimport bool from quantlib.time.businessdayconvention cimport BusinessDayConvention from quantlib.time._schedule cimport DateGeneration diff --git a/quantlib/instruments/_make_swaption.pxd b/quantlib/instruments/_make_swaption.pxd index 46d1afd25..fb5cd5897 100644 --- a/quantlib/instruments/_make_swaption.pxd +++ b/quantlib/instruments/_make_swaption.pxd @@ -1,6 +1,6 @@ include '../types.pxi' -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time._date cimport Date from quantlib.time._period cimport Period from quantlib.time.businessdayconvention cimport BusinessDayConvention diff --git a/quantlib/instruments/_make_vanilla_swap.pxd b/quantlib/instruments/_make_vanilla_swap.pxd index cb109c287..6be77159b 100644 --- a/quantlib/instruments/_make_vanilla_swap.pxd +++ b/quantlib/instruments/_make_vanilla_swap.pxd @@ -1,7 +1,8 @@ include '../types.pxi' from libcpp cimport bool -from quantlib.handle cimport shared_ptr, Handle +from quantlib.ext cimport shared_ptr +from quantlib.handle cimport Handle from quantlib.time._date cimport Date from quantlib.time._period cimport Period from quantlib.time._calendar cimport Calendar diff --git a/quantlib/instruments/_oneassetoption.pxd b/quantlib/instruments/_oneassetoption.pxd index 11190192b..db679928c 100644 --- a/quantlib/instruments/_oneassetoption.pxd +++ b/quantlib/instruments/_oneassetoption.pxd @@ -1,6 +1,6 @@ from quantlib.types cimport Real from .._option cimport Option -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from .._exercise cimport Exercise from .._payoffs cimport StrikedTypePayoff from quantlib.pricingengines._pricing_engine cimport PricingEngine diff --git a/quantlib/instruments/_overnightindexedswap.pxd b/quantlib/instruments/_overnightindexedswap.pxd index 9f6be1ffa..654b0d730 100644 --- a/quantlib/instruments/_overnightindexedswap.pxd +++ b/quantlib/instruments/_overnightindexedswap.pxd @@ -3,7 +3,7 @@ from quantlib.types cimport Integer, Natural, Rate, Real, Spread from quantlib.cashflows.rateaveraging cimport RateAveraging from libcpp cimport bool from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib._cashflow cimport Leg from quantlib.time._calendar cimport BusinessDayConvention, Calendar from quantlib.time._schedule cimport Schedule diff --git a/quantlib/instruments/_overnightindexfuture.pxd b/quantlib/instruments/_overnightindexfuture.pxd index 45ec6d5a5..ed4e35207 100644 --- a/quantlib/instruments/_overnightindexfuture.pxd +++ b/quantlib/instruments/_overnightindexfuture.pxd @@ -1,7 +1,8 @@ from libcpp cimport bool from quantlib.types cimport Real from quantlib.cashflows.rateaveraging cimport RateAveraging -from quantlib.handle cimport Handle, shared_ptr +from quantlib._handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib.indexes._ibor_index cimport OvernightIndex from quantlib._instrument cimport Instrument from quantlib._quote cimport Quote diff --git a/quantlib/instruments/_swaption.pxd b/quantlib/instruments/_swaption.pxd index 4c9f9e56d..32f829480 100644 --- a/quantlib/instruments/_swaption.pxd +++ b/quantlib/instruments/_swaption.pxd @@ -1,13 +1,13 @@ include '../types.pxi' -from quantlib.handle cimport shared_ptr, optional -from ._fixedvsfloatingswap cimport FixedVsFloatingSwap +from quantlib.ext cimport shared_ptr, optional +from ._fixedvsfloatingswap cimport FixedVsFloatingSwap from ._overnightindexedswap cimport OvernightIndexedSwap from .._option cimport Option from .._exercise cimport Exercise from .swap cimport Type as SwapType from quantlib.termstructures._yield_term_structure cimport YieldTermStructure from quantlib.termstructures.volatility.volatilitytype cimport VolatilityType -from quantlib.handle cimport Handle, optional +from quantlib.handle cimport Handle from .swaption cimport Type, Method cdef extern from 'ql/instruments/swaption.hpp' namespace 'QuantLib': diff --git a/quantlib/instruments/_vanillaoption.pxd b/quantlib/instruments/_vanillaoption.pxd index 426907c6c..e6f86731c 100644 --- a/quantlib/instruments/_vanillaoption.pxd +++ b/quantlib/instruments/_vanillaoption.pxd @@ -5,7 +5,7 @@ from .._payoffs cimport StrikedTypePayoff from .._exercise cimport Exercise from quantlib.processes._black_scholes_process cimport GeneralizedBlackScholesProcess -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cdef extern from 'ql/instruments/vanillaoption.hpp' namespace 'QuantLib' nogil: diff --git a/quantlib/instruments/_vanillaswap.pxd b/quantlib/instruments/_vanillaswap.pxd index c3521321d..aa12a147f 100644 --- a/quantlib/instruments/_vanillaswap.pxd +++ b/quantlib/instruments/_vanillaswap.pxd @@ -9,7 +9,7 @@ from quantlib.types cimport Rate, Real, Spread -from quantlib.handle cimport shared_ptr, optional +from quantlib.ext cimport shared_ptr, optional from quantlib.time._calendar cimport BusinessDayConvention, Calendar from quantlib.time._date cimport Date from quantlib.time._daycounter cimport DayCounter diff --git a/quantlib/instruments/_zerocouponswap.pxd b/quantlib/instruments/_zerocouponswap.pxd index eaa9a7fe8..0054dafa4 100644 --- a/quantlib/instruments/_zerocouponswap.pxd +++ b/quantlib/instruments/_zerocouponswap.pxd @@ -1,5 +1,5 @@ from quantlib.types cimport Natural, Rate, Real -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time._calendar cimport BusinessDayConvention, Calendar from quantlib.time._date cimport Date from quantlib.time._daycounter cimport DayCounter diff --git a/quantlib/instruments/asian_options.pyx b/quantlib/instruments/asian_options.pyx index da1df2635..42a75ff5a 100644 --- a/quantlib/instruments/asian_options.pyx +++ b/quantlib/instruments/asian_options.pyx @@ -2,7 +2,7 @@ from quantlib.types cimport Real, Size from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast cimport quantlib.time._date as _date from quantlib.time.date cimport Date from quantlib.payoffs cimport StrikedTypePayoff diff --git a/quantlib/instruments/assetswap.pyx b/quantlib/instruments/assetswap.pyx index 3037885e9..1e473c9f5 100644 --- a/quantlib/instruments/assetswap.pyx +++ b/quantlib/instruments/assetswap.pyx @@ -1,7 +1,7 @@ from cython.operator cimport dereference as deref from libcpp cimport bool from quantlib.types cimport Real, Spread -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast from quantlib.indexes.ibor_index cimport IborIndex from quantlib.indexes cimport _ibor_index as _ib from quantlib.time.schedule cimport Schedule diff --git a/quantlib/instruments/bondforward.pyx b/quantlib/instruments/bondforward.pyx index a87172b24..8ad6cd389 100644 --- a/quantlib/instruments/bondforward.pyx +++ b/quantlib/instruments/bondforward.pyx @@ -4,7 +4,7 @@ from quantlib.time.businessdayconvention cimport BusinessDayConvention from quantlib.time.calendar cimport Calendar from quantlib.time.daycounter cimport DayCounter from quantlib.types cimport Natural, Real -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast from quantlib.position cimport Position from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure from . cimport _bondforward as _bf diff --git a/quantlib/instruments/bonds/_amortizingfloatingratebond.pxd b/quantlib/instruments/bonds/_amortizingfloatingratebond.pxd index 7e8700ca5..c0a5f27ab 100644 --- a/quantlib/instruments/bonds/_amortizingfloatingratebond.pxd +++ b/quantlib/instruments/bonds/_amortizingfloatingratebond.pxd @@ -1,6 +1,6 @@ from quantlib.types cimport Integer, Natural, Rate, Real, Spread from libcpp cimport bool -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.indexes._ibor_index cimport IborIndex from quantlib.time.businessdayconvention cimport BusinessDayConvention from quantlib.time._calendar cimport Calendar diff --git a/quantlib/instruments/bonds/_cpibond.pxd b/quantlib/instruments/bonds/_cpibond.pxd index 4deee8a78..16bb89a5a 100644 --- a/quantlib/instruments/bonds/_cpibond.pxd +++ b/quantlib/instruments/bonds/_cpibond.pxd @@ -9,7 +9,7 @@ from quantlib.time._date cimport Date from quantlib.time._daycounter cimport DayCounter from quantlib.time._period cimport Period from quantlib.time._schedule cimport Schedule -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.indexes._inflation_index cimport ZeroInflationIndex from .cpibond cimport InterpolationType diff --git a/quantlib/instruments/bonds/_floatingratebond.pxd b/quantlib/instruments/bonds/_floatingratebond.pxd index 6b57438f5..12a5dded9 100644 --- a/quantlib/instruments/bonds/_floatingratebond.pxd +++ b/quantlib/instruments/bonds/_floatingratebond.pxd @@ -1,7 +1,7 @@ from .._bond cimport Bond from quantlib.indexes._ibor_index cimport IborIndex from quantlib.types cimport Natural, Rate, Real, Spread -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time._calendar cimport Calendar from quantlib.time._date cimport Date from quantlib.time._period cimport Period diff --git a/quantlib/instruments/bonds/amortizingfloatingratebond.pyx b/quantlib/instruments/bonds/amortizingfloatingratebond.pyx index 2be6cdd00..b000c00aa 100644 --- a/quantlib/instruments/bonds/amortizingfloatingratebond.pyx +++ b/quantlib/instruments/bonds/amortizingfloatingratebond.pyx @@ -2,7 +2,7 @@ from cython.operator cimport dereference as deref from libcpp cimport bool from libcpp.vector cimport vector -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast cimport quantlib.indexes._ibor_index as _ii from quantlib.indexes.ibor_index cimport IborIndex from quantlib.types cimport Natural, Integer, Real, Rate, Spread diff --git a/quantlib/instruments/bonds/cpibond.pyx b/quantlib/instruments/bonds/cpibond.pyx index f079f8d02..24f97100f 100644 --- a/quantlib/instruments/bonds/cpibond.pyx +++ b/quantlib/instruments/bonds/cpibond.pyx @@ -4,7 +4,7 @@ from libcpp cimport bool from libcpp.vector cimport vector from . cimport _cpibond -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast cimport quantlib.indexes._inflation_index as _inf from quantlib.indexes.inflation_index cimport ZeroInflationIndex from quantlib.time.businessdayconvention cimport BusinessDayConvention, Following, Unadjusted diff --git a/quantlib/instruments/bonds/floatingratebond.pyx b/quantlib/instruments/bonds/floatingratebond.pyx index 13e614303..2ba71301b 100644 --- a/quantlib/instruments/bonds/floatingratebond.pyx +++ b/quantlib/instruments/bonds/floatingratebond.pyx @@ -2,7 +2,7 @@ from quantlib.types cimport Natural, Rate, Real, Spread from cython.operator cimport dereference as deref from libcpp.vector cimport vector from libcpp cimport bool -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast from quantlib.indexes.ibor_index cimport IborIndex cimport quantlib.indexes._ibor_index as _ii from quantlib.time.businessdayconvention cimport BusinessDayConvention, Following, Unadjusted diff --git a/quantlib/instruments/credit_default_swap.pyx b/quantlib/instruments/credit_default_swap.pyx index 1f77ec3b4..03d554c3e 100644 --- a/quantlib/instruments/credit_default_swap.pyx +++ b/quantlib/instruments/credit_default_swap.pyx @@ -11,7 +11,7 @@ from cython.operator cimport dereference as deref from libcpp cimport bool -from quantlib.handle cimport shared_ptr, optional +from quantlib.ext cimport shared_ptr, optional from quantlib.default cimport Protection cimport quantlib.instruments._credit_default_swap as _cds diff --git a/quantlib/instruments/dividendschedule.pxd b/quantlib/instruments/dividendschedule.pxd index ea8865d45..058d4adc7 100644 --- a/quantlib/instruments/dividendschedule.pxd +++ b/quantlib/instruments/dividendschedule.pxd @@ -1,6 +1,6 @@ from libcpp.vector cimport vector from quantlib.cashflows._dividend cimport Dividend -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cdef class DividendSchedule: cdef vector[shared_ptr[Dividend]] schedule diff --git a/quantlib/instruments/europeanoption.pxd b/quantlib/instruments/europeanoption.pxd index ee4af6849..f5111861f 100644 --- a/quantlib/instruments/europeanoption.pxd +++ b/quantlib/instruments/europeanoption.pxd @@ -1,3 +1,4 @@ +"""European option on a single asset""" from .vanillaoption cimport VanillaOption cdef class EuropeanOption(VanillaOption): diff --git a/quantlib/instruments/europeanoption.pyx b/quantlib/instruments/europeanoption.pyx index ddad03852..6a08c0a3e 100644 --- a/quantlib/instruments/europeanoption.pyx +++ b/quantlib/instruments/europeanoption.pyx @@ -3,7 +3,7 @@ from . cimport _europeanoption as _eo from ..payoffs cimport StrikedTypePayoff from ..exercise cimport Exercise from .. cimport _payoffs -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast cdef class EuropeanOption(VanillaOption): """European option on a single asset""" diff --git a/quantlib/instruments/implied_volatility.pyx b/quantlib/instruments/implied_volatility.pyx index 41fe3a754..5cfb8435b 100644 --- a/quantlib/instruments/implied_volatility.pyx +++ b/quantlib/instruments/implied_volatility.pyx @@ -9,7 +9,7 @@ from quantlib.types cimport Natural, Real, Volatility from cython.operator cimport dereference as deref -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast from quantlib.instrument cimport Instrument from quantlib.pricingengines.engine cimport PricingEngine from quantlib.quotes.simplequote cimport SimpleQuote diff --git a/quantlib/instruments/make_cds.pyx b/quantlib/instruments/make_cds.pyx index 4b2d555dc..fb28d1524 100644 --- a/quantlib/instruments/make_cds.pyx +++ b/quantlib/instruments/make_cds.pyx @@ -2,7 +2,7 @@ from quantlib.types cimport Natural, Real from cython.operator cimport dereference as deref from quantlib.default cimport Protection -from quantlib.handle cimport static_pointer_cast, shared_ptr +from quantlib.ext cimport static_pointer_cast, shared_ptr from quantlib.time.date cimport Date, Period from quantlib.time.daycounter cimport DayCounter from quantlib.time._date cimport Date as QlDate, Period as QlPeriod diff --git a/quantlib/instruments/make_cms.pyx b/quantlib/instruments/make_cms.pyx index b7eba1d19..3579c4c6e 100644 --- a/quantlib/instruments/make_cms.pyx +++ b/quantlib/instruments/make_cms.pyx @@ -1,7 +1,7 @@ from quantlib.types cimport Real, Spread from cython.operator cimport dereference as deref from quantlib.instruments.swap cimport Swap -from quantlib.handle cimport static_pointer_cast, shared_ptr +from quantlib.ext cimport static_pointer_cast, shared_ptr from quantlib.indexes.swap_index cimport SwapIndex from quantlib.indexes.ibor_index cimport IborIndex from quantlib.time.date cimport Period, Date diff --git a/quantlib/instruments/make_ois.pyx b/quantlib/instruments/make_ois.pyx index 81e36c174..6bf453f10 100644 --- a/quantlib/instruments/make_ois.pyx +++ b/quantlib/instruments/make_ois.pyx @@ -1,7 +1,7 @@ from quantlib.types cimport Natural, Rate, Real, Spread from libcpp cimport bool from cython.operator cimport dereference as deref -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast from quantlib.cashflows.rateaveraging cimport RateAveraging from quantlib.utilities.null cimport Null from quantlib.time.date cimport Date, Period diff --git a/quantlib/instruments/make_swaption.pyx b/quantlib/instruments/make_swaption.pyx index 4222b9512..7a7657268 100644 --- a/quantlib/instruments/make_swaption.pyx +++ b/quantlib/instruments/make_swaption.pyx @@ -1,7 +1,7 @@ from cython.operator cimport dereference as deref from quantlib.utilities.null cimport Null from quantlib.instruments.swap cimport Swap -from quantlib.handle cimport static_pointer_cast, shared_ptr +from quantlib.ext cimport static_pointer_cast, shared_ptr from quantlib.indexes.swap_index cimport SwapIndex from quantlib.time.date cimport Period, Date from quantlib.time.businessdayconvention cimport BusinessDayConvention diff --git a/quantlib/instruments/make_vanilla_swap.pyx b/quantlib/instruments/make_vanilla_swap.pyx index f06923165..6e17c7fb6 100644 --- a/quantlib/instruments/make_vanilla_swap.pyx +++ b/quantlib/instruments/make_vanilla_swap.pyx @@ -2,7 +2,7 @@ from cython.operator cimport dereference as deref from libcpp cimport bool from quantlib.utilities.null cimport Null from quantlib.instruments.swap cimport Swap -from quantlib.handle cimport static_pointer_cast, shared_ptr +from quantlib.ext cimport static_pointer_cast, shared_ptr from quantlib.indexes.ibor_index cimport IborIndex from quantlib.time.date cimport Period, Date from quantlib.time.businessdayconvention cimport BusinessDayConvention diff --git a/quantlib/instruments/oneassetoption.pyx b/quantlib/instruments/oneassetoption.pyx index fc5118ce8..7dba54e56 100644 --- a/quantlib/instruments/oneassetoption.pyx +++ b/quantlib/instruments/oneassetoption.pyx @@ -1,6 +1,7 @@ """Option on a single asset""" cdef class OneAssetOption(Option): """Base class for option on a single asset""" + cdef inline _oa.OneAssetOption* as_ptr(self) noexcept nogil: return <_oa.OneAssetOption*>self._thisptr.get() diff --git a/quantlib/instruments/overnightindexedswap.pyx b/quantlib/instruments/overnightindexedswap.pyx index 3a7c18e4b..92e78a048 100644 --- a/quantlib/instruments/overnightindexedswap.pyx +++ b/quantlib/instruments/overnightindexedswap.pyx @@ -12,7 +12,7 @@ from quantlib.time.businessdayconvention cimport BusinessDayConvention, Followin from quantlib.time.calendar cimport Calendar from quantlib.time.daycounter cimport DayCounter from quantlib.time.schedule cimport Schedule -from quantlib.handle cimport make_shared, static_pointer_cast +from quantlib.ext cimport make_shared, static_pointer_cast from quantlib.utilities.null cimport Null from .swap cimport Type from . cimport _overnightindexedswap as _ois diff --git a/quantlib/instruments/overnightindexfuture.pyx b/quantlib/instruments/overnightindexfuture.pyx index 6d2aa02c3..b50bba5ed 100644 --- a/quantlib/instruments/overnightindexfuture.pyx +++ b/quantlib/instruments/overnightindexfuture.pyx @@ -1,5 +1,5 @@ from cython.operator cimport dereference as deref -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast from . cimport _overnightindexfuture as _oif from quantlib.cashflows.rateaveraging cimport RateAveraging from quantlib.indexes.ibor_index cimport OvernightIndex diff --git a/quantlib/instruments/swaption.pyx b/quantlib/instruments/swaption.pyx index fb33f5556..d5fb0f48b 100644 --- a/quantlib/instruments/swaption.pyx +++ b/quantlib/instruments/swaption.pyx @@ -1,6 +1,6 @@ from quantlib.types cimport Natural, Real, Volatility from . cimport _swaption -from quantlib.handle cimport shared_ptr, static_pointer_cast, Handle +from quantlib.ext cimport shared_ptr, static_pointer_cast from quantlib.termstructures.volatility.volatilitytype cimport ( VolatilityType, ShiftedLognormal ) from quantlib.termstructures.yield_term_structure cimport YieldTermStructure diff --git a/quantlib/instruments/vanillaoption.pyx b/quantlib/instruments/vanillaoption.pyx index 11ea8a76a..092f15537 100644 --- a/quantlib/instruments/vanillaoption.pyx +++ b/quantlib/instruments/vanillaoption.pyx @@ -1,5 +1,5 @@ """Vanilla option on a single asset""" -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast from quantlib.types cimport Real, Size, Volatility from quantlib.processes.black_scholes_process cimport GeneralizedBlackScholesProcess from quantlib.processes cimport _black_scholes_process as _bsp diff --git a/quantlib/instruments/vanillaswap.pyx b/quantlib/instruments/vanillaswap.pyx index 449e7b6cf..846a6902f 100644 --- a/quantlib/instruments/vanillaswap.pyx +++ b/quantlib/instruments/vanillaswap.pyx @@ -1,7 +1,7 @@ """Simple fixed-rate vs Libor swap""" from cython.operator cimport dereference as deref from quantlib.types cimport Rate, Real, Spread -from quantlib.handle cimport optional, static_pointer_cast +from quantlib.ext cimport optional, static_pointer_cast from quantlib.indexes.ibor_index cimport IborIndex cimport quantlib.indexes._ibor_index as _ib from quantlib.time.businessdayconvention cimport BusinessDayConvention diff --git a/quantlib/instruments/zerocouponswap.pyx b/quantlib/instruments/zerocouponswap.pyx index 4c01f8db6..f98cd79f4 100644 --- a/quantlib/instruments/zerocouponswap.pyx +++ b/quantlib/instruments/zerocouponswap.pyx @@ -1,5 +1,5 @@ from quantlib.types cimport Real, Natural -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast from quantlib.time.date cimport Date from quantlib.time.calendar cimport Calendar from quantlib.time.businessdayconvention cimport BusinessDayConvention, Following diff --git a/quantlib/math/_hestonhwcorrelationconstraint.pxd b/quantlib/math/_hestonhwcorrelationconstraint.pxd index 1dc9fd446..5e7d5e3bf 100644 --- a/quantlib/math/_hestonhwcorrelationconstraint.pxd +++ b/quantlib/math/_hestonhwcorrelationconstraint.pxd @@ -7,11 +7,10 @@ FOR A PARTICULAR PURPOSE. See the license for more details. """ -include '../types.pxi' - +from quantlib.types cimport Real cimport quantlib.math._optimization as _opt -from quantlib.handle cimport shared_ptr - -cdef extern from "constraint_support_code.hpp" namespace "QuantLib": - cdef shared_ptr[_opt.Constraint] constraint_factory(Real x) except + +from quantlib.ext cimport shared_ptr +cdef extern from "constraint_support_code.hpp" namespace "QuantLib" nogil: + cdef cppclass HestonHullWhiteCorrelationConstraint(_opt.Constraint): + HestonHullWhiteCorrelationConstraint(double) diff --git a/quantlib/math/hestonhwcorrelationconstraint.pyx b/quantlib/math/hestonhwcorrelationconstraint.pyx index 76607730c..e709aed51 100644 --- a/quantlib/math/hestonhwcorrelationconstraint.pyx +++ b/quantlib/math/hestonhwcorrelationconstraint.pyx @@ -5,16 +5,15 @@ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the license for more details. -from quantlib.handle cimport shared_ptr from quantlib.math.optimization cimport Constraint -from . cimport _optimization as _opt from . cimport _hestonhwcorrelationconstraint as _hhw cdef class HestonHullWhiteCorrelationConstraint(Constraint): def __init__(self, double equity_short_rate_corr): - self._thisptr = shared_ptr[_opt.Constraint]( - _hhw.constraint_factory(equity_short_rate_corr)) + self._thisptr.reset( + new _hhw.HestonHullWhiteCorrelationConstraint(equity_short_rate_corr) + ) def __str__(self): return 'Heston/Hull-White correlation constraint' diff --git a/quantlib/math/optimization.pxd b/quantlib/math/optimization.pxd index b792cc011..d9be39159 100644 --- a/quantlib/math/optimization.pxd +++ b/quantlib/math/optimization.pxd @@ -1,6 +1,6 @@ from . cimport _optimization as _opt -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cdef class OptimizationMethod: diff --git a/quantlib/math/optimization.pyx b/quantlib/math/optimization.pyx index 02e2cc4cd..913c867e0 100644 --- a/quantlib/math/optimization.pyx +++ b/quantlib/math/optimization.pyx @@ -1,4 +1,4 @@ -from quantlib.handle cimport shared_ptr, make_shared +from quantlib.ext cimport shared_ptr, make_shared from . cimport _optimization as _opt from quantlib.math.array cimport Array diff --git a/quantlib/methods/finitedifferences/solvers/fdmbackwardsolver.pyx b/quantlib/methods/finitedifferences/solvers/fdmbackwardsolver.pyx index 081fa0fa5..dfe4f5b45 100644 --- a/quantlib/methods/finitedifferences/solvers/fdmbackwardsolver.pyx +++ b/quantlib/methods/finitedifferences/solvers/fdmbackwardsolver.pyx @@ -1,7 +1,6 @@ cimport cython from quantlib.types cimport Real -from quantlib.handle cimport shared_ptr cimport quantlib.methods.finitedifferences.solvers._fdmbackwardsolver as _fdm cdef class FdmLinearOpComposite: diff --git a/quantlib/methods/montecarlo/_multipathgenerator.pxd b/quantlib/methods/montecarlo/_multipathgenerator.pxd index 0580a4a3c..78b084dbe 100644 --- a/quantlib/methods/montecarlo/_multipathgenerator.pxd +++ b/quantlib/methods/montecarlo/_multipathgenerator.pxd @@ -1,5 +1,5 @@ from libcpp cimport bool -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib._time_grid cimport TimeGrid from libcpp.vector cimport vector diff --git a/quantlib/models/_calibration_helper.pxd b/quantlib/models/_calibration_helper.pxd index 40ecfedf0..0ac879c3d 100644 --- a/quantlib/models/_calibration_helper.pxd +++ b/quantlib/models/_calibration_helper.pxd @@ -1,7 +1,8 @@ from quantlib.types cimport Real, Size, Volatility from quantlib.pricingengines._pricing_engine cimport PricingEngine from quantlib.termstructures.volatility.volatilitytype cimport VolatilityType -from quantlib.handle cimport shared_ptr, Handle +from quantlib.handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib._quote cimport Quote cdef extern from 'ql/models/calibrationhelper.hpp' namespace 'QuantLib': diff --git a/quantlib/models/_model.pxd b/quantlib/models/_model.pxd index 3fc5be03e..3eea74426 100644 --- a/quantlib/models/_model.pxd +++ b/quantlib/models/_model.pxd @@ -2,7 +2,8 @@ from libcpp cimport bool from libcpp.vector cimport vector from quantlib.types cimport DiscountFactor, Real, Size, Time -from quantlib.handle cimport shared_ptr, Handle +from quantlib.ext cimport shared_ptr +from quantlib.handle cimport Handle from quantlib.termstructures._yield_term_structure cimport YieldTermStructure from quantlib.option cimport OptionType from quantlib._numericalmethod cimport Lattice diff --git a/quantlib/models/calibration_helper.pxd b/quantlib/models/calibration_helper.pxd index d5ceaf8e0..4b96a4e01 100644 --- a/quantlib/models/calibration_helper.pxd +++ b/quantlib/models/calibration_helper.pxd @@ -8,7 +8,7 @@ """ from . cimport _calibration_helper as _ch -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cpdef enum CalibrationErrorType: RelativePriceError = _ch.RelativePriceError diff --git a/quantlib/models/calibration_helper.pyx b/quantlib/models/calibration_helper.pyx index f691f418a..56f2f0d51 100644 --- a/quantlib/models/calibration_helper.pyx +++ b/quantlib/models/calibration_helper.pyx @@ -6,7 +6,7 @@ # FOR A PARTICULAR PURPOSE. See the license for more details. from quantlib.types cimport Real, Size, Volatility -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.pricingengines.engine cimport PricingEngine globals().update(getattr(CalibrationErrorType, "__members__")) diff --git a/quantlib/models/equity/_bates_model.pxd b/quantlib/models/equity/_bates_model.pxd index 36f3b8ceb..bad2450d8 100644 --- a/quantlib/models/equity/_bates_model.pxd +++ b/quantlib/models/equity/_bates_model.pxd @@ -1,6 +1,6 @@ include '../../types.pxi' -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.models.equity._heston_model cimport HestonModel cimport quantlib.processes._heston_process as _hp diff --git a/quantlib/models/equity/_heston_model.pxd b/quantlib/models/equity/_heston_model.pxd index 286279b88..2c1c500ce 100644 --- a/quantlib/models/equity/_heston_model.pxd +++ b/quantlib/models/equity/_heston_model.pxd @@ -2,7 +2,8 @@ include '../../types.pxi' from libcpp.vector cimport vector -from quantlib.handle cimport Handle, shared_ptr +from quantlib._handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib.processes._heston_process cimport HestonProcess from quantlib.pricingengines._pricing_engine cimport PricingEngine diff --git a/quantlib/models/equity/bates_model.pxd b/quantlib/models/equity/bates_model.pxd index dcdddc261..b686c7515 100644 --- a/quantlib/models/equity/bates_model.pxd +++ b/quantlib/models/equity/bates_model.pxd @@ -6,9 +6,6 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. """ -cimport quantlib.models.equity._bates_model as _bm - -from quantlib.handle cimport shared_ptr from quantlib.models.equity.heston_model cimport HestonModel cdef class BatesModel(HestonModel): diff --git a/quantlib/models/equity/bates_model.pyx b/quantlib/models/equity/bates_model.pyx index 6fe1d9c75..4b005e8ac 100644 --- a/quantlib/models/equity/bates_model.pyx +++ b/quantlib/models/equity/bates_model.pyx @@ -23,7 +23,7 @@ from . cimport _bates_model as _bm from . cimport _heston_model as _hm cimport quantlib.processes._heston_process as _hp cimport quantlib._stochastic_process as _sp -from quantlib.handle cimport Handle, shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast from quantlib.processes.heston_process cimport HestonProcess from quantlib.processes.bates_process cimport BatesProcess from .heston_model cimport HestonModel diff --git a/quantlib/models/equity/heston_model.pxd b/quantlib/models/equity/heston_model.pxd index 56d51b4d9..4f6fe9226 100644 --- a/quantlib/models/equity/heston_model.pxd +++ b/quantlib/models/equity/heston_model.pxd @@ -7,7 +7,7 @@ from . cimport _heston_model as _hm -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.models.calibration_helper cimport BlackCalibrationHelper diff --git a/quantlib/models/equity/heston_model.pyx b/quantlib/models/equity/heston_model.pyx index d4b027e69..72afc4281 100644 --- a/quantlib/models/equity/heston_model.pyx +++ b/quantlib/models/equity/heston_model.pyx @@ -18,7 +18,7 @@ cimport quantlib._stochastic_process as _sp cimport quantlib.termstructures.yields._flat_forward as _ffwd cimport quantlib.pricingengines._pricing_engine as _pe -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast from quantlib.math.optimization cimport (Constraint,OptimizationMethod, EndCriteria) diff --git a/quantlib/models/marketmodels/_brownian_generator.pxd b/quantlib/models/marketmodels/_brownian_generator.pxd index 399bc6309..f5305e6e8 100644 --- a/quantlib/models/marketmodels/_brownian_generator.pxd +++ b/quantlib/models/marketmodels/_brownian_generator.pxd @@ -1,6 +1,6 @@ from libcpp.vector cimport vector from quantlib.types cimport Real, Size -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cdef extern from 'ql/models/marketmodels/browniangenerator.hpp' namespace 'QuantLib' nogil: cdef cppclass BrownianGenerator: diff --git a/quantlib/models/marketmodels/brownian_generator.pxd b/quantlib/models/marketmodels/brownian_generator.pxd index f2a76e864..cb7e073c3 100644 --- a/quantlib/models/marketmodels/brownian_generator.pxd +++ b/quantlib/models/marketmodels/brownian_generator.pxd @@ -1,4 +1,4 @@ -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from . cimport _brownian_generator as _bg cdef class BrownianGenerator: diff --git a/quantlib/models/marketmodels/browniangenerators/_mt_brownian_generator.pxd b/quantlib/models/marketmodels/browniangenerators/_mt_brownian_generator.pxd index 143700265..6ca3745a6 100644 --- a/quantlib/models/marketmodels/browniangenerators/_mt_brownian_generator.pxd +++ b/quantlib/models/marketmodels/browniangenerators/_mt_brownian_generator.pxd @@ -1,6 +1,6 @@ from quantlib.types cimport Size from quantlib.types cimport Real, Size -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from .._brownian_generator cimport BrownianGenerator, BrownianGeneratorFactory cdef extern from 'ql/models/marketmodels/browniangenerators/mtbrowniangenerator.hpp' namespace 'QuantLib' nogil: diff --git a/quantlib/models/model.pxd b/quantlib/models/model.pxd index 8bb59a17b..58c4a4815 100644 --- a/quantlib/models/model.pxd +++ b/quantlib/models/model.pxd @@ -8,7 +8,7 @@ """ from . cimport _model as _mo -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cdef class CalibratedModel: diff --git a/quantlib/models/model.pyx b/quantlib/models/model.pyx index 51ff3610a..bcbf3fdb9 100644 --- a/quantlib/models/model.pyx +++ b/quantlib/models/model.pyx @@ -7,7 +7,7 @@ include '../types.pxi' -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from cython.operator cimport dereference as deref from quantlib.math.array cimport Array cimport quantlib.math._array as _arr diff --git a/quantlib/models/shortrate/_onefactor_model.pxd b/quantlib/models/shortrate/_onefactor_model.pxd index 949c920ba..20e3c0c75 100644 --- a/quantlib/models/shortrate/_onefactor_model.pxd +++ b/quantlib/models/shortrate/_onefactor_model.pxd @@ -1,7 +1,7 @@ from quantlib.types cimport DiscountFactor, Rate, Real, Time from quantlib.math._array cimport Array from quantlib.models._model cimport ShortRateModel, AffineModel -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib._stochastic_process cimport StochasticProcess1D cdef extern from 'ql/models/shortrate/onefactormodel.hpp' namespace 'QuantLib' nogil: diff --git a/quantlib/models/shortrate/_twofactor_model.pxd b/quantlib/models/shortrate/_twofactor_model.pxd index 7bd05883d..b69638b75 100644 --- a/quantlib/models/shortrate/_twofactor_model.pxd +++ b/quantlib/models/shortrate/_twofactor_model.pxd @@ -1,7 +1,7 @@ from quantlib.types cimport DiscountFactor, Rate, Real, Time from quantlib.math._array cimport Array from quantlib.models._model cimport ShortRateModel, AffineModel -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib._stochastic_process cimport StochasticProcess1D cdef extern from 'ql/models/shortrate/twofactormodel.hpp' namespace 'QuantLib' nogil: diff --git a/quantlib/models/shortrate/calibrationhelpers/_swaption_helper.pxd b/quantlib/models/shortrate/calibrationhelpers/_swaption_helper.pxd index 2de1eebbb..99402bbd5 100644 --- a/quantlib/models/shortrate/calibrationhelpers/_swaption_helper.pxd +++ b/quantlib/models/shortrate/calibrationhelpers/_swaption_helper.pxd @@ -8,7 +8,8 @@ """ from quantlib.types cimport Real -from quantlib.handle cimport Handle, shared_ptr +from quantlib._handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib.termstructures._yield_term_structure cimport YieldTermStructure from quantlib.termstructures.volatility.volatilitytype cimport VolatilityType from quantlib.time._daycounter cimport DayCounter diff --git a/quantlib/models/shortrate/calibrationhelpers/swaption_helper.pxd b/quantlib/models/shortrate/calibrationhelpers/swaption_helper.pxd index 19a6a4925..10042594f 100644 --- a/quantlib/models/shortrate/calibrationhelpers/swaption_helper.pxd +++ b/quantlib/models/shortrate/calibrationhelpers/swaption_helper.pxd @@ -7,7 +7,6 @@ FOR A PARTICULAR PURPOSE. See the license for more details. """ -from quantlib.handle cimport shared_ptr from quantlib.models.calibration_helper cimport BlackCalibrationHelper cdef class SwaptionHelper(BlackCalibrationHelper): diff --git a/quantlib/models/shortrate/calibrationhelpers/swaption_helper.pyx b/quantlib/models/shortrate/calibrationhelpers/swaption_helper.pyx index c47b2c80e..de7c87322 100644 --- a/quantlib/models/shortrate/calibrationhelpers/swaption_helper.pyx +++ b/quantlib/models/shortrate/calibrationhelpers/swaption_helper.pyx @@ -6,7 +6,7 @@ # FOR A PARTICULAR PURPOSE. See the license for more details. from quantlib.types cimport Real -from quantlib.handle cimport Handle, shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast from cython.operator cimport dereference as deref from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure diff --git a/quantlib/models/shortrate/onefactor_model.pxd b/quantlib/models/shortrate/onefactor_model.pxd index e1c057c77..116e0f4ac 100644 --- a/quantlib/models/shortrate/onefactor_model.pxd +++ b/quantlib/models/shortrate/onefactor_model.pxd @@ -7,7 +7,7 @@ # FOR A PARTICULAR PURPOSE. See the license for more details. from quantlib.models.model cimport ShortRateModel -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from . cimport _onefactor_model as _ofm cdef class ShortRateDynamics: diff --git a/quantlib/models/shortrate/onefactor_model.pyx b/quantlib/models/shortrate/onefactor_model.pyx index 974373630..c5202bf12 100644 --- a/quantlib/models/shortrate/onefactor_model.pyx +++ b/quantlib/models/shortrate/onefactor_model.pyx @@ -8,7 +8,7 @@ from quantlib.types cimport Rate, Real, Time -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast from quantlib.option cimport OptionType cimport quantlib.models.shortrate._onefactor_model as _ofm cimport quantlib._stochastic_process as _sp diff --git a/quantlib/models/shortrate/onefactormodels/_blackkarasinski.pxd b/quantlib/models/shortrate/onefactormodels/_blackkarasinski.pxd index 388697dff..c2ab935c7 100644 --- a/quantlib/models/shortrate/onefactormodels/_blackkarasinski.pxd +++ b/quantlib/models/shortrate/onefactormodels/_blackkarasinski.pxd @@ -1,6 +1,6 @@ from quantlib.types cimport Real from quantlib.models.shortrate._onefactor_model cimport OneFactorModel -from quantlib.handle cimport Handle, shared_ptr +from quantlib._handle cimport Handle from quantlib.termstructures._yield_term_structure cimport YieldTermStructure cdef extern from 'ql/models/shortrate/onefactormodels/blackkarasinski.hpp' namespace 'QuantLib': diff --git a/quantlib/models/shortrate/onefactormodels/_gaussian1dmodel.pxd b/quantlib/models/shortrate/onefactormodels/_gaussian1dmodel.pxd index 0c32725bc..e1f1567fb 100644 --- a/quantlib/models/shortrate/onefactormodels/_gaussian1dmodel.pxd +++ b/quantlib/models/shortrate/onefactormodels/_gaussian1dmodel.pxd @@ -1,7 +1,8 @@ from libcpp cimport bool from quantlib.time._date cimport Date from quantlib.types cimport Rate, Real, SizeTime -from quantlib.handle cimport Handle, shared_ptr +from quantlib._handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib.termstructures._yield_term_structure cimport YieldTermStructure from quantlib.option cimport OptionType from ..._model cimport TermStructureConsistentModel diff --git a/quantlib/models/shortrate/onefactormodels/blackkarasinski.pyx b/quantlib/models/shortrate/onefactormodels/blackkarasinski.pyx index 0e831ad01..d42ac5ee3 100644 --- a/quantlib/models/shortrate/onefactormodels/blackkarasinski.pyx +++ b/quantlib/models/shortrate/onefactormodels/blackkarasinski.pyx @@ -3,8 +3,8 @@ from quantlib.types cimport Real cimport quantlib.models._model as _mo from . cimport _blackkarasinski as _bk -from quantlib.handle cimport shared_ptr -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.ext cimport shared_ptr +from quantlib.handle cimport HandleYieldTermStructure cdef class BlackKarasinski(OneFactorModel): r"""Standard Black-Karasinski model diff --git a/quantlib/models/shortrate/onefactormodels/hullwhite.pyx b/quantlib/models/shortrate/onefactormodels/hullwhite.pyx index da4676b7f..5237be247 100644 --- a/quantlib/models/shortrate/onefactormodels/hullwhite.pyx +++ b/quantlib/models/shortrate/onefactormodels/hullwhite.pyx @@ -13,7 +13,7 @@ from cython.operator cimport dereference as deref from . cimport _hullwhite as _hw from . cimport _vasicek as _va -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cimport quantlib.termstructures.yields._flat_forward as _ff cimport quantlib.models._calibration_helper as _ch cimport quantlib.models._model as _mo diff --git a/quantlib/models/shortrate/onefactormodels/vasicek.pxd b/quantlib/models/shortrate/onefactormodels/vasicek.pxd index e194df754..de8b333df 100644 --- a/quantlib/models/shortrate/onefactormodels/vasicek.pxd +++ b/quantlib/models/shortrate/onefactormodels/vasicek.pxd @@ -1,5 +1,4 @@ from . cimport _vasicek as _va -from quantlib.handle cimport Handle, shared_ptr from quantlib.models.shortrate.onefactor_model cimport OneFactorAffineModel diff --git a/quantlib/models/shortrate/onefactormodels/vasicek.pyx b/quantlib/models/shortrate/onefactormodels/vasicek.pyx index 890a52420..1b79a4b0c 100644 --- a/quantlib/models/shortrate/onefactormodels/vasicek.pyx +++ b/quantlib/models/shortrate/onefactormodels/vasicek.pyx @@ -10,7 +10,7 @@ from quantlib.types cimport Rate, Real cimport quantlib.models._model as _mo from . cimport _vasicek as _va -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cdef class Vasicek(OneFactorAffineModel): r"""Vasicek model diff --git a/quantlib/models/shortrate/twofactor_model.pxd b/quantlib/models/shortrate/twofactor_model.pxd index f5d81ded5..72e923b18 100644 --- a/quantlib/models/shortrate/twofactor_model.pxd +++ b/quantlib/models/shortrate/twofactor_model.pxd @@ -1,5 +1,5 @@ from quantlib.models.model cimport ShortRateModel -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from . cimport _twofactor_model as _tfm cdef class ShortRateDynamics: diff --git a/quantlib/models/shortrate/twofactor_model.pyx b/quantlib/models/shortrate/twofactor_model.pyx index f48e41977..fe874e64f 100644 --- a/quantlib/models/shortrate/twofactor_model.pyx +++ b/quantlib/models/shortrate/twofactor_model.pyx @@ -1,6 +1,6 @@ from quantlib.types cimport Real, Time -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast from . cimport _twofactor_model as _tfm cimport quantlib._stochastic_process as _sp from quantlib.stochastic_process cimport StochasticProcess1D diff --git a/quantlib/observable.pxd b/quantlib/observable.pxd index 91f8b9ecb..07b2e25f2 100644 --- a/quantlib/observable.pxd +++ b/quantlib/observable.pxd @@ -1,5 +1,5 @@ from ._observable cimport PyObserver, Observable as QlObservable -from .handle cimport shared_ptr +from .ext cimport shared_ptr cdef class Observable: cdef shared_ptr[QlObservable] as_observable(self) noexcept nogil diff --git a/quantlib/payoffs.pxd b/quantlib/payoffs.pxd index 94b8372a5..31f199732 100644 --- a/quantlib/payoffs.pxd +++ b/quantlib/payoffs.pxd @@ -1,4 +1,4 @@ -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from . cimport _payoffs cdef class Payoff: diff --git a/quantlib/pricingengines/_swap.pxd b/quantlib/pricingengines/_swap.pxd index 14f238ee3..1b74215eb 100644 --- a/quantlib/pricingengines/_swap.pxd +++ b/quantlib/pricingengines/_swap.pxd @@ -1,7 +1,8 @@ include '../types.pxi' -from quantlib.handle cimport Handle, optional -from quantlib.termstructures.yields._flat_forward cimport YieldTermStructure +from quantlib.ext cimport optional +from quantlib.handle cimport Handle +from quantlib.termstructures._yield_term_structure cimport YieldTermStructure from libcpp cimport bool from quantlib.time._date cimport Date diff --git a/quantlib/pricingengines/asian/_analyticcontgeomavprice.pxd b/quantlib/pricingengines/asian/_analyticcontgeomavprice.pxd index 2e92a908b..6c40de955 100644 --- a/quantlib/pricingengines/asian/_analyticcontgeomavprice.pxd +++ b/quantlib/pricingengines/asian/_analyticcontgeomavprice.pxd @@ -1,4 +1,4 @@ -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.processes._black_scholes_process cimport GeneralizedBlackScholesProcess from quantlib.pricingengines._pricing_engine cimport PricingEngine diff --git a/quantlib/pricingengines/asian/analyticcontgeomavprice.pyx b/quantlib/pricingengines/asian/analyticcontgeomavprice.pyx index bfde2ca5b..4f4fd4d44 100644 --- a/quantlib/pricingengines/asian/analyticcontgeomavprice.pyx +++ b/quantlib/pricingengines/asian/analyticcontgeomavprice.pyx @@ -1,4 +1,4 @@ -from quantlib.handle cimport static_pointer_cast, shared_ptr +from quantlib.ext cimport static_pointer_cast, shared_ptr cimport quantlib.pricingengines.asian._analyticcontgeomavprice as _acgap from quantlib.processes.black_scholes_process cimport GeneralizedBlackScholesProcess cimport quantlib.processes._black_scholes_process as _bsp diff --git a/quantlib/pricingengines/asian/analyticdiscrgeomavprice.pyx b/quantlib/pricingengines/asian/analyticdiscrgeomavprice.pyx index 1f3f65840..580e4b56b 100644 --- a/quantlib/pricingengines/asian/analyticdiscrgeomavprice.pyx +++ b/quantlib/pricingengines/asian/analyticdiscrgeomavprice.pyx @@ -1,6 +1,6 @@ from cython.operator cimport dereference as deref -from quantlib.handle cimport static_pointer_cast, shared_ptr +from quantlib.ext cimport static_pointer_cast, shared_ptr from quantlib.pricingengines._pricing_engine cimport PricingEngine as QlPricingEngine cimport quantlib.pricingengines.asian._analyticdiscrgeomavprice as _adgap from quantlib.processes.black_scholes_process cimport GeneralizedBlackScholesProcess @@ -21,11 +21,10 @@ cdef class AnalyticDiscreteGeometricAveragePriceAsianEngine(PricingEngine): - the correctness of the available greeks is tested against numerical calculations """ - + def __init__(self, GeneralizedBlackScholesProcess process): cdef shared_ptr[_bsp.GeneralizedBlackScholesProcess] process_ptr = \ static_pointer_cast[_bsp.GeneralizedBlackScholesProcess](process._thisptr) self._thisptr.reset( new _adgap.AnalyticDiscreteGeometricAveragePriceAsianEngine( process_ptr)) - diff --git a/quantlib/pricingengines/bond/_bondfunctions.pxd b/quantlib/pricingengines/bond/_bondfunctions.pxd index 0c41398c8..80f316783 100644 --- a/quantlib/pricingengines/bond/_bondfunctions.pxd +++ b/quantlib/pricingengines/bond/_bondfunctions.pxd @@ -1,7 +1,7 @@ from quantlib.types cimport Rate, Real, Spread, Size, Time from quantlib.instruments._bond cimport Bond -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time._period cimport Frequency from quantlib.time._date cimport Date from quantlib.termstructures._yield_term_structure cimport YieldTermStructure diff --git a/quantlib/pricingengines/bond/_discountingbondengine.pxd b/quantlib/pricingengines/bond/_discountingbondengine.pxd index 197a59b5a..f25fa7ac5 100644 --- a/quantlib/pricingengines/bond/_discountingbondengine.pxd +++ b/quantlib/pricingengines/bond/_discountingbondengine.pxd @@ -9,7 +9,8 @@ from libcpp cimport bool from quantlib.pricingengines._pricing_engine cimport PricingEngine -from quantlib.handle cimport Handle, optional +from quantlib.handle cimport Handle +from quantlib.ext cimport optional from quantlib.termstructures._yield_term_structure cimport YieldTermStructure cdef extern from 'ql/pricingengines/bond/discountingbondengine.hpp' namespace \ diff --git a/quantlib/pricingengines/bond/bondfunctions.pyx b/quantlib/pricingengines/bond/bondfunctions.pyx index 0fb0cd73c..dfa4938d6 100644 --- a/quantlib/pricingengines/bond/bondfunctions.pyx +++ b/quantlib/pricingengines/bond/bondfunctions.pyx @@ -7,7 +7,7 @@ from quantlib.types cimport Rate, Real, Size from quantlib.time.frequency cimport Frequency from . cimport _bondfunctions as _bf -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast from cython.operator cimport dereference as deref from quantlib.instruments.bond cimport Bond, Price from quantlib.time.date cimport date_from_qldate, Date diff --git a/quantlib/pricingengines/credit/_isda_cds_engine.pxd b/quantlib/pricingengines/credit/_isda_cds_engine.pxd index d00821b91..2dd2e7c9a 100644 --- a/quantlib/pricingengines/credit/_isda_cds_engine.pxd +++ b/quantlib/pricingengines/credit/_isda_cds_engine.pxd @@ -2,7 +2,8 @@ include '../../types.pxi' from libcpp cimport bool from libcpp.vector cimport vector -from quantlib.handle cimport Handle, optional, shared_ptr +from quantlib.ext cimport optional, shared_ptr +from quantlib.handle cimport Handle from quantlib.termstructures._default_term_structure cimport DefaultProbabilityTermStructure from quantlib.termstructures._yield_term_structure cimport YieldTermStructure from quantlib.pricingengines._pricing_engine cimport PricingEngine diff --git a/quantlib/pricingengines/credit/_midpoint_cds_engine.pxd b/quantlib/pricingengines/credit/_midpoint_cds_engine.pxd index f89c8c875..8d8910724 100644 --- a/quantlib/pricingengines/credit/_midpoint_cds_engine.pxd +++ b/quantlib/pricingengines/credit/_midpoint_cds_engine.pxd @@ -1,7 +1,8 @@ include '../../types.pxi' from libcpp cimport bool -from quantlib.handle cimport Handle, optional +from quantlib.handle cimport Handle +from quantlib.ext cimport optional from quantlib.termstructures._default_term_structure cimport DefaultProbabilityTermStructure from quantlib.termstructures._yield_term_structure cimport YieldTermStructure from quantlib.pricingengines._pricing_engine cimport PricingEngine diff --git a/quantlib/pricingengines/credit/isda_cds_engine.pyx b/quantlib/pricingengines/credit/isda_cds_engine.pyx index c46d11c7a..cb8d3d1b6 100644 --- a/quantlib/pricingengines/credit/isda_cds_engine.pyx +++ b/quantlib/pricingengines/credit/isda_cds_engine.pyx @@ -1,7 +1,7 @@ from cython.operator cimport dereference as deref from libcpp cimport bool from libcpp.vector cimport vector -from quantlib.handle cimport optional +from quantlib.ext cimport optional from quantlib.pricingengines.engine cimport PricingEngine diff --git a/quantlib/pricingengines/credit/midpoint_cds_engine.pyx b/quantlib/pricingengines/credit/midpoint_cds_engine.pyx index e29c702f7..f775ed27d 100644 --- a/quantlib/pricingengines/credit/midpoint_cds_engine.pyx +++ b/quantlib/pricingengines/credit/midpoint_cds_engine.pyx @@ -8,7 +8,7 @@ from cython.operator cimport dereference as deref from libcpp cimport bool -from quantlib.handle cimport optional +from quantlib.ext cimport optional from . cimport _midpoint_cds_engine as _mce from quantlib.pricingengines.engine cimport PricingEngine diff --git a/quantlib/pricingengines/engine.pxd b/quantlib/pricingengines/engine.pxd index e69139a2d..6f027b791 100644 --- a/quantlib/pricingengines/engine.pxd +++ b/quantlib/pricingengines/engine.pxd @@ -1,4 +1,4 @@ -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cimport quantlib.pricingengines._pricing_engine as _pe cdef class PricingEngine: diff --git a/quantlib/pricingengines/forward/_mc_variance_swap_engine.pxd b/quantlib/pricingengines/forward/_mc_variance_swap_engine.pxd index af669bc69..7a67ea907 100644 --- a/quantlib/pricingengines/forward/_mc_variance_swap_engine.pxd +++ b/quantlib/pricingengines/forward/_mc_variance_swap_engine.pxd @@ -2,7 +2,7 @@ include '../../types.pxi' from libcpp cimport bool -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.pricingengines._pricing_engine cimport PricingEngine from quantlib.processes._black_scholes_process cimport GeneralizedBlackScholesProcess diff --git a/quantlib/pricingengines/forward/_replicating_variance_swap_engine.pxd b/quantlib/pricingengines/forward/_replicating_variance_swap_engine.pxd index c4c3bb81f..546c1f7dc 100644 --- a/quantlib/pricingengines/forward/_replicating_variance_swap_engine.pxd +++ b/quantlib/pricingengines/forward/_replicating_variance_swap_engine.pxd @@ -1,7 +1,7 @@ include '../../types.pxi' from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.pricingengines._pricing_engine cimport PricingEngine from quantlib.processes._black_scholes_process cimport GeneralizedBlackScholesProcess diff --git a/quantlib/pricingengines/forward/mc_variance_swap_engine.pyx b/quantlib/pricingengines/forward/mc_variance_swap_engine.pyx index cb2fbf762..548fd328a 100644 --- a/quantlib/pricingengines/forward/mc_variance_swap_engine.pyx +++ b/quantlib/pricingengines/forward/mc_variance_swap_engine.pyx @@ -4,7 +4,7 @@ from cython.operator cimport dereference as deref from libcpp cimport bool from quantlib.utilities.null cimport Null -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast from quantlib.pricingengines.engine cimport PricingEngine from quantlib.pricingengines._pricing_engine cimport PricingEngine as _PricingEngine from quantlib.processes.black_scholes_process cimport GeneralizedBlackScholesProcess @@ -18,9 +18,9 @@ cdef class MCVarianceSwapEngine(PricingEngine): as described in Demeterfi, Derman, Kamal & Zou, "A Guide to Volatility and Variance Swaps", 1999 - TODO define tolerance of numerical integral and incorporate it + TODO define tolerance of numerical integral and incorporate it in errorEstimate - + Test returned fair variances checked for consistency with implied volatility curve. diff --git a/quantlib/pricingengines/forward/replicating_variance_swap_engine.pyx b/quantlib/pricingengines/forward/replicating_variance_swap_engine.pyx index a2f6eda13..a2318f338 100644 --- a/quantlib/pricingengines/forward/replicating_variance_swap_engine.pyx +++ b/quantlib/pricingengines/forward/replicating_variance_swap_engine.pyx @@ -1,7 +1,7 @@ include '../../types.pxi' from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast from quantlib.processes.black_scholes_process cimport GeneralizedBlackScholesProcess from quantlib.processes._black_scholes_process cimport GeneralizedBlackScholesProcess as _GeneralizedBlackScholesProcess from quantlib.pricingengines._pricing_engine cimport PricingEngine as _PricingEngine diff --git a/quantlib/pricingengines/swap.pyx b/quantlib/pricingengines/swap.pyx index 1be0a9bd9..0dd7a18c1 100644 --- a/quantlib/pricingengines/swap.pyx +++ b/quantlib/pricingengines/swap.pyx @@ -1,9 +1,9 @@ from cython.operator cimport dereference as deref from libcpp cimport bool -from quantlib.handle cimport shared_ptr, optional +from quantlib.ext cimport optional from quantlib.pricingengines.vanilla.vanilla cimport PricingEngine -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure cimport quantlib.pricingengines._swap as _swap cimport quantlib.termstructures._yield_term_structure as _yts diff --git a/quantlib/pricingengines/swaption/_fdg2_swaption_engine.pxd b/quantlib/pricingengines/swaption/_fdg2_swaption_engine.pxd index 959deccce..a79378514 100644 --- a/quantlib/pricingengines/swaption/_fdg2_swaption_engine.pxd +++ b/quantlib/pricingengines/swaption/_fdg2_swaption_engine.pxd @@ -1,5 +1,5 @@ from quantlib.types cimport Real Size -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.models.shortrate.twofactormodels._g2 cimport G2 from quantlib.pricingengines._pricingengine cimport PricingEngine from quantlib.mdethods.finitedifferences.solvers._fdmbackwardsolver cimport FdmSchemeDesc diff --git a/quantlib/pricingengines/swaption/_fdhullwhite_swaption_engine.pxd b/quantlib/pricingengines/swaption/_fdhullwhite_swaption_engine.pxd index 829a7831b..5782fdc35 100644 --- a/quantlib/pricingengines/swaption/_fdhullwhite_swaption_engine.pxd +++ b/quantlib/pricingengines/swaption/_fdhullwhite_swaption_engine.pxd @@ -1,5 +1,5 @@ from quantlib.types cimport Real, Size -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.pricingengines._pricing_engine cimport PricingEngine from quantlib.models.shortrate.onefactormodels._hullwhite cimport HullWhite from quantlib.methods.finitedifferences.solvers._fdmbackwardsolver cimport FdmSchemeDesc diff --git a/quantlib/pricingengines/swaption/_g2_swaption_engine.pxd b/quantlib/pricingengines/swaption/_g2_swaption_engine.pxd index 378bc291a..f2db048db 100644 --- a/quantlib/pricingengines/swaption/_g2_swaption_engine.pxd +++ b/quantlib/pricingengines/swaption/_g2_swaption_engine.pxd @@ -1,5 +1,5 @@ from quantlib.types cimport Real Size -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.models.shortrate.twofactormodels._g2 cimport G2 from quantlib.pricingengines._pricingengine cimport PricingEngine diff --git a/quantlib/pricingengines/swaption/_jamshidian_swaption_engine.pxd b/quantlib/pricingengines/swaption/_jamshidian_swaption_engine.pxd index ac9206808..a7bd54c60 100644 --- a/quantlib/pricingengines/swaption/_jamshidian_swaption_engine.pxd +++ b/quantlib/pricingengines/swaption/_jamshidian_swaption_engine.pxd @@ -1,4 +1,5 @@ -from quantlib.handle cimport shared_ptr, Handle +from quantlib.handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib.termstructures._yield_term_structure cimport YieldTermStructure from quantlib.pricingengines._pricing_engine cimport PricingEngine cimport quantlib.models.shortrate._onefactor_model as _ofm diff --git a/quantlib/pricingengines/swaption/_tree_swaption_engine.pxd b/quantlib/pricingengines/swaption/_tree_swaption_engine.pxd index 1bf8389e7..7de6ddea0 100644 --- a/quantlib/pricingengines/swaption/_tree_swaption_engine.pxd +++ b/quantlib/pricingengines/swaption/_tree_swaption_engine.pxd @@ -1,4 +1,5 @@ -from quantlib.handle cimport Handle, shared_ptr +from quantlib._handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib.types cimport Size from quantlib.models.shortrate._onefactor_model cimport ShortRateModel from quantlib.termstructures._yield_term_structure cimport YieldTermStructure diff --git a/quantlib/pricingengines/swaption/fdhullwhite_swaption_engine.pyx b/quantlib/pricingengines/swaption/fdhullwhite_swaption_engine.pyx index d28755f3b..9dd7caee4 100644 --- a/quantlib/pricingengines/swaption/fdhullwhite_swaption_engine.pyx +++ b/quantlib/pricingengines/swaption/fdhullwhite_swaption_engine.pyx @@ -1,6 +1,6 @@ from cython.operator cimport dereference as deref from quantlib.types cimport Real, Size -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast from quantlib.methods.finitedifferences.solvers.fdmbackwardsolver cimport FdmSchemeDesc from quantlib.models.shortrate.onefactormodels.hullwhite cimport HullWhite from quantlib.pricingengines.engine cimport PricingEngine diff --git a/quantlib/pricingengines/swaption/tree_swaption_engine.pyx b/quantlib/pricingengines/swaption/tree_swaption_engine.pyx index e098f8ff3..4fda82224 100644 --- a/quantlib/pricingengines/swaption/tree_swaption_engine.pyx +++ b/quantlib/pricingengines/swaption/tree_swaption_engine.pyx @@ -1,4 +1,4 @@ -from quantlib.handle cimport Handle, shared_ptr, static_pointer_cast +from quantlib.ext cimport static_pointer_cast from quantlib.types cimport Size cimport quantlib.models._model as _mo from quantlib.models.model cimport ShortRateModel diff --git a/quantlib/pricingengines/vanilla/_analytic_heston_engine.pxd b/quantlib/pricingengines/vanilla/_analytic_heston_engine.pxd index 95b18492c..fa6f4864a 100644 --- a/quantlib/pricingengines/vanilla/_analytic_heston_engine.pxd +++ b/quantlib/pricingengines/vanilla/_analytic_heston_engine.pxd @@ -1,5 +1,5 @@ from quantlib.types cimport Real, Size -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.models.equity._heston_model cimport HestonModel from quantlib.pricingengines._pricing_engine cimport PricingEngine diff --git a/quantlib/pricingengines/vanilla/_fdblackscholesvanillaengine.pxd b/quantlib/pricingengines/vanilla/_fdblackscholesvanillaengine.pxd index 3ccd828f7..b5e86089e 100644 --- a/quantlib/pricingengines/vanilla/_fdblackscholesvanillaengine.pxd +++ b/quantlib/pricingengines/vanilla/_fdblackscholesvanillaengine.pxd @@ -1,5 +1,5 @@ from libcpp cimport bool -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.types cimport Size, Real from quantlib.instruments._vanillaoption cimport VanillaOption from quantlib.instruments._dividendschedule cimport DividendSchedule diff --git a/quantlib/pricingengines/vanilla/_mceuropeanhestonengine.pxd b/quantlib/pricingengines/vanilla/_mceuropeanhestonengine.pxd index a3d063f20..7500a7991 100644 --- a/quantlib/pricingengines/vanilla/_mceuropeanhestonengine.pxd +++ b/quantlib/pricingengines/vanilla/_mceuropeanhestonengine.pxd @@ -2,7 +2,7 @@ from quantlib.types cimport BigNatural, Real, Size from libcpp cimport bool from quantlib.processes._heston_process cimport HestonProcess from quantlib.pricingengines._pricing_engine cimport PricingEngine -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from ._mcvanillaengine cimport MCVanillaEngine from quantlib.methods.montecarlo._mctraits cimport MultiVariate diff --git a/quantlib/pricingengines/vanilla/_mchestonhullwhiteengine.pxd b/quantlib/pricingengines/vanilla/_mchestonhullwhiteengine.pxd index dd8de0c3c..0c2ccb6d1 100644 --- a/quantlib/pricingengines/vanilla/_mchestonhullwhiteengine.pxd +++ b/quantlib/pricingengines/vanilla/_mchestonhullwhiteengine.pxd @@ -2,7 +2,7 @@ from quantlib.types cimport BigNatural, Real, Size from libcpp cimport bool from quantlib.processes._hybrid_heston_hullwhite_process cimport HybridHestonHullWhiteProcess from quantlib.pricingengines._pricing_engine cimport PricingEngine -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from ._mcvanillaengine cimport MCVanillaEngine from quantlib.methods.montecarlo._mctraits cimport MultiVariate diff --git a/quantlib/pricingengines/vanilla/_mcvanillaengine.pxd b/quantlib/pricingengines/vanilla/_mcvanillaengine.pxd index fc253e5d1..046494a87 100644 --- a/quantlib/pricingengines/vanilla/_mcvanillaengine.pxd +++ b/quantlib/pricingengines/vanilla/_mcvanillaengine.pxd @@ -9,7 +9,7 @@ from quantlib.types cimport BigNatural, Real, Size from libcpp cimport bool -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cimport quantlib._stochastic_process as _sp from quantlib.pricingengines._pricing_engine cimport PricingEngine diff --git a/quantlib/pricingengines/vanilla/_vanilla.pxd b/quantlib/pricingengines/vanilla/_vanilla.pxd index 82e243955..dd963be5d 100644 --- a/quantlib/pricingengines/vanilla/_vanilla.pxd +++ b/quantlib/pricingengines/vanilla/_vanilla.pxd @@ -3,7 +3,7 @@ include '../../types.pxi' from libcpp cimport bool from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.instruments._dividendschedule cimport DividendSchedule from quantlib.processes._black_scholes_process cimport GeneralizedBlackScholesProcess from quantlib.models.shortrate.onefactormodels._hullwhite cimport HullWhite diff --git a/quantlib/pricingengines/vanilla/fdblackscholesvanillaengine.pyx b/quantlib/pricingengines/vanilla/fdblackscholesvanillaengine.pyx index c19686d47..db257cad7 100644 --- a/quantlib/pricingengines/vanilla/fdblackscholesvanillaengine.pyx +++ b/quantlib/pricingengines/vanilla/fdblackscholesvanillaengine.pyx @@ -3,7 +3,7 @@ from libcpp cimport bool from cython.operator cimport dereference as deref from quantlib.utilities.null cimport Null from quantlib.instruments.dividendschedule cimport DividendSchedule -from quantlib.handle cimport static_pointer_cast, shared_ptr +from quantlib.ext cimport static_pointer_cast, shared_ptr from quantlib.types cimport Size, Real from quantlib.pricingengines._pricing_engine cimport PricingEngine as QlPricingEngine from quantlib.processes.black_scholes_process cimport GeneralizedBlackScholesProcess diff --git a/quantlib/pricingengines/vanilla/mceuropeanhestonengine.pyx b/quantlib/pricingengines/vanilla/mceuropeanhestonengine.pyx index 62abd062b..daeedcbb5 100644 --- a/quantlib/pricingengines/vanilla/mceuropeanhestonengine.pyx +++ b/quantlib/pricingengines/vanilla/mceuropeanhestonengine.pyx @@ -1,7 +1,7 @@ from quantlib.types cimport BigNatural, Integer, Real, Size from libcpp cimport bool from quantlib._defines cimport QL_MAX_INTEGER -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast from quantlib.utilities.null cimport Null from quantlib.processes.heston_process cimport HestonProcess cimport quantlib.processes._heston_process as _hp diff --git a/quantlib/pricingengines/vanilla/mchestonhullwhiteengine.pyx b/quantlib/pricingengines/vanilla/mchestonhullwhiteengine.pyx index a20d0cc2b..0cafb54d4 100644 --- a/quantlib/pricingengines/vanilla/mchestonhullwhiteengine.pyx +++ b/quantlib/pricingengines/vanilla/mchestonhullwhiteengine.pyx @@ -1,6 +1,6 @@ from quantlib.types cimport BigNatural, Integer, Real, Size from libcpp cimport bool -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast from quantlib.utilities.null cimport Null from quantlib.processes.hybrid_heston_hullwhite_process cimport HybridHestonHullWhiteProcess cimport quantlib.processes._hybrid_heston_hullwhite_process as _hhwp diff --git a/quantlib/pricingengines/vanilla/vanilla.pyx b/quantlib/pricingengines/vanilla/vanilla.pyx index 66697f7f2..004d45d9a 100644 --- a/quantlib/pricingengines/vanilla/vanilla.pyx +++ b/quantlib/pricingengines/vanilla/vanilla.pyx @@ -5,7 +5,7 @@ from libcpp cimport bool from cython.operator cimport dereference as deref from quantlib.instruments.dividendschedule cimport DividendSchedule -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast cimport quantlib.processes._black_scholes_process as _bsp cimport quantlib.models.equity._bates_model as _bm cimport quantlib.models.shortrate.onefactormodels._hullwhite as _hw diff --git a/quantlib/processes/_black_scholes_process.pxd b/quantlib/processes/_black_scholes_process.pxd index 5d66ab16b..2098d3116 100644 --- a/quantlib/processes/_black_scholes_process.pxd +++ b/quantlib/processes/_black_scholes_process.pxd @@ -9,8 +9,8 @@ include '../types.pxi' -from quantlib.handle cimport Handle, shared_ptr -from quantlib.termstructures.yields._flat_forward cimport YieldTermStructure +from quantlib.handle cimport Handle +from quantlib.termstructures._yield_term_structure cimport YieldTermStructure cimport quantlib._quote as _qt from quantlib._stochastic_process cimport StochasticProcess1D from quantlib.termstructures.volatility.equityfx._black_vol_term_structure cimport BlackVolTermStructure diff --git a/quantlib/processes/_heston_process.pxd b/quantlib/processes/_heston_process.pxd index b94a769a4..a8ce0673c 100644 --- a/quantlib/processes/_heston_process.pxd +++ b/quantlib/processes/_heston_process.pxd @@ -7,7 +7,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. """ -from quantlib.handle cimport Handle, shared_ptr +from quantlib._handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib.termstructures.yields._flat_forward cimport YieldTermStructure from quantlib.types cimport Real, Size cimport quantlib._quote as _qt diff --git a/quantlib/processes/_hybrid_heston_hullwhite_process.pxd b/quantlib/processes/_hybrid_heston_hullwhite_process.pxd index e3eb11b2a..884c85a0c 100644 --- a/quantlib/processes/_hybrid_heston_hullwhite_process.pxd +++ b/quantlib/processes/_hybrid_heston_hullwhite_process.pxd @@ -1,5 +1,5 @@ from quantlib.types cimport Real -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib._stochastic_process cimport StochasticProcess from ._heston_process cimport HestonProcess from ._hullwhite_process cimport HullWhiteForwardProcess diff --git a/quantlib/processes/bates_process.pyx b/quantlib/processes/bates_process.pyx index 49edb1e3e..e2f166dab 100644 --- a/quantlib/processes/bates_process.pyx +++ b/quantlib/processes/bates_process.pyx @@ -14,7 +14,7 @@ cimport quantlib._stochastic_process as _sp from ._heston_process cimport BatesProcess as QlBatesProcess from .heston_process cimport HestonProcess, Discretization, FullTruncation -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.quote cimport Quote from quantlib.quotes.simplequote cimport SimpleQuote from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure diff --git a/quantlib/processes/hybrid_heston_hullwhite_process.pyx b/quantlib/processes/hybrid_heston_hullwhite_process.pyx index faef55441..3e551fc4c 100644 --- a/quantlib/processes/hybrid_heston_hullwhite_process.pyx +++ b/quantlib/processes/hybrid_heston_hullwhite_process.pyx @@ -1,5 +1,5 @@ from quantlib.types cimport Real -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast from .hullwhite_process cimport HullWhiteForwardProcess from .heston_process cimport HestonProcess from . cimport _hullwhite_process as _hw diff --git a/quantlib/quote.pxd b/quantlib/quote.pxd index 7b061d5fc..4452732a1 100644 --- a/quantlib/quote.pxd +++ b/quantlib/quote.pxd @@ -1,5 +1,6 @@ cimport quantlib._quote as _qt -from quantlib.handle cimport Handle, shared_ptr +from quantlib._handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib.observable cimport Observable cdef class Quote(Observable): diff --git a/quantlib/quote.pyx b/quantlib/quote.pyx index 7fc10911d..8649357c5 100644 --- a/quantlib/quote.pyx +++ b/quantlib/quote.pyx @@ -1,5 +1,5 @@ """Abstract base class for market observables""" -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast from quantlib._observable cimport Observable as QlObservable cdef class Quote(Observable): diff --git a/quantlib/quotes/_futuresconvadjustmentquote.pxd b/quantlib/quotes/_futuresconvadjustmentquote.pxd index 21d8df1f5..200b4b3f9 100644 --- a/quantlib/quotes/_futuresconvadjustmentquote.pxd +++ b/quantlib/quotes/_futuresconvadjustmentquote.pxd @@ -1,5 +1,6 @@ from libcpp.string cimport string -from quantlib.handle cimport Handle, shared_ptr +from quantlib._handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib.types cimport Real from quantlib.time._date cimport Date from quantlib.indexes._ibor_index cimport IborIndex diff --git a/quantlib/quotes/futuresconvadjustmentquote.pyx b/quantlib/quotes/futuresconvadjustmentquote.pyx index 28752c0ef..fe76b1287 100644 --- a/quantlib/quotes/futuresconvadjustmentquote.pyx +++ b/quantlib/quotes/futuresconvadjustmentquote.pyx @@ -1,6 +1,6 @@ from libcpp.string cimport string from cython.operator cimport dereference as deref -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast from quantlib.time.date cimport Date, _pydate_from_qldate from quantlib.indexes.ibor_index cimport IborIndex cimport quantlib.indexes._ibor_index as _ii diff --git a/quantlib/settings.pyx b/quantlib/settings.pyx index 977008eb4..1e3239613 100644 --- a/quantlib/settings.pyx +++ b/quantlib/settings.pyx @@ -1,7 +1,7 @@ from cython.operator cimport dereference as deref from libcpp cimport bool -from quantlib.handle cimport optional, shared_ptr, nullopt +from quantlib.ext cimport optional, shared_ptr, nullopt from quantlib.time._date cimport Date as QlDate from quantlib.time.date cimport Date, date_from_qldate from quantlib.observable cimport Observable diff --git a/quantlib/sim/simulate.pyx b/quantlib/sim/simulate.pyx index dad01dca2..262cc2b30 100644 --- a/quantlib/sim/simulate.pyx +++ b/quantlib/sim/simulate.pyx @@ -1,7 +1,7 @@ include '../types.pxi' from cython.operator cimport dereference as deref -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from libcpp cimport bool cimport quantlib._stochastic_process as _sp diff --git a/quantlib/stochastic_process.pxd b/quantlib/stochastic_process.pxd index c062c48bf..658ac0668 100644 --- a/quantlib/stochastic_process.pxd +++ b/quantlib/stochastic_process.pxd @@ -1,4 +1,4 @@ -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cimport quantlib._stochastic_process as _sp cdef class StochasticProcess: diff --git a/quantlib/termstructure.pxd b/quantlib/termstructure.pxd index a870f3a91..68be57b83 100644 --- a/quantlib/termstructure.pxd +++ b/quantlib/termstructure.pxd @@ -1,6 +1,6 @@ from . cimport _termstructure as _ts from quantlib.observable cimport Observable -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib._observable cimport Observable as QlObservable cdef class TermStructure(Observable): diff --git a/quantlib/termstructure.pyx b/quantlib/termstructure.pyx index b5570b730..9850fcdd9 100644 --- a/quantlib/termstructure.pyx +++ b/quantlib/termstructure.pyx @@ -1,4 +1,4 @@ -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast from quantlib.time.date cimport Date, date_from_qldate from quantlib.time._date cimport Date as QlDate from quantlib.time.daycounter cimport DayCounter diff --git a/quantlib/termstructures/_inflation_term_structure.pxd b/quantlib/termstructures/_inflation_term_structure.pxd index bccca5d10..45d982137 100644 --- a/quantlib/termstructures/_inflation_term_structure.pxd +++ b/quantlib/termstructures/_inflation_term_structure.pxd @@ -11,7 +11,8 @@ include '../types.pxi' from libcpp cimport bool -from quantlib.handle cimport shared_ptr, Handle +from quantlib.ext cimport shared_ptr +from quantlib.handle cimport Handle from quantlib.time._date cimport Date from quantlib.time._calendar cimport Calendar from quantlib.time._daycounter cimport DayCounter diff --git a/quantlib/termstructures/_yield_term_structure.pxd b/quantlib/termstructures/_yield_term_structure.pxd index 2db50a6bd..7eb2f4a0b 100644 --- a/quantlib/termstructures/_yield_term_structure.pxd +++ b/quantlib/termstructures/_yield_term_structure.pxd @@ -11,7 +11,6 @@ from quantlib.types cimport * from libcpp cimport bool from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr, Handle, RelinkableHandle from quantlib.time._calendar cimport Calendar from quantlib.time._date cimport Date, Period from quantlib.time._daycounter cimport DayCounter diff --git a/quantlib/termstructures/credit/_credit_helpers.pxd b/quantlib/termstructures/credit/_credit_helpers.pxd index e8026d38e..bb65f9088 100644 --- a/quantlib/termstructures/credit/_credit_helpers.pxd +++ b/quantlib/termstructures/credit/_credit_helpers.pxd @@ -11,7 +11,8 @@ include '../../types.pxi' from libcpp cimport bool -from quantlib.handle cimport Handle, shared_ptr +from quantlib.ext cimport shared_ptr +from quantlib.handle cimport Handle from quantlib._quote cimport Quote from quantlib.time._calendar cimport BusinessDayConvention, Calendar from quantlib.time._date cimport Date diff --git a/quantlib/termstructures/credit/_piecewise_default_curve.pxd b/quantlib/termstructures/credit/_piecewise_default_curve.pxd index d7be7db2c..b4d334bcb 100644 --- a/quantlib/termstructures/credit/_piecewise_default_curve.pxd +++ b/quantlib/termstructures/credit/_piecewise_default_curve.pxd @@ -11,7 +11,7 @@ include '../../types.pxi' from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.termstructures.credit._credit_helpers cimport DefaultProbabilityHelper from quantlib.termstructures._default_term_structure cimport DefaultProbabilityTermStructure from quantlib.time._date cimport Date diff --git a/quantlib/termstructures/credit/default_probability_helpers.pxd b/quantlib/termstructures/credit/default_probability_helpers.pxd index 3c1b56f37..0caf3d4f8 100644 --- a/quantlib/termstructures/credit/default_probability_helpers.pxd +++ b/quantlib/termstructures/credit/default_probability_helpers.pxd @@ -1,4 +1,4 @@ -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cimport quantlib.termstructures.credit._credit_helpers as _ci cdef class DefaultProbabilityHelper: diff --git a/quantlib/termstructures/credit/default_probability_helpers.pyx b/quantlib/termstructures/credit/default_probability_helpers.pyx index 4275ca8cc..94f6863c8 100644 --- a/quantlib/termstructures/credit/default_probability_helpers.pyx +++ b/quantlib/termstructures/credit/default_probability_helpers.pyx @@ -11,7 +11,7 @@ include '../../types.pxi' from cython.operator cimport dereference as deref from libcpp cimport bool -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast cimport quantlib.termstructures.credit._credit_helpers as _ci cimport quantlib.termstructures._yield_term_structure as _yts @@ -24,7 +24,7 @@ from quantlib.time.date cimport Period, date_from_qldate, Date cimport quantlib.time._date as _date from quantlib.time.calendar cimport Calendar from quantlib.time.daycounter cimport DayCounter -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure cimport quantlib._quote as _qt from quantlib.termstructures.default_term_structure cimport DefaultProbabilityTermStructure from quantlib.instruments.credit_default_swap cimport CreditDefaultSwap diff --git a/quantlib/termstructures/credit/flat_hazard_rate.pyx b/quantlib/termstructures/credit/flat_hazard_rate.pyx index 3c25faab5..dee766e52 100644 --- a/quantlib/termstructures/credit/flat_hazard_rate.pyx +++ b/quantlib/termstructures/credit/flat_hazard_rate.pyx @@ -1,12 +1,10 @@ include '../../types.pxi' from cython.operator cimport dereference as deref -from quantlib.handle cimport shared_ptr from quantlib.termstructures.default_term_structure cimport DefaultProbabilityTermStructure cimport quantlib.termstructures.credit._flat_hazardrate as _fhr -cimport quantlib.termstructures._default_term_structure as _dts from quantlib.time.date cimport Date from quantlib.time.daycounter cimport DayCounter from quantlib.time.calendar cimport Calendar @@ -32,13 +30,13 @@ cdef class FlatHazardRate(DefaultProbabilityTermStructure): def __init__(self, int settlement_days, Calendar calendar not None, hazard_rate, DayCounter day_counter not None): if isinstance(hazard_rate, float): - self._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure]( + self._thisptr.reset( new _fhr.FlatHazardRate(settlement_days, calendar._thisptr, hazard_rate, deref(day_counter._thisptr))) elif isinstance(hazard_rate, Quote): - self._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure]( + self._thisptr.reset( new _fhr.FlatHazardRate( settlement_days, calendar._thisptr, @@ -65,12 +63,12 @@ cdef class FlatHazardRate(DefaultProbabilityTermStructure): cdef FlatHazardRate instance = cls.__new__(cls) if isinstance(hazard_rate, float): - instance._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure]( + instance._thisptr.reset( new _fhr.FlatHazardRate(reference_date._thisptr, hazard_rate, deref(day_counter._thisptr))) elif isinstance(hazard_rate, Quote): - instance._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure]( + instance._thisptr.reset( new _fhr.FlatHazardRate( reference_date._thisptr, ((hazard_rate).handle()), diff --git a/quantlib/termstructures/credit/interpolated_hazardrate_curve.pyx b/quantlib/termstructures/credit/interpolated_hazardrate_curve.pyx index e9b807bcc..b59793fab 100644 --- a/quantlib/termstructures/credit/interpolated_hazardrate_curve.pyx +++ b/quantlib/termstructures/credit/interpolated_hazardrate_curve.pyx @@ -1,6 +1,6 @@ from libcpp.vector cimport vector from cython.operator cimport dereference as deref -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr include '../../types.pxi' diff --git a/quantlib/termstructures/credit/piecewise_default_curve.pyx b/quantlib/termstructures/credit/piecewise_default_curve.pyx index 70973ac5a..a1a8e39ea 100644 --- a/quantlib/termstructures/credit/piecewise_default_curve.pyx +++ b/quantlib/termstructures/credit/piecewise_default_curve.pyx @@ -8,7 +8,7 @@ from libcpp.string cimport string from . cimport _piecewise_default_curve as _pdc -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time.date cimport Date, date_from_qldate cimport quantlib.time._date as _date from quantlib.time.daycounter cimport DayCounter diff --git a/quantlib/termstructures/default_term_structure.pyx b/quantlib/termstructures/default_term_structure.pyx index e3ff4fc11..7555b04dc 100644 --- a/quantlib/termstructures/default_term_structure.pyx +++ b/quantlib/termstructures/default_term_structure.pyx @@ -3,7 +3,7 @@ from libcpp cimport bool from libcpp.vector cimport vector from quantlib.time.date cimport Date, date_from_qldate cimport quantlib.time._date as _date -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast cdef class DefaultProbabilityTermStructure(TermStructure): diff --git a/quantlib/termstructures/inflation/_inflation_helpers.pxd b/quantlib/termstructures/inflation/_inflation_helpers.pxd index 8aa1a81e2..1559bd8be 100644 --- a/quantlib/termstructures/inflation/_inflation_helpers.pxd +++ b/quantlib/termstructures/inflation/_inflation_helpers.pxd @@ -1,5 +1,6 @@ from quantlib._quote cimport Quote -from quantlib.handle cimport shared_ptr, Handle +from quantlib.ext cimport shared_ptr +from quantlib.handle cimport Handle from quantlib.time.businessdayconvention cimport BusinessDayConvention from quantlib.time._date cimport Date from quantlib.time._daycounter cimport DayCounter diff --git a/quantlib/termstructures/inflation/_interpolated_zero_inflation_curve.pxd b/quantlib/termstructures/inflation/_interpolated_zero_inflation_curve.pxd index 0a953b090..4d7e47038 100644 --- a/quantlib/termstructures/inflation/_interpolated_zero_inflation_curve.pxd +++ b/quantlib/termstructures/inflation/_interpolated_zero_inflation_curve.pxd @@ -9,7 +9,7 @@ from quantlib.time._date cimport Date from quantlib.time._daycounter cimport DayCounter from quantlib.time._calendar cimport Calendar from quantlib.time._period cimport Frequency, Period -from quantlib.handle cimport Handle, shared_ptr +from quantlib.ext cimport shared_ptr from ._seasonality cimport Seasonality cdef extern from 'ql/termstructures/inflation/interpolatedzeroinflationcurve.hpp' namespace 'QuantLib' nogil: diff --git a/quantlib/termstructures/inflation/_piecewise_zero_inflation_curve.pxd b/quantlib/termstructures/inflation/_piecewise_zero_inflation_curve.pxd index be9517fd1..f0d12b9de 100644 --- a/quantlib/termstructures/inflation/_piecewise_zero_inflation_curve.pxd +++ b/quantlib/termstructures/inflation/_piecewise_zero_inflation_curve.pxd @@ -1,6 +1,6 @@ from quantlib.types cimport Real from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time._date cimport Date from quantlib.time._period cimport Frequency from quantlib.time._daycounter cimport DayCounter diff --git a/quantlib/termstructures/inflation/inflation_helpers.pxd b/quantlib/termstructures/inflation/inflation_helpers.pxd index 3546dc6b0..91c429201 100644 --- a/quantlib/termstructures/inflation/inflation_helpers.pxd +++ b/quantlib/termstructures/inflation/inflation_helpers.pxd @@ -1,4 +1,4 @@ -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.termstructures.inflation.inflation_traits cimport ( ZeroInflationTraits, YoYInflationTraits ) diff --git a/quantlib/termstructures/inflation/inflation_helpers.pyx b/quantlib/termstructures/inflation/inflation_helpers.pyx index f68a2de07..73f212995 100644 --- a/quantlib/termstructures/inflation/inflation_helpers.pyx +++ b/quantlib/termstructures/inflation/inflation_helpers.pyx @@ -1,7 +1,7 @@ from cython.operator cimport dereference as deref from . cimport _inflation_helpers as _ih -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast from quantlib.time.businessdayconvention cimport BusinessDayConvention from quantlib.quote cimport Quote from quantlib.time.daycounter cimport DayCounter diff --git a/quantlib/termstructures/inflation/piecewise_zero_inflation_curve.pyx b/quantlib/termstructures/inflation/piecewise_zero_inflation_curve.pyx index af10d6823..16c514b9b 100644 --- a/quantlib/termstructures/inflation/piecewise_zero_inflation_curve.pyx +++ b/quantlib/termstructures/inflation/piecewise_zero_inflation_curve.pyx @@ -1,7 +1,7 @@ from quantlib.types cimport Real from libcpp.vector cimport vector from cython.operator cimport dereference as deref -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time._period cimport Frequency from quantlib.time.date cimport Date diff --git a/quantlib/termstructures/inflation/seasonality.pxd b/quantlib/termstructures/inflation/seasonality.pxd index 8e09870cd..0220012c4 100644 --- a/quantlib/termstructures/inflation/seasonality.pxd +++ b/quantlib/termstructures/inflation/seasonality.pxd @@ -8,7 +8,7 @@ """ from . cimport _seasonality as _se -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cdef class Seasonality: cdef shared_ptr[_se.Seasonality] _thisptr diff --git a/quantlib/termstructures/inflation/seasonality.pyx b/quantlib/termstructures/inflation/seasonality.pyx index cf053b2f7..8dddf7e53 100644 --- a/quantlib/termstructures/inflation/seasonality.pyx +++ b/quantlib/termstructures/inflation/seasonality.pyx @@ -6,7 +6,7 @@ # FOR A PARTICULAR PURPOSE. See the license for more details. from quantlib.types cimport Rate -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from cython.operator cimport dereference as deref from libcpp.vector cimport vector diff --git a/quantlib/termstructures/inflation_term_structure.pyx b/quantlib/termstructures/inflation_term_structure.pyx index 87e88c92c..1109040d3 100644 --- a/quantlib/termstructures/inflation_term_structure.pyx +++ b/quantlib/termstructures/inflation_term_structure.pyx @@ -14,7 +14,7 @@ from quantlib.time.date cimport Date, Period, date_from_qldate, period_from_qlpe from libcpp.vector cimport vector from cython.operator cimport dereference as deref -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast cimport quantlib.time._daycounter as _dc from quantlib.time.daycounter cimport DayCounter diff --git a/quantlib/termstructures/vol_term_structure.pxd b/quantlib/termstructures/vol_term_structure.pxd index 26deb4bdd..f197cf7d8 100644 --- a/quantlib/termstructures/vol_term_structure.pxd +++ b/quantlib/termstructures/vol_term_structure.pxd @@ -1,5 +1,5 @@ from libcpp cimport bool as cbool -from quantlib.handle cimport Handle, RelinkableHandle, shared_ptr +from quantlib.ext cimport shared_ptr from . cimport _vol_term_structure as _vts cdef class VolatilityTermStructure: diff --git a/quantlib/termstructures/volatility/_sabr_interpolated_smilesection.pxd b/quantlib/termstructures/volatility/_sabr_interpolated_smilesection.pxd index bee455c69..c20b96cee 100644 --- a/quantlib/termstructures/volatility/_sabr_interpolated_smilesection.pxd +++ b/quantlib/termstructures/volatility/_sabr_interpolated_smilesection.pxd @@ -1,7 +1,8 @@ include "../../types.pxi" from ._smilesection cimport SmileSection from quantlib._quote cimport Quote -from quantlib.handle cimport Handle, shared_ptr +from quantlib._handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib.time._daycounter cimport DayCounter from quantlib.time._date cimport Date from quantlib.math._optimization cimport EndCriteria, OptimizationMethod diff --git a/quantlib/termstructures/volatility/equityfx/black_constant_vol.pyx b/quantlib/termstructures/volatility/equityfx/black_constant_vol.pyx index 594f61231..e4fb6edb1 100644 --- a/quantlib/termstructures/volatility/equityfx/black_constant_vol.pyx +++ b/quantlib/termstructures/volatility/equityfx/black_constant_vol.pyx @@ -1,6 +1,5 @@ from cython.operator cimport dereference as deref -from quantlib.handle cimport shared_ptr from quantlib.time.calendar cimport Calendar from quantlib.time.date cimport Date from quantlib.time.daycounter cimport DayCounter diff --git a/quantlib/termstructures/volatility/equityfx/black_variance_curve.pyx b/quantlib/termstructures/volatility/equityfx/black_variance_curve.pyx index 20721354f..f60340b8a 100644 --- a/quantlib/termstructures/volatility/equityfx/black_variance_curve.pyx +++ b/quantlib/termstructures/volatility/equityfx/black_variance_curve.pyx @@ -4,7 +4,7 @@ from cython.operator cimport dereference as deref from libcpp cimport bool from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time.date cimport Date, date_from_qldate from quantlib.time._date cimport Date as _Date from quantlib.time.daycounter cimport DayCounter diff --git a/quantlib/termstructures/volatility/equityfx/black_variance_surface.pyx b/quantlib/termstructures/volatility/equityfx/black_variance_surface.pyx index 621960715..2aceeee05 100644 --- a/quantlib/termstructures/volatility/equityfx/black_variance_surface.pyx +++ b/quantlib/termstructures/volatility/equityfx/black_variance_surface.pyx @@ -4,7 +4,6 @@ from cython.operator cimport dereference as deref from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr from quantlib.math.matrix cimport Matrix from quantlib.math.interpolation cimport Interpolation, Bilinear, Bicubic diff --git a/quantlib/termstructures/volatility/equityfx/local_vol_surface.pyx b/quantlib/termstructures/volatility/equityfx/local_vol_surface.pyx index 70ba37fa8..40297ac12 100644 --- a/quantlib/termstructures/volatility/equityfx/local_vol_surface.pyx +++ b/quantlib/termstructures/volatility/equityfx/local_vol_surface.pyx @@ -6,7 +6,7 @@ from .black_vol_term_structure cimport BlackVolTermStructure from . cimport _black_vol_term_structure as _bvts from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure from quantlib.quote cimport Quote -from quantlib.handle cimport static_pointer_cast, Handle +from quantlib.ext cimport static_pointer_cast from quantlib.time.date cimport Date cdef class LocalVolSurface(LocalVolTermStructure): diff --git a/quantlib/termstructures/volatility/optionlet/optionlet_volatility_structure.pxd b/quantlib/termstructures/volatility/optionlet/optionlet_volatility_structure.pxd index 7a6de76d6..56ff23838 100644 --- a/quantlib/termstructures/volatility/optionlet/optionlet_volatility_structure.pxd +++ b/quantlib/termstructures/volatility/optionlet/optionlet_volatility_structure.pxd @@ -1,5 +1,6 @@ -from quantlib.handle cimport shared_ptr from . cimport _optionlet_volatility_structure as _ov +from quantlib.ext cimport shared_ptr +from quantlib.handle cimport Handle cdef class OptionletVolatilityStructure: cdef shared_ptr[_ov.OptionletVolatilityStructure] _thisptr diff --git a/quantlib/termstructures/volatility/sabr_interpolated_smilesection.pyx b/quantlib/termstructures/volatility/sabr_interpolated_smilesection.pyx index 5ce980537..5412803d5 100644 --- a/quantlib/termstructures/volatility/sabr_interpolated_smilesection.pyx +++ b/quantlib/termstructures/volatility/sabr_interpolated_smilesection.pyx @@ -5,7 +5,8 @@ from libcpp.vector cimport vector from libcpp cimport bool from . cimport _smilesection as _ss -from quantlib.handle cimport shared_ptr, Handle +from quantlib.ext cimport shared_ptr +from quantlib.handle cimport Handle from quantlib.quote cimport Quote cimport quantlib._quote as _qt from quantlib.math.optimization cimport EndCriteria, OptimizationMethod diff --git a/quantlib/termstructures/volatility/smilesection.pxd b/quantlib/termstructures/volatility/smilesection.pxd index 83d3c93c3..bd9be028c 100644 --- a/quantlib/termstructures/volatility/smilesection.pxd +++ b/quantlib/termstructures/volatility/smilesection.pxd @@ -1,4 +1,4 @@ -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from . cimport _smilesection as _ss cdef class SmileSection: diff --git a/quantlib/termstructures/volatility/swaption/_sabr_swaption_volatility_cube.pxd b/quantlib/termstructures/volatility/swaption/_sabr_swaption_volatility_cube.pxd index 0808e7205..6c5df5397 100644 --- a/quantlib/termstructures/volatility/swaption/_sabr_swaption_volatility_cube.pxd +++ b/quantlib/termstructures/volatility/swaption/_sabr_swaption_volatility_cube.pxd @@ -4,7 +4,8 @@ from libcpp cimport bool from ._swaption_vol_structure cimport SwaptionVolatilityStructure from ._swaption_vol_cube cimport SwaptionVolatilityCube from .._sabr_smile_section cimport SabrSmileSection -from quantlib.handle cimport Handle, shared_ptr +from quantlib._handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib._quote cimport Quote from quantlib.indexes._swap_index cimport SwapIndex from quantlib.math._optimization cimport EndCriteria, OptimizationMethod diff --git a/quantlib/termstructures/volatility/swaption/_swaption_vol_cube.pxd b/quantlib/termstructures/volatility/swaption/_swaption_vol_cube.pxd index cea6d6015..909e1cd57 100644 --- a/quantlib/termstructures/volatility/swaption/_swaption_vol_cube.pxd +++ b/quantlib/termstructures/volatility/swaption/_swaption_vol_cube.pxd @@ -3,7 +3,8 @@ from libcpp.vector cimport vector from libcpp cimport bool from ._swaption_vol_discrete cimport SwaptionVolatilityDiscrete from ._swaption_vol_structure cimport SwaptionVolatilityStructure -from quantlib.handle cimport Handle, shared_ptr +from quantlib._handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib._quote cimport Quote from quantlib.indexes._swap_index cimport SwapIndex from quantlib.time._date cimport Date diff --git a/quantlib/termstructures/volatility/swaption/_swaption_vol_matrix.pxd b/quantlib/termstructures/volatility/swaption/_swaption_vol_matrix.pxd index 8c6e4cd13..a377d1540 100644 --- a/quantlib/termstructures/volatility/swaption/_swaption_vol_matrix.pxd +++ b/quantlib/termstructures/volatility/swaption/_swaption_vol_matrix.pxd @@ -7,7 +7,7 @@ from quantlib.time._date cimport Date, Period from quantlib.time._calendar cimport Calendar from quantlib.time._daycounter cimport DayCounter from quantlib.time.businessdayconvention cimport BusinessDayConvention -from quantlib.handle cimport shared_ptr, Handle +from quantlib.handle cimport Handle from quantlib._quote cimport Quote from ._swaption_vol_structure cimport SwaptionVolatilityStructure from ..volatilitytype cimport VolatilityType diff --git a/quantlib/termstructures/volatility/swaption/_swaption_vol_structure.pxd b/quantlib/termstructures/volatility/swaption/_swaption_vol_structure.pxd index bc73c1c55..489de0a51 100644 --- a/quantlib/termstructures/volatility/swaption/_swaption_vol_structure.pxd +++ b/quantlib/termstructures/volatility/swaption/_swaption_vol_structure.pxd @@ -1,6 +1,6 @@ from quantlib.types cimport Natural, Rate, Real, Time, Volatility from libcpp cimport bool -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time._date cimport Date, Period from quantlib.time._daycounter cimport DayCounter from quantlib.time._calendar cimport Calendar diff --git a/quantlib/termstructures/volatility/swaption/sabr_swaption_volatility_cube.pyx b/quantlib/termstructures/volatility/swaption/sabr_swaption_volatility_cube.pyx index c73500a98..d78ab67fc 100644 --- a/quantlib/termstructures/volatility/swaption/sabr_swaption_volatility_cube.pyx +++ b/quantlib/termstructures/volatility/swaption/sabr_swaption_volatility_cube.pyx @@ -3,7 +3,8 @@ include '../../../types.pxi' from libcpp cimport bool from libcpp.vector cimport vector from cython.operator cimport dereference as deref -from quantlib.handle cimport Handle, make_shared, static_pointer_cast +from quantlib.ext cimport make_shared, static_pointer_cast +from quantlib.handle cimport Handle, HandleSwaptionVolatilityStructure from quantlib.math.optimization cimport OptimizationMethod, EndCriteria from quantlib.indexes.swap_index cimport SwapIndex from quantlib.utilities.null cimport Null @@ -20,7 +21,7 @@ from ..._vol_term_structure cimport VolatilityTermStructure cdef class SabrSwaptionVolatilityCube(SwaptionVolatilityCube): - def __init__(self, atm_vol_structure not None, + def __init__(self, HandleSwaptionVolatilityStructure atm_vol_structure not None, list option_tenors not None, list swap_tenors not None, vector[Spread] strike_spreads, @@ -65,8 +66,8 @@ cdef class SabrSwaptionVolatilityCube(SwaptionVolatilityCube): for p in swap_tenors: swap_tenors_vec.push_back(deref(p._thisptr)) - self._derived_ptr = make_shared[_ssvc.SabrSwaptionVolatilityCube]( - SwaptionVolatilityStructure.swaption_vol_handle(atm_vol_structure), + self._thisptr = make_shared[_ssvc.SabrSwaptionVolatilityCube]( + atm_vol_structure.handle(), option_tenors_vec, swap_tenors_vec, strike_spreads, @@ -86,4 +87,3 @@ cdef class SabrSwaptionVolatilityCube(SwaptionVolatilityCube): backward_flat, cutoff_strike ) - self._thisptr = self._derived_ptr diff --git a/quantlib/termstructures/volatility/swaption/spreaded_swaption_vol.pxd b/quantlib/termstructures/volatility/swaption/spreaded_swaption_vol.pxd index 615696e6c..07ac8f3f8 100644 --- a/quantlib/termstructures/volatility/swaption/spreaded_swaption_vol.pxd +++ b/quantlib/termstructures/volatility/swaption/spreaded_swaption_vol.pxd @@ -1,6 +1,5 @@ from . cimport _spreaded_swaption_vol as _ssv from .swaption_vol_structure cimport SwaptionVolatilityStructure -from quantlib.handle cimport shared_ptr cdef class SpreadedSwaptionVolatility(SwaptionVolatilityStructure): pass diff --git a/quantlib/termstructures/volatility/swaption/spreaded_swaption_vol.pyx b/quantlib/termstructures/volatility/swaption/spreaded_swaption_vol.pyx index a1adba654..b111daa97 100644 --- a/quantlib/termstructures/volatility/swaption/spreaded_swaption_vol.pyx +++ b/quantlib/termstructures/volatility/swaption/spreaded_swaption_vol.pyx @@ -1,13 +1,12 @@ from quantlib.quote cimport Quote -from quantlib.handle cimport Handle, shared_ptr, make_shared -from . cimport _swaption_vol_structure as _svs -from ..._vol_term_structure cimport VolatilityTermStructure +from quantlib.handle cimport HandleSwaptionVolatilityStructure cdef class SpreadedSwaptionVolatility(SwaptionVolatilityStructure): - def __init__(self, vs not None, + def __init__(self, HandleSwaptionVolatilityStructure vs not None, Quote spread not None): - self._derived_ptr = make_shared[_ssv.SpreadedSwaptionVolatility]( - SwaptionVolatilityStructure.swaption_vol_handle(vs), spread.handle() + self._thisptr.reset( + new _ssv.SpreadedSwaptionVolatility( + vs.handle(), spread.handle() + ) ) - self._thisptr = self._derived_ptr diff --git a/quantlib/termstructures/volatility/swaption/swaption_constant_vol.pyx b/quantlib/termstructures/volatility/swaption/swaption_constant_vol.pyx index 75e71fc9b..08c73b32b 100644 --- a/quantlib/termstructures/volatility/swaption/swaption_constant_vol.pyx +++ b/quantlib/termstructures/volatility/swaption/swaption_constant_vol.pyx @@ -2,7 +2,7 @@ from quantlib.types cimport Natural, Real, Volatility from libcpp cimport bool from libcpp.vector cimport vector from cython.operator cimport dereference as deref -from quantlib.handle cimport make_shared +from quantlib.ext cimport make_shared from quantlib.time.date cimport Date from quantlib.time.calendar cimport Calendar @@ -24,7 +24,7 @@ cdef class ConstantSwaptionVolatility(SwaptionVolatilityStructure): Real shift=0.): if isinstance(volatility, float): - self._derived_ptr = make_shared[_scv.ConstantSwaptionVolatility]( + self._thisptr = make_shared[_scv.ConstantSwaptionVolatility]( settlement_days, calendar._thisptr, bdc, @@ -34,7 +34,7 @@ cdef class ConstantSwaptionVolatility(SwaptionVolatilityStructure): shift ) elif isinstance(volatility, Quote): - self._derived_ptr = make_shared[_scv.ConstantSwaptionVolatility]( + self._thisptr = make_shared[_scv.ConstantSwaptionVolatility]( settlement_days, calendar._thisptr, bdc, @@ -45,7 +45,6 @@ cdef class ConstantSwaptionVolatility(SwaptionVolatilityStructure): ) else: raise TypeError - self._thisptr = self._derived_ptr @@ -60,7 +59,7 @@ cdef class ConstantSwaptionVolatility(SwaptionVolatilityStructure): cdef ConstantSwaptionVolatility instance = cls.__new__(cls) if isinstance(volatility, float): - instance._derived_ptr = make_shared[_scv.ConstantSwaptionVolatility]( + instance._thisptr = make_shared[_scv.ConstantSwaptionVolatility]( reference_date._thisptr, calendar._thisptr, bdc, @@ -70,7 +69,7 @@ cdef class ConstantSwaptionVolatility(SwaptionVolatilityStructure): shift ) elif isinstance(volatility, Quote): - instance._derived_ptr = make_shared[_scv.ConstantSwaptionVolatility]( + instance._thisptr = make_shared[_scv.ConstantSwaptionVolatility]( reference_date._thisptr, calendar._thisptr, bdc, @@ -81,5 +80,4 @@ cdef class ConstantSwaptionVolatility(SwaptionVolatilityStructure): ) else: raise TypeError - instance._thisptr = instance._derived_ptr return instance diff --git a/quantlib/termstructures/volatility/swaption/swaption_vol_cube.pyx b/quantlib/termstructures/volatility/swaption/swaption_vol_cube.pyx index 95f59356b..210aa071d 100644 --- a/quantlib/termstructures/volatility/swaption/swaption_vol_cube.pyx +++ b/quantlib/termstructures/volatility/swaption/swaption_vol_cube.pyx @@ -1,6 +1,6 @@ from . cimport _swaption_vol_cube as _svc from libcpp.vector cimport vector -from quantlib.handle cimport Handle +from quantlib._handle cimport Handle from quantlib.time.date cimport Date, Period from cython.operator cimport dereference as deref cimport quantlib._quote as _qt diff --git a/quantlib/termstructures/volatility/swaption/swaption_vol_matrix.pyx b/quantlib/termstructures/volatility/swaption/swaption_vol_matrix.pyx index e3e990644..9d265c54c 100644 --- a/quantlib/termstructures/volatility/swaption/swaption_vol_matrix.pyx +++ b/quantlib/termstructures/volatility/swaption/swaption_vol_matrix.pyx @@ -2,7 +2,8 @@ include '../../../types.pxi' from libcpp cimport bool from libcpp.vector cimport vector from cython.operator cimport dereference as deref -from quantlib.handle cimport make_shared, Handle +from quantlib.ext cimport make_shared +from quantlib.handle cimport Handle from quantlib._quote cimport Quote as QlQuote from quantlib.quote cimport Quote @@ -58,7 +59,7 @@ cdef class SwaptionVolatilityMatrix(SwaptionVolatilityDiscrete): shifts = Matrix.__new__(Matrix) if isinstance(volatilities, Matrix) and isinstance(shifts, Matrix): - self._derived_ptr = make_shared[_svm.SwaptionVolatilityMatrix]( + self._thisptr = make_shared[_svm.SwaptionVolatilityMatrix]( calendar._thisptr, bdc, option_tenors_vec, @@ -72,7 +73,7 @@ cdef class SwaptionVolatilityMatrix(SwaptionVolatilityDiscrete): elif isinstance(volatilities, list) and isinstance(shifts, list): build_vols_shifts(volatilities, shifts, c_vols, c_shifts) - self._derived_ptr = make_shared[_svm.SwaptionVolatilityMatrix]( + self._thisptr = make_shared[_svm.SwaptionVolatilityMatrix]( calendar._thisptr, bdc, option_tenors_vec, @@ -86,7 +87,6 @@ cdef class SwaptionVolatilityMatrix(SwaptionVolatilityDiscrete): else: raise TypeError("volatilities and shifts need to be both either Matrices, " "or lists of lists") - self._thisptr = self._derived_ptr @classmethod def from_reference_date(cls, Date reference_date not None, @@ -115,7 +115,7 @@ cdef class SwaptionVolatilityMatrix(SwaptionVolatilityDiscrete): shifts = Matrix.__new__(Matrix) if isinstance(volatilities, Matrix) and isinstance(shifts, Matrix): - instance._derived_ptr = make_shared[_svm.SwaptionVolatilityMatrix]( + instance._thisptr = make_shared[_svm.SwaptionVolatilityMatrix]( reference_date._thisptr, calendar._thisptr, bdc, @@ -129,7 +129,7 @@ cdef class SwaptionVolatilityMatrix(SwaptionVolatilityDiscrete): ) elif isinstance(volatilities, list) and isinstance(shifts, list): build_vols_shifts(volatilities, shifts, c_vols, c_shifts) - instance._derived_ptr = make_shared[_svm.SwaptionVolatilityMatrix]( + instance._thisptr = make_shared[_svm.SwaptionVolatilityMatrix]( reference_date._thisptr, calendar._thisptr, bdc, @@ -144,5 +144,4 @@ cdef class SwaptionVolatilityMatrix(SwaptionVolatilityDiscrete): else: raise TypeError("volatilities and shifts need to be both either Matrices, " "or lists of lists") - instance._thisptr = instance._derived_ptr return instance diff --git a/quantlib/termstructures/volatility/swaption/swaption_vol_structure.pxd b/quantlib/termstructures/volatility/swaption/swaption_vol_structure.pxd index c638318dd..4631e1db7 100644 --- a/quantlib/termstructures/volatility/swaption/swaption_vol_structure.pxd +++ b/quantlib/termstructures/volatility/swaption/swaption_vol_structure.pxd @@ -1,13 +1,6 @@ -from libcpp cimport bool -from quantlib.handle cimport shared_ptr, Handle, RelinkableHandle from ...vol_term_structure cimport VolatilityTermStructure from . cimport _swaption_vol_structure as _svs +from quantlib.ext cimport shared_ptr cdef class SwaptionVolatilityStructure(VolatilityTermStructure): - cdef shared_ptr[_svs.SwaptionVolatilityStructure] _derived_ptr cdef inline _svs.SwaptionVolatilityStructure* get_svs(self) nogil - @staticmethod - cdef Handle[_svs.SwaptionVolatilityStructure] swaption_vol_handle(object vol) - -cdef class HandleSwaptionVolatilityStructure: - cdef RelinkableHandle[_svs.SwaptionVolatilityStructure] handle diff --git a/quantlib/termstructures/volatility/swaption/swaption_vol_structure.pyx b/quantlib/termstructures/volatility/swaption/swaption_vol_structure.pyx index 40010696d..b8683a814 100644 --- a/quantlib/termstructures/volatility/swaption/swaption_vol_structure.pyx +++ b/quantlib/termstructures/volatility/swaption/swaption_vol_structure.pyx @@ -1,23 +1,14 @@ include '../../../types.pxi' +from libcpp cimport bool from cython.operator cimport dereference as deref from quantlib.time.date cimport Date, Period -from quantlib.handle cimport shared_ptr from ..smilesection cimport SmileSection from ..volatilitytype import VolatilityType cdef class SwaptionVolatilityStructure(VolatilityTermStructure): cdef inline _svs.SwaptionVolatilityStructure* get_svs(self) nogil: - return self._derived_ptr.get() - - @staticmethod - cdef Handle[_svs.SwaptionVolatilityStructure] swaption_vol_handle(vol): - if isinstance(vol, SwaptionVolatilityStructure): - return Handle[_svs.SwaptionVolatilityStructure]((vol)._derived_ptr, False) - elif isinstance(vol, HandleSwaptionVolatilityStructure): - return (vol).handle - else: - raise TypeError("vol needs to be either a SwaptionVolatilityStructure or a HandleSwaptionVolatilityStructure") + return <_svs.SwaptionVolatilityStructure*>self._thisptr.get() def volatility(self, option_date, swap_date, Rate strike, bool extrapolate=False): @@ -166,22 +157,3 @@ cdef class SwaptionVolatilityStructure(VolatilityTermStructure): @property def volatility_type(self): return VolatilityType(self.get_svs().volatilityType()) - - -cdef class HandleSwaptionVolatilityStructure: - def __init__(self, SwaptionVolatilityStructure structure=None, bool register_as_observer=True): - if structure is not None: - self.handle = RelinkableHandle[_svs.SwaptionVolatilityStructure](structure._derived_ptr, register_as_observer) - - def link_to(self, SwaptionVolatilityStructure structure not None, bool register_as_observer=True): - self.handle.linkTo(structure._derived_ptr, register_as_observer) - - @property - def current_link(self): - cdef SwaptionVolatilityStructure instance = SwaptionVolatilityStructure.__new__(SwaptionVolatilityStructure) - if not self.handle.empty(): - instance._derived_ptr = self.handle.currentLink() - instance._thisptr = instance._derived_ptr - return instance - else: - raise ValueError("can't dereference empty handle") diff --git a/quantlib/termstructures/yields/_bond_helpers.pxd b/quantlib/termstructures/yields/_bond_helpers.pxd index d9840ee57..80102211a 100644 --- a/quantlib/termstructures/yields/_bond_helpers.pxd +++ b/quantlib/termstructures/yields/_bond_helpers.pxd @@ -1,8 +1,8 @@ from quantlib.types cimport Natural, Rate, Real from libcpp cimport bool from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr, Handle - +from quantlib.ext cimport shared_ptr +from quantlib.handle cimport Handle from quantlib._quote cimport Quote from quantlib.instruments._bond cimport Bond from quantlib.termstructures._helpers cimport BootstrapHelper diff --git a/quantlib/termstructures/yields/_flat_forward.pxd b/quantlib/termstructures/yields/_flat_forward.pxd index ce939cf98..ad4517cc6 100644 --- a/quantlib/termstructures/yields/_flat_forward.pxd +++ b/quantlib/termstructures/yields/_flat_forward.pxd @@ -11,7 +11,7 @@ from quantlib.types cimport * from libcpp cimport bool from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr, Handle, RelinkableHandle +from quantlib.handle cimport Handle from quantlib.time._calendar cimport Calendar from quantlib.time._date cimport Date from quantlib.time._daycounter cimport DayCounter diff --git a/quantlib/termstructures/yields/_forward_spreaded_term_structure.pxd b/quantlib/termstructures/yields/_forward_spreaded_term_structure.pxd index 886f51a12..9d6dd39db 100644 --- a/quantlib/termstructures/yields/_forward_spreaded_term_structure.pxd +++ b/quantlib/termstructures/yields/_forward_spreaded_term_structure.pxd @@ -1,4 +1,4 @@ -from quantlib.handle cimport shared_ptr, Handle +from quantlib.handle cimport Handle from quantlib._quote cimport Quote from ._flat_forward cimport YieldTermStructure from quantlib.time._date cimport Date diff --git a/quantlib/termstructures/yields/_ois_rate_helper.pxd b/quantlib/termstructures/yields/_ois_rate_helper.pxd index c19cb2d85..94751c6bc 100644 --- a/quantlib/termstructures/yields/_ois_rate_helper.pxd +++ b/quantlib/termstructures/yields/_ois_rate_helper.pxd @@ -5,7 +5,8 @@ from libcpp cimport bool from quantlib._quote cimport Quote from quantlib.cashflows.rateaveraging cimport RateAveraging from quantlib.cashflows._coupon_pricer cimport FloatingRateCouponPricer -from quantlib.handle cimport shared_ptr, Handle, optional +from quantlib.ext cimport shared_ptr, optional +from quantlib.handle cimport Handle from quantlib.time._date cimport Date from quantlib.time._period cimport Period, Frequency from quantlib.termstructures.helpers cimport Pillar diff --git a/quantlib/termstructures/yields/_overnightindexfutureratehelper.pxd b/quantlib/termstructures/yields/_overnightindexfutureratehelper.pxd index 0571626ed..1f89a5ed1 100644 --- a/quantlib/termstructures/yields/_overnightindexfutureratehelper.pxd +++ b/quantlib/termstructures/yields/_overnightindexfutureratehelper.pxd @@ -1,7 +1,8 @@ from quantlib.types cimport Real from quantlib.cashflows.rateaveraging cimport RateAveraging from ._rate_helpers cimport RateHelper -from quantlib.handle cimport Handle, shared_ptr +from quantlib._handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib.indexes._ibor_index cimport OvernightIndex from quantlib.time._date cimport Date, Month, Year from quantlib.time.frequency cimport Frequency diff --git a/quantlib/termstructures/yields/_piecewise_yield_curve.pxd b/quantlib/termstructures/yields/_piecewise_yield_curve.pxd index b165bc1f6..89d77f33d 100644 --- a/quantlib/termstructures/yields/_piecewise_yield_curve.pxd +++ b/quantlib/termstructures/yields/_piecewise_yield_curve.pxd @@ -2,7 +2,7 @@ from quantlib.types cimport Natural, Real, Time from libcpp.vector cimport vector from libcpp.pair cimport pair -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time._calendar cimport Calendar from quantlib.time._date cimport Date from quantlib.time._daycounter cimport DayCounter diff --git a/quantlib/termstructures/yields/_rate_helpers.pxd b/quantlib/termstructures/yields/_rate_helpers.pxd index d71585559..4ad4b6716 100644 --- a/quantlib/termstructures/yields/_rate_helpers.pxd +++ b/quantlib/termstructures/yields/_rate_helpers.pxd @@ -11,7 +11,8 @@ include '../../types.pxi' from libcpp cimport bool -from quantlib.handle cimport shared_ptr, Handle, RelinkableHandle +from quantlib.handle cimport Handle +from quantlib.ext cimport shared_ptr from quantlib._quote cimport Quote from quantlib.time._calendar cimport BusinessDayConvention, Calendar from quantlib.time._date cimport Date diff --git a/quantlib/termstructures/yields/bond_helpers.pyx b/quantlib/termstructures/yields/bond_helpers.pyx index 1d2bcc947..8f42332e0 100644 --- a/quantlib/termstructures/yields/bond_helpers.pyx +++ b/quantlib/termstructures/yields/bond_helpers.pyx @@ -3,7 +3,7 @@ from cython.operator cimport dereference as deref from libcpp cimport bool from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast cimport quantlib.time._calendar as _calendar from . cimport _bond_helpers as _bh diff --git a/quantlib/termstructures/yields/discount_curve.pyx.in b/quantlib/termstructures/yields/discount_curve.pyx.in index 23455f204..c52d463b0 100644 --- a/quantlib/termstructures/yields/discount_curve.pyx.in +++ b/quantlib/termstructures/yields/discount_curve.pyx.in @@ -2,7 +2,6 @@ from libcpp.vector cimport vector from libcpp.pair cimport pair from quantlib.types cimport DiscountFactor from cython.operator cimport dereference as deref, preincrement as preinc -from quantlib.handle cimport shared_ptr from quantlib.time.date cimport Date, date_from_qldate cimport quantlib.time._date as _date diff --git a/quantlib/termstructures/yields/forward_curve.pyx.in b/quantlib/termstructures/yields/forward_curve.pyx.in index f3285ccb1..f7c048923 100644 --- a/quantlib/termstructures/yields/forward_curve.pyx.in +++ b/quantlib/termstructures/yields/forward_curve.pyx.in @@ -2,7 +2,6 @@ from libcpp.vector cimport vector from libcpp.pair cimport pair from quantlib.types cimport Rate from cython.operator cimport dereference as deref, preincrement as preinc -from quantlib.handle cimport shared_ptr from quantlib.time.date cimport Date, date_from_qldate cimport quantlib.time._date as _date diff --git a/quantlib/termstructures/yields/ois_rate_helper.pyx b/quantlib/termstructures/yields/ois_rate_helper.pyx index aeb16f422..30c77b858 100644 --- a/quantlib/termstructures/yields/ois_rate_helper.pyx +++ b/quantlib/termstructures/yields/ois_rate_helper.pyx @@ -6,7 +6,8 @@ from cython.operator cimport dereference as deref from quantlib.cashflows.rateaveraging cimport RateAveraging from quantlib.cashflows.coupon_pricer cimport FloatingRateCouponPricer from quantlib.termstructures.helpers cimport Pillar -from quantlib.handle cimport shared_ptr, static_pointer_cast, Handle, optional +from quantlib.ext cimport shared_ptr, static_pointer_cast, optional +from quantlib.handle cimport HandleYieldTermStructure from quantlib.quote cimport Quote from quantlib.time.date cimport Date, Period from quantlib.termstructures.yields.rate_helpers cimport RelativeDateRateHelper, RateHelper diff --git a/quantlib/termstructures/yields/overnightindexfutureratehelper.pyx b/quantlib/termstructures/yields/overnightindexfutureratehelper.pyx index 1527f9de2..1cc92f7ab 100644 --- a/quantlib/termstructures/yields/overnightindexfutureratehelper.pyx +++ b/quantlib/termstructures/yields/overnightindexfutureratehelper.pyx @@ -1,6 +1,6 @@ from quantlib.types cimport Real from cython.operator cimport dereference as deref -from quantlib.handle cimport static_pointer_cast +from quantlib.ext cimport static_pointer_cast from quantlib.cashflows.rateaveraging cimport RateAveraging from quantlib.time.frequency cimport Frequency from quantlib.quote cimport Quote diff --git a/quantlib/termstructures/yields/piecewise_yield_curve.pyx.in b/quantlib/termstructures/yields/piecewise_yield_curve.pyx.in index b22ebd6a3..86f3bbe2e 100644 --- a/quantlib/termstructures/yields/piecewise_yield_curve.pyx.in +++ b/quantlib/termstructures/yields/piecewise_yield_curve.pyx.in @@ -3,7 +3,7 @@ from cython.operator cimport dereference as deref from libcpp.pair cimport pair from libcpp.vector cimport vector -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from . cimport _rate_helpers as _rh from .. cimport _yield_term_structure as _yts diff --git a/quantlib/termstructures/yields/rate_helpers.pxd b/quantlib/termstructures/yields/rate_helpers.pxd index 32fddc4ee..f4cc7ce9a 100644 --- a/quantlib/termstructures/yields/rate_helpers.pxd +++ b/quantlib/termstructures/yields/rate_helpers.pxd @@ -1,5 +1,5 @@ from . cimport _rate_helpers as _rh -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cdef class RateHelper: cdef shared_ptr[_rh.RateHelper] _thisptr diff --git a/quantlib/termstructures/yields/rate_helpers.pyx b/quantlib/termstructures/yields/rate_helpers.pyx index 1a0c5bc2d..138aefbab 100644 --- a/quantlib/termstructures/yields/rate_helpers.pyx +++ b/quantlib/termstructures/yields/rate_helpers.pyx @@ -13,7 +13,8 @@ cimport quantlib._instrument as _ins from quantlib.instruments.vanillaswap cimport VanillaSwap cimport quantlib.instruments._vanillaswap as _vs -from quantlib.handle cimport shared_ptr, Handle, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast +from quantlib.handle cimport HandleYieldTermStructure cimport quantlib.indexes._ibor_index as _ib cimport quantlib.indexes._swap_index as _si from quantlib.instruments.futures cimport FuturesType diff --git a/quantlib/termstructures/yields/zero_curve.pyx.in b/quantlib/termstructures/yields/zero_curve.pyx.in index c6888ccc2..7c5876c5b 100644 --- a/quantlib/termstructures/yields/zero_curve.pyx.in +++ b/quantlib/termstructures/yields/zero_curve.pyx.in @@ -2,7 +2,7 @@ from libcpp.vector cimport vector from libcpp.pair cimport pair from quantlib.types cimport Rate from cython.operator cimport dereference as deref, preincrement as preinc -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.time.date cimport Date, date_from_qldate cimport quantlib.time._date as _date diff --git a/quantlib/time/_schedule.pxd b/quantlib/time/_schedule.pxd index 5d94328e5..32ddf42d6 100644 --- a/quantlib/time/_schedule.pxd +++ b/quantlib/time/_schedule.pxd @@ -4,7 +4,7 @@ from libcpp.vector cimport vector from ._period cimport Period from ._date cimport Date from ._calendar cimport Calendar, BusinessDayConvention -from quantlib.handle cimport optional +from quantlib.ext cimport optional from .dategeneration cimport DateGeneration cdef extern from 'ql/time/schedule.hpp' namespace 'QuantLib' nogil: diff --git a/quantlib/time/date.pxd b/quantlib/time/date.pxd index 52d8b8a8f..fbcb0343a 100644 --- a/quantlib/time/date.pxd +++ b/quantlib/time/date.pxd @@ -10,7 +10,7 @@ from libcpp cimport bool from ._date cimport Date as QlDate cimport quantlib.time._period as _period -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr cdef extern from 'ql/time/weekday.hpp' namespace "QuantLib" nogil: diff --git a/quantlib/time/schedule.pyx b/quantlib/time/schedule.pyx index 493134125..681a80011 100644 --- a/quantlib/time/schedule.pyx +++ b/quantlib/time/schedule.pyx @@ -2,7 +2,7 @@ from cython.operator cimport dereference as deref, preincrement as preinc from libcpp cimport bool from libcpp.vector cimport vector from libcpp.utility cimport move -from quantlib.handle cimport optional +from quantlib.ext cimport optional cimport quantlib.time._date as _date cimport quantlib.time._calendar as _calendar From 91a14643b1e3b70749a5abc1a2ddbc563fd7e030 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Mon, 2 Jun 2025 23:57:00 -0400 Subject: [PATCH 2/7] generate handle.pxd and handle.pyx from template --- Makefile | 1 + quantlib/_handle.pxd | 16 +++++++++++++++ quantlib/handle.pxd.in | 35 +++++++++++++++------------------ quantlib/handle.pyx.in | 44 ++++++++++++++++++++++++++++++++---------- setup.py | 22 +++++++++++++-------- 5 files changed, 81 insertions(+), 37 deletions(-) create mode 100644 quantlib/_handle.pxd diff --git a/Makefile b/Makefile index 320c228d6..b25e2cead 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,7 @@ clean: find quantlib -name \*.c -exec rm {} + find quantlib -name \*.h -exec rm {} + -rm quantlib/termstructures/yields/{piecewise_yield_curve,discount_curve,forward_curve,zero_curve}.{pxd,pyx} + -rm quantlib/handle.{pxd,pyx} rm -rf build rm -rf dist diff --git a/quantlib/_handle.pxd b/quantlib/_handle.pxd new file mode 100644 index 000000000..c64b59f4f --- /dev/null +++ b/quantlib/_handle.pxd @@ -0,0 +1,16 @@ +from libcpp cimport bool +from .ext cimport shared_ptr + +cdef extern from 'ql/handle.hpp' namespace 'QuantLib' nogil: + cdef cppclass Handle[T]: + Handle() + Handle(Handle&) + Handle(shared_ptr[T]&) + Handle(shared_ptr[T]&, bool registerAsObserver) + shared_ptr[T]& currentLink() + bool empty() + + cdef cppclass RelinkableHandle[T](Handle): + RelinkableHandle() + RelinkableHandle(shared_ptr[T]&, bool registerAsObserver) + void linkTo(shared_ptr[T]&, bool registerAsObserver) diff --git a/quantlib/handle.pxd.in b/quantlib/handle.pxd.in index 26e1551f4..bde53daa8 100644 --- a/quantlib/handle.pxd.in +++ b/quantlib/handle.pxd.in @@ -1,24 +1,21 @@ -from libcpp cimport bool -cdef extern from 'ql/handle.hpp' namespace 'QuantLib' nogil: - cdef cppclass Handle[T]: - Handle() - Handle(shared_ptr[T]&) - Handle(shared_ptr[T]&, bool registerAsObserver) - shared_ptr[T]& currentLink() - bool empty() - - cdef cppclass RelinkableHandle[T](Handle): - RelinkableHandle() - RelinkableHandle(T*) - RelinkableHandle(shared_ptr[T]&) - RelinkableHandle(shared_ptr[T]&, bool registerAsObserver) - void linkTo(shared_ptr[T]&) - void linkTo(shared_ptr[T]&, bool registerAsObserver) - +from cython.operator cimport dereference as deref +from ._handle cimport Handle from quantlib.termstructures._yield_term_structure cimport YieldTermStructure as QlYieldTermStructure +from quantlib.termstructures._vol_term_structure cimport VolatilityTermStructure as QlVolatilityTermStructure from quantlib.termstructures.volatility.optionlet._optionlet_volatility_structure cimport OptionletVolatilityStructure as QlOptionletVolatilityStructure +from quantlib.termstructures.volatility.equityfx._black_vol_term_structure cimport BlackVolTermStructure as QlBlackVolTermStructure +from quantlib.termstructures.volatility.swaption._swaption_vol_structure cimport SwaptionVolatilityStructure as QlSwaptionVolatilityStructure +from quantlib.termstructures._default_term_structure cimport DefaultProbabilityTermStructure as QlDefaultProbabilityTermStructure +from quantlib.termstructures._inflation_term_structure cimport ZeroInflationTermStructure as QlZeroInflationTermStructure, YoYInflationTermStructure as QlYoYInflationTermStructure + -{{for T in ("YieldTermStructure", "OptionletVolatilityStructure")}} +{{for T in ("YieldTermStructure", "VolatilityTermStructure", "OptionletVolatilityStructure", "BlackVolTermStructure", "DefaultProbabilityTermStructure", "ZeroInflationTermStructure", "YoYInflationTermStructure", "SwaptionVolatilityStructure")}} cdef class Handle{{T}}: - cdef RelinkableHandler[{{T}}] handle + cdef Handle[Ql{{T}}]* _handle + + cdef inline Handle[Ql{{T}}] handle(self) noexcept nogil: + return deref(self._handle) + +cdef class RelinkableHandle{{T}}(Handle{{T}}): + pass {{endfor}} diff --git a/quantlib/handle.pyx.in b/quantlib/handle.pyx.in index 2310e60cf..dea8dc774 100644 --- a/quantlib/handle.pyx.in +++ b/quantlib/handle.pyx.in @@ -1,25 +1,49 @@ +cimport cython +from libcpp cimport bool +from .ext cimport static_pointer_cast +from ._handle cimport RelinkableHandle from quantlib.termstructures.yield_term_structure cimport YieldTermStructure +from quantlib.termstructures.vol_term_structure cimport VolatilityTermStructure from quantlib.termstructures.volatility.optionlet.optionlet_volatility_structure cimport OptionletVolatilityStructure +from quantlib.termstructures.volatility.equityfx.black_vol_term_structure cimport BlackVolTermStructure +from quantlib.termstructures.volatility.swaption.swaption_vol_structure cimport SwaptionVolatilityStructure +from quantlib.termstructures.default_term_structure cimport DefaultProbabilityTermStructure +from quantlib.termstructures.inflation_term_structure cimport ZeroInflationTermStructure, YoYInflationTermStructure -{{for T in ("YieldTermStructure", "VolatilityTermStructure")}} +{{for T in ("YieldTermStructure", "VolatilityTermStructure", "OptionletVolatilityStructure", "BlackVolTermStructure", "DefaultProbabilityTermStructure", "ZeroInflationTermStructure", "YoYInflationTermStructure", "SwaptionVolatilityStructure")}} cdef class Handle{{T}}: -def __init__(self, {{T}} t=None, bool register_as_observer=True): + def __init__(self, {{T}} t=None, bool register_as_observer=True): if t is not None: - self.handle = RelinkableHandle[Ql{{T}}]( + self._handle = new Handle[Ql{{T}}]( static_pointer_cast[Ql{{T}}](t._thisptr), register_as_observer) + else: + self._handle = new Handle[Ql{{T}}]() @property def current_link(self): - cdef instance = {{T}}.__new__({{T}}) - if self.handle.empty(): + cdef {{T}} instance = {{T}}.__new__({{T}}) + if self._handle.empty(): raise ValueError("empty handle") - instance._thisptr = self.handle.currentLink() + instance._thisptr = self._handle.currentLink() return instance - def link_to(self, {{T}} t, bool register_as_observer=True): - self.handle.linkTo(static_pointer_cast[Ql{{T}}](t._thisptr), register_as_observer) - def __bool__(self): - return not self.handle.empty() + return not self._handle.empty() + + def __dealloc__(self): + del self._handle + +@cython.final +cdef class RelinkableHandle{{T}}: + def __init__(self, {{T}} t=None, bool register_as_observer=True): + if t is not None: + self._handle = new RelinkableHandle[Ql{{T}}]( + static_pointer_cast[Ql{{T}}](t._thisptr), + register_as_observer) + else: + self._handle = new RelinkableHandle[Ql{{T}}]() + + def link_to(self, {{T}} t, bool register_as_observer=True): + (self._handle).linkTo(static_pointer_cast[Ql{{T}}](t._thisptr), register_as_observer) {{endfor}} diff --git a/setup.py b/setup.py index 5cbad0ad4..6d39a65c3 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ import os import platform import sys +from pathlib import Path from Cython.Distutils import build_ext from Cython.Build import cythonize @@ -115,14 +116,19 @@ def get_extra_link_args(): "auto_pickle": False} def render_templates(): - for basename in ["piecewise_yield_curve", "discount_curve", "forward_curve", "zero_curve"]: - for ext in ("pxd", "pyx"): - fname = f"quantlib/termstructures/yields/{basename}.{ext}.in" - output = fname[:-3] - if not os.path.exists(output) or (os.stat(output).st_mtime < os.stat(fname).st_mtime): - template = Template.from_filename(fname, encoding="utf-8") - with open(output, "wt") as f: - f.write(template.substitute()) + paths = [ + (Path("quantlib/termstructures/yields"), ["piecewise_yield_curve", "discount_curve", "forward_curve", "zero_curve"]), + (Path("quantlib"), ["handle"]), + ] + for p, names in paths: + for basename in names: + for ext in (".pxd", ".pyx"): + output = (p / basename).with_suffix(ext) + fname = output.with_suffix(f"{ext}.in") + if not output.exists() or (output.stat().st_mtime < fname.stat().st_mtime): + template = Template.from_filename(fname, encoding="utf-8") + with output.open("wt") as f: + f.write(template.substitute()) def collect_extensions(): """ Collect all the directories with Cython extensions and return the list From 55dd47525dfd32180d5fb6af0968ceb70f3b2822 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Tue, 3 Jun 2025 09:54:21 -0400 Subject: [PATCH 3/7] add couple nogil --- quantlib/cashflows/_cap_floored_coupon.pxd | 2 +- quantlib/cashflows/_cms_coupon.pxd | 2 +- quantlib/cashflows/_conundrum_pricer.pxd | 2 +- quantlib/cashflows/_coupon_pricer.pxd | 10 ++++------ quantlib/cashflows/_ibor_coupon.pxd | 2 +- quantlib/cashflows/_inflation_coupon_pricer.pxd | 2 +- quantlib/experimental/coupons/_cms_spread_coupon.pxd | 2 +- quantlib/instruments/_make_cms.pxd | 2 +- quantlib/instruments/_make_ois.pxd | 2 +- quantlib/math/_optimization.pxd | 2 +- quantlib/models/_calibration_helper.pxd | 2 +- quantlib/models/equity/_bates_model.pxd | 2 +- quantlib/models/equity/_heston_model.pxd | 2 +- .../shortrate/onefactormodels/_blackkarasinski.pxd | 2 +- .../pricingengines/asian/_analyticdiscrgeomavprice.pxd | 5 ++--- quantlib/pricingengines/credit/_isda_cds_engine.pxd | 2 +- .../pricingengines/credit/_midpoint_cds_engine.pxd | 2 +- .../forward/_mc_variance_swap_engine.pxd | 2 +- .../forward/_replicating_variance_swap_engine.pxd | 2 +- .../vanilla/_fdblackscholesvanillaengine.pxd | 2 +- quantlib/processes/_black_scholes_process.pxd | 2 +- .../swaption/_sabr_swaption_volatility_cube.pxd | 2 +- .../volatility/swaption/_swaption_vol_cube.pxd | 2 +- .../volatility/swaption/_swaption_vol_discrete.pxd | 2 +- .../volatility/swaption/_swaption_vol_matrix.pxd | 2 +- quantlib/termstructures/volatility/volatilitytype.pxd | 2 +- quantlib/termstructures/yields/_flat_forward.pxd | 2 +- .../yields/_forward_spreaded_term_structure.pxd | 2 +- quantlib/time/_daycounter.pxd | 2 +- 29 files changed, 33 insertions(+), 36 deletions(-) diff --git a/quantlib/cashflows/_cap_floored_coupon.pxd b/quantlib/cashflows/_cap_floored_coupon.pxd index 559d058a0..969b26170 100644 --- a/quantlib/cashflows/_cap_floored_coupon.pxd +++ b/quantlib/cashflows/_cap_floored_coupon.pxd @@ -8,7 +8,7 @@ from quantlib.time._daycounter cimport DayCounter from ._floating_rate_coupon cimport FloatingRateCoupon from ._coupon_pricer cimport FloatingRateCouponPricer -cdef extern from 'ql/cashflows/capflooredcoupon.hpp' namespace 'QuantLib': +cdef extern from 'ql/cashflows/capflooredcoupon.hpp' namespace 'QuantLib' nogil: # Capped and/or floored floating-rate coupon # The payoff $P$ of a capped floating-rate coupon is: # \[ P = N \times T \times \min(a L + b, C). \] diff --git a/quantlib/cashflows/_cms_coupon.pxd b/quantlib/cashflows/_cms_coupon.pxd index ea2482e03..c81a80760 100644 --- a/quantlib/cashflows/_cms_coupon.pxd +++ b/quantlib/cashflows/_cms_coupon.pxd @@ -7,7 +7,7 @@ from quantlib.time._daycounter cimport DayCounter from quantlib.indexes._swap_index cimport SwapIndex from ._floating_rate_coupon cimport FloatingRateCoupon -cdef extern from 'ql/cashflows/cmscoupon.hpp' namespace 'QuantLib': +cdef extern from 'ql/cashflows/cmscoupon.hpp' namespace 'QuantLib' nogil: cdef cppclass CmsCoupon(FloatingRateCoupon): CmsCoupon(const Date& paymentDate, Real nominal, diff --git a/quantlib/cashflows/_conundrum_pricer.pxd b/quantlib/cashflows/_conundrum_pricer.pxd index 25fc3bda5..1c587b839 100644 --- a/quantlib/cashflows/_conundrum_pricer.pxd +++ b/quantlib/cashflows/_conundrum_pricer.pxd @@ -12,7 +12,7 @@ cdef extern from 'ql/cashflows/conundrumpricer.hpp' namespace 'QuantLib::GFuncti ParallelShifts NonParallelShifts -cdef extern from 'ql/cashflows/conundrumpricer.hpp' namespace 'QuantLib': +cdef extern from 'ql/cashflows/conundrumpricer.hpp' namespace 'QuantLib' nogil: cdef cppclass HaganPricer(CmsCouponPricer): pass diff --git a/quantlib/cashflows/_coupon_pricer.pxd b/quantlib/cashflows/_coupon_pricer.pxd index 65ba32bd9..2c30f03c5 100644 --- a/quantlib/cashflows/_coupon_pricer.pxd +++ b/quantlib/cashflows/_coupon_pricer.pxd @@ -12,7 +12,6 @@ from quantlib._quote cimport Quote cdef extern from 'ql/cashflows/couponpricer.hpp' namespace 'QuantLib' nogil: cdef cppclass FloatingRateCouponPricer: - FloatingRateCouponPricer() except + Real swapletPrice() except + Rate swapletRate() except + Real capletPrice(Rate effectiveCap) except + @@ -22,21 +21,20 @@ cdef extern from 'ql/cashflows/couponpricer.hpp' namespace 'QuantLib' nogil: void initialize(const FloatingRateCoupon& coupon) cdef cppclass IborCouponPricer(FloatingRateCouponPricer): - IborCouponPricer() except + IborCouponPricer( - const Handle[OptionletVolatilityStructure]& v) except + + const Handle[OptionletVolatilityStructure]& v, + optional[bool] useIndexedCoupon) except + cdef cppclass BlackIborCouponPricer(IborCouponPricer): - BlackIborCouponPricer() except + BlackIborCouponPricer( Handle[OptionletVolatilityStructure]& v, TimingAdjustment timing_adjustment, - const Handle[Quote] correlation) except + + const Handle[Quote] correlation, + optional[bool] useIndexedCoupon) except + void setCouponPricer(Leg& leg, shared_ptr[FloatingRateCouponPricer]& pricer) except + cdef cppclass CmsCouponPricer(FloatingRateCouponPricer): - CmsCouponPricer() CmsCouponPricer(const Handle[SwaptionVolatilityStructure]& v) except + Handle[SwaptionVolatilityStructure] swaptionVolatility() void setSwaptionVolatility(const Handle[SwaptionVolatilityStructure]& v) diff --git a/quantlib/cashflows/_ibor_coupon.pxd b/quantlib/cashflows/_ibor_coupon.pxd index 14c4de7be..b32369865 100644 --- a/quantlib/cashflows/_ibor_coupon.pxd +++ b/quantlib/cashflows/_ibor_coupon.pxd @@ -9,7 +9,7 @@ from quantlib._interest_rate cimport InterestRate from quantlib.cashflows._floating_rate_coupon cimport FloatingRateCoupon from quantlib.indexes._ibor_index cimport IborIndex -cdef extern from 'ql/cashflows/iborcoupon.hpp' namespace 'QuantLib': +cdef extern from 'ql/cashflows/iborcoupon.hpp' namespace 'QuantLib' nogil: cdef cppclass IborCoupon(FloatingRateCoupon): IborCoupon(const Date& paymentDate, Real nominal, diff --git a/quantlib/cashflows/_inflation_coupon_pricer.pxd b/quantlib/cashflows/_inflation_coupon_pricer.pxd index 549d6d1a1..f2d508983 100644 --- a/quantlib/cashflows/_inflation_coupon_pricer.pxd +++ b/quantlib/cashflows/_inflation_coupon_pricer.pxd @@ -2,7 +2,7 @@ from quantlib.handle cimport Handle from quantlib.ext cimport shared_ptr from quantlib.termstructures._yield_term_structure cimport YieldTermStructure from quantlib._cashflow cimport Leg -cdef extern from 'ql/cashflows/inflationcouponpricer.hpp' namespace 'QuantLib': +cdef extern from 'ql/cashflows/inflationcouponpricer.hpp' namespace 'QuantLib' nogil: cdef cppclass InflationCouponPricer: pass diff --git a/quantlib/experimental/coupons/_cms_spread_coupon.pxd b/quantlib/experimental/coupons/_cms_spread_coupon.pxd index d06757fe3..962f3818a 100644 --- a/quantlib/experimental/coupons/_cms_spread_coupon.pxd +++ b/quantlib/experimental/coupons/_cms_spread_coupon.pxd @@ -11,7 +11,7 @@ from quantlib.time._date cimport Date from quantlib.time._daycounter cimport DayCounter from quantlib._quote cimport Quote -cdef extern from 'ql/experimental/coupons/cmsspreadcoupon.hpp' namespace 'QuantLib': +cdef extern from 'ql/experimental/coupons/cmsspreadcoupon.hpp' namespace 'QuantLib' nogil: cdef cppclass CmsSpreadCoupon(FloatingRateCoupon): CmsSpreadCoupon(const Date& paymentDate, Real nominal, diff --git a/quantlib/instruments/_make_cms.pxd b/quantlib/instruments/_make_cms.pxd index 248015dce..6109f6ca8 100644 --- a/quantlib/instruments/_make_cms.pxd +++ b/quantlib/instruments/_make_cms.pxd @@ -14,7 +14,7 @@ from quantlib.time.dategeneration cimport DateGeneration from quantlib.handle cimport Handle from quantlib.termstructures._yield_term_structure cimport YieldTermStructure -cdef extern from 'ql/instruments/makecms.hpp' namespace 'QuantLib': +cdef extern from 'ql/instruments/makecms.hpp' namespace 'QuantLib' nogil: cdef cppclass MakeCms: MakeCms(const Period& swapTenor, const shared_ptr[SwapIndex]& swapIndex, diff --git a/quantlib/instruments/_make_ois.pxd b/quantlib/instruments/_make_ois.pxd index f3490872d..91960380c 100644 --- a/quantlib/instruments/_make_ois.pxd +++ b/quantlib/instruments/_make_ois.pxd @@ -14,7 +14,7 @@ from quantlib.indexes._ibor_index cimport OvernightIndex from quantlib.cashflows.rateaveraging cimport RateAveraging from ._overnightindexedswap cimport OvernightIndexedSwap -cdef extern from 'ql/instruments/makeois.hpp' namespace 'QuantLib': +cdef extern from 'ql/instruments/makeois.hpp' namespace 'QuantLib' nogil: cdef cppclass MakeOIS: MakeOIS(const Period& swapTenor, const shared_ptr[OvernightIndex]& overnightIndex, diff --git a/quantlib/math/_optimization.pxd b/quantlib/math/_optimization.pxd index 423611ace..9472fc81b 100644 --- a/quantlib/math/_optimization.pxd +++ b/quantlib/math/_optimization.pxd @@ -39,7 +39,7 @@ cdef extern from 'ql/math/optimization/endcriteria.hpp' namespace 'QuantLib': ) -cdef extern from 'ql/math/optimization/constraint.hpp' namespace 'QuantLib': +cdef extern from 'ql/math/optimization/constraint.hpp' namespace 'QuantLib' nogil: cdef cppclass Constraint: Constraint() diff --git a/quantlib/models/_calibration_helper.pxd b/quantlib/models/_calibration_helper.pxd index 0ac879c3d..945636ff5 100644 --- a/quantlib/models/_calibration_helper.pxd +++ b/quantlib/models/_calibration_helper.pxd @@ -5,7 +5,7 @@ from quantlib.handle cimport Handle from quantlib.ext cimport shared_ptr from quantlib._quote cimport Quote -cdef extern from 'ql/models/calibrationhelper.hpp' namespace 'QuantLib': +cdef extern from 'ql/models/calibrationhelper.hpp' namespace 'QuantLib' nogil: cdef cppclass CalibrationHelper: pass diff --git a/quantlib/models/equity/_bates_model.pxd b/quantlib/models/equity/_bates_model.pxd index bad2450d8..bea0b0012 100644 --- a/quantlib/models/equity/_bates_model.pxd +++ b/quantlib/models/equity/_bates_model.pxd @@ -4,7 +4,7 @@ from quantlib.ext cimport shared_ptr from quantlib.models.equity._heston_model cimport HestonModel cimport quantlib.processes._heston_process as _hp -cdef extern from 'ql/models/equity/batesmodel.hpp' namespace 'QuantLib': +cdef extern from 'ql/models/equity/batesmodel.hpp' namespace 'QuantLib' nogil: cdef cppclass BatesModel(HestonModel): diff --git a/quantlib/models/equity/_heston_model.pxd b/quantlib/models/equity/_heston_model.pxd index 2c1c500ce..ba2cded3c 100644 --- a/quantlib/models/equity/_heston_model.pxd +++ b/quantlib/models/equity/_heston_model.pxd @@ -17,7 +17,7 @@ cimport quantlib._quote as _qt from quantlib.time._calendar cimport Calendar from quantlib.time._period cimport Period -cdef extern from 'ql/models/equity/hestonmodelhelper.hpp' namespace 'QuantLib': +cdef extern from 'ql/models/equity/hestonmodelhelper.hpp' namespace 'QuantLib' nogil: cdef cppclass HestonModelHelper(BlackCalibrationHelper): diff --git a/quantlib/models/shortrate/onefactormodels/_blackkarasinski.pxd b/quantlib/models/shortrate/onefactormodels/_blackkarasinski.pxd index c2ab935c7..ef9c4948b 100644 --- a/quantlib/models/shortrate/onefactormodels/_blackkarasinski.pxd +++ b/quantlib/models/shortrate/onefactormodels/_blackkarasinski.pxd @@ -3,7 +3,7 @@ from quantlib.models.shortrate._onefactor_model cimport OneFactorModel from quantlib._handle cimport Handle from quantlib.termstructures._yield_term_structure cimport YieldTermStructure -cdef extern from 'ql/models/shortrate/onefactormodels/blackkarasinski.hpp' namespace 'QuantLib': +cdef extern from 'ql/models/shortrate/onefactormodels/blackkarasinski.hpp' namespace 'QuantLib' nogil: cdef cppclass BlackKarasinski(OneFactorModel): diff --git a/quantlib/pricingengines/asian/_analyticdiscrgeomavprice.pxd b/quantlib/pricingengines/asian/_analyticdiscrgeomavprice.pxd index 2549dada9..554263383 100644 --- a/quantlib/pricingengines/asian/_analyticdiscrgeomavprice.pxd +++ b/quantlib/pricingengines/asian/_analyticdiscrgeomavprice.pxd @@ -1,12 +1,11 @@ -from quantlib.handle cimport shared_ptr +from quantlib.ext cimport shared_ptr from quantlib.processes._black_scholes_process cimport GeneralizedBlackScholesProcess from quantlib.pricingengines._pricing_engine cimport PricingEngine -cdef extern from 'ql/pricingengines/asian/analytic_discr_geom_av_price.hpp' namespace 'QuantLib': +cdef extern from 'ql/pricingengines/asian/analytic_discr_geom_av_price.hpp' namespace 'QuantLib' nogil: cdef cppclass AnalyticDiscreteGeometricAveragePriceAsianEngine(PricingEngine): AnalyticDiscreteGeometricAveragePriceAsianEngine( shared_ptr[GeneralizedBlackScholesProcess] process ) except + - diff --git a/quantlib/pricingengines/credit/_isda_cds_engine.pxd b/quantlib/pricingengines/credit/_isda_cds_engine.pxd index 2dd2e7c9a..4424d3751 100644 --- a/quantlib/pricingengines/credit/_isda_cds_engine.pxd +++ b/quantlib/pricingengines/credit/_isda_cds_engine.pxd @@ -10,7 +10,7 @@ from quantlib.pricingengines._pricing_engine cimport PricingEngine from quantlib.termstructures.credit._credit_helpers cimport DefaultProbabilityHelper, CdsHelper from quantlib.termstructures.yields._rate_helpers cimport RateHelper -cdef extern from 'ql/pricingengines/credit/isdacdsengine.hpp' namespace 'QuantLib': +cdef extern from 'ql/pricingengines/credit/isdacdsengine.hpp' namespace 'QuantLib' nogil: cdef cppclass IsdaCdsEngine(PricingEngine): IsdaCdsEngine( diff --git a/quantlib/pricingengines/credit/_midpoint_cds_engine.pxd b/quantlib/pricingengines/credit/_midpoint_cds_engine.pxd index 8d8910724..6e53bba84 100644 --- a/quantlib/pricingengines/credit/_midpoint_cds_engine.pxd +++ b/quantlib/pricingengines/credit/_midpoint_cds_engine.pxd @@ -7,7 +7,7 @@ from quantlib.termstructures._default_term_structure cimport DefaultProbabilityT from quantlib.termstructures._yield_term_structure cimport YieldTermStructure from quantlib.pricingengines._pricing_engine cimport PricingEngine -cdef extern from 'ql/pricingengines/credit/midpointcdsengine.hpp' namespace 'QuantLib': +cdef extern from 'ql/pricingengines/credit/midpointcdsengine.hpp' namespace 'QuantLib' nogil: cdef cppclass MidPointCdsEngine(PricingEngine): MidPointCdsEngine( diff --git a/quantlib/pricingengines/forward/_mc_variance_swap_engine.pxd b/quantlib/pricingengines/forward/_mc_variance_swap_engine.pxd index 7a67ea907..1840a0671 100644 --- a/quantlib/pricingengines/forward/_mc_variance_swap_engine.pxd +++ b/quantlib/pricingengines/forward/_mc_variance_swap_engine.pxd @@ -7,7 +7,7 @@ from quantlib.pricingengines._pricing_engine cimport PricingEngine from quantlib.processes._black_scholes_process cimport GeneralizedBlackScholesProcess -cdef extern from 'ql/pricingengines/forward/mcvarianceswapengine.hpp' namespace 'QuantLib': +cdef extern from 'ql/pricingengines/forward/mcvarianceswapengine.hpp' namespace 'QuantLib' nogil: cdef cppclass MCVarianceSwapEngine[RNG=*, S=*](PricingEngine): MCVarianceSwapEngine( diff --git a/quantlib/pricingengines/forward/_replicating_variance_swap_engine.pxd b/quantlib/pricingengines/forward/_replicating_variance_swap_engine.pxd index 546c1f7dc..f4e6841dc 100644 --- a/quantlib/pricingengines/forward/_replicating_variance_swap_engine.pxd +++ b/quantlib/pricingengines/forward/_replicating_variance_swap_engine.pxd @@ -6,7 +6,7 @@ from quantlib.ext cimport shared_ptr from quantlib.pricingengines._pricing_engine cimport PricingEngine from quantlib.processes._black_scholes_process cimport GeneralizedBlackScholesProcess -cdef extern from 'ql/pricingengines/forward/replicatingvarianceswapengine.hpp' namespace 'QuantLib': +cdef extern from 'ql/pricingengines/forward/replicatingvarianceswapengine.hpp' namespace 'QuantLib' nogil: cdef cppclass ReplicatingVarianceSwapEngine(PricingEngine): diff --git a/quantlib/pricingengines/vanilla/_fdblackscholesvanillaengine.pxd b/quantlib/pricingengines/vanilla/_fdblackscholesvanillaengine.pxd index b5e86089e..d4c0692c6 100644 --- a/quantlib/pricingengines/vanilla/_fdblackscholesvanillaengine.pxd +++ b/quantlib/pricingengines/vanilla/_fdblackscholesvanillaengine.pxd @@ -11,7 +11,7 @@ cdef extern from 'ql/pricingengines/vanilla/fdblackscholesvanillaengine.hpp' nam Spot Escrowed -cdef extern from 'ql/pricingengines/vanilla/fdblackscholesvanillaengine.hpp' namespace 'QuantLib': +cdef extern from 'ql/pricingengines/vanilla/fdblackscholesvanillaengine.hpp' namespace 'QuantLib' nogil: cdef cppclass FdBlackScholesVanillaEngine(VanillaOption.engine): enum CashDividendModel: diff --git a/quantlib/processes/_black_scholes_process.pxd b/quantlib/processes/_black_scholes_process.pxd index 2098d3116..7963e3964 100644 --- a/quantlib/processes/_black_scholes_process.pxd +++ b/quantlib/processes/_black_scholes_process.pxd @@ -15,7 +15,7 @@ cimport quantlib._quote as _qt from quantlib._stochastic_process cimport StochasticProcess1D from quantlib.termstructures.volatility.equityfx._black_vol_term_structure cimport BlackVolTermStructure -cdef extern from 'ql/processes/blackscholesprocess.hpp' namespace 'QuantLib': +cdef extern from 'ql/processes/blackscholesprocess.hpp' namespace 'QuantLib' nogil: cdef cppclass GeneralizedBlackScholesProcess(StochasticProcess1D): GeneralizedBlackScholesProcess() diff --git a/quantlib/termstructures/volatility/swaption/_sabr_swaption_volatility_cube.pxd b/quantlib/termstructures/volatility/swaption/_sabr_swaption_volatility_cube.pxd index 6c5df5397..857648e45 100644 --- a/quantlib/termstructures/volatility/swaption/_sabr_swaption_volatility_cube.pxd +++ b/quantlib/termstructures/volatility/swaption/_sabr_swaption_volatility_cube.pxd @@ -14,7 +14,7 @@ from quantlib.math._interpolations cimport SABRInterpolation from quantlib.time._date cimport Date from quantlib.time._period cimport Period -cdef extern from 'ql/termstructures/volatility/swaption/sabrswaptionvolatilitycube.hpp' namespace 'QuantLib': +cdef extern from 'ql/termstructures/volatility/swaption/sabrswaptionvolatilitycube.hpp' namespace 'QuantLib' nogil: cdef cppclass XabrSwaptionVolatilityCube[Model](SwaptionVolatilityCube): cppclass Cube: Cube(const vector[Date]& optionDates, diff --git a/quantlib/termstructures/volatility/swaption/_swaption_vol_cube.pxd b/quantlib/termstructures/volatility/swaption/_swaption_vol_cube.pxd index 909e1cd57..ca8be48b0 100644 --- a/quantlib/termstructures/volatility/swaption/_swaption_vol_cube.pxd +++ b/quantlib/termstructures/volatility/swaption/_swaption_vol_cube.pxd @@ -10,7 +10,7 @@ from quantlib.indexes._swap_index cimport SwapIndex from quantlib.time._date cimport Date from quantlib.time._period cimport Period -cdef extern from 'ql/termstructures/volatility/swaption/swaptionvolcube.hpp' namespace 'QuantLib': +cdef extern from 'ql/termstructures/volatility/swaption/swaptionvolcube.hpp' namespace 'QuantLib' nogil: cdef cppclass SwaptionVolatilityCube(SwaptionVolatilityDiscrete): SwaptionVolatilityCube( const Handle[SwaptionVolatilityStructure]& atmVolStructure, diff --git a/quantlib/termstructures/volatility/swaption/_swaption_vol_discrete.pxd b/quantlib/termstructures/volatility/swaption/_swaption_vol_discrete.pxd index 39da60d2a..f95cda912 100644 --- a/quantlib/termstructures/volatility/swaption/_swaption_vol_discrete.pxd +++ b/quantlib/termstructures/volatility/swaption/_swaption_vol_discrete.pxd @@ -8,7 +8,7 @@ from quantlib.time.businessdayconvention cimport BusinessDayConvention from quantlib.termstructures.volatility.swaption._swaption_vol_structure \ cimport SwaptionVolatilityStructure -cdef extern from 'ql/termstructures/volatility/swaption/swaptionvoldiscrete.hpp' namespace 'QuantLib': +cdef extern from 'ql/termstructures/volatility/swaption/swaptionvoldiscrete.hpp' namespace 'QuantLib' nogil: cdef cppclass SwaptionVolatilityDiscrete(SwaptionVolatilityStructure): # floating reference date, floating market data SwaptionVolatilityDiscrete( diff --git a/quantlib/termstructures/volatility/swaption/_swaption_vol_matrix.pxd b/quantlib/termstructures/volatility/swaption/_swaption_vol_matrix.pxd index a377d1540..db38d320b 100644 --- a/quantlib/termstructures/volatility/swaption/_swaption_vol_matrix.pxd +++ b/quantlib/termstructures/volatility/swaption/_swaption_vol_matrix.pxd @@ -13,7 +13,7 @@ from ._swaption_vol_structure cimport SwaptionVolatilityStructure from ..volatilitytype cimport VolatilityType from quantlib.math._matrix cimport Matrix -cdef extern from 'ql/termstructures/volatility/swaption/swaptionvolmatrix.hpp' namespace 'QuantLib': +cdef extern from 'ql/termstructures/volatility/swaption/swaptionvolmatrix.hpp' namespace 'QuantLib' nogil: cdef cppclass SwaptionVolatilityMatrix(SwaptionVolatilityStructure): # floating reference date, floating market data SwaptionVolatilityMatrix( diff --git a/quantlib/termstructures/volatility/volatilitytype.pxd b/quantlib/termstructures/volatility/volatilitytype.pxd index 9d3f6809c..870483ea4 100644 --- a/quantlib/termstructures/volatility/volatilitytype.pxd +++ b/quantlib/termstructures/volatility/volatilitytype.pxd @@ -1,4 +1,4 @@ -cdef extern from 'ql/termstructures/volatility/volatilitytype.hpp' namespace 'QuantLib': +cdef extern from 'ql/termstructures/volatility/volatilitytype.hpp' namespace 'QuantLib' nogil: cpdef enum VolatilityType: ShiftedLognormal Normal diff --git a/quantlib/termstructures/yields/_flat_forward.pxd b/quantlib/termstructures/yields/_flat_forward.pxd index ad4517cc6..cc7b388c2 100644 --- a/quantlib/termstructures/yields/_flat_forward.pxd +++ b/quantlib/termstructures/yields/_flat_forward.pxd @@ -21,7 +21,7 @@ from quantlib.compounding cimport Compounding from quantlib.termstructures._yield_term_structure cimport YieldTermStructure -cdef extern from 'ql/termstructures/yield/flatforward.hpp' namespace 'QuantLib': +cdef extern from 'ql/termstructures/yield/flatforward.hpp' namespace 'QuantLib' nogil: cdef cppclass FlatForward(YieldTermStructure): diff --git a/quantlib/termstructures/yields/_forward_spreaded_term_structure.pxd b/quantlib/termstructures/yields/_forward_spreaded_term_structure.pxd index 9d6dd39db..3b5ffb726 100644 --- a/quantlib/termstructures/yields/_forward_spreaded_term_structure.pxd +++ b/quantlib/termstructures/yields/_forward_spreaded_term_structure.pxd @@ -5,7 +5,7 @@ from quantlib.time._date cimport Date from quantlib.time._daycounter cimport DayCounter -cdef extern from 'ql/termstructures/yield/forwardspreadedtermstructure.hpp' namespace 'QuantLib': +cdef extern from 'ql/termstructures/yield/forwardspreadedtermstructure.hpp' namespace 'QuantLib' nogil: cdef cppclass ForwardSpreadedTermStructure(YieldTermStructure): diff --git a/quantlib/time/_daycounter.pxd b/quantlib/time/_daycounter.pxd index e2c69445e..4fed3a9cc 100644 --- a/quantlib/time/_daycounter.pxd +++ b/quantlib/time/_daycounter.pxd @@ -5,7 +5,7 @@ from ._date cimport Date, serial_type from ._calendar cimport Calendar -cdef extern from 'ql/time/daycounter.hpp' namespace 'QuantLib': +cdef extern from 'ql/time/daycounter.hpp' namespace 'QuantLib' nogil: cdef cppclass DayCounter: DayCounter() nogil From 1c021b1b2413fca287e03962c068a25830e0aea3 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Tue, 3 Jun 2025 10:02:22 -0400 Subject: [PATCH 4/7] use the new handles --- quantlib/cashflows/conundrum_pricer.pyx | 42 +++++++++---------- quantlib/cashflows/coupon_pricer.pyx | 42 +++++++++---------- quantlib/cashflows/cpi_coupon_pricer.pyx | 7 ++-- .../cashflows/inflation_coupon_pricer.pyx | 4 +- quantlib/cashflows/linear_tsr_pricer.pyx | 21 +++++----- .../coupons/lognormal_cmsspread_pricer.pyx | 4 +- .../crosscurrencyratehelpers.pyx | 6 +-- quantlib/indexes/_inflation_index.pxd | 1 + quantlib/indexes/ibor/eonia.pyx | 4 +- quantlib/indexes/ibor/euribor.pyx | 17 ++++---- quantlib/indexes/ibor/libor.pyx | 22 +++++----- quantlib/indexes/ibor/sofr.pyx | 4 +- quantlib/indexes/ibor/usdlibor.pyx | 8 ++-- quantlib/indexes/ibor_index.pyx | 10 ++--- quantlib/indexes/inflation/aucpi.pyx | 6 +-- quantlib/indexes/inflation/euhicp.pyx | 20 ++++----- quantlib/indexes/inflation/ukrpi.pyx | 7 ++-- quantlib/indexes/inflation_index.pyx | 42 ++++++++++++------- quantlib/indexes/swap/euribor_swap.pyx | 24 +++++------ quantlib/indexes/swap/usd_libor_swap.pyx | 24 +++++------ quantlib/indexes/swap_index.pyx | 30 ++++++------- quantlib/instruments/_swap.pxd | 1 - quantlib/instruments/bondforward.pyx | 4 +- quantlib/instruments/credit_default_swap.pyx | 6 +-- quantlib/instruments/forward.pyx | 4 +- quantlib/instruments/make_cms.pyx | 4 +- quantlib/instruments/make_ois.pyx | 4 +- quantlib/instruments/make_vanilla_swap.pyx | 4 +- quantlib/instruments/swaption.pyx | 11 ++--- quantlib/instruments/variance_swap.pyx | 22 +++++----- quantlib/interest_rate.pxd | 1 - quantlib/mlab/fixed_income.py | 4 +- quantlib/mlab/option_pricing.py | 13 +++--- quantlib/models/equity/heston_model.pyx | 8 ++-- .../calibrationhelpers/swaption_helper.pyx | 8 ++-- .../onefactormodels/blackkarasinski.pyx | 2 +- .../models/shortrate/onefactormodels/gsr.pyx | 2 +- .../shortrate/onefactormodels/hullwhite.pyx | 4 +- .../models/shortrate/twofactormodels/g2.pyx | 4 +- .../bond/discountingbondengine.pyx | 4 +- .../pricingengines/credit/isda_cds_engine.pyx | 17 ++++---- .../credit/midpoint_cds_engine.pyx | 6 +-- quantlib/pricingengines/swap.pyx | 2 +- .../swaption/black_swaption_engine.pyx | 30 ++++++------- .../swaption/jamshidian_swaption_engine.pyx | 6 +-- .../swaption/tree_swaption_engine.pyx | 6 +-- quantlib/processes/bates_process.pyx | 6 +-- quantlib/processes/black_scholes_process.pyx | 36 ++++++---------- quantlib/processes/heston_process.pyx | 9 ++-- quantlib/processes/hullwhite_process.pyx | 6 +-- .../_default_term_structure.pxd | 3 +- .../termstructures/_yield_term_structure.pxd | 8 ++-- quantlib/termstructures/credit/api.py | 2 +- .../credit/default_probability_helpers.pyx | 8 ++-- .../termstructures/default_term_structure.pxd | 4 -- .../termstructures/default_term_structure.pyx | 21 ---------- .../inflation/inflation_helpers.pyx | 6 +-- .../inflation_term_structure.pxd | 7 ++-- .../inflation_term_structure.pyx | 20 +-------- .../termstructures/vol_term_structure.pxd | 6 --- .../termstructures/vol_term_structure.pyx | 16 ------- quantlib/termstructures/volatility/api.py | 2 +- .../volatility/equityfx/local_vol_surface.pyx | 12 +++--- .../optionlet_volatility_structure.pyx | 4 -- .../termstructures/yield_term_structure.pxd | 4 -- .../termstructures/yield_term_structure.pyx | 22 ---------- .../termstructures/yields/_flat_forward.pxd | 6 +-- quantlib/termstructures/yields/api.py | 3 +- .../forward_spreaded_term_structure.pyx | 5 ++- .../yields/implied_term_structure.pyx | 4 +- .../termstructures/yields/ois_rate_helper.pyx | 5 +-- .../piecewise_zerospreaded_termstructure.pyx | 4 +- .../termstructures/yields/rate_helpers.pyx | 11 +++-- .../yields/zero_spreaded_term_structure.pyx | 4 +- 74 files changed, 324 insertions(+), 442 deletions(-) diff --git a/quantlib/cashflows/conundrum_pricer.pyx b/quantlib/cashflows/conundrum_pricer.pyx index 48e45e326..c810aacb4 100644 --- a/quantlib/cashflows/conundrum_pricer.pyx +++ b/quantlib/cashflows/conundrum_pricer.pyx @@ -1,11 +1,6 @@ -include '../types.pxi' - +from quantlib.types cimport Rate, Real from . cimport _conundrum_pricer as _conp -from . cimport _coupon_pricer as _cp -cimport quantlib.termstructures.volatility.swaption._swaption_vol_structure as _svs -from quantlib.termstructures.volatility.swaption.swaption_vol_structure \ - cimport SwaptionVolatilityStructure -from quantlib.handle cimport Handle, shared_ptr, static_pointer_cast +from quantlib.handle cimport HandleSwaptionVolatilityStructure from quantlib.quote cimport Quote cpdef enum YieldCurveModel: @@ -16,27 +11,32 @@ cpdef enum YieldCurveModel: cdef class NumericHaganPricer(CmsCouponPricer): - def __init__(self, swaption_vol not None, + def __init__(self, HandleSwaptionVolatilityStructure swaption_vol not None, YieldCurveModel yieldcurve_model, Quote mean_reversion not None, Rate lower_limit=0., Rate upper_limit=1., Real precision=1e-6): - self._thisptr = shared_ptr[_cp.FloatingRateCouponPricer](new _conp.NumericHaganPricer( - SwaptionVolatilityStructure.swaption_vol_handle(swaption_vol), - yieldcurve_model, - mean_reversion.handle(), - lower_limit, - upper_limit, - precision - )) + self._thisptr.reset( + new _conp.NumericHaganPricer( + swaption_vol.handle(), + yieldcurve_model, + mean_reversion.handle(), + lower_limit, + upper_limit, + precision + ) + ) cdef class AnalyticHaganPricer(CmsCouponPricer): - def __init__(self, swaption_vol not None, + def __init__(self, HandleSwaptionVolatilityStructure swaption_vol not None, YieldCurveModel yieldcurve_model, Quote mean_reversion not None): - self._thisptr = shared_ptr[_cp.FloatingRateCouponPricer](new _conp.AnalyticHaganPricer( - SwaptionVolatilityStructure.swaption_vol_handle(swaption_vol), - yieldcurve_model, - mean_reversion.handle())) + self._thisptr.reset( + new _conp.AnalyticHaganPricer( + swaption_vol.handle(), + yieldcurve_model, + mean_reversion.handle() + ) + ) diff --git a/quantlib/cashflows/coupon_pricer.pyx b/quantlib/cashflows/coupon_pricer.pyx index 4c456de9c..cfaf08626 100644 --- a/quantlib/cashflows/coupon_pricer.pyx +++ b/quantlib/cashflows/coupon_pricer.pyx @@ -1,13 +1,10 @@ +from libcpp cimport bool from quantlib.types cimport Rate from cython.operator cimport dereference as deref from quantlib.cashflow cimport Leg -from quantlib.termstructures.volatility.optionlet.optionlet_volatility_structure cimport OptionletVolatilityStructure -cimport quantlib.termstructures.volatility.optionlet._optionlet_volatility_structure as _ovs -from quantlib.termstructures.volatility.swaption.swaption_vol_structure \ - cimport SwaptionVolatilityStructure -from quantlib.termstructures._vol_term_structure cimport VolatilityTermStructure cimport quantlib.termstructures.volatility.swaption._swaption_vol_structure as _svs -from quantlib.handle cimport Handle, static_pointer_cast +from quantlib.ext cimport static_pointer_cast, optional +from quantlib.handle cimport Handle, HandleSwaptionVolatilityStructure, HandleOptionletVolatilityStructure from quantlib.time.calendar cimport Calendar from quantlib.time.date cimport Date from quantlib.time.daycounter cimport DayCounter @@ -53,16 +50,19 @@ cpdef enum TimingAdjustment: cdef class BlackIborCouponPricer(IborCouponPricer): def __init__(self, - OptionletVolatilityStructure ovs=OptionletVolatilityStructure(), + HandleOptionletVolatilityStructure ovs=HandleOptionletVolatilityStructure(), TimingAdjustment timing_adjustment=Black76, - Quote correlation=SimpleQuote(1.)): - cdef Handle[_ovs.OptionletVolatilityStructure] ovs_handle = \ - Handle[_ovs.OptionletVolatilityStructure](ovs._thisptr) - self._thisptr = shared_ptr[_cp.FloatingRateCouponPricer]( + Quote correlation=SimpleQuote(1.), + use_indexed_coupon=None): + cdef optional[bool] indexed_coupon + if use_indexed_coupon is not None: + indexed_coupon = use_indexed_coupon + self._thisptr.reset( new _cp.BlackIborCouponPricer( - ovs_handle, + ovs.handle(), timing_adjustment, - correlation.handle() + correlation.handle(), + indexed_coupon, ) ) @@ -80,14 +80,14 @@ cdef class CmsCouponPricer(FloatingRateCouponPricer): @property def swaption_volatility(self): - cdef Handle[_svs.SwaptionVolatilityStructure] vol_handle = \ - (<_cp.CmsCouponPricer*>self._thisptr.get()).swaptionVolatility() - cdef SwaptionVolatilityStructure instance = (SwaptionVolatilityStructure. - __new__(SwaptionVolatilityStructure)) - if not vol_handle.empty(): - instance._thisptr = vol_handle.currentLink() + cdef HandleSwaptionVolatilityStructure instance = ( + HandleSwaptionVolatilityStructure.__new__(HandleSwaptionVolatilityStructure) + ) + instance._handle = new Handle[_svs.SwaptionVolatilityStructure]( + (<_cp.CmsCouponPricer*>self._thisptr.get()).swaptionVolatility() + ) return instance @swaption_volatility.setter - def swaption_volatility(self, v not None): - (<_cp.CmsCouponPricer*>self._thisptr.get()).setSwaptionVolatility(SwaptionVolatilityStructure.swaption_vol_handle(v)) + def swaption_volatility(self, HandleSwaptionVolatilityStructure v not None): + (<_cp.CmsCouponPricer*>self._thisptr.get()).setSwaptionVolatility(v.handle()) diff --git a/quantlib/cashflows/cpi_coupon_pricer.pyx b/quantlib/cashflows/cpi_coupon_pricer.pyx index 1d1ea6b52..ccc994df5 100644 --- a/quantlib/cashflows/cpi_coupon_pricer.pyx +++ b/quantlib/cashflows/cpi_coupon_pricer.pyx @@ -1,9 +1,8 @@ -from quantlib.handle cimport shared_ptr from ._inflation_coupon_pricer cimport InflationCouponPricer as QlInflationCouponPricer -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure cdef class CPICouponPricer(InflationCouponPricer): def __init__(self, HandleYieldTermStructure nominal_ts): - self._thisptr = shared_ptr[QlInflationCouponPricer]( - new _cpi.CPICouponPricer(nominal_ts.handle) + self._thisptr.reset( + new _cpi.CPICouponPricer(nominal_ts.handle()) ) diff --git a/quantlib/cashflows/inflation_coupon_pricer.pyx b/quantlib/cashflows/inflation_coupon_pricer.pyx index 52c7062be..0802007cb 100644 --- a/quantlib/cashflows/inflation_coupon_pricer.pyx +++ b/quantlib/cashflows/inflation_coupon_pricer.pyx @@ -1,6 +1,6 @@ from quantlib.cashflow cimport Leg from .inflation_coupon_pricer cimport InflationCouponPricer -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure cdef class InflationCouponPricer: pass @@ -8,7 +8,7 @@ cdef class InflationCouponPricer: cdef class YoYInflationCouponPricer(InflationCouponPricer): def __init__(self, HandleYieldTermStructure nominal_ts): self._thisptr = shared_ptr[_icp.InflationCouponPricer]( - new _icp.YoYInflationCouponPricer(nominal_ts.handle) + new _icp.YoYInflationCouponPricer(nominal_ts.handle()) ) def set_coupon_pricer(Leg leg, InflationCouponPricer pricer): diff --git a/quantlib/cashflows/linear_tsr_pricer.pyx b/quantlib/cashflows/linear_tsr_pricer.pyx index 62981e3fd..65a2023b9 100644 --- a/quantlib/cashflows/linear_tsr_pricer.pyx +++ b/quantlib/cashflows/linear_tsr_pricer.pyx @@ -1,26 +1,25 @@ include '../types.pxi' from . cimport _coupon_pricer as _cp -cimport quantlib.termstructures.volatility.swaption._swaption_vol_structure as _svs from quantlib.termstructures.volatility.swaption.swaption_vol_structure \ cimport SwaptionVolatilityStructure -from quantlib.handle cimport Handle, shared_ptr, static_pointer_cast -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure, HandleSwaptionVolatilityStructure from quantlib.quote cimport Quote cdef class LinearTsrPricer(CmsCouponPricer): - def __init__(self, swaption_vol not None, + def __init__(self, HandleSwaptionVolatilityStructure swaption_vol not None, Quote mean_reversion not None, HandleYieldTermStructure coupon_discount_curve=HandleYieldTermStructure(), Settings settings=Settings()): - self._thisptr = shared_ptr[_cp.FloatingRateCouponPricer]( - new QlLinearTsrPricer( - SwaptionVolatilityStructure.swaption_vol_handle(swaption_vol), - mean_reversion.handle(), - coupon_discount_curve.handle, - settings._thisptr - )) + self._thisptr.reset( + new QlLinearTsrPricer( + swaption_vol.handle(), + mean_reversion.handle(), + coupon_discount_curve.handle(), + settings._thisptr + ) + ) cdef class Settings: def with_rate_bound(self, Real lower_rate_bound=0.0001, diff --git a/quantlib/experimental/coupons/lognormal_cmsspread_pricer.pyx b/quantlib/experimental/coupons/lognormal_cmsspread_pricer.pyx index beb87b59a..1929298fc 100644 --- a/quantlib/experimental/coupons/lognormal_cmsspread_pricer.pyx +++ b/quantlib/experimental/coupons/lognormal_cmsspread_pricer.pyx @@ -5,7 +5,7 @@ from quantlib.ext cimport optional, shared_ptr, static_pointer_cast from .cms_spread_coupon cimport CmsSpreadCouponPricer from quantlib.cashflows.coupon_pricer cimport CmsCouponPricer from quantlib.quote cimport Quote -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from quantlib.termstructures.volatility.volatilitytype cimport VolatilityType from quantlib.utilities.null cimport Null cimport quantlib.cashflows._coupon_pricer as _cp @@ -27,7 +27,7 @@ cdef class LognormalCmsSpreadPricer(CmsSpreadCouponPricer): new _lcp.LognormalCmsSpreadPricer( static_pointer_cast[_cp.CmsCouponPricer](cms_pricer._thisptr), correlation.handle(), - coupon_discount_curve.handle, + coupon_discount_curve.handle(), integration_points, vol_type_option, shift1, diff --git a/quantlib/experimental/termstructures/crosscurrencyratehelpers.pyx b/quantlib/experimental/termstructures/crosscurrencyratehelpers.pyx index dca109299..2a6815eb1 100644 --- a/quantlib/experimental/termstructures/crosscurrencyratehelpers.pyx +++ b/quantlib/experimental/termstructures/crosscurrencyratehelpers.pyx @@ -8,7 +8,7 @@ from quantlib.time.calendar cimport Calendar from quantlib.indexes.ibor_index cimport IborIndex from quantlib.indexes cimport _ibor_index as _ii from quantlib.quote cimport Quote -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from . cimport _crosscurrencyratehelpers as _ccyrh cdef class ConstNotionalCrossCurrencyBasisSwapRateHelper(RelativeDateRateHelper): @@ -50,7 +50,7 @@ cdef class ConstNotionalCrossCurrencyBasisSwapRateHelper(RelativeDateRateHelper) end_of_month, static_pointer_cast[_ii.IborIndex](base_currency_index._thisptr), static_pointer_cast[_ii.IborIndex](quote_currency_index._thisptr), - collateral_curve.handle, + collateral_curve.handle(), is_fx_base_currency_collateral_currency, is_basis_on_fx_base_currency_leg ) @@ -85,7 +85,7 @@ cdef class MtMCrossCurrencyBasisSwapRateHelper(RelativeDateRateHelper): end_of_month, static_pointer_cast[_ii.IborIndex](base_currency_index._thisptr), static_pointer_cast[_ii.IborIndex](quote_currency_index._thisptr), - collateral_curve.handle, + collateral_curve.handle(), is_fx_base_currency_collateral_currency, is_basis_on_fx_base_currency_leg, is_fx_base_currency_leg_resettable, diff --git a/quantlib/indexes/_inflation_index.pxd b/quantlib/indexes/_inflation_index.pxd index f78be87da..1c487e103 100644 --- a/quantlib/indexes/_inflation_index.pxd +++ b/quantlib/indexes/_inflation_index.pxd @@ -62,3 +62,4 @@ cdef extern from 'ql/indexes/inflationindex.hpp' namespace 'QuantLib' nogil: const Currency& currency, const Handle[_its.YoYInflationTermStructure]& ts # = Handle()); ) except + + Handle[_its.YoYInflationTermStructure] yoyInflationTermStructure() diff --git a/quantlib/indexes/ibor/eonia.pyx b/quantlib/indexes/ibor/eonia.pyx index ed6f78875..3feef121f 100644 --- a/quantlib/indexes/ibor/eonia.pyx +++ b/quantlib/indexes/ibor/eonia.pyx @@ -1,8 +1,8 @@ -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from . cimport _eonia as _eo from ... cimport _index as _in cdef class Eonia(OvernightIndex): def __init__(self, HandleYieldTermStructure yts=HandleYieldTermStructure()): - self._thisptr.reset(new _eo.Eonia(yts.handle)) + self._thisptr.reset(new _eo.Eonia(yts.handle())) diff --git a/quantlib/indexes/ibor/euribor.pyx b/quantlib/indexes/ibor/euribor.pyx index 7ca2d1502..3e00503e8 100644 --- a/quantlib/indexes/ibor/euribor.pyx +++ b/quantlib/indexes/ibor/euribor.pyx @@ -7,34 +7,31 @@ FOR A PARTICULAR PURPOSE. See the license for more details. """ -from quantlib.handle cimport Handle, shared_ptr - from cython.operator cimport dereference as deref -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from . cimport _euribor as _eu -cimport quantlib._index as _in from quantlib.time.date cimport Period cdef class Euribor(IborIndex): def __init__(self, Period tenor not None, HandleYieldTermStructure ts=HandleYieldTermStructure()): - self._thisptr = shared_ptr[_in.Index]( + self._thisptr.reset( new _eu.Euribor( - deref(tenor._thisptr), ts.handle + deref(tenor._thisptr), ts.handle() ) ) cdef class Euribor3M(Euribor): def __init__(self, HandleYieldTermStructure ts=HandleYieldTermStructure()): - self._thisptr = shared_ptr[_in.Index]( - new _eu.Euribor3M(ts.handle) + self._thisptr.reset( + new _eu.Euribor3M(ts.handle()) ) cdef class Euribor6M(Euribor): def __init__(self, HandleYieldTermStructure ts=HandleYieldTermStructure()): - self._thisptr = shared_ptr[_in.Index]( - new _eu.Euribor6M(ts.handle) + self._thisptr.reset( + new _eu.Euribor6M(ts.handle()) ) diff --git a/quantlib/indexes/ibor/libor.pyx b/quantlib/indexes/ibor/libor.pyx index d836ef48a..0d4b2158f 100644 --- a/quantlib/indexes/ibor/libor.pyx +++ b/quantlib/indexes/ibor/libor.pyx @@ -18,8 +18,7 @@ cimport quantlib._index as _in cimport quantlib.time._calendar as _calendar # PyQL cimport -from quantlib.handle cimport shared_ptr -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from quantlib.currency.currency cimport Currency from quantlib.time.calendar cimport Calendar from quantlib.time.date cimport Period @@ -45,15 +44,16 @@ cdef class Libor(IborIndex): # convert the Python str to C++ string cdef string familyName_string = familyName.encode('utf-8') - self._thisptr = shared_ptr[_in.Index]( - new _libor.Libor( - familyName_string, - deref(tenor._thisptr), - settlementDays, - deref(currency._thisptr), - financial_center_calendar._thisptr, - deref(dayCounter._thisptr), - ts.handle)) + self._thisptr.reset( + new _libor.Libor( + familyName_string, + deref(tenor._thisptr), + settlementDays, + deref(currency._thisptr), + financial_center_calendar._thisptr, + deref(dayCounter._thisptr), + ts.handle()) + ) @property def joint_calendar(self): diff --git a/quantlib/indexes/ibor/sofr.pyx b/quantlib/indexes/ibor/sofr.pyx index c827a59b3..17efc841d 100644 --- a/quantlib/indexes/ibor/sofr.pyx +++ b/quantlib/indexes/ibor/sofr.pyx @@ -1,7 +1,7 @@ -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from . cimport _sofr as _sfr from ... cimport _index as _in cdef class Sofr(OvernightIndex): def __init__(self, HandleYieldTermStructure yts=HandleYieldTermStructure()): - self._thisptr.reset(new _sfr.Sofr(yts.handle)) + self._thisptr.reset(new _sfr.Sofr(yts.handle())) diff --git a/quantlib/indexes/ibor/usdlibor.pyx b/quantlib/indexes/ibor/usdlibor.pyx index b03437d87..1d5efb3eb 100644 --- a/quantlib/indexes/ibor/usdlibor.pyx +++ b/quantlib/indexes/ibor/usdlibor.pyx @@ -1,7 +1,5 @@ -from quantlib.handle cimport Handle, shared_ptr - from cython.operator cimport dereference as deref -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from . cimport _usdlibor as _usd cimport quantlib._index as _in from quantlib.time.date cimport Period @@ -9,8 +7,8 @@ from quantlib.time.date cimport Period cdef class USDLibor(Libor): def __init__(self, Period tenor not None, HandleYieldTermStructure ts=HandleYieldTermStructure()): - self._thisptr = shared_ptr[_in.Index]( + self._thisptr.reset( new _usd.USDLibor( - deref(tenor._thisptr), ts.handle + deref(tenor._thisptr), ts.handle() ) ) diff --git a/quantlib/indexes/ibor_index.pyx b/quantlib/indexes/ibor_index.pyx index 8d098c942..5aad7c8d9 100644 --- a/quantlib/indexes/ibor_index.pyx +++ b/quantlib/indexes/ibor_index.pyx @@ -9,7 +9,7 @@ from quantlib.time.daycounter cimport DayCounter from quantlib.currency.currency cimport Currency from quantlib.time.calendar cimport Calendar from quantlib.time.businessdayconvention cimport ModifiedFollowing, BusinessDayConvention -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport Handle, HandleYieldTermStructure cimport quantlib.termstructures._yield_term_structure as _yts cimport quantlib._index as _in @@ -36,7 +36,7 @@ cdef class IborIndex(InterestRateIndex): convention, end_of_month, deref(day_counter._thisptr), - yts.handle) + yts.handle()) ) property business_day_convention: @@ -54,9 +54,7 @@ cdef class IborIndex(InterestRateIndex): cdef: _ib.IborIndex* ref = <_ib.IborIndex*>self._thisptr.get() HandleYieldTermStructure yts = HandleYieldTermStructure.__new__(HandleYieldTermStructure) - Handle[_yts.YieldTermStructure] _yts = ref.forwardingTermStructure() - if not _yts.empty(): - yts.handle.linkTo(_yts.currentLink()) + yts._handle = new Handle[_yts.YieldTermStructure](ref.forwardingTermStructure()) return yts @staticmethod @@ -96,5 +94,5 @@ cdef class OvernightIndex(IborIndex): deref(currency._thisptr), fixing_calendar._thisptr, deref(day_counter._thisptr), - yts.handle) + yts.handle()) ) diff --git a/quantlib/indexes/inflation/aucpi.pyx b/quantlib/indexes/inflation/aucpi.pyx index 501406dea..ddefd6ce2 100644 --- a/quantlib/indexes/inflation/aucpi.pyx +++ b/quantlib/indexes/inflation/aucpi.pyx @@ -1,11 +1,11 @@ from libcpp cimport bool from . cimport _aucpi from quantlib.time.frequency cimport Frequency -from quantlib.termstructures.inflation_term_structure cimport ZeroInflationTermStructure +from quantlib.handle cimport HandleZeroInflationTermStructure cdef class AUCPI(ZeroInflationIndex): def __init__(self, Frequency frequency, bool revised, - ZeroInflationTermStructure ts=ZeroInflationTermStructure()): - self._thisptr.reset(new _aucpi.AUCPI(frequency, revised, ts._handle)) + HandleZeroInflationTermStructure ts=HandleZeroInflationTermStructure()): + self._thisptr.reset(new _aucpi.AUCPI(frequency, revised, ts.handle())) diff --git a/quantlib/indexes/inflation/euhicp.pyx b/quantlib/indexes/inflation/euhicp.pyx index 8c8eb10d0..41027c46f 100644 --- a/quantlib/indexes/inflation/euhicp.pyx +++ b/quantlib/indexes/inflation/euhicp.pyx @@ -1,21 +1,21 @@ from . cimport _euhicp from libcpp cimport bool -from quantlib.termstructures.inflation_term_structure cimport ( - ZeroInflationTermStructure, YoYInflationTermStructure) +from quantlib.handle cimport ( + HandleZeroInflationTermStructure, HandleYoYInflationTermStructure) cdef class EUHICP(ZeroInflationIndex): - def __init__(self, ZeroInflationTermStructure ts=ZeroInflationTermStructure()): - self._thisptr.reset(new _euhicp.EUHICP(ts._handle)) + def __init__(self, HandleZeroInflationTermStructure ts=HandleZeroInflationTermStructure()): + self._thisptr.reset(new _euhicp.EUHICP(ts.handle())) cdef class EUHICPXT(ZeroInflationIndex): - def __init__(self, ZeroInflationTermStructure ts=ZeroInflationTermStructure()): - self._thisptr.reset(new _euhicp.EUHICPXT(ts._handle)) + def __init__(self, HandleZeroInflationTermStructure ts=HandleZeroInflationTermStructure()): + self._thisptr.reset(new _euhicp.EUHICPXT(ts.handle())) cdef class YYEUHICP(YoYInflationIndex): - def __init__(self, YoYInflationTermStructure ts=YoYInflationTermStructure()): - self._thisptr.reset(new _euhicp.YYEUHICP(ts._handle)) + def __init__(self, HandleYoYInflationTermStructure ts=HandleYoYInflationTermStructure()): + self._thisptr.reset(new _euhicp.YYEUHICP(ts.handle())) cdef class YYEUHICPXT(YoYInflationIndex): - def __init__(self, YoYInflationTermStructure ts=YoYInflationTermStructure()): - self._thisptr.reset(new _euhicp.YYEUHICPXT(ts._handle)) + def __init__(self, HandleYoYInflationTermStructure ts=HandleYoYInflationTermStructure()): + self._thisptr.reset(new _euhicp.YYEUHICPXT(ts.handle())) diff --git a/quantlib/indexes/inflation/ukrpi.pyx b/quantlib/indexes/inflation/ukrpi.pyx index 27447e9fe..03c70e285 100644 --- a/quantlib/indexes/inflation/ukrpi.pyx +++ b/quantlib/indexes/inflation/ukrpi.pyx @@ -1,9 +1,8 @@ from . cimport _ukrpi from quantlib.indexes.inflation_index cimport ZeroInflationIndex -from quantlib.termstructures.inflation_term_structure \ - cimport ZeroInflationTermStructure +from quantlib.handle cimport HandleZeroInflationTermStructure cdef class UKRPI(ZeroInflationIndex): - def __init__(self, ZeroInflationTermStructure ts=ZeroInflationTermStructure()): - self._thisptr.reset(new _ukrpi.UKRPI(ts._handle)) + def __init__(self, HandleZeroInflationTermStructure ts=HandleZeroInflationTermStructure()): + self._thisptr.reset(new _ukrpi.UKRPI(ts.handle())) diff --git a/quantlib/indexes/inflation_index.pyx b/quantlib/indexes/inflation_index.pyx index 4748b745e..58bdc8163 100644 --- a/quantlib/indexes/inflation_index.pyx +++ b/quantlib/indexes/inflation_index.pyx @@ -18,17 +18,18 @@ from quantlib.time.frequency cimport Frequency from quantlib.indexes.region cimport Region from quantlib.currency.currency cimport Currency -from quantlib.termstructures.inflation_term_structure cimport \ - ZeroInflationTermStructure, YoYInflationTermStructure +from quantlib.handle cimport ( + Handle, HandleZeroInflationTermStructure, HandleYoYInflationTermStructure +) cimport quantlib._index as _in cimport quantlib.indexes._inflation_index as _ii -cimport quantlib.termstructures._inflation_term_structure as _its cimport quantlib._interest_rate as _ir cimport quantlib.time._period as _pe cimport quantlib.currency._currency as _cu cimport quantlib.indexes._region as _region +from quantlib.termstructures._inflation_term_structure cimport ZeroInflationTermStructure, YoYInflationTermStructure cdef class InflationIndex(Index): @@ -72,12 +73,12 @@ cdef class ZeroInflationIndex(InflationIndex): Frequency frequency, Period availabilityLag, Currency currency, - ZeroInflationTermStructure ts=ZeroInflationTermStructure()): + HandleZeroInflationTermStructure ts=HandleZeroInflationTermStructure()): # convert the Python str to C++ string cdef string c_family_name = family_name.encode('utf-8') - self._thisptr = shared_ptr[_in.Index]( + self._thisptr.reset( new _ii.ZeroInflationIndex( c_family_name, deref(region._thisptr), @@ -85,14 +86,17 @@ cdef class ZeroInflationIndex(InflationIndex): frequency, deref(availabilityLag._thisptr), deref(currency._thisptr), - ts._handle)) + ts.handle()) + ) + @property def zero_inflation_term_structure(self): - cdef ZeroInflationTermStructure r = \ - ZeroInflationTermStructure.__new__(ZeroInflationTermStructure) - r._thisptr = static_pointer_cast[_its.InflationTermStructure]( - (<_ii.ZeroInflationIndex*>(self._thisptr.get())). - zeroInflationTermStructure().currentLink()) + cdef HandleZeroInflationTermStructure r = \ + HandleZeroInflationTermStructure.__new__(HandleZeroInflationTermStructure) + r._handle = new Handle[ZeroInflationTermStructure]( + (<_ii.ZeroInflationIndex*>(self._thisptr.get())).zeroInflationTermStructure() + ) + return r @property def last_fixing_date(self): @@ -105,13 +109,23 @@ cdef class YoYInflationIndex(ZeroInflationIndex): def __init__(self, family_name, Region region, bool revised, Frequency frequency, Period availability_lag, Currency currency, - YoYInflationTermStructure ts=YoYInflationTermStructure()): + HandleYoYInflationTermStructure ts=HandleYoYInflationTermStructure()): cdef string c_family_name = family_name.encode('utf-8') - self._thisptr = shared_ptr[_in.Index]( + self._thisptr.reset( new _ii.YoYInflationIndex( c_family_name, deref(region._thisptr), revised, frequency, deref(availability_lag._thisptr), - deref(currency._thisptr), ts._handle)) + deref(currency._thisptr), ts.handle()) + ) + + @property + def yoy_inflation_term_structure(self): + cdef HandleYoYInflationTermStructure r = \ + HandleYoYInflationTermStructure.__new__(HandleYoYInflationTermStructure) + r._handle = new Handle[YoYInflationTermStructure]( + (<_ii.YoYInflationIndex*>(self._thisptr.get())).yoyInflationTermStructure() + ) + return r diff --git a/quantlib/indexes/swap/euribor_swap.pyx b/quantlib/indexes/swap/euribor_swap.pyx index f32fdd098..84f03665a 100644 --- a/quantlib/indexes/swap/euribor_swap.pyx +++ b/quantlib/indexes/swap/euribor_swap.pyx @@ -1,36 +1,34 @@ from cython.operator cimport dereference as deref -from quantlib.handle cimport shared_ptr from quantlib.time.date cimport Period -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from quantlib.indexes.swap_index cimport SwapIndex cimport quantlib.indexes.swap._euribor_swap as _es -cimport quantlib._index as _in cdef class EuriborSwapIsdaFixA(SwapIndex): def __init__(self, Period tenor, HandleYieldTermStructure forwarding=HandleYieldTermStructure(), HandleYieldTermStructure discounting=None): if discounting is None: - self._thisptr = shared_ptr[_in.Index]( + self._thisptr.reset( new _es.EuriborSwapIsdaFixA(deref(tenor._thisptr), - forwarding.handle)) + forwarding.handle())) else: - self._thisptr = shared_ptr[_in.Index]( + self._thisptr.reset( new _es.EuriborSwapIsdaFixA(deref(tenor._thisptr), - forwarding.handle, - discounting.handle) + forwarding.handle(), + discounting.handle()) ) cdef class EuriborSwapIsdaFixB(SwapIndex): def __init__(self, Period tenor, HandleYieldTermStructure forwarding=HandleYieldTermStructure(), HandleYieldTermStructure discounting=None): if discounting is None: - self._thisptr = shared_ptr[_in.Index]( + self._thisptr.reset( new _es.EuriborSwapIsdaFixA(deref(tenor._thisptr), - forwarding.handle)) + forwarding.handle())) else: - self._thisptr = shared_ptr[_in.Index]( + self._thisptr.reset( new _es.EuriborSwapIsdaFixB(deref(tenor._thisptr), - forwarding.handle, - discounting.handle) + forwarding.handle(), + discounting.handle()) ) diff --git a/quantlib/indexes/swap/usd_libor_swap.pyx b/quantlib/indexes/swap/usd_libor_swap.pyx index 2110d9ac2..1dee405bc 100644 --- a/quantlib/indexes/swap/usd_libor_swap.pyx +++ b/quantlib/indexes/swap/usd_libor_swap.pyx @@ -1,38 +1,36 @@ from cython.operator cimport dereference as deref -from quantlib.handle cimport shared_ptr from quantlib.time.date cimport Period -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from quantlib.indexes.swap_index cimport SwapIndex cimport quantlib.indexes.swap._usd_libor_swap as _ls -cimport quantlib._index as _in cdef class UsdLiborSwapIsdaFixAm(SwapIndex): def __init__(self, Period tenor, HandleYieldTermStructure forwarding=HandleYieldTermStructure(), HandleYieldTermStructure discounting=None): if discounting is None: - self._thisptr = shared_ptr[_in.Index]( + self._thisptr.reset( new _ls.UsdLiborSwapIsdaFixAm(deref(tenor._thisptr), - forwarding.handle) + forwarding.handle()) ) else: - self._thisptr = shared_ptr[_in.Index]( + self._thisptr.reset( new _ls.UsdLiborSwapIsdaFixAm(deref(tenor._thisptr), - forwarding.handle, - discounting.handle) + forwarding.handle(), + discounting.handle()) ) cdef class UsdLiborSwapIsdaFixPm(SwapIndex): def __init__(self, Period tenor, HandleYieldTermStructure forwarding=HandleYieldTermStructure(), HandleYieldTermStructure discounting=None): if discounting is None: - self._thisptr = shared_ptr[_in.Index]( + self._thisptr.reset( new _ls.UsdLiborSwapIsdaFixPm(deref(tenor._thisptr), - forwarding.handle) + forwarding.handle()) ) else: - self._thisptr = shared_ptr[_in.Index]( + self._thisptr.reset( new _ls.UsdLiborSwapIsdaFixPm(deref(tenor._thisptr), - forwarding.handle, - discounting.handle) + forwarding.handle(), + discounting.handle()) ) diff --git a/quantlib/indexes/swap_index.pyx b/quantlib/indexes/swap_index.pyx index 81ea59d6b..302efb260 100644 --- a/quantlib/indexes/swap_index.pyx +++ b/quantlib/indexes/swap_index.pyx @@ -25,7 +25,7 @@ from quantlib.currency.currency cimport Currency from quantlib.time.date cimport Date from quantlib.time.calendar cimport Calendar from quantlib.time._calendar cimport BusinessDayConvention -from quantlib.termstructures.yield_term_structure cimport YieldTermStructure, HandleYieldTermStructure +from quantlib.handle cimport Handle, HandleYieldTermStructure cimport quantlib.termstructures._yield_term_structure as _yts cimport quantlib._index as _in @@ -71,7 +71,7 @@ cdef class SwapIndex(InterestRateIndex): fixed_leg_convention, deref(fixed_leg_daycounter._thisptr), static_pointer_cast[_ii.IborIndex](ibor_index._thisptr), - discounting_term_structure.handle + discounting_term_structure.handle() ) ) @@ -91,27 +91,21 @@ cdef class SwapIndex(InterestRateIndex): @property def forwarding_term_structure(self): - cdef YieldTermStructure yts = YieldTermStructure.__new__(YieldTermStructure) + cdef HandleYieldTermStructure h = HandleYieldTermStructure.__new__(HandleYieldTermStructure) cdef _si.SwapIndex* swap_index = <_si.SwapIndex*>self._thisptr.get() - if not swap_index.forwardingTermStructure().empty(): - yts._thisptr = (swap_index. - forwardingTermStructure(). - currentLink()) - return yts - else: - raise RuntimeError("Cannot dereference empty handle") + h._handle = new Handle[_yts.YieldTermStructure]( + swap_index.forwardingTermStructure() + ) + return h @property def discounting_term_structure(self): - cdef YieldTermStructure yts = YieldTermStructure.__new__(YieldTermStructure) + cdef HandleYieldTermStructure h = HandleYieldTermStructure.__new__(HandleYieldTermStructure) cdef _si.SwapIndex* swap_index = <_si.SwapIndex*>self._thisptr.get() - if not swap_index.discountingTermStructure().empty(): - yts._thisptr = (swap_index. - discountingTermStructure(). - currentLink()) - return yts - else: - raise RuntimeError("Cannot dereference empty handle") + h._handle = new Handle[_yts.YieldTermStructure]( + swap_index.discountingTermStructure() + ) + return h cdef class OvernightIndexedSwapIndex(SwapIndex): diff --git a/quantlib/instruments/_swap.pxd b/quantlib/instruments/_swap.pxd index 2644cb69d..d60b304ae 100644 --- a/quantlib/instruments/_swap.pxd +++ b/quantlib/instruments/_swap.pxd @@ -11,7 +11,6 @@ from quantlib.types cimport DiscountFactor, Real, Size from libcpp.vector cimport vector from libcpp cimport bool -from quantlib.handle cimport shared_ptr, Handle from .._instrument cimport Instrument from quantlib.time._calendar cimport BusinessDayConvention, Calendar from quantlib.time._date cimport Date diff --git a/quantlib/instruments/bondforward.pyx b/quantlib/instruments/bondforward.pyx index 8ad6cd389..5202b9daa 100644 --- a/quantlib/instruments/bondforward.pyx +++ b/quantlib/instruments/bondforward.pyx @@ -6,7 +6,7 @@ from quantlib.time.daycounter cimport DayCounter from quantlib.types cimport Natural, Real from quantlib.ext cimport static_pointer_cast from quantlib.position cimport Position -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from . cimport _bondforward as _bf from . cimport _bond from .bond cimport Bond @@ -53,7 +53,7 @@ cdef class BondForward(Forward): self._thisptr.reset( new _bf.BondForward(value_date._thisptr, maturity_date._thisptr, position_type, strike, settlement_days, deref(day_counter._thisptr), calendar._thisptr, convention, - static_pointer_cast[_bond.Bond](bond._thisptr), discount_curve.handle, income_discount_curve.handle) + static_pointer_cast[_bond.Bond](bond._thisptr), discount_curve.handle(), income_discount_curve.handle()) ) @property diff --git a/quantlib/instruments/credit_default_swap.pyx b/quantlib/instruments/credit_default_swap.pyx index 03d554c3e..ad01e486f 100644 --- a/quantlib/instruments/credit_default_swap.pyx +++ b/quantlib/instruments/credit_default_swap.pyx @@ -20,7 +20,7 @@ cimport quantlib.pricingengines._pricing_engine as _pe cimport quantlib.time._calendar as _calendar from quantlib.time.dategeneration cimport DateGeneration -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from quantlib.pricingengines.engine cimport PricingEngine from quantlib.time.date cimport Date, Period from quantlib.time.daycounter cimport DayCounter @@ -303,7 +303,7 @@ cdef class CreditDefaultSwap(Instrument): PricingModel model=PricingModel.Midpoint): return _get_cds(self).conventionalSpread(recovery, - yts.handle, + yts.handle(), deref(dc._thisptr), model) @@ -314,7 +314,7 @@ cdef class CreditDefaultSwap(Instrument): PricingModel model=PricingModel.Midpoint): return _get_cds(self).impliedHazardRate(target_npv, - yts.handle, + yts.handle(), deref(dc._thisptr), recovery_rate, accuracy, diff --git a/quantlib/instruments/forward.pyx b/quantlib/instruments/forward.pyx index 3d6d0a682..1c1becada 100644 --- a/quantlib/instruments/forward.pyx +++ b/quantlib/instruments/forward.pyx @@ -3,7 +3,7 @@ from quantlib.types cimport Real from quantlib.compounding cimport Compounding from quantlib.time.date cimport Date from quantlib.time.daycounter cimport DayCounter -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from quantlib.interest_rate cimport InterestRate from libcpp.utility cimport move from quantlib cimport _interest_rate as _ir @@ -23,7 +23,7 @@ cdef class Forward(Instrument): def spot_income(self, HandleYieldTermStructure income_discount_curve): """NPV of income/dividends/storate-cossts etc. of underlying instrument""" - return (<_forward.Forward*>self._thisptr.get()).spotIncome(income_discount_curve.handle) + return (<_forward.Forward*>self._thisptr.get()).spotIncome(income_discount_curve.handle()) def implied_yield(self, Real underlying_spot_value, Real forward_value, Date settlement_date, Compounding convention, DayCounter day_counter): diff --git a/quantlib/instruments/make_cms.pyx b/quantlib/instruments/make_cms.pyx index 3579c4c6e..2af0d6abe 100644 --- a/quantlib/instruments/make_cms.pyx +++ b/quantlib/instruments/make_cms.pyx @@ -6,7 +6,7 @@ from quantlib.indexes.swap_index cimport SwapIndex from quantlib.indexes.ibor_index cimport IborIndex from quantlib.time.date cimport Period, Date from quantlib.time._period cimport Days -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure cimport quantlib.indexes._swap_index as _si cimport quantlib.indexes._ibor_index as _ii cimport quantlib._instrument as _in @@ -55,7 +55,7 @@ cdef class MakeCms: def with_discounting_term_structure(self, HandleYieldTermStructure discounting_term_structure not None): self._thisptr.withDiscountingTermStructure( - discounting_term_structure.handle) + discounting_term_structure.handle()) return self def with_cms_leg_tenor(self, Period t not None): diff --git a/quantlib/instruments/make_ois.pyx b/quantlib/instruments/make_ois.pyx index 6bf453f10..38ef98a94 100644 --- a/quantlib/instruments/make_ois.pyx +++ b/quantlib/instruments/make_ois.pyx @@ -10,7 +10,7 @@ from quantlib.time.businessdayconvention cimport BusinessDayConvention from quantlib.time.calendar cimport Calendar from quantlib.time.daycounter cimport DayCounter from quantlib.time.dategeneration cimport DateGeneration -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from quantlib.pricingengines.engine cimport PricingEngine cimport quantlib.indexes._ibor_index as _ii from .. cimport _instrument as _in @@ -107,7 +107,7 @@ cdef class MakeOIS: return self def with_discounting_term_structure(self, HandleYieldTermStructure ts): - self._thisptr.withDiscountingTermStructure(ts.handle) + self._thisptr.withDiscountingTermStructure(ts.handle()) return self def with_telescopic_value_dates(self, bool telescopic_value_dates): diff --git a/quantlib/instruments/make_vanilla_swap.pyx b/quantlib/instruments/make_vanilla_swap.pyx index 6e17c7fb6..b8e5732e7 100644 --- a/quantlib/instruments/make_vanilla_swap.pyx +++ b/quantlib/instruments/make_vanilla_swap.pyx @@ -9,7 +9,7 @@ from quantlib.time.businessdayconvention cimport BusinessDayConvention from quantlib.time.daycounter cimport DayCounter from quantlib.time._period cimport Days from quantlib.time.dategeneration cimport DateGeneration -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from quantlib.pricingengines.engine cimport PricingEngine cimport quantlib.indexes._ibor_index as _ii cimport quantlib._instrument as _in @@ -88,7 +88,7 @@ cdef class MakeVanillaSwap: return self def with_discounting_term_structure(self, HandleYieldTermStructure yts not None): - self._thisptr.withDiscountingTermStructure(yts.handle) + self._thisptr.withDiscountingTermStructure(yts.handle()) return self def with_pricing_engine(self, PricingEngine engine not None): diff --git a/quantlib/instruments/swaption.pyx b/quantlib/instruments/swaption.pyx index d5fb0f48b..f98bae5a6 100644 --- a/quantlib/instruments/swaption.pyx +++ b/quantlib/instruments/swaption.pyx @@ -3,8 +3,7 @@ from . cimport _swaption from quantlib.ext cimport shared_ptr, static_pointer_cast from quantlib.termstructures.volatility.volatilitytype cimport ( VolatilityType, ShiftedLognormal ) -from quantlib.termstructures.yield_term_structure cimport YieldTermStructure -from quantlib.termstructures cimport _yield_term_structure as _yts +from quantlib.handle cimport HandleYieldTermStructure from ..exercise cimport Exercise from .swap cimport Type as SwapType from .fixedvsfloatingswap cimport FixedVsFloatingSwap @@ -36,7 +35,7 @@ cdef class Swaption(Option): return <_swaption.Swaption*>self._thisptr.get() def implied_volatility(self, Real price, - YieldTermStructure discount_curve not None, + HandleYieldTermStructure discount_curve not None, Volatility guess, Real accuracy=1e-4, Natural max_evaluations=100, @@ -46,11 +45,7 @@ cdef class Swaption(Option): Real displacement=0.): return self.get_swaption().impliedVolatility( price, - Handle[_yts.YieldTermStructure]( - static_pointer_cast[_yts.YieldTermStructure]( - discount_curve._thisptr - ) - ), + discount_curve.handle(), guess, accuracy, max_evaluations, diff --git a/quantlib/instruments/variance_swap.pyx b/quantlib/instruments/variance_swap.pyx index a0953e539..52b472360 100644 --- a/quantlib/instruments/variance_swap.pyx +++ b/quantlib/instruments/variance_swap.pyx @@ -1,16 +1,15 @@ from quantlib.types cimport Real -from quantlib.handle cimport shared_ptr from .._instrument cimport Instrument as _Instrument -from quantlib.time.date cimport (Date, _pydate_from_qldate, _qldate_from_pydate) +from quantlib.time.date cimport Date, _pydate_from_qldate, _qldate_from_pydate from libcpp cimport bool -from ._variance_swap cimport (VarianceSwap as _VarianceSwap, Type as _Type) +from ._variance_swap cimport VarianceSwap as _VarianceSwap, Type as _Type import datetime cpdef public enum SwapType: Long = _Type.Long Short = _Type.Short -cdef inline _VarianceSwap* get_varianceswap(VarianceSwap swap): +cdef inline _VarianceSwap* get_varianceswap(VarianceSwap swap) noexcept nogil: """ Utility function to extract a properly casted Swap pointer out of the internal _thisptr attribute of the Instrument base class. @@ -40,12 +39,15 @@ cdef class VarianceSwap(Instrument): Date start_date, Date maturity_date): - self._thisptr = shared_ptr[_Instrument](new _VarianceSwap(<_Type>position, - strike, - notional, - start_date._thisptr, - maturity_date._thisptr, - )) + self._thisptr.reset( + new _VarianceSwap( + <_Type>position, + strike, + notional, + start_date._thisptr, + maturity_date._thisptr, + ) + ) @property def strike(self): diff --git a/quantlib/interest_rate.pxd b/quantlib/interest_rate.pxd index 92bb8f1ce..ae51d4a6f 100644 --- a/quantlib/interest_rate.pxd +++ b/quantlib/interest_rate.pxd @@ -1,4 +1,3 @@ -from quantlib.handle cimport shared_ptr from . cimport _interest_rate as _ir cdef class InterestRate: diff --git a/quantlib/mlab/fixed_income.py b/quantlib/mlab/fixed_income.py index 31f0660ed..f0aa7c5b8 100644 --- a/quantlib/mlab/fixed_income.py +++ b/quantlib/mlab/fixed_income.py @@ -27,7 +27,7 @@ from quantlib.time.dategeneration import DateGeneration from quantlib.settings import Settings from quantlib.termstructures.yields.api import ( - FlatForward, HandleYieldTermStructure + FlatForward, RelinkableHandleYieldTermStructure ) from quantlib.time.daycounter import DayCounter @@ -135,7 +135,7 @@ def _bndprice(bond_yield, coupon_rate, pricing_date, maturity_date, issue_date ) - discounting_term_structure = HandleYieldTermStructure() + discounting_term_structure = RelinkableHandleYieldTermStructure() cnt_yield = DayCounter.from_name('Actual/Actual (Historical)') diff --git a/quantlib/mlab/option_pricing.py b/quantlib/mlab/option_pricing.py index ac9c303c0..7735a7b74 100644 --- a/quantlib/mlab/option_pricing.py +++ b/quantlib/mlab/option_pricing.py @@ -25,7 +25,7 @@ AnalyticHestonEngine) from quantlib.processes.api import BlackScholesMertonProcess from quantlib.termstructures.yields.api import FlatForward, HandleYieldTermStructure -from quantlib.termstructures.volatility.api import BlackConstantVol +from quantlib.termstructures.volatility.api import BlackConstantVol, HandleBlackVolTermStructure from quantlib.time.api import today, NullCalendar, ActualActual from quantlib.time.date import (Period, Days) @@ -108,8 +108,10 @@ def _blsprice(spot, strike, risk_free_rate, time, volatility, daycounter = ActualActual(ActualActual.ISMA) risk_free_ts = HandleYieldTermStructure(FlatForward(today(), risk_free_rate, daycounter)) dividend_ts = HandleYieldTermStructure(FlatForward(today(), dividend, daycounter)) - volatility_ts = BlackConstantVol(today(), NullCalendar(), - volatility, daycounter) + volatility_ts = HandleBlackVolTermStructure( + BlackConstantVol(today(), NullCalendar(), + volatility, daycounter) + ) process = BlackScholesMertonProcess(_spot, dividend_ts, risk_free_ts, volatility_ts) @@ -166,8 +168,9 @@ def _blsimpv(price, spot, strike, risk_free_rate, time, daycounter = ActualActual(ActualActual.ISMA) risk_free_ts = HandleYieldTermStructure(FlatForward(today(), risk_free_rate, daycounter)) dividend_ts = HandleYieldTermStructure(FlatForward(today(), dividend, daycounter)) - volatility_ts = BlackConstantVol(today(), NullCalendar(), - .3, daycounter) + volatility_ts = HandleBlackVolTermStructure( + BlackConstantVol(today(), NullCalendar(), .3, daycounter) + ) process = BlackScholesMertonProcess(spot, dividend_ts, risk_free_ts, volatility_ts) diff --git a/quantlib/models/equity/heston_model.pyx b/quantlib/models/equity/heston_model.pyx index 72afc4281..f657710dd 100644 --- a/quantlib/models/equity/heston_model.pyx +++ b/quantlib/models/equity/heston_model.pyx @@ -27,9 +27,7 @@ from quantlib.pricingengines.engine cimport PricingEngine from quantlib.quote cimport Quote from quantlib.time.calendar cimport Calendar from quantlib.time.date cimport Period -from quantlib.termstructures.yield_term_structure cimport ( - HandleYieldTermStructure -) +from quantlib.handle cimport HandleYieldTermStructure from quantlib.models.calibration_helper cimport BlackCalibrationHelper, CalibrationErrorType @@ -55,8 +53,8 @@ cdef class HestonModelHelper(BlackCalibrationHelper): s0, strike_price, volatility.handle(), - risk_free_rate.handle, - dividend_yield.handle, + risk_free_rate.handle(), + dividend_yield.handle(), error_type ) ) diff --git a/quantlib/models/shortrate/calibrationhelpers/swaption_helper.pyx b/quantlib/models/shortrate/calibrationhelpers/swaption_helper.pyx index de7c87322..d9cc61c61 100644 --- a/quantlib/models/shortrate/calibrationhelpers/swaption_helper.pyx +++ b/quantlib/models/shortrate/calibrationhelpers/swaption_helper.pyx @@ -9,7 +9,7 @@ from quantlib.types cimport Real from quantlib.ext cimport shared_ptr, static_pointer_cast from cython.operator cimport dereference as deref -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from quantlib.termstructures.volatility.volatilitytype cimport VolatilityType from quantlib.time.daycounter cimport DayCounter from quantlib.indexes.ibor_index cimport IborIndex @@ -55,7 +55,7 @@ cdef class SwaptionHelper(BlackCalibrationHelper): deref(fixed_leg_tenor._thisptr), deref(fixed_leg_daycounter._thisptr), deref(floating_leg_daycounter._thisptr), - ts.handle, + ts.handle(), error_type, strike, nominal, @@ -73,7 +73,7 @@ cdef class SwaptionHelper(BlackCalibrationHelper): deref(fixed_leg_tenor._thisptr), deref(fixed_leg_daycounter._thisptr), deref(floating_leg_daycounter._thisptr), - ts.handle, + ts.handle(), error_type, strike, nominal, @@ -91,7 +91,7 @@ cdef class SwaptionHelper(BlackCalibrationHelper): deref(fixed_leg_tenor._thisptr), deref(fixed_leg_daycounter._thisptr), deref(floating_leg_daycounter._thisptr), - ts.handle, + ts.handle(), error_type, strike, nominal, diff --git a/quantlib/models/shortrate/onefactormodels/blackkarasinski.pyx b/quantlib/models/shortrate/onefactormodels/blackkarasinski.pyx index d42ac5ee3..367debdf1 100644 --- a/quantlib/models/shortrate/onefactormodels/blackkarasinski.pyx +++ b/quantlib/models/shortrate/onefactormodels/blackkarasinski.pyx @@ -24,6 +24,6 @@ cdef class BlackKarasinski(OneFactorModel): self._thisptr = shared_ptr[_mo.CalibratedModel]( new _bk.BlackKarasinski( - term_structure.handle, a, sigma + term_structure.handle(), a, sigma ) ) diff --git a/quantlib/models/shortrate/onefactormodels/gsr.pyx b/quantlib/models/shortrate/onefactormodels/gsr.pyx index 62977a230..61e4df593 100644 --- a/quantlib/models/shortrate/onefactormodels/gsr.pyx +++ b/quantlib/models/shortrate/onefactormodels/gsr.pyx @@ -1,6 +1,6 @@ from quantlib.types cimport Real from libcpp.vector cimport vector -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure cdef class Gsr(Gaussian1dModel): def __init__(self, HandleYieldTermStructure h, vol_step_date, vector[Real] volatilities, Real reversion, Real T=60.0): diff --git a/quantlib/models/shortrate/onefactormodels/hullwhite.pyx b/quantlib/models/shortrate/onefactormodels/hullwhite.pyx index 5237be247..49142bc0b 100644 --- a/quantlib/models/shortrate/onefactormodels/hullwhite.pyx +++ b/quantlib/models/shortrate/onefactormodels/hullwhite.pyx @@ -22,7 +22,7 @@ from quantlib.math.optimization cimport Constraint from quantlib.models.shortrate.calibrationhelpers.swaption_helper cimport SwaptionHelper from quantlib.models.calibration_helper cimport BlackCalibrationHelper -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from quantlib.math.optimization cimport OptimizationMethod, EndCriteria from .vasicek cimport Vasicek @@ -47,7 +47,7 @@ cdef class HullWhite(Vasicek): self._thisptr = shared_ptr[_mo.CalibratedModel]( new _hw.HullWhite( - term_structure.handle, + term_structure.handle(), a, sigma ) ) diff --git a/quantlib/models/shortrate/twofactormodels/g2.pyx b/quantlib/models/shortrate/twofactormodels/g2.pyx index 3a8e9d144..bdaae62dc 100644 --- a/quantlib/models/shortrate/twofactormodels/g2.pyx +++ b/quantlib/models/shortrate/twofactormodels/g2.pyx @@ -1,5 +1,5 @@ from quantlib.types cimport Real -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from . cimport _g2 cdef class G2(TwoFactorModel): @@ -10,4 +10,4 @@ cdef class G2(TwoFactorModel): Real b=0.1, Real eta=0.01, Real rho=-0.75): - self._thisptr.reset(new _g2.G2(h.handle, a, sigma, b, eta, rho)) + self._thisptr.reset(new _g2.G2(h.handle(), a, sigma, b, eta, rho)) diff --git a/quantlib/pricingengines/bond/discountingbondengine.pyx b/quantlib/pricingengines/bond/discountingbondengine.pyx index a95c5aa7d..ff17202c6 100644 --- a/quantlib/pricingengines/bond/discountingbondengine.pyx +++ b/quantlib/pricingengines/bond/discountingbondengine.pyx @@ -9,7 +9,7 @@ from . cimport _discountingbondengine as _dbe from ..engine cimport PricingEngine -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure cdef class DiscountingBondEngine(PricingEngine): @@ -17,4 +17,4 @@ cdef class DiscountingBondEngine(PricingEngine): """ """ - self._thisptr.reset(new _dbe.DiscountingBondEngine(discount_curve.handle)) + self._thisptr.reset(new _dbe.DiscountingBondEngine(discount_curve.handle())) diff --git a/quantlib/pricingengines/credit/isda_cds_engine.pyx b/quantlib/pricingengines/credit/isda_cds_engine.pyx index cb8d3d1b6..7c89948ed 100644 --- a/quantlib/pricingengines/credit/isda_cds_engine.pyx +++ b/quantlib/pricingengines/credit/isda_cds_engine.pyx @@ -10,8 +10,7 @@ from . cimport _isda_cds_engine as _ice cimport quantlib.termstructures._default_term_structure as _dts cimport quantlib.termstructures._yield_term_structure as _yts -from quantlib.termstructures.default_term_structure cimport DefaultProbabilityTermStructure, HandleDefaultProbabilityTermStructure -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure, YieldTermStructure +from quantlib.handle cimport Handle, HandleDefaultProbabilityTermStructure, HandleYieldTermStructure from quantlib.termstructures.yields.rate_helpers cimport RateHelper from quantlib.termstructures.credit.default_probability_helpers cimport CdsHelper @@ -46,8 +45,8 @@ cdef class IsdaCdsEngine(PricingEngine): settlement_flows = include_settlement_date_flows self._thisptr.reset( - new _ice.IsdaCdsEngine(ts.handle, recovery_rate, - discount_curve.handle, + new _ice.IsdaCdsEngine(ts.handle(), recovery_rate, + discount_curve.handle(), settlement_flows, <_ice.NumericalFix>numerical_fix, <_ice.AccrualBias>accrual_bias, @@ -59,12 +58,14 @@ cdef class IsdaCdsEngine(PricingEngine): @property def isda_rate_curve(self): - cdef YieldTermStructure yts = YieldTermStructure.__new__(YieldTermStructure) - yts._thisptr.reset(self._get_cds_engine().isdaRateCurve().currentLink().get()) + cdef HandleYieldTermStructure yts = HandleYieldTermStructure.__new__(HandleYieldTermStructure) + yts._handle = new Handle[_yts.YieldTermStructure](self._get_cds_engine().isdaRateCurve()) return yts @property def isda_credit_curve(self): - cdef DefaultProbabilityTermStructure dts = DefaultProbabilityTermStructure.__new__(DefaultProbabilityTermStructure) - dts._thisptr = self._get_cds_engine().isdaCreditCurve().currentLink() + cdef HandleDefaultProbabilityTermStructure dts = HandleDefaultProbabilityTermStructure.__new__(HandleDefaultProbabilityTermStructure) + dts._handle = new Handle[_dts.DefaultProbabilityTermStructure]( + self._get_cds_engine().isdaCreditCurve() + ) return dts diff --git a/quantlib/pricingengines/credit/midpoint_cds_engine.pyx b/quantlib/pricingengines/credit/midpoint_cds_engine.pyx index f775ed27d..02d3d4d3b 100644 --- a/quantlib/pricingengines/credit/midpoint_cds_engine.pyx +++ b/quantlib/pricingengines/credit/midpoint_cds_engine.pyx @@ -13,9 +13,7 @@ from . cimport _midpoint_cds_engine as _mce from quantlib.pricingengines.engine cimport PricingEngine -cimport quantlib.termstructures._default_term_structure as _dts -from quantlib.termstructures.default_term_structure cimport HandleDefaultProbabilityTermStructure -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleDefaultProbabilityTermStructure, HandleYieldTermStructure cdef class MidPointCdsEngine(PricingEngine): @@ -34,7 +32,7 @@ cdef class MidPointCdsEngine(PricingEngine): if include_settlement_date_flows is not None: include_settlement_date_flows_opt = include_settlement_date_flows self._thisptr.reset( - new _mce.MidPointCdsEngine(ts.handle, recovery_rate, discount_curve.handle, + new _mce.MidPointCdsEngine(ts.handle(), recovery_rate, discount_curve.handle(), include_settlement_date_flows_opt, ) ) diff --git a/quantlib/pricingengines/swap.pyx b/quantlib/pricingengines/swap.pyx index 0dd7a18c1..ab029bc60 100644 --- a/quantlib/pricingengines/swap.pyx +++ b/quantlib/pricingengines/swap.pyx @@ -20,7 +20,7 @@ cdef class DiscountingSwapEngine(PricingEngine): include_settlement_date_flows_opt = include_settlement_date_flows self._thisptr.reset( new _swap.DiscountingSwapEngine( - discount_curve.handle, + discount_curve.handle(), include_settlement_date_flows_opt, settlement_date._thisptr, npv_date._thisptr diff --git a/quantlib/pricingengines/swaption/black_swaption_engine.pyx b/quantlib/pricingengines/swaption/black_swaption_engine.pyx index e8bdec23f..f789724c7 100644 --- a/quantlib/pricingengines/swaption/black_swaption_engine.pyx +++ b/quantlib/pricingengines/swaption/black_swaption_engine.pyx @@ -2,13 +2,11 @@ include '../../types.pxi' from cython.operator cimport dereference as deref from quantlib.pricingengines.engine cimport PricingEngine cimport quantlib.pricingengines._pricing_engine as _pe -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure -from quantlib.handle cimport shared_ptr, Handle, static_pointer_cast +from quantlib.handle cimport HandleYieldTermStructure, HandleSwaptionVolatilityStructure +from quantlib.time.date cimport Date from quantlib.time.daycounter cimport DayCounter from quantlib.time.daycounters.simple cimport Actual365Fixed from quantlib.quote cimport Quote -from quantlib.termstructures.volatility.swaption.swaption_vol_structure \ - cimport SwaptionVolatilityStructure from ._black_swaption_engine cimport BlackSwaptionEngine as _BlackSwaptionEngine, BachelierSwaptionEngine as _BachelierSwaptionEngine cpdef enum CashAnnuityModel: @@ -32,7 +30,7 @@ cdef class BlackSwaptionEngine(PricingEngine): if isinstance(vol, float): self._thisptr.reset( new _BlackSwaptionEngine( - discount_curve.handle, + discount_curve.handle(), vol, deref(dc._thisptr), displacement, @@ -42,21 +40,23 @@ cdef class BlackSwaptionEngine(PricingEngine): elif isinstance(vol, Quote): self._thisptr.reset( new _BlackSwaptionEngine( - discount_curve.handle, + discount_curve.handle(), (vol).handle(), deref(dc._thisptr), displacement, <_BlackSwaptionEngine.CashAnnuityModel>model, ) ) - else: + elif isinstance(vol, HandleSwaptionVolatilityStructure): self._thisptr.reset( new _BlackSwaptionEngine( - discount_curve.handle, - SwaptionVolatilityStructure.swaption_vol_handle(vol), + discount_curve.handle(), + (vol).handle(), <_BlackSwaptionEngine.CashAnnuityModel>model, ) ) + else: + raise TypeError() cdef class BachelierSwaptionEngine(PricingEngine): @@ -77,7 +77,7 @@ cdef class BachelierSwaptionEngine(PricingEngine): if isinstance(vol, float): self._thisptr.reset( new _BachelierSwaptionEngine( - discount_curve.handle, + discount_curve.handle(), vol, deref(dc._thisptr), <_BachelierSwaptionEngine.CashAnnuityModel>model, @@ -86,17 +86,19 @@ cdef class BachelierSwaptionEngine(PricingEngine): elif isinstance(vol, Quote): self._thisptr.reset( new _BachelierSwaptionEngine( - discount_curve.handle, + discount_curve.handle(), (vol).handle(), deref(dc._thisptr), <_BachelierSwaptionEngine.CashAnnuityModel>model, ) ) - else: + elif isinstance(vol, HandleSwaptionVolatilityStructure): self._thisptr.reset( new _BachelierSwaptionEngine( - discount_curve.handle, - SwaptionVolatilityStructure.swaption_vol_handle(vol), + discount_curve.handle(), + (vol).handle(), <_BachelierSwaptionEngine.CashAnnuityModel>model, ) ) + else: + raise TypeError() diff --git a/quantlib/pricingengines/swaption/jamshidian_swaption_engine.pyx b/quantlib/pricingengines/swaption/jamshidian_swaption_engine.pyx index 3c232b82e..4645fa32a 100644 --- a/quantlib/pricingengines/swaption/jamshidian_swaption_engine.pyx +++ b/quantlib/pricingengines/swaption/jamshidian_swaption_engine.pyx @@ -5,14 +5,14 @@ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the license for more details. -from quantlib.handle cimport Handle, shared_ptr, static_pointer_cast +from quantlib.ext cimport shared_ptr, static_pointer_cast cimport quantlib.pricingengines._pricing_engine as _pe cimport quantlib.models.shortrate._onefactor_model as _ofm from quantlib.pricingengines.engine cimport PricingEngine from . cimport _jamshidian_swaption_engine as _jse -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from quantlib.models.shortrate.onefactor_model cimport OneFactorAffineModel @@ -23,4 +23,4 @@ cdef class JamshidianSwaptionEngine(PricingEngine): self._thisptr.reset(new _jse.JamshidianSwaptionEngine( static_pointer_cast[_ofm.OneFactorAffineModel](model._thisptr), - ts.handle)) + ts.handle())) diff --git a/quantlib/pricingengines/swaption/tree_swaption_engine.pyx b/quantlib/pricingengines/swaption/tree_swaption_engine.pyx index 4fda82224..24a12a73f 100644 --- a/quantlib/pricingengines/swaption/tree_swaption_engine.pyx +++ b/quantlib/pricingengines/swaption/tree_swaption_engine.pyx @@ -2,7 +2,7 @@ from quantlib.ext cimport static_pointer_cast from quantlib.types cimport Size cimport quantlib.models._model as _mo from quantlib.models.model cimport ShortRateModel -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from quantlib.time_grid cimport TimeGrid from . cimport _tree_swaption_engine as _tse @@ -12,13 +12,13 @@ cdef class TreeSwaptionEngine(PricingEngine): self._thisptr.reset( new _tse.TreeSwaptionEngine(static_pointer_cast[_mo.ShortRateModel](model._thisptr), (time_steps_or_time_grid)._thisptr, - term_structure.handle) + term_structure.handle()) ) elif isinstance(time_steps_or_time_grid, int): self._thisptr.reset( new _tse.TreeSwaptionEngine(static_pointer_cast[_mo.ShortRateModel](model._thisptr), time_steps_or_time_grid, - term_structure.handle) + term_structure.handle()) ) else: raise ValueError("needs to pass either a number of time steps or a TimeGrid") diff --git a/quantlib/processes/bates_process.pyx b/quantlib/processes/bates_process.pyx index e2f166dab..32bc3258e 100644 --- a/quantlib/processes/bates_process.pyx +++ b/quantlib/processes/bates_process.pyx @@ -17,7 +17,7 @@ from .heston_process cimport HestonProcess, Discretization, FullTruncation from quantlib.ext cimport shared_ptr from quantlib.quote cimport Quote from quantlib.quotes.simplequote cimport SimpleQuote -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure cdef class BatesProcess(HestonProcess): @@ -37,8 +37,8 @@ cdef class BatesProcess(HestonProcess): self._thisptr = shared_ptr[_sp.StochasticProcess]( new QlBatesProcess( - risk_free_rate_ts.handle, - dividend_ts.handle, + risk_free_rate_ts.handle(), + dividend_ts.handle(), s0.handle(), v0, kappa, theta, sigma, rho, lambda_, nu, delta, d)) diff --git a/quantlib/processes/black_scholes_process.pyx b/quantlib/processes/black_scholes_process.pyx index 3c68071c0..da1d3a8c1 100644 --- a/quantlib/processes/black_scholes_process.pyx +++ b/quantlib/processes/black_scholes_process.pyx @@ -3,11 +3,8 @@ include '../types.pxi' from . cimport _black_scholes_process as _bsp cimport quantlib._stochastic_process as _sp -from quantlib.handle cimport Handle, shared_ptr, dynamic_pointer_cast from quantlib.quote cimport Quote -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure -cimport quantlib.termstructures.volatility.equityfx._black_vol_term_structure as _bvts -from quantlib.termstructures.volatility.equityfx.black_vol_term_structure cimport BlackVolTermStructure +from quantlib.handle cimport HandleBlackVolTermStructure, HandleYieldTermStructure cdef class GeneralizedBlackScholesProcess(StochasticProcess1D): @@ -16,18 +13,13 @@ cdef class GeneralizedBlackScholesProcess(StochasticProcess1D): cdef class BlackScholesProcess(GeneralizedBlackScholesProcess): def __init__(self, Quote x0 not None, HandleYieldTermStructure risk_free_ts not None, - BlackVolTermStructure black_vol_ts not None): + HandleBlackVolTermStructure black_vol_ts not None): - cdef Handle[_bvts.BlackVolTermStructure] black_vol_ts_handle = \ - Handle[_bvts.BlackVolTermStructure]( - dynamic_pointer_cast[_bvts.BlackVolTermStructure](black_vol_ts._thisptr) - ) - - self._thisptr = shared_ptr[_sp.StochasticProcess]( new \ + self._thisptr.reset( new \ _bsp.BlackScholesProcess( x0.handle(), - risk_free_ts.handle, - black_vol_ts_handle + risk_free_ts.handle(), + black_vol_ts.handle() ) ) @@ -37,17 +29,13 @@ cdef class BlackScholesMertonProcess(GeneralizedBlackScholesProcess): Quote x0 not None, HandleYieldTermStructure dividend_ts not None, HandleYieldTermStructure risk_free_ts not None, - BlackVolTermStructure black_vol_ts not None): - - cdef Handle[_bvts.BlackVolTermStructure] black_vol_ts_handle = \ - Handle[_bvts.BlackVolTermStructure]( - dynamic_pointer_cast[_bvts.BlackVolTermStructure](black_vol_ts._thisptr) - ) + HandleBlackVolTermStructure black_vol_ts not None): - self._thisptr = shared_ptr[_sp.StochasticProcess]( new \ + self._thisptr.reset( new \ _bsp.BlackScholesMertonProcess( x0.handle(), - dividend_ts.handle, - risk_free_ts.handle, - black_vol_ts_handle - )) + dividend_ts.handle(), + risk_free_ts.handle(), + black_vol_ts.handle() + ) + ) diff --git a/quantlib/processes/heston_process.pyx b/quantlib/processes/heston_process.pyx index 4624912fb..834237c6e 100644 --- a/quantlib/processes/heston_process.pyx +++ b/quantlib/processes/heston_process.pyx @@ -3,9 +3,8 @@ from .heston_process cimport PartialTruncation cimport quantlib._stochastic_process as _sp cimport quantlib.termstructures._yield_term_structure as _yts -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport Handle, HandleYieldTermStructure -from quantlib.handle cimport Handle, shared_ptr cimport quantlib._quote as _qt from quantlib.quote cimport Quote from quantlib.quotes.simplequote cimport SimpleQuote @@ -43,10 +42,10 @@ cdef class HestonProcess(StochasticProcess): Discretization d=PartialTruncation): #create handles - self._thisptr = shared_ptr[_sp.StochasticProcess]( + self._thisptr.reset( new QlHestonProcess( - risk_free_rate_ts.handle, - dividend_ts.handle, + risk_free_rate_ts.handle(), + dividend_ts.handle(), s0.handle(), v0, kappa, theta, sigma, rho, d ) diff --git a/quantlib/processes/hullwhite_process.pyx b/quantlib/processes/hullwhite_process.pyx index 6a0681280..3ba56d78a 100644 --- a/quantlib/processes/hullwhite_process.pyx +++ b/quantlib/processes/hullwhite_process.pyx @@ -1,7 +1,7 @@ """Hull-White stochastic process""" from quantlib.types cimport Real from .cimport _hullwhite_process as _hw -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure cdef class HullWhiteProcess(StochasticProcess1D): @@ -22,7 +22,7 @@ cdef class HullWhiteProcess(StochasticProcess1D): self._thisptr.reset( new _hw.HullWhiteProcess( - risk_free_rate_ts.handle, + risk_free_rate_ts.handle(), a, sigma) ) @@ -45,7 +45,7 @@ cdef class HullWhiteForwardProcess(ForwardMeasureProcess1D): Real a, Real sigma): self._thisptr.reset( - new _hw.HullWhiteForwardProcess(h.handle, a, sigma) + new _hw.HullWhiteForwardProcess(h.handle(), a, sigma) ) @property diff --git a/quantlib/termstructures/_default_term_structure.pxd b/quantlib/termstructures/_default_term_structure.pxd index 7ff9ab15a..1046a77d1 100644 --- a/quantlib/termstructures/_default_term_structure.pxd +++ b/quantlib/termstructures/_default_term_structure.pxd @@ -11,10 +11,11 @@ from quantlib.types cimport Probability, Rate, Time from libcpp cimport bool from libcpp.vector cimport vector from quantlib.time._date cimport Date +from .._termstructure cimport TermStructure cdef extern from 'ql/termstructures/defaulttermstructure.hpp' namespace 'QuantLib' nogil: - cdef cppclass DefaultProbabilityTermStructure: + cdef cppclass DefaultProbabilityTermStructure(TermStructure): DefaultProbabilityTermStructure() Probability survivalProbability(const Date& d, bool extrapolate) except + # = false diff --git a/quantlib/termstructures/_yield_term_structure.pxd b/quantlib/termstructures/_yield_term_structure.pxd index 7eb2f4a0b..065ce6bc3 100644 --- a/quantlib/termstructures/_yield_term_structure.pxd +++ b/quantlib/termstructures/_yield_term_structure.pxd @@ -23,10 +23,10 @@ from .._termstructure cimport TermStructure cdef extern from 'ql/termstructures/yieldtermstructure.hpp' namespace 'QuantLib' nogil: cdef cppclass YieldTermStructure(TermStructure): - YieldTermStructure(DayCounter& dc, - vector[Handle[_qt.Quote]]& jumps, - vector[Date]& jumpDates, - ) except + + # YieldTermStructure(DayCounter& dc, + # vector[Handle[_qt.Quote]]& jumps, + # vector[Date]& jumpDates, + # ) except + DiscountFactor discount(Date& d, bool extrapolate) except + DiscountFactor discount(Time t, bool extrapolate) except + InterestRate zeroRate(Date& d, diff --git a/quantlib/termstructures/credit/api.py b/quantlib/termstructures/credit/api.py index d2dc4610a..0f01b05ef 100644 --- a/quantlib/termstructures/credit/api.py +++ b/quantlib/termstructures/credit/api.py @@ -2,4 +2,4 @@ from .piecewise_default_curve import PiecewiseDefaultCurve, ProbabilityTrait, Interpolator from .flat_hazard_rate import FlatHazardRate from .interpolated_hazardrate_curve import InterpolatedHazardRateCurve -from ..default_term_structure import HandleDefaultProbabilityTermStructure +from quantlib.handle import HandleDefaultProbabilityTermStructure diff --git a/quantlib/termstructures/credit/default_probability_helpers.pyx b/quantlib/termstructures/credit/default_probability_helpers.pyx index 94f6863c8..42c09ea00 100644 --- a/quantlib/termstructures/credit/default_probability_helpers.pyx +++ b/quantlib/termstructures/credit/default_probability_helpers.pyx @@ -132,7 +132,7 @@ cdef class SpreadCdsHelper(CdsHelper): frequency, paymentConvention, date_generation_rule, deref(daycounter._thisptr), - recovery_rate, discount_curve.handle, settles_accrual, + recovery_rate, discount_curve.handle(), settles_accrual, pays_at_default_time, start_date._thisptr, deref(lastperiod._thisptr), @@ -147,7 +147,7 @@ cdef class SpreadCdsHelper(CdsHelper): frequency, paymentConvention, date_generation_rule, deref(daycounter._thisptr), - recovery_rate, discount_curve.handle, settles_accrual, + recovery_rate, discount_curve.handle(), settles_accrual, pays_at_default_time, start_date._thisptr, deref(lastperiod._thisptr), @@ -181,7 +181,7 @@ cdef class UpfrontCdsHelper(CdsHelper): settlement_days, calendar._thisptr, frequency, paymentConvention, rule, deref(daycounter._thisptr), - recovery_rate, discount_curve.handle, upfront_settlement_days, settles_accrual, + recovery_rate, discount_curve.handle(), upfront_settlement_days, settles_accrual, pays_at_default_time, start_date._thisptr, deref(lastperiod._thisptr), @@ -195,7 +195,7 @@ cdef class UpfrontCdsHelper(CdsHelper): settlement_days, calendar._thisptr, frequency, paymentConvention, rule, deref(daycounter._thisptr), - recovery_rate, discount_curve.handle, upfront_settlement_days, settles_accrual, + recovery_rate, discount_curve.handle(), upfront_settlement_days, settles_accrual, pays_at_default_time, start_date._thisptr, deref(lastperiod._thisptr), diff --git a/quantlib/termstructures/default_term_structure.pxd b/quantlib/termstructures/default_term_structure.pxd index 4918456de..3f70c2b85 100644 --- a/quantlib/termstructures/default_term_structure.pxd +++ b/quantlib/termstructures/default_term_structure.pxd @@ -1,9 +1,5 @@ from . cimport _default_term_structure as _dts from ..termstructure cimport TermStructure -from quantlib.handle cimport RelinkableHandle cdef class DefaultProbabilityTermStructure(TermStructure): cdef _dts.DefaultProbabilityTermStructure* as_dts_ptr(self) noexcept nogil - -cdef class HandleDefaultProbabilityTermStructure: - cdef RelinkableHandle[_dts.DefaultProbabilityTermStructure] handle diff --git a/quantlib/termstructures/default_term_structure.pyx b/quantlib/termstructures/default_term_structure.pyx index 7555b04dc..d0bbd010b 100644 --- a/quantlib/termstructures/default_term_structure.pyx +++ b/quantlib/termstructures/default_term_structure.pyx @@ -40,24 +40,3 @@ cdef class DefaultProbabilityTermStructure(TermStructure): for d in jd: l.append(date_from_qldate(d)) return l - -cdef class HandleDefaultProbabilityTermStructure: - def __init__(self, DefaultProbabilityTermStructure ts=None, bool register_as_observer=False): - if ts is not None: - self.handle = RelinkableHandle[_dts.DefaultProbabilityTermStructure]( - static_pointer_cast[_dts.DefaultProbabilityTermStructure](ts._thisptr), - register_as_observer) - - @property - def current_link(self): - cdef DefaultProbabilityTermStructure instance = DefaultProbabilityTermStructure.__new__(DefaultProbabilityTermStructure) - if self.handle.empty(): - raise ValueError("empty handle") - instance._thisptr = self.handle.currentLink() - return instance - - def link_to(self, DefaultProbabilityTermStructure ts, bool register_as_observer=True): - self.handle.linkTo( - static_pointer_cast[_dts.DefaultProbabilityTermStructure](ts._thisptr), - register_as_observer - ) diff --git a/quantlib/termstructures/inflation/inflation_helpers.pyx b/quantlib/termstructures/inflation/inflation_helpers.pyx index 73f212995..71b6c1f8b 100644 --- a/quantlib/termstructures/inflation/inflation_helpers.pyx +++ b/quantlib/termstructures/inflation/inflation_helpers.pyx @@ -12,7 +12,7 @@ from quantlib.indexes.inflation_index cimport ( cimport quantlib.indexes._inflation_index as _ii from quantlib.indexes._inflation_index cimport CPI from quantlib.indexes.inflation_index cimport InterpolationType -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from quantlib.termstructures.inflation_term_structure cimport ( ZeroInflationTermStructure, YoYInflationTermStructure) cimport quantlib.termstructures._inflation_term_structure as _its @@ -35,7 +35,7 @@ cdef class ZeroCouponInflationSwapHelper: deref(day_counter._thisptr), static_pointer_cast[_ii.ZeroInflationIndex](zii._thisptr), observation_interpolation, - nominal_term_structure.handle) + nominal_term_structure.handle()) ) def set_term_structure(self, ZeroInflationTermStructure ts): @@ -67,7 +67,7 @@ cdef class YearOnYearInflationSwapHelper: deref(day_counter._thisptr), static_pointer_cast[_ii.YoYInflationIndex](yii._thisptr), interpolation, - nominal_term_structure.handle) + nominal_term_structure.handle()) ) def set_term_structure(self, YoYInflationTermStructure ts): diff --git a/quantlib/termstructures/inflation_term_structure.pxd b/quantlib/termstructures/inflation_term_structure.pxd index 663539bc5..02b985677 100644 --- a/quantlib/termstructures/inflation_term_structure.pxd +++ b/quantlib/termstructures/inflation_term_structure.pxd @@ -1,12 +1,11 @@ cimport quantlib.termstructures._inflation_term_structure as _its -from libcpp cimport bool as cbool -from quantlib.handle cimport shared_ptr, RelinkableHandle +from quantlib.ext cimport shared_ptr cdef class InflationTermStructure: cdef shared_ptr[_its.InflationTermStructure] _thisptr cdef class ZeroInflationTermStructure(InflationTermStructure): - cdef RelinkableHandle[_its.ZeroInflationTermStructure] _handle + pass cdef class YoYInflationTermStructure(InflationTermStructure): - cdef RelinkableHandle[_its.YoYInflationTermStructure] _handle + pass diff --git a/quantlib/termstructures/inflation_term_structure.pyx b/quantlib/termstructures/inflation_term_structure.pyx index 1109040d3..e2d47f9bd 100644 --- a/quantlib/termstructures/inflation_term_structure.pyx +++ b/quantlib/termstructures/inflation_term_structure.pyx @@ -22,7 +22,7 @@ from quantlib.time.daycounter cimport DayCounter from quantlib.time._period cimport Frequency, Days from quantlib.time.calendar cimport Calendar -from quantlib.termstructures.yields.flat_forward cimport YieldTermStructure +from quantlib.termstructures.yield_term_structure cimport YieldTermStructure cimport quantlib.termstructures.yields._flat_forward as _ff cimport quantlib._interest_rate as _ir @@ -56,15 +56,6 @@ cdef class InflationTermStructure: cdef class ZeroInflationTermStructure(InflationTermStructure): - def __cinit__(self): - self._handle = RelinkableHandle[_if.ZeroInflationTermStructure]( - static_pointer_cast[_if.ZeroInflationTermStructure](self._thisptr)) - - def link_to(self, ZeroInflationTermStructure structure): - self._thisptr = structure._thisptr - self._handle.linkTo(static_pointer_cast[_if.ZeroInflationTermStructure]( - structure._thisptr)) - def zero_rate(self, d, Period inst_obs_lag=Period(-1, Days), bool force_linear_interpolation=False, bool extrapolate=False): @@ -83,15 +74,6 @@ cdef class ZeroInflationTermStructure(InflationTermStructure): cdef class YoYInflationTermStructure(InflationTermStructure): - def __cinit__(self): - self._handle = RelinkableHandle[_if.YoYInflationTermStructure]( - static_pointer_cast[_if.YoYInflationTermStructure](self._thisptr)) - - def link_to(self, YoYInflationTermStructure structure): - self._thisptr = structure._thisptr - self._handle.linkTo(static_pointer_cast[_if.YoYInflationTermStructure]( - structure._thisptr)) - def yoy_rate(self, d, Period inst_obs_lag=Period(-1, Days), bool force_linear_interpolation=False, bool extrapolate=False): diff --git a/quantlib/termstructures/vol_term_structure.pxd b/quantlib/termstructures/vol_term_structure.pxd index f197cf7d8..56ab8605c 100644 --- a/quantlib/termstructures/vol_term_structure.pxd +++ b/quantlib/termstructures/vol_term_structure.pxd @@ -5,9 +5,3 @@ from . cimport _vol_term_structure as _vts cdef class VolatilityTermStructure: cdef shared_ptr[_vts.VolatilityTermStructure] _thisptr cdef _vts.VolatilityTermStructure* as_ptr(self) nogil - - @staticmethod - cdef Handle[_vts.VolatilityTermStructure] handle(object vol) - -cdef class HandleVolatilityTermStructure: - cdef RelinkableHandle[_vts.VolatilityTermStructure] handle diff --git a/quantlib/termstructures/vol_term_structure.pyx b/quantlib/termstructures/vol_term_structure.pyx index b2af8504c..fdf24a9b8 100644 --- a/quantlib/termstructures/vol_term_structure.pyx +++ b/quantlib/termstructures/vol_term_structure.pyx @@ -10,15 +10,6 @@ cdef class VolatilityTermStructure: cdef inline _vts.VolatilityTermStructure* as_ptr(self) nogil: return self._thisptr.get() - @staticmethod - cdef Handle[_vts.VolatilityTermStructure] handle(vol): - if isinstance(vol, VolatilityTermStructure): - return Handle[_vts.VolatilityTermStructure]((vol)._thisptr, False) - elif isinstance(vol, HandleVolatilityTermStructure): - return (vol).handle - else: - raise TypeError("vol needs to be either a VolatilityTermStructure or a HandleVolatilityTermStructure") - def time_from_reference(self, Date date not None): return self.as_ptr().timeFromReference(date._thisptr) @@ -47,10 +38,3 @@ cdef class VolatilityTermStructure: @extrapolation.setter def extrapolation(self, bool b): self.as_ptr().enableExtrapolation(b) - -cdef class HandleVolatilityTermStructure: - def __init__(self, VolatilityTermStructure structure not None, cbool register_as_observer): - self.handle = RelinkableHandle[_vts.VolatilityTermStructure](structure._thisptr, register_as_observer) - - def link_to(self, VolatilityTermStructure structure not None, cbool register_as_observer=True): - self.handle.linkTo(structure._thisptr, register_as_observer) diff --git a/quantlib/termstructures/volatility/api.py b/quantlib/termstructures/volatility/api.py index cce1a2f63..9d7ad1526 100644 --- a/quantlib/termstructures/volatility/api.py +++ b/quantlib/termstructures/volatility/api.py @@ -4,4 +4,4 @@ from .volatilitytype import VolatilityType from .swaption.swaption_vol_matrix import SwaptionVolatilityMatrix from .swaption.swaption_constant_vol import ConstantSwaptionVolatility -from .swaption.swaption_vol_structure import HandleSwaptionVolatilityStructure +from quantlib.handle import HandleSwaptionVolatilityStructure, HandleBlackVolTermStructure, HandleOptionletVolatilityStructure diff --git a/quantlib/termstructures/volatility/equityfx/local_vol_surface.pyx b/quantlib/termstructures/volatility/equityfx/local_vol_surface.pyx index 40297ac12..f04ce0203 100644 --- a/quantlib/termstructures/volatility/equityfx/local_vol_surface.pyx +++ b/quantlib/termstructures/volatility/equityfx/local_vol_surface.pyx @@ -2,15 +2,13 @@ from libcpp cimport bool from quantlib.types cimport Real, Time from cython.operator cimport dereference as deref from . cimport _local_vol_surface as _lvs -from .black_vol_term_structure cimport BlackVolTermStructure -from . cimport _black_vol_term_structure as _bvts -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure, HandleBlackVolTermStructure from quantlib.quote cimport Quote from quantlib.ext cimport static_pointer_cast from quantlib.time.date cimport Date cdef class LocalVolSurface(LocalVolTermStructure): - def __init__(self, BlackVolTermStructure black_ts, HandleYieldTermStructure risk_free_ts, HandleYieldTermStructure dividend_ts, Quote underlying): + def __init__(self, HandleBlackVolTermStructure black_ts, HandleYieldTermStructure risk_free_ts, HandleYieldTermStructure dividend_ts, Quote underlying): """ Local volatility surface derived from a Black vol surface Parameters @@ -34,9 +32,9 @@ cdef class LocalVolSurface(LocalVolTermStructure): """ self._thisptr.reset( new _lvs.LocalVolSurface( - Handle[_bvts.BlackVolTermStructure](static_pointer_cast[_bvts.BlackVolTermStructure](black_ts._thisptr)), - risk_free_ts.handle, - dividend_ts.handle, + black_ts.handle(), + risk_free_ts.handle(), + dividend_ts.handle(), underlying.handle() ) ) diff --git a/quantlib/termstructures/volatility/optionlet/optionlet_volatility_structure.pyx b/quantlib/termstructures/volatility/optionlet/optionlet_volatility_structure.pyx index edb74b31d..6003d6343 100644 --- a/quantlib/termstructures/volatility/optionlet/optionlet_volatility_structure.pyx +++ b/quantlib/termstructures/volatility/optionlet/optionlet_volatility_structure.pyx @@ -7,10 +7,6 @@ from quantlib.time.date cimport Date from quantlib.time.daycounter cimport DayCounter -cdef class OptionletVolatilityStructure: - pass - - cdef class ConstantOptionletVolatility(OptionletVolatilityStructure): def __init__(self, diff --git a/quantlib/termstructures/yield_term_structure.pxd b/quantlib/termstructures/yield_term_structure.pxd index c5b693667..fd83e8e3b 100644 --- a/quantlib/termstructures/yield_term_structure.pxd +++ b/quantlib/termstructures/yield_term_structure.pxd @@ -1,9 +1,5 @@ from ..termstructure cimport TermStructure cimport quantlib.termstructures._yield_term_structure as _yts -from quantlib.handle cimport RelinkableHandle, shared_ptr cdef class YieldTermStructure(TermStructure): cdef inline _yts.YieldTermStructure* as_yts_ptr(self) except NULL - -cdef class HandleYieldTermStructure: - cdef RelinkableHandle[_yts.YieldTermStructure] handle diff --git a/quantlib/termstructures/yield_term_structure.pyx b/quantlib/termstructures/yield_term_structure.pyx index 5b30e9edb..6d772b788 100644 --- a/quantlib/termstructures/yield_term_structure.pyx +++ b/quantlib/termstructures/yield_term_structure.pyx @@ -14,7 +14,6 @@ from quantlib.compounding cimport Compounding cimport quantlib.termstructures._yield_term_structure as _yts cimport quantlib._quote as _qt cimport quantlib._interest_rate as _ir -from quantlib.handle cimport static_pointer_cast cimport quantlib.time._date as _date cimport quantlib.time._daycounter as _dc cimport quantlib.time._calendar as _cal @@ -150,24 +149,3 @@ cdef class YieldTermStructure(TermStructure): return discount_value - -cdef class HandleYieldTermStructure: - def __init__(self, YieldTermStructure ts=None, bool register_as_observer=True): - if ts is not None: - self.handle = RelinkableHandle[_yts.YieldTermStructure]( - static_pointer_cast[_yts.YieldTermStructure](ts._thisptr), - register_as_observer) - - @property - def current_link(self): - cdef YieldTermStructure instance = YieldTermStructure.__new__(YieldTermStructure) - if self.handle.empty(): - raise ValueError("empty handle") - instance._thisptr = self.handle.currentLink() - return instance - - def link_to(self, YieldTermStructure yts, bool register_as_observer=True): - self.handle.linkTo(static_pointer_cast[_yts.YieldTermStructure](yts._thisptr), register_as_observer) - - def __bool__(self): - return not self.handle.empty() diff --git a/quantlib/termstructures/yields/_flat_forward.pxd b/quantlib/termstructures/yields/_flat_forward.pxd index cc7b388c2..049867e7f 100644 --- a/quantlib/termstructures/yields/_flat_forward.pxd +++ b/quantlib/termstructures/yields/_flat_forward.pxd @@ -52,14 +52,14 @@ cdef extern from 'ql/termstructures/yield/flatforward.hpp' namespace 'QuantLib' Handle[_qt.Quote]& forward, DayCounter& dayCounter, ) except + - + FlatForward(Natural settlementDays, Calendar& calendar, Handle[_qt.Quote]& forward, DayCounter& dayCounter, Compounding compounding, ) except + - + FlatForward(Natural settlementDays, Calendar& calendar, Handle[_qt.Quote]& forward, @@ -67,7 +67,7 @@ cdef extern from 'ql/termstructures/yield/flatforward.hpp' namespace 'QuantLib' Compounding compounding, Frequency frequency ) except + - + # from date and forward FlatForward(Date& referenceDate, Handle[_qt.Quote]& forward, diff --git a/quantlib/termstructures/yields/api.py b/quantlib/termstructures/yields/api.py index 83d33fca5..573d61140 100644 --- a/quantlib/termstructures/yields/api.py +++ b/quantlib/termstructures/yields/api.py @@ -11,7 +11,8 @@ from .ois_rate_helper import OISRateHelper, DatedOISRateHelper from .overnightindexfutureratehelper import OvernightIndexFutureRateHelper, SofrFutureRateHelper from .discount_curve import InterpolatedDiscountCurve, DiscountCurve -from ..yield_term_structure import YieldTermStructure, HandleYieldTermStructure +from ..yield_term_structure import YieldTermStructure +from quantlib.handle import HandleYieldTermStructure, RelinkableHandleYieldTermStructure from .zero_curve import ZeroCurve from .discount_curve import DiscountCurve from .forward_curve import ForwardCurve diff --git a/quantlib/termstructures/yields/forward_spreaded_term_structure.pyx b/quantlib/termstructures/yields/forward_spreaded_term_structure.pyx index 3567db18d..984b74299 100644 --- a/quantlib/termstructures/yields/forward_spreaded_term_structure.pyx +++ b/quantlib/termstructures/yields/forward_spreaded_term_structure.pyx @@ -1,6 +1,7 @@ cimport quantlib.termstructures.yields._forward_spreaded_term_structure as _fsts -from quantlib.termstructures.yield_term_structure cimport YieldTermStructure, HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure +from ..yield_term_structure cimport YieldTermStructure from quantlib.quote cimport Quote cdef class ForwardSpreadedTermStructure(YieldTermStructure): @@ -14,7 +15,7 @@ cdef class ForwardSpreadedTermStructure(YieldTermStructure): self._thisptr.reset( new _fsts.ForwardSpreadedTermStructure( - yts.handle, + yts.handle(), spread.handle() ) ) diff --git a/quantlib/termstructures/yields/implied_term_structure.pyx b/quantlib/termstructures/yields/implied_term_structure.pyx index 76b4c5678..dfb2c65da 100644 --- a/quantlib/termstructures/yields/implied_term_structure.pyx +++ b/quantlib/termstructures/yields/implied_term_structure.pyx @@ -1,5 +1,5 @@ cimport quantlib.termstructures.yields._implied_term_structure as _its -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from quantlib.time.date cimport Date cdef class ImpliedTermStructure(YieldTermStructure): @@ -7,5 +7,5 @@ cdef class ImpliedTermStructure(YieldTermStructure): Date reference_date not None): self._thisptr.reset( - new _its.ImpliedTermStructure(h.handle, reference_date._thisptr) + new _its.ImpliedTermStructure(h.handle(), reference_date._thisptr) ) diff --git a/quantlib/termstructures/yields/ois_rate_helper.pyx b/quantlib/termstructures/yields/ois_rate_helper.pyx index 30c77b858..393792d80 100644 --- a/quantlib/termstructures/yields/ois_rate_helper.pyx +++ b/quantlib/termstructures/yields/ois_rate_helper.pyx @@ -12,7 +12,6 @@ from quantlib.quote cimport Quote from quantlib.time.date cimport Date, Period from quantlib.termstructures.yields.rate_helpers cimport RelativeDateRateHelper, RateHelper from quantlib.indexes.ibor_index cimport OvernightIndex -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure from quantlib.time.calendar cimport Calendar from quantlib.utilities.null cimport Null @@ -64,7 +63,7 @@ cdef class OISRateHelper(RelativeDateRateHelper): deref(tenor._thisptr), fixed_rate.handle(), static_pointer_cast[_ib.OvernightIndex](overnight_index._thisptr), - discounting_curve.handle, + discounting_curve.handle(), telescopic_value_dates, payment_lag, <_rh.BusinessDayConvention> payment_convention, @@ -120,7 +119,7 @@ cdef class OISRateHelper(RelativeDateRateHelper): end_date._thisptr, fixed_rate.handle(), static_pointer_cast[_ib.OvernightIndex](overnight_index._thisptr), - discounting_curve.handle, + discounting_curve.handle(), telescopic_value_dates, payment_lag, <_rh.BusinessDayConvention> payment_convention, diff --git a/quantlib/termstructures/yields/piecewise_zerospreaded_termstructure.pyx b/quantlib/termstructures/yields/piecewise_zerospreaded_termstructure.pyx index 3bc459056..092eee59a 100644 --- a/quantlib/termstructures/yields/piecewise_zerospreaded_termstructure.pyx +++ b/quantlib/termstructures/yields/piecewise_zerospreaded_termstructure.pyx @@ -8,7 +8,7 @@ from quantlib.time._date cimport Date as QlDate from quantlib.time.date cimport Date from quantlib.quote cimport Quote cimport quantlib._quote as _qt -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from . cimport _piecewise_zerospreaded_termstructure as _pzt cdef class PiecewiseZeroSpreadedTermStructure(YieldTermStructure): @@ -27,7 +27,7 @@ cdef class PiecewiseZeroSpreadedTermStructure(YieldTermStructure): self._thisptr.reset( new _pzt.PiecewiseZeroSpreadedTermStructure( - h.handle, + h.handle(), spreads_vec, dates_vec, comp, diff --git a/quantlib/termstructures/yields/rate_helpers.pyx b/quantlib/termstructures/yields/rate_helpers.pyx index 138aefbab..e86b6488f 100644 --- a/quantlib/termstructures/yields/rate_helpers.pyx +++ b/quantlib/termstructures/yields/rate_helpers.pyx @@ -32,7 +32,6 @@ from quantlib.indexes.ibor_index cimport IborIndex from quantlib.indexes.swap_index cimport SwapIndex from ..helpers cimport Pillar from quantlib.utilities.null cimport Null -from ..yield_term_structure cimport HandleYieldTermStructure cdef class RateHelper: @@ -158,7 +157,7 @@ cdef class SwapRateHelper(RelativeDateRateHelper): static_pointer_cast[_ib.IborIndex](iborIndex._thisptr), spread.handle(), deref(fwdStart._thisptr), - discounting_curve.handle, + discounting_curve.handle(), settlement_days, pillar, custom_pillar_date._thisptr, @@ -177,7 +176,7 @@ cdef class SwapRateHelper(RelativeDateRateHelper): static_pointer_cast[_ib.IborIndex](iborIndex._thisptr), spread.handle(), deref(fwdStart._thisptr), - discounting_curve.handle, + discounting_curve.handle(), settlement_days, pillar, custom_pillar_date._thisptr, @@ -206,7 +205,7 @@ cdef class SwapRateHelper(RelativeDateRateHelper): static_pointer_cast[_si.SwapIndex](index._thisptr), spread.handle(), deref(fwdStart._thisptr), - discounting_curve.handle, + discounting_curve.handle(), pillar, custom_pillar_date._thisptr, end_of_month @@ -219,7 +218,7 @@ cdef class SwapRateHelper(RelativeDateRateHelper): static_pointer_cast[_si.SwapIndex](index._thisptr), spread.handle(), deref(fwdStart._thisptr), - discounting_curve.handle, + discounting_curve.handle(), pillar, custom_pillar_date._thisptr, end_of_month @@ -449,7 +448,7 @@ cdef class FxSwapRateHelper(RelativeDateRateHelper): <_rh.BusinessDayConvention>convention, end_of_month, is_fx_base_currency_collateral_currency, - collateral_curve.handle, + collateral_curve.handle(), trading_calendar._thisptr, ) ) diff --git a/quantlib/termstructures/yields/zero_spreaded_term_structure.pyx b/quantlib/termstructures/yields/zero_spreaded_term_structure.pyx index 0bcd4aa98..69219397c 100644 --- a/quantlib/termstructures/yields/zero_spreaded_term_structure.pyx +++ b/quantlib/termstructures/yields/zero_spreaded_term_structure.pyx @@ -1,6 +1,6 @@ from cython.operator cimport dereference as deref from quantlib.compounding cimport Compounding -from quantlib.termstructures.yield_term_structure cimport HandleYieldTermStructure +from quantlib.handle cimport HandleYieldTermStructure from quantlib.time.daycounter cimport DayCounter from quantlib.time.frequency cimport Frequency, NoFrequency from quantlib.quote cimport Quote @@ -13,7 +13,7 @@ cdef class ZeroSpreadedTermStructure(YieldTermStructure): self._thisptr.reset( new _zsts.ZeroSpreadedTermStructure( - h.handle, + h.handle(), spread.handle(), comp, freq, From ddf886917df7139ef3fe1078a08ccab18d1438bd Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Tue, 3 Jun 2025 09:55:29 -0400 Subject: [PATCH 5/7] fix tests --- test/test_asian.py | 20 +++++---- test/test_assetswap.py | 4 +- test/test_bermudan_swaption.py | 4 +- test/test_bondforward.py | 2 +- test/test_bonds.py | 21 ++++++---- test/test_cms.py | 17 ++++---- test/test_cms_spread.py | 31 ++++++++------ test/test_heston_model.py | 4 +- test/test_hullwhite_model.py | 2 +- test/test_hybridhestonhullwhite_process.py | 49 +++++++++++++--------- test/test_indexes.py | 39 +++++++++-------- test/test_inflation.py | 5 +-- test/test_overnight_indexed_coupon.py | 4 +- test/test_overnight_indexed_swap.py | 4 +- test/test_swap.py | 7 ++-- test/test_swaption_vol_cube.py | 24 ++++++----- test/test_termstructures.py | 10 ++--- test/test_vanilla_option.py | 14 ++++--- test/test_variance_swap.py | 12 ++++-- 19 files changed, 156 insertions(+), 117 deletions(-) diff --git a/test/test_asian.py b/test/test_asian.py index e4d64ce5d..722e15f36 100644 --- a/test/test_asian.py +++ b/test/test_asian.py @@ -17,7 +17,7 @@ from quantlib.processes.black_scholes_process import BlackScholesMertonProcess from quantlib.settings import Settings from quantlib.time.api import Date, NullCalendar, June, Actual360, Years -from quantlib.termstructures.yield_term_structure import HandleYieldTermStructure +from quantlib.handle import HandleYieldTermStructure, HandleBlackVolTermStructure from quantlib.termstructures.yields.flat_forward import FlatForward from quantlib.quotes import SimpleQuote from quantlib.termstructures.volatility.api import BlackConstantVol @@ -47,7 +47,7 @@ def setUp(self): stack = contextlib.ExitStack() self.settings = stack.enter_context(Settings()) self.addCleanup(stack.close) - + self.calendar = NullCalendar() self.today = Date(6, June, 2021) @@ -83,11 +83,13 @@ def setUp(self): ) ) - self.flat_vol_ts = BlackConstantVol( - self.today, - self.calendar, - self.volatility, - self.daycounter + self.flat_vol_ts = HandleBlackVolTermStructure( + BlackConstantVol( + self.today, + self.calendar, + self.volatility, + self.daycounter + ) ) self.black_scholes_merton_process = BlackScholesMertonProcess( @@ -170,7 +172,9 @@ def test_analytic_cont_geo_av_price_greeks(self): q_ts = HandleYieldTermStructure(flat_rate(q_rate, self.daycounter), True) r_ts = HandleYieldTermStructure(flat_rate(r_rate, self.daycounter), True) - vol_ts = BlackConstantVol(self.today, self.calendar, vol, self.daycounter) + vol_ts = HandleBlackVolTermStructure( + BlackConstantVol(self.today, self.calendar, vol, self.daycounter) + ) process = BlackScholesMertonProcess(spot, q_ts, r_ts, vol_ts) diff --git a/test/test_assetswap.py b/test/test_assetswap.py index 3cb2a8f84..c368c747e 100644 --- a/test/test_assetswap.py +++ b/test/test_assetswap.py @@ -3,13 +3,13 @@ from quantlib.time.api import Date, Period, Annual, TARGET, Unadjusted, Schedule, DateGeneration, Actual365Fixed, Semiannual, ActualActual, Following from quantlib.instruments.api import FixedRateBond, AssetSwap from quantlib.pricingengines.api import DiscountingBondEngine, DiscountingSwapEngine -from quantlib.termstructures.yields.api import HandleYieldTermStructure +from quantlib.termstructures.yields.api import RelinkableHandleYieldTermStructure from quantlib.indexes.api import Euribor from .utilities import flat_rate class TestMarketASWSpread(unittest.TestCase): def setUp(self): - self.term_structure = HandleYieldTermStructure() + self.term_structure = RelinkableHandleYieldTermStructure() self.today = Date(24, 4, 2007) self.ibor_index = Euribor(Period(Semiannual), self.term_structure) self.term_structure.link_to(flat_rate(0.05, Actual365Fixed(), self.today)) diff --git a/test/test_bermudan_swaption.py b/test/test_bermudan_swaption.py index 9041f019a..681fb4777 100644 --- a/test/test_bermudan_swaption.py +++ b/test/test_bermudan_swaption.py @@ -7,7 +7,7 @@ Thirty360, Days, Years, DateGeneration, Schedule, Actual365Fixed, Period) from quantlib.time.daycounters.thirty360 import Convention from quantlib.indexes.api import Euribor6M -from quantlib.termstructures.yields.api import HandleYieldTermStructure +from quantlib.termstructures.yields.api import RelinkableHandleYieldTermStructure from quantlib.models.api import HullWhite from quantlib.settings import Settings from quantlib.pricingengines.api import DiscountingSwapEngine, TreeSwaptionEngine @@ -27,7 +27,7 @@ def setUp(self): self.fixed_frequency = Annual self.floating_frequency = Semiannual self.fixed_day_count = Thirty360(Convention.BondBasis) - self.term_structure = HandleYieldTermStructure() + self.term_structure = RelinkableHandleYieldTermStructure() self.index = Euribor6M(self.term_structure) self.calendar = self.index.fixing_calendar self.today = self.calendar.adjust(today()) diff --git a/test/test_bondforward.py b/test/test_bondforward.py index 10f7ba391..d39da3780 100644 --- a/test/test_bondforward.py +++ b/test/test_bondforward.py @@ -2,7 +2,7 @@ from quantlib.settings import Settings from quantlib.time.api import ActualActual, Annual, Date, DateGeneration, Period, Schedule, Following, TARGET, Actual365Fixed from quantlib.instruments.api import BondForward, FixedRateBond -from quantlib.termstructures.yield_term_structure import HandleYieldTermStructure +from quantlib.handle import HandleYieldTermStructure from quantlib.pricingengines.api import DiscountingBondEngine from quantlib.position import Position from .utilities import flat_rate diff --git a/test/test_bonds.py b/test/test_bonds.py index 46786adf1..9815473f3 100644 --- a/test/test_bonds.py +++ b/test/test_bonds.py @@ -21,8 +21,10 @@ from quantlib.time.dategeneration import DateGeneration from quantlib.settings import Settings from quantlib.termstructures.yields.api import ( - FlatForward, HandleYieldTermStructure + FlatForward, RelinkableHandleYieldTermStructure ) +from quantlib.handle import RelinkableHandleOptionletVolatilityStructure + from quantlib.indexes.api import Libor, Euribor6M from quantlib.currency.api import USDCurrency from quantlib.time.api import Months, Unadjusted, Following, ModifiedFollowing @@ -61,7 +63,7 @@ def test_pricing_bond(self): coupon_rate = 0.03625 bond_yield = 0.034921 - discounting_term_structure = HandleYieldTermStructure() + discounting_term_structure = RelinkableHandleYieldTermStructure() flat_term_structure = FlatForward( reference_date = settlement_date, forward = bond_yield, @@ -78,7 +80,7 @@ def test_pricing_bond(self): issue_date, maturity_date, Period(Semiannual), - UnitedStates(market=GOVERNMENTBOND), + UnitedStates(market=UnitedStates.GovernmentBond), Unadjusted, Unadjusted, DateGeneration.Backward, @@ -168,7 +170,7 @@ def test_excel_example_with_fixed_rate_bond(self): issue_date ) - discounting_term_structure = HandleYieldTermStructure() + discounting_term_structure = RelinkableHandleYieldTermStructure() flat_term_structure = FlatForward( settlement_days = 1, forward = 0.044, @@ -210,7 +212,7 @@ def test_excel_example_with_zero_coupon_bond(self): 100.0, todays_date ) - discounting_term_structure = HandleYieldTermStructure() + discounting_term_structure = RelinkableHandleYieldTermStructure() flat_term_structure = FlatForward( settlement_days = 1, forward = 0.044, @@ -229,6 +231,7 @@ def test_excel_example_with_zero_coupon_bond(self): ) self.assertEqual(0., bond.accrued_amount(bond.settlement_date())) self.assertAlmostEqual(57.6915, bond.clean_price(), 4) + def test_excel_example_with_floating_rate_bond(self): todays_date = Date(25, August, 2011) @@ -258,8 +261,8 @@ def test_excel_example_with_floating_rate_bond(self): DateGeneration.Backward )#3 - flat_discounting_term_structure = HandleYieldTermStructure() - forecastTermStructure = HandleYieldTermStructure() + flat_discounting_term_structure = RelinkableHandleYieldTermStructure() + forecastTermStructure = RelinkableHandleYieldTermStructure() dc = Actual360() @@ -295,7 +298,9 @@ def test_excel_example_with_floating_rate_bond(self): float_bond.set_pricing_engine(engine) cons_option_vol = ConstantOptionletVolatility(settlement_days, UnitedStates(Market.Settlement), pmt_conv, 0.95, Actual365Fixed()) - coupon_pricer = BlackIborCouponPricer(cons_option_vol) + coupon_pricer = BlackIborCouponPricer( + RelinkableHandleOptionletVolatilityStructure(cons_option_vol) + ) set_coupon_pricer(float_bond.cashflows, coupon_pricer) diff --git a/test/test_cms.py b/test/test_cms.py index ac2421537..fd99dbebe 100644 --- a/test/test_cms.py +++ b/test/test_cms.py @@ -5,7 +5,7 @@ UnitedStates, today, Unadjusted) from quantlib.math.matrix import Matrix import numpy as np -from quantlib.termstructures.yield_term_structure import HandleYieldTermStructure +from quantlib.handle import HandleYieldTermStructure, HandleSwaptionVolatilityStructure from quantlib.termstructures.volatility.swaption.swaption_vol_matrix \ import SwaptionVolatilityMatrix from quantlib.indexes.api import EuriborSwapIsdaFixA @@ -36,12 +36,15 @@ def setUp(self): M = Matrix.from_ndarray(m) calendar = UnitedStates() - self.atm_vol = SwaptionVolatilityMatrix(calendar, - Following, - atm_option_tenors, - atm_swap_tenors, - M, - Actual365Fixed()) + self.atm_vol = HandleSwaptionVolatilityStructure( + SwaptionVolatilityMatrix(calendar, + Following, + atm_option_tenors, + atm_swap_tenors, + M, + Actual365Fixed() + ) + ) reference_date = calendar.adjust(today()) Settings().evaluation_date = reference_date diff --git a/test/test_cms_spread.py b/test/test_cms_spread.py index 24336a8bc..f672d675c 100644 --- a/test/test_cms_spread.py +++ b/test/test_cms_spread.py @@ -5,7 +5,7 @@ from quantlib.indexes.api import EuriborSwapIsdaFixA from quantlib.termstructures.yields.api import FlatForward, HandleYieldTermStructure from quantlib.termstructures.volatility.api import ( - ConstantSwaptionVolatility, VolatilityType) + ConstantSwaptionVolatility, VolatilityType, HandleSwaptionVolatilityStructure) from quantlib.experimental.coupons.lognormal_cmsspread_pricer import \ LognormalCmsSpreadPricer from quantlib.experimental.coupons.swap_spread_index import SwapSpreadIndex @@ -28,15 +28,21 @@ def setUp(self): self.ref_date = Date(23, 2, 2018) Settings().evaluation_date = self.ref_date self.yts = HandleYieldTermStructure(FlatForward(self.ref_date, 0.02, Actual365Fixed())) - self.swLn = ConstantSwaptionVolatility.from_reference_date( - self.ref_date, TARGET(), Following, - 0.2, Actual365Fixed(), VolatilityType.ShiftedLognormal, 0.) - self.swSLn = ConstantSwaptionVolatility.from_reference_date( - self.ref_date, TARGET(), Following, - 0.1, Actual365Fixed(), VolatilityType.ShiftedLognormal, 0.01) - self.swN = ConstantSwaptionVolatility.from_reference_date( - self.ref_date, TARGET(), Following, - 0.075, Actual365Fixed(), VolatilityType.Normal, 0.01) + self.swLn = HandleSwaptionVolatilityStructure( + ConstantSwaptionVolatility.from_reference_date( + self.ref_date, TARGET(), Following, + 0.2, Actual365Fixed(), VolatilityType.ShiftedLognormal, 0.) + ) + self.swSLn = HandleSwaptionVolatilityStructure( + ConstantSwaptionVolatility.from_reference_date( + self.ref_date, TARGET(), Following, + 0.1, Actual365Fixed(), VolatilityType.ShiftedLognormal, 0.01) + ) + self.swN = HandleSwaptionVolatilityStructure( + ConstantSwaptionVolatility.from_reference_date( + self.ref_date, TARGET(), Following, + 0.075, Actual365Fixed(), VolatilityType.Normal, 0.01) + ) reversion = SimpleQuote(0.01) self.cms_pricer_ln = LinearTsrPricer(self.swLn, reversion, self.yts) self.cms_pricer_sln = LinearTsrPricer(self.swSLn, reversion, self.yts) @@ -145,12 +151,13 @@ def test_coupon_pricing(self): @staticmethod def mc_reference_value(cpn1, cpn2, vol, correlation): + vol = vol.current_link samples = 1000000 Cov = Matrix(2, 2) Cov[0,0] = vol.black_variance(cpn1.fixing_date, cpn1.index.tenor, - cpn1.index_fixing) + cpn1.index_fixing) Cov[1,1] = vol.black_variance(cpn1.fixing_date, cpn1.index.tenor, - cpn1.index_fixing) + cpn1.index_fixing) Cov[0,1] = Cov[1,0] = sqrt(Cov[0,0] * Cov[1,1]) * correlation C = pseudo_sqrt(Cov).to_ndarray() atm_rate = np.array([cpn1.index_fixing, diff --git a/test/test_heston_model.py b/test/test_heston_model.py index f43a2fc9d..e65cf5c41 100644 --- a/test/test_heston_model.py +++ b/test/test_heston_model.py @@ -1,5 +1,3 @@ -from __future__ import division -from __future__ import print_function import numpy as np import unittest @@ -26,7 +24,7 @@ Actual365Fixed, TARGET, Weeks, ActualActual ) from quantlib.termstructures.yields.flat_forward import FlatForward -from quantlib.termstructures.yield_term_structure import HandleYieldTermStructure +from quantlib.handle import HandleYieldTermStructure from quantlib.quotes import SimpleQuote from quantlib.termstructures.yields.zero_curve import ZeroCurve diff --git a/test/test_hullwhite_model.py b/test/test_hullwhite_model.py index d271930d2..be3558b69 100644 --- a/test/test_hullwhite_model.py +++ b/test/test_hullwhite_model.py @@ -8,7 +8,7 @@ February, NullCalendar) from quantlib.termstructures.yields.flat_forward import FlatForward -from quantlib.termstructures.yield_term_structure import HandleYieldTermStructure +from quantlib.handle import HandleYieldTermStructure from quantlib.indexes.ibor.euribor import Euribor6M from quantlib.pricingengines.swaption.jamshidian_swaption_engine import JamshidianSwaptionEngine from quantlib.quotes import SimpleQuote diff --git a/test/test_hybridhestonhullwhite_process.py b/test/test_hybridhestonhullwhite_process.py index bf1d263bc..b5fffa191 100644 --- a/test/test_hybridhestonhullwhite_process.py +++ b/test/test_hybridhestonhullwhite_process.py @@ -25,7 +25,7 @@ HestonModel) from quantlib.termstructures.yields.api import ZeroCurve, FlatForward, HandleYieldTermStructure -from quantlib.termstructures.volatility.api import BlackConstantVol +from quantlib.termstructures.volatility.api import BlackConstantVol, HandleBlackVolTermStructure from quantlib.pricingengines.api import ( AnalyticEuropeanEngine, @@ -79,11 +79,13 @@ def setUp(self): self.r_ts = HandleYieldTermStructure(ZeroCurve(dates, rates, self.daycounter)) self.q_ts = HandleYieldTermStructure(ZeroCurve(dates, divRates, self.daycounter)) - self.vol_ts = BlackConstantVol( - self.settlement_date, - self.calendar, - self.volatility, - self.daycounter + self.vol_ts = HandleBlackVolTermStructure( + BlackConstantVol( + self.settlement_date, + self.calendar, + self.volatility, + self.daycounter + ) ) self.black_scholes_merton_process = BlackScholesMertonProcess( @@ -110,7 +112,9 @@ def test_bsm_hw(self): q_ts = HandleYieldTermStructure(flat_rate(0.04, dc)) r_ts = HandleYieldTermStructure(flat_rate(0.0525, dc)) - vol_ts = BlackConstantVol(todays_date, NullCalendar(), 0.25, dc) + vol_ts = HandleBlackVolTermStructure( + BlackConstantVol(todays_date, NullCalendar(), 0.25, dc) + ) hullWhiteModel = HullWhite(r_ts, 0.00883, 0.00526) @@ -139,8 +143,10 @@ def test_bsm_hw(self): option.set_pricing_engine(bsm_hw_engine) npv = option.npv - compVolTS = BlackConstantVol(todays_date, NullCalendar(), - v, dc) + compVolTS = HandleBlackVolTermStructure( + BlackConstantVol(todays_date, NullCalendar(), + v, dc) + ) bs_process = BlackScholesMertonProcess(spot, q_ts, r_ts, compVolTS) @@ -189,11 +195,12 @@ def test_compare_bsm_bsmhw_hestonhw(self): q_ts = HandleYieldTermStructure(ZeroCurve(dates, divRates, dc)) vol = SimpleQuote(0.25) - vol_ts = BlackConstantVol( - todays_date, - NullCalendar(), - vol.value, dc) - + vol_ts = HandleBlackVolTermStructure( + BlackConstantVol( + todays_date, + NullCalendar(), + vol.value, dc) + ) bsm_process = BlackScholesMertonProcess( spot, q_ts, r_ts, vol_ts) @@ -271,10 +278,12 @@ def test_compare_BsmHW_HestonHW(self): q_ts = HandleYieldTermStructure(ZeroCurve(dates, divRates, dc)) vol = SimpleQuote(0.25) - vol_ts = BlackConstantVol( - todays_date, - NullCalendar(), - vol.value, dc) + vol_ts = HandleBlackVolTermStructure( + BlackConstantVol( + todays_date, + NullCalendar(), + vol.value, dc) + ) bsm_process = BlackScholesMertonProcess( spot, q_ts, r_ts, vol_ts) @@ -433,7 +442,9 @@ def test_mc_vanilla_pricing(self): r_ts = HandleYieldTermStructure(ZeroCurve(dates, rates, dc)) q_ts = HandleYieldTermStructure(ZeroCurve(dates, div_rates, dc)) vol = SimpleQuote(0.25) - vol_ts = BlackConstantVol(todays_date, NullCalendar(), vol, dc) + vol_ts = HandleBlackVolTermStructure( + BlackConstantVol(todays_date, NullCalendar(), vol, dc) + ) bsm_process= BlackScholesMertonProcess(s0, q_ts, r_ts, vol_ts) heston_process = HestonProcess(r_ts, q_ts, s0, 0.0625, 0.5, 0.0625, 1e-5, 0.3) hw_process = HullWhiteForwardProcess(r_ts, 0.01, 0.01) diff --git a/test/test_indexes.py b/test/test_indexes.py index c527f985e..4619416a0 100644 --- a/test/test_indexes.py +++ b/test/test_indexes.py @@ -69,9 +69,9 @@ def test_create_libor_index(self): # must be a business day settlement_date = calendar.adjust(settlement_date) - term_structure = HandleYieldTermStructure() - term_structure.link_to(FlatForward(settlement_date, 0.05, - Actual365Fixed())) + term_structure = HandleYieldTermStructure( + FlatForward(settlement_date, 0.05, Actual365Fixed()) + ) index = Libor('USDLibor', Period(6, Months), settlement_days, USDCurrency(), calendar, Actual360(), @@ -89,9 +89,9 @@ class TestEuribor(unittest.TestCase): def test_creation(self): settlement_date = Date(1, January, 2014) - term_structure = HandleYieldTermStructure() - term_structure.link_to(FlatForward(settlement_date, 0.05, - Actual365Fixed())) + term_structure = HandleYieldTermStructure( + FlatForward(settlement_date, 0.05, Actual365Fixed()) + ) # Makes sure the constructor does not segfault anymore ;-) index = Euribor6M(term_structure) @@ -108,9 +108,9 @@ class TestUSDLibor(unittest.TestCase): def test_creation(self): settlement_date = Date(1, January, 2014) - term_structure = HandleYieldTermStructure() - term_structure.link_to(FlatForward(settlement_date, 0.05, - Actual365Fixed())) + term_structure = HandleYieldTermStructure( + FlatForward(settlement_date, 0.05, Actual365Fixed()) + ) index = USDLibor(Period(3, Months), term_structure) self.assertEqual(index.name, 'USDLibor3M Actual/360') @@ -125,11 +125,12 @@ class SwapIndexTestCase(unittest.TestCase): def test_create_swap_index(self): - term_structure = HandleYieldTermStructure() - term_structure.link_to(FlatForward(forward=0.05, - daycounter=Actual365Fixed(), - settlement_days=2, - calendar=UnitedStates())) + term_structure = HandleYieldTermStructure( + FlatForward(forward=0.05, + daycounter=Actual365Fixed(), + settlement_days=2, + calendar=UnitedStates()) + ) ibor_index = USDLibor(Period(3, Months), term_structure) @@ -146,9 +147,13 @@ def test_create_swap_index(self): class IndexManagerTestCase(unittest.TestCase): settlement_date = Date(1, January, 2014) - term_structure = HandleYieldTermStructure() - term_structure.link_to(FlatForward(settlement_date, 0.05, - Actual365Fixed())) + term_structure = HandleYieldTermStructure( + FlatForward( + settlement_date, + 0.05, + Actual365Fixed() + ) + ) index = USDLibor(Period(3, Months), term_structure) index.add_fixing(Date(5, 2, 2018), 1.79345) index.add_fixing(Date(2, 2, 2018), 1.78902) diff --git a/test/test_inflation.py b/test/test_inflation.py index c2eb741d2..3bdf8c524 100644 --- a/test/test_inflation.py +++ b/test/test_inflation.py @@ -17,8 +17,7 @@ from quantlib.instruments.bonds.cpibond import CPIBond, InterpolationType from quantlib.pricingengines.bond import DiscountingBondEngine from quantlib.settings import Settings -from quantlib.termstructures.inflation_term_structure import \ - ZeroInflationTermStructure +from quantlib.handle import RelinkableHandleZeroInflationTermStructure from quantlib.termstructures.yields.api import FlatForward, HandleYieldTermStructure from quantlib.indexes.inflation.ukrpi import UKRPI from quantlib.indexes.inflation_index import InterpolationType @@ -49,7 +48,7 @@ def setUp(self): Period(1, Months), self.calendar, ModifiedFollowing) - self.cpi_ts = ZeroInflationTermStructure() + self.cpi_ts = RelinkableHandleZeroInflationTermStructure() self.yts = HandleYieldTermStructure(FlatForward(evaluation_date, 0.05, day_counter)) self.ii = UKRPI(self.cpi_ts) fix_data = [206.1, 207.3, 208.0, 208.9, 209.7, 210.9, diff --git a/test/test_overnight_indexed_coupon.py b/test/test_overnight_indexed_coupon.py index 3852489d1..b34f76d91 100644 --- a/test/test_overnight_indexed_coupon.py +++ b/test/test_overnight_indexed_coupon.py @@ -2,7 +2,7 @@ from quantlib.cashflows.api import OvernightIndexedCoupon from quantlib.time.date import Date, October, November, December, January, March from quantlib.settings import Settings -from quantlib.termstructures.yields.api import HandleYieldTermStructure, FlatForward +from quantlib.termstructures.yields.api import RelinkableHandleYieldTermStructure, FlatForward from quantlib.time.api import Actual360 from quantlib.indexes.api import Sofr from .utilities import flat_rate @@ -12,7 +12,7 @@ class TestOvernightIndexedCoupon(unittest.TestCase): def setUp(self): self.today = Date(23, November, 2021) Settings().evaluation_date = self.today - self.forecast_curve = HandleYieldTermStructure() + self.forecast_curve = RelinkableHandleYieldTermStructure() self.notional = 10_000 self.sofr = Sofr(self.forecast_curve) diff --git a/test/test_overnight_indexed_swap.py b/test/test_overnight_indexed_swap.py index 837277b3f..e5d7452a5 100644 --- a/test/test_overnight_indexed_swap.py +++ b/test/test_overnight_indexed_swap.py @@ -4,7 +4,7 @@ from quantlib.instruments.api import MakeOIS from quantlib.settings import Settings from quantlib.time.api import Date, Days, Weeks, Months, Years, Following, Actual360 -from quantlib.termstructures.yields.api import HandleYieldTermStructure +from quantlib.termstructures.yields.api import RelinkableHandleYieldTermStructure from .utilities import flat_rate import math @@ -66,7 +66,7 @@ def setUp(self): self.nominal = 100 self.settings = Settings().__enter__() self.settings.evaluation_date = self.today - self.eonia_term_structure = HandleYieldTermStructure() + self.eonia_term_structure = RelinkableHandleYieldTermStructure() self.eonia_index = Eonia(self.eonia_term_structure) self.calendar = self.eonia_index.fixing_calendar self.settlement = self.calendar.advance(self.today, self.settlement_days, Following) diff --git a/test/test_swap.py b/test/test_swap.py index de4e232f3..4c2b433f4 100644 --- a/test/test_swap.py +++ b/test/test_swap.py @@ -45,9 +45,10 @@ def test_swap_QL(self): # must be a business day settlement_date = calendar.adjust(settlement_date) - termStructure = HandleYieldTermStructure() - termStructure.link_to(FlatForward(settlement_date, 0.05, - Actual365Fixed())) + termStructure = HandleYieldTermStructure( + FlatForward(settlement_date, 0.05, + Actual365Fixed()) + ) index = Libor('USD Libor', Period(6, Months), settlement_days, USDCurrency(), calendar, Actual360(), diff --git a/test/test_swaption_vol_cube.py b/test/test_swaption_vol_cube.py index f3318c3bc..995860e10 100644 --- a/test/test_swaption_vol_cube.py +++ b/test/test_swaption_vol_cube.py @@ -4,8 +4,8 @@ Following, Actual365Fixed) from quantlib.termstructures.yields.api import FlatForward, HandleYieldTermStructure from quantlib.quotes import SimpleQuote -from quantlib.termstructures.volatility.swaption.swaption_vol_matrix \ - import SwaptionVolatilityMatrix +from quantlib.termstructures.volatility.api import ( + SwaptionVolatilityMatrix, HandleSwaptionVolatilityStructure) from quantlib.termstructures.volatility.swaption.sabr_swaption_volatility_cube \ import SabrSwaptionVolatilityCube from quantlib.termstructures.volatility.swaption.spreaded_swaption_vol \ @@ -31,12 +31,14 @@ def setUp(self): M = Matrix.from_ndarray(m) calendar = UnitedStates() - self.atm_vol_matrix = SwaptionVolatilityMatrix(calendar, - Following, - atm_option_tenors, - atm_swap_tenors, - M, - Actual365Fixed()) + self.atm_vol_matrix = SwaptionVolatilityMatrix( + calendar, + Following, + atm_option_tenors, + atm_swap_tenors, + M, + Actual365Fixed() + ) term_structure = HandleYieldTermStructure( FlatForward(forward=0.05, settlement_days=2, calendar=calendar, daycounter=Actual365Fixed()) @@ -72,7 +74,7 @@ def test_sabr_vols(self): parameters_guess.append([SimpleQuote(0.2), SimpleQuote(0.5), SimpleQuote(0.4), SimpleQuote(0.)]) is_parameter_fixed = [False] * 4 - vol_cube = SabrSwaptionVolatilityCube(self.atm_vol_matrix, + vol_cube = SabrSwaptionVolatilityCube(HandleSwaptionVolatilityStructure(self.atm_vol_matrix), self.cube.option_tenors, self.cube.swap_tenors, self.cube.strike_spreads, @@ -110,7 +112,7 @@ def test_spreaded_cube(self): SimpleQuote(0.4), SimpleQuote(0.)]) is_parameter_fixed = [False] * 4 spread = SimpleQuote(0.0001) - vol_cube = SabrSwaptionVolatilityCube(self.atm_vol_matrix, + vol_cube = SabrSwaptionVolatilityCube(HandleSwaptionVolatilityStructure(self.atm_vol_matrix), self.cube.option_tenors, self.cube.swap_tenors, self.cube.strike_spreads, @@ -121,7 +123,7 @@ def test_spreaded_cube(self): parameters_guess, is_parameter_fixed, True) - spreaded_vol_cube = SpreadedSwaptionVolatility(vol_cube, + spreaded_vol_cube = SpreadedSwaptionVolatility(HandleSwaptionVolatilityStructure(vol_cube), spread) strikes = np.linspace(0.01, 0.99, 99) for t1 in self.cube.option_tenors: diff --git a/test/test_termstructures.py b/test/test_termstructures.py index 63ddfdbaa..a4ad414fa 100644 --- a/test/test_termstructures.py +++ b/test/test_termstructures.py @@ -9,10 +9,10 @@ import unittest from quantlib.termstructures.yields.api import ( - FlatForward, YieldTermStructure, ForwardSpreadedTermStructure, + FlatForward, HandleYieldTermStructure, RelinkableHandleYieldTermStructure, + ForwardSpreadedTermStructure, DiscountCurve, ImpliedTermStructure ) -from quantlib.termstructures.yield_term_structure import HandleYieldTermStructure from quantlib.quotes import SimpleQuote from quantlib.settings import Settings @@ -37,14 +37,13 @@ def test_default_constructor(self): def test_relinkable_structures(self): - discounting_term_structure = HandleYieldTermStructure() + settlement_days = 3 flat_term_structure = FlatForward(settlement_days=settlement_days, forward=0.044, calendar=NullCalendar(), daycounter=Actual360()) - + discounting_term_structure = RelinkableHandleYieldTermStructure() discounting_term_structure.link_to(flat_term_structure) - evaluation_date = Settings().evaluation_date +100 self.assertEqual( flat_term_structure.discount(evaluation_date), @@ -125,7 +124,6 @@ def test_forward_spreaded_ts(self): forecast_ts = m._forecast_term_structure discount_spd = 0.05 forecast_spd = 0.08 - fwd_spd_dts = ForwardSpreadedTermStructure(discount_ts, SimpleQuote(discount_spd)) fwd_spd_fts = ForwardSpreadedTermStructure(forecast_ts, SimpleQuote(forecast_spd)) diff --git a/test/test_vanilla_option.py b/test/test_vanilla_option.py index 9503ceedc..fe339080d 100644 --- a/test/test_vanilla_option.py +++ b/test/test_vanilla_option.py @@ -17,7 +17,7 @@ from quantlib.processes.black_scholes_process import BlackScholesMertonProcess from quantlib.settings import Settings from quantlib.time.api import Date, TARGET, May, Actual365Fixed -from quantlib.termstructures.yield_term_structure import HandleYieldTermStructure +from quantlib.handle import HandleYieldTermStructure, HandleBlackVolTermStructure from quantlib.termstructures.yields.flat_forward import FlatForward from quantlib.quotes import SimpleQuote from quantlib.methods.finitedifferences.solvers.fdmbackwardsolver import FdmSchemeDesc @@ -70,11 +70,13 @@ def setUp(self): ) ) - self.flat_vol_ts = BlackConstantVol( - self.settlement_date, - self.calendar, - self.volatility, - self.daycounter + self.flat_vol_ts = HandleBlackVolTermStructure( + BlackConstantVol( + self.settlement_date, + self.calendar, + self.volatility, + self.daycounter + ) ) self.black_scholes_merton_process = BlackScholesMertonProcess( diff --git a/test/test_variance_swap.py b/test/test_variance_swap.py index 9c5b5d9d2..3f9956ffd 100644 --- a/test/test_variance_swap.py +++ b/test/test_variance_swap.py @@ -12,7 +12,7 @@ from quantlib.pricingengines.forward.mc_variance_swap_engine import MCVarianceSwapEngine from quantlib.processes.api import BlackScholesMertonProcess from quantlib.quotes import SimpleQuote -from quantlib.termstructures.yield_term_structure import HandleYieldTermStructure +from quantlib.handle import HandleYieldTermStructure, HandleBlackVolTermStructure from quantlib.termstructures.yields.flat_forward import FlatForward from quantlib.termstructures.volatility.equityfx.black_variance_curve import BlackVarianceCurve from quantlib.termstructures.volatility.equityfx.black_variance_surface import BlackVarianceSurface @@ -113,8 +113,10 @@ def test_replicating_variance_swap(self): vols_mat = Matrix.from_ndarray(vols) - vol_ts = BlackVarianceSurface(self.today, NullCalendar(), dates, strikes, - vols_mat, self.dc) + vol_ts = HandleBlackVolTermStructure( + BlackVarianceSurface(self.today, NullCalendar(), dates, strikes, + vols_mat, self.dc) + ) stoch_process = BlackScholesMertonProcess(self.spot, self.q_ts, self.r_ts, @@ -160,7 +162,9 @@ def test_mc_variance_swap(self): # is unreliable. Result should be v*v for arbitrary t1 and v1 # (as long as 0<=t1 Date: Thu, 12 Jun 2025 11:40:21 -0400 Subject: [PATCH 6/7] add reset method --- quantlib/_handle.pxd | 1 + quantlib/handle.pyx.in | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/quantlib/_handle.pxd b/quantlib/_handle.pxd index c64b59f4f..81f4ae521 100644 --- a/quantlib/_handle.pxd +++ b/quantlib/_handle.pxd @@ -14,3 +14,4 @@ cdef extern from 'ql/handle.hpp' namespace 'QuantLib' nogil: RelinkableHandle() RelinkableHandle(shared_ptr[T]&, bool registerAsObserver) void linkTo(shared_ptr[T]&, bool registerAsObserver) + void reset() diff --git a/quantlib/handle.pyx.in b/quantlib/handle.pyx.in index dea8dc774..080aee692 100644 --- a/quantlib/handle.pyx.in +++ b/quantlib/handle.pyx.in @@ -46,4 +46,9 @@ cdef class RelinkableHandle{{T}}: def link_to(self, {{T}} t, bool register_as_observer=True): (self._handle).linkTo(static_pointer_cast[Ql{{T}}](t._thisptr), register_as_observer) + + def reset(self): + (self._handle).reset() + + {{endfor}} From e85bbac0deb8758c374f6e46fba0d65c8de6669e Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Fri, 2 Jan 2026 10:54:13 -0500 Subject: [PATCH 7/7] do not bomb if template files are missing --- setup.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 6d39a65c3..5ab73934f 100644 --- a/setup.py +++ b/setup.py @@ -125,10 +125,11 @@ def render_templates(): for ext in (".pxd", ".pyx"): output = (p / basename).with_suffix(ext) fname = output.with_suffix(f"{ext}.in") - if not output.exists() or (output.stat().st_mtime < fname.stat().st_mtime): - template = Template.from_filename(fname, encoding="utf-8") - with output.open("wt") as f: - f.write(template.substitute()) + if fname.exists(): + if not output.exists() or (output.stat().st_mtime < fname.stat().st_mtime): + template = Template.from_filename(fname, encoding="utf-8") + with output.open("wt") as f: + f.write(template.substitute()) def collect_extensions(): """ Collect all the directories with Cython extensions and return the list @@ -238,6 +239,7 @@ def run(self): fh.write("\n".join(map(os.path.basename, dlls))) if __name__ == '__main__': + render_templates() setup( name = 'quantlib', version = '0.1',