Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion quantlib/indexes/_inflation_index.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ cdef extern from 'ql/indexes/inflationindex.hpp' namespace 'QuantLib' nogil:

cdef cppclass CPI:
enum InterpolationType:
AsIndex
Flat
Linear

Expand Down
1 change: 0 additions & 1 deletion quantlib/indexes/inflation_index.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ from quantlib.index cimport Index

cdef extern from "ql/indexes/inflationindex.hpp" namespace "QuantLib::CPI" nogil:
cpdef enum InterpolationType "QuantLib::CPI::InterpolationType":
AsIndex
Flat
Linear

Expand Down
8 changes: 2 additions & 6 deletions quantlib/instruments/bonds/_cpibond.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from quantlib.types cimport Natural, Rate, Real
from libcpp cimport bool
from libcpp.vector cimport vector
from .._bond cimport Bond

Expand All @@ -10,19 +9,16 @@ from quantlib.time._daycounter cimport DayCounter
from quantlib.time._period cimport Period
from quantlib.time._schedule cimport Schedule
from quantlib.ext cimport shared_ptr
from quantlib.indexes._inflation_index cimport ZeroInflationIndex

from .cpibond cimport InterpolationType
from quantlib.indexes._inflation_index cimport ZeroInflationIndex, CPI

cdef extern from 'ql/instruments/bonds/cpibond.hpp' namespace 'QuantLib' nogil:
cdef cppclass CPIBond(Bond):
CPIBond(Natural settlementDays,
Real faceAmount,
bool growthOnly,
Real baseCPI,
const Period& observationLag,
shared_ptr[ZeroInflationIndex]& cpiIndex,
InterpolationType observationInterpolation,
CPI.InterpolationType observationInterpolation,
const Schedule& schedule,
vector[Rate]& coupons,
const DayCounter& accrualDayCounter,
Expand Down
6 changes: 0 additions & 6 deletions quantlib/instruments/bonds/cpibond.pxd
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
from ..bond cimport Bond

cdef extern from 'ql/cashflows/cpicoupon.hpp' namespace 'QuantLib::CPI':
cpdef enum InterpolationType:
AsIndex
Flat
Linear

cdef class CPIBond(Bond):
pass
7 changes: 3 additions & 4 deletions quantlib/instruments/bonds/cpibond.pyx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from cython.operator cimport dereference as deref
from quantlib.types cimport Natural, Rate, Real
from libcpp cimport bool
from libcpp.vector cimport vector
from . cimport _cpibond

from quantlib.ext cimport static_pointer_cast
cimport quantlib.indexes._inflation_index as _inf
from quantlib.indexes.inflation_index cimport ZeroInflationIndex
from quantlib.indexes.inflation_index cimport InterpolationType, ZeroInflationIndex
from quantlib.time.businessdayconvention cimport BusinessDayConvention, Following, Unadjusted
from quantlib.time.calendar cimport Calendar
from quantlib.time.schedule cimport Schedule
Expand All @@ -15,7 +14,7 @@ from quantlib.time.daycounter cimport DayCounter

cdef class CPIBond(Bond):
""" CPI bond """
def __init__(self, Natural settlement_days, Real face_amount, bool growth_only,
def __init__(self, Natural settlement_days, Real face_amount,
Real baseCPI, Period observation_lag not None,
ZeroInflationIndex cpi_index not None,
InterpolationType observation_interpolation,
Expand All @@ -29,7 +28,7 @@ cdef class CPIBond(Bond):

self._thisptr.reset(
new _cpibond.CPIBond(
settlement_days, face_amount, growth_only, baseCPI,
settlement_days, face_amount, baseCPI,
deref(observation_lag._thisptr),
static_pointer_cast[_inf.ZeroInflationIndex](
cpi_index._thisptr),
Expand Down
4 changes: 2 additions & 2 deletions quantlib/instruments/swap.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ cdef class Swap(Instrument):
"""The discount factor at the NPV date."""
return get_swap(self).npvDateDiscount()

def leg(self, int i):
def leg(self, Size i):
"""The i-th leg of the swap.

Parameters
Expand All @@ -117,7 +117,7 @@ cdef class Swap(Instrument):
raise IndexError(f"leg #{i} doesn't exist")
return leg

def __getitem__(self, int i):
def __getitem__(self, Size i):
"""The i-th leg of the swap."""
cdef Leg leg = Leg.__new__(Leg)
cdef _swap.Swap* swap = <_swap.Swap*>self._thisptr.get()
Expand Down
2 changes: 1 addition & 1 deletion quantlib/math/matrix.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cdef class Matrix:
dims[1] = self._thisptr.columns()
cdef arr = np.PyArray_SimpleNew(2, &dims[0], np.NPY_DOUBLE)
cdef double[:,::1] r = arr
cdef size_t i, j
cdef np.npy_intp i, j
for i in range(dims[0]):
for j in range(dims[1]):
r[i,j] = self._thisptr[i][j]
Expand Down
1 change: 0 additions & 1 deletion quantlib/pricingengines/bond/_bondfunctions.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ cdef extern from 'ql/pricingengines/bond/bondfunctions.hpp' namespace 'QuantLib:
cdef Spread zSpread(Bond bond,
Bond.Price Price,
shared_ptr[YieldTermStructure],
DayCounter dayCounter,
Compounding compounding,
Frequency frequency,
Date settlementDate,
Expand Down
2 changes: 0 additions & 2 deletions quantlib/pricingengines/bond/bondfunctions.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ def basisPointValue(Bond bond not None,

def zSpread(Bond bond, Price price,
YieldTermStructure yts not None,
DayCounter day_counter not None,
Compounding compounding,
Frequency frequency,
Date settlement_date=Date(),
Expand All @@ -145,7 +144,6 @@ def zSpread(Bond bond, Price price,
deref(bond.as_ptr()),
price._this,
static_pointer_cast[_yts.YieldTermStructure](yts._thisptr),
deref(day_counter._thisptr),
compounding,
frequency,
settlement_date._thisptr,
Expand Down
33 changes: 0 additions & 33 deletions quantlib/reference/data_structures.py

This file was deleted.

13 changes: 3 additions & 10 deletions quantlib/termstructures/_inflation_term_structure.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ cdef extern from 'ql/termstructures/inflationtermstructure.hpp' namespace 'Quant
const shared_ptr[Seasonality] &seasonality # = boost::shared_ptr<Seasonality>()
) except +

Rate zeroRate(Date& d,
Period& inst_obs_lag,
bool force_linear_interpolation,
Rate zeroRate(Date d,
bool extrapolate)

Rate zeroRate(Time t,
bool extrapolate)

Expand All @@ -73,12 +70,8 @@ cdef extern from 'ql/termstructures/inflationtermstructure.hpp' namespace 'Quant
Frequency frequency,
const DayCounter& dayCounter,
const shared_ptr[Seasonality]& seasonality) except +

Rate yoyRate(Date& d,
Period& inst_obs_lag,
bool force_linear_interpolation,
bool extrapolate) except +

Rate yoyRate(Date d,
bool extrapolate) except +
Rate yoyRate(Time t,
bool extrapolate) except +

Expand Down
3 changes: 1 addition & 2 deletions quantlib/termstructures/inflation/_inflation_helpers.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ cdef extern from 'ql/termstructures/inflation/inflationhelpers.hpp' namespace 'Q
BusinessDayConvention payment_convention,
const DayCounter& day_counter,
const shared_ptr[ZeroInflationIndex]& zii,
CPI.InterpolationType observationInterpolation,
const Handle[_yts.YieldTermStructure]& nominal_term_structure) except +
CPI.InterpolationType observationInterpolation) except +

# Year-on-year inflation-swap bootstrap helper
cdef cppclass YearOnYearInflationSwapHelper(YoYInflationTraits.helper):
Expand Down
6 changes: 2 additions & 4 deletions quantlib/termstructures/inflation/inflation_helpers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ cdef class ZeroCouponInflationSwapHelper:
BusinessDayConvention payment_convention,
DayCounter day_counter not None,
ZeroInflationIndex zii not None,
InterpolationType observation_interpolation,
HandleYieldTermStructure nominal_term_structure not None):
InterpolationType observation_interpolation):
self._thisptr = shared_ptr[ZeroInflationTraits.helper](
new _ih.ZeroCouponInflationSwapHelper(
quote.handle(),
Expand All @@ -34,8 +33,7 @@ cdef class ZeroCouponInflationSwapHelper:
calendar._thisptr, payment_convention,
deref(day_counter._thisptr),
static_pointer_cast[_ii.ZeroInflationIndex](zii._thisptr),
<CPI.InterpolationType>observation_interpolation,
nominal_term_structure.handle())
<CPI.InterpolationType>observation_interpolation)
)

def set_term_structure(self, ZeroInflationTermStructure ts):
Expand Down
11 changes: 2 additions & 9 deletions quantlib/termstructures/inflation_term_structure.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ cdef class InflationTermStructure(TermStructure):

cdef class ZeroInflationTermStructure(InflationTermStructure):

def zero_rate(self, d, Period inst_obs_lag=Period(-1, Days),
bool force_linear_interpolation=False, bool extrapolate=False):
def zero_rate(self, d, bool extrapolate=False):


cdef _if.ZeroInflationTermStructure* term_structure = \
Expand All @@ -44,26 +43,20 @@ cdef class ZeroInflationTermStructure(InflationTermStructure):
if isinstance(d, Date):
return term_structure.zeroRate(
(<Date>d)._thisptr,
deref(inst_obs_lag._thisptr),
force_linear_interpolation,
extrapolate)
else:
return term_structure.zeroRate(<Time?>d, extrapolate)

cdef class YoYInflationTermStructure(InflationTermStructure):

def yoy_rate(self, d, Period inst_obs_lag=Period(-1, Days),
bool force_linear_interpolation=False,
bool extrapolate=False):
def yoy_rate(self, Date d, bool extrapolate=False):

cdef _if.YoYInflationTermStructure* term_structure = \
<_if.YoYInflationTermStructure*>self._thisptr.get()

if isinstance(d, Date):
return term_structure.yoyRate(
(<Date>d)._thisptr,
deref(inst_obs_lag._thisptr),
force_linear_interpolation,
extrapolate)
else:
return term_structure.yoyRate(<Time?>d, extrapolate)
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from libcpp.vector cimport vector
from quantlib._handle cimport Handle
from quantlib.time._date cimport Date
from quantlib.time._daycounter cimport DayCounter
from quantlib.time.frequency cimport Frequency

from quantlib.termstructures._yield_term_structure cimport YieldTermStructure
Expand All @@ -16,7 +15,6 @@ cdef extern from 'ql/termstructures/yield/piecewisezerospreadedtermstructure.hpp
const vector[Handle[Quote]]& spreads,
const vector[Date]& dates,
Compounding comp, # = Continuous,
Frequency freq, # = NoFrequency,
const DayCounter& dc), # = DayCounter(),
Frequency freq) # = NoFrequency,
#const Interpolator& factory) # = Interpolator())
ctypedef InterpolatedPiecewiseZeroSpreadedTermStructure[Linear] PiecewiseZeroSpreadedTermStructure
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from libcpp.vector cimport vector
from quantlib._handle cimport Handle
from quantlib.time._date cimport Date
from quantlib.time._daycounter cimport DayCounter
from quantlib.time.frequency cimport Frequency

from quantlib.termstructures._yield_term_structure cimport YieldTermStructure
Expand All @@ -15,5 +14,4 @@ cdef extern from 'ql/termstructures/yield/zerospreadedtermstructure.hpp' namespa
const Handle[YieldTermStructure]&,
Handle[Quote]& spread,
Compounding comp, # = Continuous,
Frequency freq, # = NoFrequency,
const DayCounter& dc), # = DayCounter(),
Frequency freq) # = NoFrequency,
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ from cython.operator cimport dereference as deref
from libcpp.vector cimport vector
from quantlib.compounding cimport Compounding
from quantlib.handle cimport Handle
from quantlib.time.daycounter cimport DayCounter
from quantlib.time.frequency cimport Frequency, NoFrequency
from quantlib.time._date cimport Date as QlDate
from quantlib.time.date cimport Date
Expand All @@ -13,8 +12,8 @@ from . cimport _piecewise_zerospreaded_termstructure as _pzt

cdef class PiecewiseZeroSpreadedTermStructure(YieldTermStructure):
def __init__(self, HandleYieldTermStructure h not None, list spreads, list dates,
Compounding comp=Compounding.Continuous, Frequency freq=NoFrequency,
DayCounter dc not None=DayCounter()):
Compounding comp=Compounding.Continuous,
Frequency freq=NoFrequency):
cdef vector[Handle[_qt.Quote]] spreads_vec
cdef vector[QlDate] dates_vec
cdef Quote s
Expand All @@ -32,6 +31,5 @@ cdef class PiecewiseZeroSpreadedTermStructure(YieldTermStructure):
dates_vec,
comp,
freq,
deref(dc._thisptr)
)
)
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
from cython.operator cimport dereference as deref
from quantlib.compounding cimport Compounding
from quantlib.handle cimport HandleYieldTermStructure
from quantlib.time.daycounter cimport DayCounter
from quantlib.time.frequency cimport Frequency, NoFrequency
from quantlib.quote cimport Quote
from . cimport _zero_spreaded_term_structure as _zsts

cdef class ZeroSpreadedTermStructure(YieldTermStructure):
def __init__(self, HandleYieldTermStructure h not None, Quote spread,
Compounding comp=Compounding.Continuous, Frequency freq=NoFrequency,
DayCounter dc not None=DayCounter()):
Compounding comp=Compounding.Continuous,
Frequency freq=NoFrequency):

self._thisptr.reset(
new _zsts.ZeroSpreadedTermStructure(
h.handle(),
spread.handle(),
comp,
freq,
deref(dc._thisptr)
)
)
9 changes: 5 additions & 4 deletions quantlib/util/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import numpy as np
import quantlib.reference.names as nm
import quantlib.reference.data_structures as ds
from pandas import DataFrame

from quantlib.instruments.vanillaoption import VanillaOption
Expand Down Expand Up @@ -107,9 +106,11 @@ def options_to_rates(options, t_min=1. / 12., n_min=6):
implied_dividend_yields.append(dividend_yield)
expiry_dates.append(expiry_date)

rates = ds.riskfree_dividend_template().reindex(index=expiry_dates)
rates[nm.INTEREST_RATE] = implied_interest_rates
rates[nm.DIVIDEND_YIELD] = implied_dividend_yields
return DataFrame({
nm.INTEREST_RATE: implied_interest_rates,
nm.DIVIDEND_YIELD: implied_dividend_yields,
},
index=expiry_dates

return rates

Expand Down
6 changes: 3 additions & 3 deletions test/test_bondfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_display(self):

d = bf.start_date(self.bond)

zspd = bf.zSpread(self.bond, Price(100.0), self.flat_term_structure, Actual365Fixed(),
zspd = bf.zSpread(self.bond, Price(100.0), self.flat_term_structure,
Compounded, Semiannual, self.settlement_date, 1e-6, 100, 0.5)


Expand Down Expand Up @@ -149,10 +149,10 @@ def test_display(self):
self.settlement_date, rate_helpers,
ts_day_counter, accuracy=tolerance)

pyc_zspd=bf.zSpread(self.bond, Price(102.0), ts, ActualActual(ActualActual.ISDA),
pyc_zspd=bf.zSpread(self.bond, Price(102.0), ts,
Compounded, Semiannual, Date(1, April, 2015), 1e-6, 100, 0.05)

pyc_zspd_disco=bf.zSpread(self.bond, Price(95.0), ts, ActualActual(ActualActual.ISDA),
pyc_zspd_disco=bf.zSpread(self.bond, Price(95.0), ts,
Compounded, Semiannual, self.settlement_date, 1e-6, 100, 0.05)


Expand Down
Loading
Loading