From 11e64118fd9b23c6931865ad29bdb86daadc553b Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Tue, 7 Nov 2023 21:32:29 -0500 Subject: [PATCH] simplify compounding --- quantlib/_interest_rate.pxd | 2 +- quantlib/cashflows/_fixed_rate_coupon.pxd | 2 +- quantlib/cashflows/fixed_rate_coupon.pyx | 3 +-- quantlib/{_compounding.pxd => compounding.pxd} | 2 +- quantlib/compounding.pyx | 8 -------- quantlib/interest_rate.pyx | 2 +- quantlib/pricingengines/bondfunctions.pyx | 2 +- quantlib/termstructures/_yield_term_structure.pxd | 2 +- quantlib/termstructures/yield_term_structure.pyx | 2 +- quantlib/termstructures/yields/_flat_forward.pxd | 5 ++--- .../yields/_piecewise_zerospreaded_termstructure.pxd | 2 +- quantlib/termstructures/yields/_zero_curve.pxd | 2 +- .../yields/_zero_spreaded_term_structure.pxd | 2 +- quantlib/termstructures/yields/flat_forward.pyx | 2 +- .../yields/piecewise_zerospreaded_termstructure.pyx | 2 +- quantlib/termstructures/yields/zero_curve.pyx.in | 2 +- .../yields/zero_spreaded_term_structure.pyx | 2 +- 17 files changed, 17 insertions(+), 27 deletions(-) rename quantlib/{_compounding.pxd => compounding.pxd} (86%) diff --git a/quantlib/_interest_rate.pxd b/quantlib/_interest_rate.pxd index 1e9c34bc6..95e6e278c 100644 --- a/quantlib/_interest_rate.pxd +++ b/quantlib/_interest_rate.pxd @@ -12,7 +12,7 @@ include 'types.pxi' from libcpp.string cimport string from quantlib.time._daycounter cimport DayCounter from quantlib.time._period cimport Frequency -from quantlib._compounding cimport Compounding +from quantlib.compounding cimport Compounding cdef extern from 'ql/interestrate.hpp' namespace 'QuantLib': diff --git a/quantlib/cashflows/_fixed_rate_coupon.pxd b/quantlib/cashflows/_fixed_rate_coupon.pxd index ad5e18500..b0b5008d5 100644 --- a/quantlib/cashflows/_fixed_rate_coupon.pxd +++ b/quantlib/cashflows/_fixed_rate_coupon.pxd @@ -6,7 +6,7 @@ from quantlib.time.businessdayconvention cimport BusinessDayConvention from quantlib.time._date cimport Date from quantlib.time._period cimport Frequency, Period from quantlib.time._calendar cimport Calendar -from quantlib._compounding cimport Compounding +from quantlib.compounding cimport Compounding from quantlib.time._daycounter cimport DayCounter from quantlib.time._schedule cimport Schedule from quantlib._cashflow cimport CashFlow diff --git a/quantlib/cashflows/fixed_rate_coupon.pyx b/quantlib/cashflows/fixed_rate_coupon.pyx index 2a1fe6d3d..481ccfc27 100644 --- a/quantlib/cashflows/fixed_rate_coupon.pyx +++ b/quantlib/cashflows/fixed_rate_coupon.pyx @@ -2,8 +2,7 @@ include '../types.pxi' from cython.operator cimport dereference as deref, preincrement as preinc from libcpp.vector cimport vector -from quantlib.compounding import Compounding -from quantlib._compounding cimport Compounding +from quantlib.compounding cimport Compounding from quantlib.handle cimport shared_ptr from quantlib.time.businessdayconvention cimport BusinessDayConvention from quantlib.time.calendar cimport Calendar diff --git a/quantlib/_compounding.pxd b/quantlib/compounding.pxd similarity index 86% rename from quantlib/_compounding.pxd rename to quantlib/compounding.pxd index 0ee9db891..4f2a9b5f3 100644 --- a/quantlib/_compounding.pxd +++ b/quantlib/compounding.pxd @@ -1,5 +1,5 @@ cdef extern from "ql/compounding.hpp" namespace "QuantLib": - enum Compounding: + cpdef enum Compounding: Simple = 0 Continuous = 1 Compounded = 2 diff --git a/quantlib/compounding.pyx b/quantlib/compounding.pyx index ccdb4cd90..e69de29bb 100644 --- a/quantlib/compounding.pyx +++ b/quantlib/compounding.pyx @@ -1,8 +0,0 @@ -from . cimport _compounding - -cpdef enum Compounding: - Simple = _compounding.Simple - Compounded = _compounding.Compounded - Continuous = _compounding.Continuous - SimpleThenCompounded = _compounding.SimpleThenCompounded - CompoundedThenSimple = _compounding.CompoundedThenSimple diff --git a/quantlib/interest_rate.pyx b/quantlib/interest_rate.pyx index 7f7886e70..faf128101 100644 --- a/quantlib/interest_rate.pyx +++ b/quantlib/interest_rate.pyx @@ -13,7 +13,7 @@ from quantlib.handle cimport shared_ptr from quantlib.time.daycounter cimport DayCounter cimport quantlib.time._daycounter as _daycounter -from quantlib._compounding cimport Compounding +from quantlib.compounding cimport Compounding from quantlib.time.frequency cimport Frequency cdef class InterestRate: diff --git a/quantlib/pricingengines/bondfunctions.pyx b/quantlib/pricingengines/bondfunctions.pyx index f26fe470e..b798a96d2 100644 --- a/quantlib/pricingengines/bondfunctions.pyx +++ b/quantlib/pricingengines/bondfunctions.pyx @@ -12,7 +12,7 @@ from quantlib.instruments.bonds cimport Bond from quantlib.time.date cimport date_from_qldate, Date from quantlib.termstructures.yield_term_structure cimport YieldTermStructure from quantlib.time.daycounter cimport DayCounter -from quantlib._compounding cimport Compounding +from quantlib.compounding cimport Compounding cimport quantlib.time._date as _dt cpdef enum DurationType: diff --git a/quantlib/termstructures/_yield_term_structure.pxd b/quantlib/termstructures/_yield_term_structure.pxd index 3015ec88d..ba9610cba 100644 --- a/quantlib/termstructures/_yield_term_structure.pxd +++ b/quantlib/termstructures/_yield_term_structure.pxd @@ -18,7 +18,7 @@ from quantlib.time._daycounter cimport DayCounter from quantlib.time._period cimport Frequency cimport quantlib._quote as _qt from quantlib._interest_rate cimport InterestRate -from quantlib._compounding cimport Compounding +from quantlib.compounding cimport Compounding cdef extern from 'ql/termstructures/yieldtermstructure.hpp' namespace 'QuantLib' nogil: diff --git a/quantlib/termstructures/yield_term_structure.pyx b/quantlib/termstructures/yield_term_structure.pyx index 38c8bcab6..8677e9bcd 100644 --- a/quantlib/termstructures/yield_term_structure.pyx +++ b/quantlib/termstructures/yield_term_structure.pyx @@ -9,7 +9,7 @@ from quantlib.time.calendar cimport Calendar from quantlib.time.daycounter cimport DayCounter from quantlib.time.date cimport Date, date_from_qldate, Period -from quantlib._compounding cimport Compounding +from quantlib.compounding cimport Compounding from quantlib.time.date import Annual cimport quantlib.termstructures._yield_term_structure as _yts diff --git a/quantlib/termstructures/yields/_flat_forward.pxd b/quantlib/termstructures/yields/_flat_forward.pxd index 8a6aec7bf..ce939cf98 100644 --- a/quantlib/termstructures/yields/_flat_forward.pxd +++ b/quantlib/termstructures/yields/_flat_forward.pxd @@ -7,8 +7,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. """ -include '../../types.pxi' - +from quantlib.types cimport * from libcpp cimport bool from libcpp.vector cimport vector @@ -18,7 +17,7 @@ from quantlib.time._date cimport Date from quantlib.time._daycounter cimport DayCounter from quantlib.time._period cimport Frequency cimport quantlib._quote as _qt -from quantlib._compounding cimport Compounding +from quantlib.compounding cimport Compounding from quantlib.termstructures._yield_term_structure cimport YieldTermStructure diff --git a/quantlib/termstructures/yields/_piecewise_zerospreaded_termstructure.pxd b/quantlib/termstructures/yields/_piecewise_zerospreaded_termstructure.pxd index e4d5de0fe..00b7bedba 100644 --- a/quantlib/termstructures/yields/_piecewise_zerospreaded_termstructure.pxd +++ b/quantlib/termstructures/yields/_piecewise_zerospreaded_termstructure.pxd @@ -7,7 +7,7 @@ from quantlib.time.frequency cimport Frequency from quantlib.termstructures._yield_term_structure cimport YieldTermStructure from quantlib._quote cimport Quote from quantlib.math._interpolations cimport Linear -from quantlib._compounding cimport Compounding +from quantlib.compounding cimport Compounding cdef extern from 'ql/termstructures/yield/piecewisezerospreadedtermstructure.hpp' namespace 'QuantLib': cdef cppclass InterpolatedPiecewiseZeroSpreadedTermStructure[I](YieldTermStructure): diff --git a/quantlib/termstructures/yields/_zero_curve.pxd b/quantlib/termstructures/yields/_zero_curve.pxd index 2592cc4d1..e52744d6b 100644 --- a/quantlib/termstructures/yields/_zero_curve.pxd +++ b/quantlib/termstructures/yields/_zero_curve.pxd @@ -4,7 +4,7 @@ from libcpp.pair cimport pair from quantlib.termstructures._yield_term_structure cimport YieldTermStructure -from quantlib._compounding cimport Compounding +from quantlib.compounding cimport Compounding from quantlib.time._date cimport Date from quantlib.time._daycounter cimport DayCounter from quantlib.time._calendar cimport Calendar diff --git a/quantlib/termstructures/yields/_zero_spreaded_term_structure.pxd b/quantlib/termstructures/yields/_zero_spreaded_term_structure.pxd index 9582400d8..251f6095a 100644 --- a/quantlib/termstructures/yields/_zero_spreaded_term_structure.pxd +++ b/quantlib/termstructures/yields/_zero_spreaded_term_structure.pxd @@ -7,7 +7,7 @@ from quantlib.time.frequency cimport Frequency from quantlib.termstructures._yield_term_structure cimport YieldTermStructure from quantlib._quote cimport Quote from quantlib.math._interpolations cimport Linear -from quantlib._compounding cimport Compounding +from quantlib.compounding cimport Compounding cdef extern from 'ql/termstructures/yield/zerospreadedtermstructure.hpp' namespace 'QuantLib': cdef cppclass ZeroSpreadedTermStructure(YieldTermStructure): diff --git a/quantlib/termstructures/yields/flat_forward.pyx b/quantlib/termstructures/yields/flat_forward.pyx index b345afba3..abf743de7 100644 --- a/quantlib/termstructures/yields/flat_forward.pyx +++ b/quantlib/termstructures/yields/flat_forward.pyx @@ -14,7 +14,7 @@ from quantlib.time.calendar cimport Calendar from quantlib.time.daycounter cimport DayCounter from quantlib.time.date cimport Date, date_from_qldate -from quantlib._compounding cimport Compounding +from quantlib.compounding cimport Compounding from quantlib.time.date import Annual from quantlib.handle cimport shared_ptr, RelinkableHandle, Handle diff --git a/quantlib/termstructures/yields/piecewise_zerospreaded_termstructure.pyx b/quantlib/termstructures/yields/piecewise_zerospreaded_termstructure.pyx index 16b9b4349..a059603a6 100644 --- a/quantlib/termstructures/yields/piecewise_zerospreaded_termstructure.pyx +++ b/quantlib/termstructures/yields/piecewise_zerospreaded_termstructure.pyx @@ -1,7 +1,7 @@ from cython.operator cimport dereference as deref from libcpp.vector cimport vector from quantlib.handle cimport Handle, make_shared, static_pointer_cast -from quantlib._compounding cimport Compounding, Continuous +from quantlib.compounding cimport Compounding, Continuous from quantlib.time.daycounter cimport DayCounter from quantlib.time.frequency cimport Frequency, NoFrequency from quantlib.time._date cimport Date as QlDate diff --git a/quantlib/termstructures/yields/zero_curve.pyx.in b/quantlib/termstructures/yields/zero_curve.pyx.in index 9cf7718a0..3513852ce 100644 --- a/quantlib/termstructures/yields/zero_curve.pyx.in +++ b/quantlib/termstructures/yields/zero_curve.pyx.in @@ -9,7 +9,7 @@ cimport quantlib.time._date as _date from quantlib.time.frequency cimport Frequency from .. cimport _yield_term_structure as _yts -from quantlib._compounding cimport Compounding +from quantlib.compounding cimport Compounding from quantlib.time.daycounter cimport DayCounter from quantlib.time.calendar cimport Calendar from quantlib.math.interpolation cimport Linear, LogLinear, BackwardFlat, Cubic diff --git a/quantlib/termstructures/yields/zero_spreaded_term_structure.pyx b/quantlib/termstructures/yields/zero_spreaded_term_structure.pyx index 1c20fd253..9bbf3637a 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.handle cimport Handle, make_shared, static_pointer_cast -from quantlib._compounding cimport Compounding, Continuous +from quantlib.compounding cimport Compounding, Continuous from quantlib.time.daycounter cimport DayCounter from quantlib.time.frequency cimport Frequency, NoFrequency from quantlib.quote cimport Quote