Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More bonds fixups #321

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion quantlib/instrument.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Abstract instrument class"""
from cython.operator cimport dereference as deref
from quantlib.time.date cimport date_from_qldate
from quantlib.pricingengines.engine cimport PricingEngine
from quantlib.handle cimport static_pointer_cast
Expand Down
5 changes: 1 addition & 4 deletions quantlib/models/calibration_helper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
FOR A PARTICULAR PURPOSE. See the license for more details.
"""

include '../types.pxi'

from quantlib.types cimport Real, Size, Volatility
from quantlib.handle cimport shared_ptr
from cython.operator cimport dereference as deref

cimport quantlib.pricingengines._pricing_engine as _pe
from quantlib.pricingengines.engine cimport PricingEngine


Expand Down
2 changes: 1 addition & 1 deletion quantlib/pricingengines/_pricing_engine.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cdef extern from 'ql/pricingengine.hpp' namespace 'QuantLib':
cdef extern from 'ql/pricingengine.hpp' namespace 'QuantLib' nogil:

cdef cppclass PricingEngine:
pass
1 change: 1 addition & 0 deletions quantlib/pricingengines/bond/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .discountingbondengine import DiscountingBondEngine
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include '../types.pxi'
from quantlib.types cimport Rate, Real, Spread, Size, Time

from quantlib.instruments._bond cimport Bond
from quantlib.handle cimport shared_ptr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ from quantlib.handle cimport Handle, optional
from quantlib.termstructures._yield_term_structure cimport YieldTermStructure

cdef extern from 'ql/pricingengines/bond/discountingbondengine.hpp' namespace \
'QuantLib':
'QuantLib' nogil:

cdef cppclass DiscountingBondEngine(PricingEngine):

DiscountingBondEngine()
DiscountingBondEngine(Handle[YieldTermStructure]& discountCurve)
DiscountingBondEngine(Handle[YieldTermStructure]& discountCurve,
optional[bool] includeSettlementDateFlows)
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
include '../types.pxi'

from quantlib.types cimport Rate, Real, Size
from quantlib.time._date cimport Day, Month, Year, Date as QLDate
from quantlib.time._period cimport Frequency
from quantlib.time._daycounter cimport DayCounter as _DayCounter
cimport quantlib.pricingengines._bondfunctions as _bf
from . cimport _bondfunctions as _bf

from quantlib.handle cimport shared_ptr, Handle
from cython.operator cimport dereference as deref
Expand Down Expand Up @@ -46,10 +45,10 @@ def bond_yield(Bond bond not None,
DayCounter dayCounter not None,
Compounding compounding,
Frequency frequency,
Date settlementDate not None,
Real accuracy,
Size maxIterations,
Rate guess):
Date settlementDate=Date(),
Real accuracy=1e-10,
Size maxIterations=100,
Rate guess=0.05):

return _bf.bf_yield(
deref(bond.as_ptr()),
Expand All @@ -68,7 +67,7 @@ def basisPointValue(Bond bond not None,
DayCounter dayCounter not None,
Compounding compounding,
Frequency frequency,
Date settlementDate not None):
Date settlementDate=Date()):
return _bf.basisPointValue(
deref(bond.as_ptr()),
yld,
Expand All @@ -83,10 +82,10 @@ def zSpread(Bond bond, Real cleanPrice,
DayCounter dayCounter not None,
Compounding compounding,
Frequency frequency,
Date settlementDate not None,
Real accuracy,
Size maxIterations,
Rate guess):
Date settlementDate=Date(),
Real accuracy=1e-10,
Size maxIterations=100,
Rate guess=0):

return _bf.zSpread(
deref(bond.as_ptr()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
"""
from cython.operator cimport dereference as deref
from . cimport _discountingbondengine as _dbe

from quantlib.handle cimport Handle, shared_ptr
from .cimport _pricing_engine as _pe
from . cimport _bond
from ..engine cimport PricingEngine

from .engine cimport PricingEngine

cimport quantlib.termstructures._yield_term_structure as _yts
from quantlib.termstructures.yield_term_structure cimport YieldTermStructure

cdef class DiscountingBondEngine(PricingEngine):
Expand All @@ -22,4 +17,4 @@ cdef class DiscountingBondEngine(PricingEngine):
"""
"""

self._thisptr.reset(new _bond.DiscountingBondEngine(discount_curve._thisptr))
self._thisptr.reset(new _dbe.DiscountingBondEngine(discount_curve._thisptr))
5 changes: 2 additions & 3 deletions quantlib/pricingengines/credit/isda_cds_engine.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ cdef class IsdaCdsEngine(PricingEngine):
<_ice.ForwardsInCouponPeriod>forwards_in_coupon_period)
)

cdef _ice.IsdaCdsEngine* _get_cds_engine(self):
cdef _ice.IsdaCdsEngine* ref = <_ice.IsdaCdsEngine*>(self._thisptr.get())
return ref
cdef inline _ice.IsdaCdsEngine* _get_cds_engine(self) nogil:
return <_ice.IsdaCdsEngine*>(self._thisptr.get())

@property
def isda_rate_curve(self):
Expand Down
1 change: 0 additions & 1 deletion quantlib/pricingengines/credit/midpoint_cds_engine.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ from cython.operator cimport dereference as deref
from libcpp cimport bool

from quantlib.handle cimport Handle, shared_ptr, optional
cimport quantlib.pricingengines._pricing_engine as _pe
from . cimport _midpoint_cds_engine as _mce

from quantlib.pricingengines.engine cimport PricingEngine
Expand Down
2 changes: 0 additions & 2 deletions quantlib/pricingengines/engine.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ cimport quantlib.pricingengines._pricing_engine as _pe

cdef class PricingEngine:
cdef shared_ptr[_pe.PricingEngine] _thisptr


1 change: 0 additions & 1 deletion quantlib/pricingengines/swap.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ from quantlib.pricingengines.vanilla.vanilla cimport PricingEngine
from quantlib.termstructures.yield_term_structure cimport YieldTermStructure

cimport quantlib.pricingengines._swap as _swap
cimport quantlib.pricingengines._pricing_engine as _pe
cimport quantlib.termstructures._yield_term_structure as _yts
from quantlib.time.date cimport Date

Expand Down
2 changes: 0 additions & 2 deletions quantlib/pricingengines/vanilla/mceuropeanhestonengine.pyx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from quantlib.types cimport BigNatural, Integer, Real, Size
from libcpp cimport bool
from cython.operator cimport dereference as deref
from quantlib.handle cimport shared_ptr, static_pointer_cast
from quantlib.utilities.null cimport Null
cimport quantlib.pricingengines._pricing_engine as _pe
from quantlib.processes.heston_process cimport HestonProcess
cimport quantlib.processes._heston_process as _hp
from .mcvanillaengine cimport MCVanillaEngine
Expand Down
2 changes: 1 addition & 1 deletion test/test_bondfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from quantlib.math.interpolation import LogLinear
from quantlib.quotes import SimpleQuote

import quantlib.pricingengines.bondfunctions as bf
import quantlib.pricingengines.bond.bondfunctions as bf


class BondFunctionTestCase(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion test/test_sensitivity_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
AnalyticEuropeanEngine
)
from quantlib.instruments.payoffs import PlainVanillaPayoff
import quantlib.pricingengines.bondfunctions as bf
import quantlib.pricingengines.bond.bondfunctions as bf
from quantlib.experimental.risk.sensitivityanalysis import (
bucket_analysis, parallel_analysis, Centered)
from numpy.testing import assert_allclose
Expand Down
Loading