Skip to content

Commit

Permalink
just store calendar as an object
Browse files Browse the repository at this point in the history
  • Loading branch information
thrasibule committed Nov 21, 2023
1 parent 8c59784 commit 82f7a46
Show file tree
Hide file tree
Showing 46 changed files with 116 additions and 133 deletions.
2 changes: 1 addition & 1 deletion quantlib/cashflows/fixed_rate_coupon.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ cdef class FixedRateLeg(Leg):
return self

def with_payment_calendar(self, Calendar cal):
self.frl.withPaymentCalendar(deref(cal._thisptr))
self.frl.withPaymentCalendar(cal._thisptr)
return self

def with_last_period_day_counter(self, DayCounter dc):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ cdef class ConstNotionalCrossCurrencyBasisSwapRateHelper(RelativeDateRateHelper)
basis.handle(),
deref(tenor._thisptr),
fixing_days,
deref(calendar._thisptr),
calendar._thisptr,
convention,
end_of_month,
static_pointer_cast[_ii.IborIndex](base_currency_index._thisptr),
Expand Down Expand Up @@ -80,7 +80,7 @@ cdef class MtMCrossCurrencyBasisSwapRateHelper(RelativeDateRateHelper):
basis.handle(),
deref(tenor._thisptr),
fixing_days,
deref(calendar._thisptr),
calendar._thisptr,
convention,
end_of_month,
static_pointer_cast[_ii.IborIndex](base_currency_index._thisptr),
Expand Down
2 changes: 1 addition & 1 deletion quantlib/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ cdef class Index:
"""the calendar defining valid fixing dates"""
def __get__(self):
cdef Calendar cal = Calendar.__new__(Calendar)
cal._thisptr = new _calendar.Calendar(self._thisptr.get().fixingCalendar())
cal._thisptr = self._thisptr.get().fixingCalendar()
return cal

@property
Expand Down
4 changes: 2 additions & 2 deletions quantlib/indexes/ibor/libor.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ cdef class Libor(IborIndex):
deref(tenor._thisptr),
<Natural> settlementDays,
deref(currency._thisptr),
deref(financial_center_calendar._thisptr),
financial_center_calendar._thisptr,
deref(dayCounter._thisptr),
ts._thisptr))

@property
def joint_calendar(self):
cdef Calendar cal = Calendar.__new__(Calendar)
cal._thisptr = new _calendar.Calendar((<_libor.Libor*>self._thisptr.get()).jointCalendar())
cal._thisptr = (<_libor.Libor*>self._thisptr.get()).jointCalendar()
return cal
4 changes: 2 additions & 2 deletions quantlib/indexes/ibor_index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cdef class IborIndex(InterestRateIndex):
deref(tenor._thisptr),
settlement_days,
deref(currency._thisptr),
deref(fixing_calendar._thisptr),
fixing_calendar._thisptr,
<BusinessDayConvention> convention,
end_of_month,
deref(day_counter._thisptr),
Expand Down Expand Up @@ -94,7 +94,7 @@ cdef class OvernightIndex(IborIndex):
new _ib.OvernightIndex(family_name.encode('utf-8'),
settlement_days,
deref(currency._thisptr),
deref(fixing_calendar._thisptr),
fixing_calendar._thisptr,
deref(day_counter._thisptr),
yts._thisptr)
)
2 changes: 1 addition & 1 deletion quantlib/indexes/swap_index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ cdef class SwapIndex(InterestRateIndex):
deref(tenor._thisptr),
<Natural> settlement_days,
deref(currency._thisptr),
deref(calendar._thisptr),
calendar._thisptr,
deref(fixed_leg_tenor._thisptr),
<BusinessDayConvention> fixed_leg_convention,
deref(fixed_leg_daycounter._thisptr),
Expand Down
10 changes: 5 additions & 5 deletions quantlib/instruments/bonds.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ cdef class FixedRateBond(Bond):
deref(accrual_day_counter._thisptr),
payment_convention,
redemption, deref(issue_date._thisptr),
deref(payment_calendar._thisptr),
payment_calendar._thisptr,
deref(ex_coupon_period._thisptr),
deref(ex_coupon_calendar._thisptr),
ex_coupon_calendar._thisptr,
ex_coupon_convention,
ex_coupon_end_of_month)
)
Expand Down Expand Up @@ -211,7 +211,7 @@ cdef class ZeroCouponBond(Bond):

self._thisptr = shared_ptr[_instrument.Instrument](
new _bonds.ZeroCouponBond(settlement_days,
deref(calendar._thisptr), face_amount,
calendar._thisptr, face_amount,
deref(maturity_date._thisptr),
payment_convention, redemption,
deref(issue_date._thisptr)
Expand Down Expand Up @@ -299,7 +299,7 @@ cdef class CPIBond(Bond):
deref(schedule._thisptr), coupons,
deref(accrual_day_counter._thisptr), payment_convention,
deref(issue_date._thisptr),
deref(payment_calendar._thisptr), deref(ex_coupon_period._thisptr),
deref(ex_coupon_calendar._thisptr), ex_coupon_convention,
payment_calendar._thisptr, deref(ex_coupon_period._thisptr),
ex_coupon_calendar._thisptr, ex_coupon_convention,
ex_coupon_end_of_month)
)
2 changes: 1 addition & 1 deletion quantlib/instruments/make_ois.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ cdef class MakeOIS:
return self

def with_payment_calendar(self, Calendar cal not None):
self._thisptr.withPaymentCalendar(deref(cal._thisptr))
self._thisptr.withPaymentCalendar(cal._thisptr)
return self

def with_end_of_month(self, bool flag=True):
Expand Down
4 changes: 2 additions & 2 deletions quantlib/instruments/overnightindexedswap.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cdef class OvernightIndexedSwap(Swap):
make_shared[_ois.OvernightIndexedSwap](
swap_type, <Real>nominal, deref(schedule._thisptr), fixed_rate,
deref(fixed_dc._thisptr), static_pointer_cast[_ii.OvernightIndex](overnight_index._thisptr),
spread, payment_lag, payment_adjustment, deref(payment_calendar._thisptr),
spread, payment_lag, payment_adjustment, payment_calendar._thisptr,
telescopic_value_dates, averaging_method
)
)
Expand All @@ -52,7 +52,7 @@ cdef class OvernightIndexedSwap(Swap):
make_shared[_ois.OvernightIndexedSwap](
swap_type, nominals, deref(schedule._thisptr), fixed_rate,
deref(fixed_dc._thisptr), static_pointer_cast[_ii.OvernightIndex](overnight_index._thisptr),
spread, payment_lag, payment_adjustment, deref(payment_calendar._thisptr),
spread, payment_lag, payment_adjustment, payment_calendar._thisptr,
telescopic_value_dates, averaging_method
)
)
Expand Down
2 changes: 1 addition & 1 deletion quantlib/models/equity/heston_model.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ cdef class HestonModelHelper(BlackCalibrationHelper):
self._thisptr = shared_ptr[_ch.CalibrationHelper](
new _hm.HestonModelHelper(
deref(maturity._thisptr),
deref(calendar._thisptr),
calendar._thisptr,
s0,
strike_price,
volatility.handle(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ cdef class SpreadCdsHelper(CdsHelper):
self._thisptr = shared_ptr[_ci.DefaultProbabilityHelper](
new _ci.SpreadCdsHelper(
<Rate>running_spread, deref(tenor._thisptr),
settlement_days, deref(calendar._thisptr),
settlement_days, calendar._thisptr,
<Frequency>frequency,
<BusinessDayConvention>paymentConvention, date_generation_rule,
deref(daycounter._thisptr),
Expand All @@ -143,7 +143,7 @@ cdef class SpreadCdsHelper(CdsHelper):
self._thisptr = shared_ptr[_ci.DefaultProbabilityHelper](
new _ci.SpreadCdsHelper(
(<Quote>running_spread).handle(), deref(tenor._thisptr),
settlement_days, deref(calendar._thisptr),
settlement_days, calendar._thisptr,
<Frequency>frequency,
<BusinessDayConvention>paymentConvention, date_generation_rule,
deref(daycounter._thisptr),
Expand Down Expand Up @@ -178,7 +178,7 @@ cdef class UpfrontCdsHelper(CdsHelper):
self._thisptr = shared_ptr[_ci.DefaultProbabilityHelper](
new _ci.UpfrontCdsHelper(
<Rate>upfront, running_spread, deref(tenor._thisptr.get()),
settlement_days, deref(calendar._thisptr), <Frequency>frequency,
settlement_days, calendar._thisptr, <Frequency>frequency,
<BusinessDayConvention>paymentConvention, rule,
deref(daycounter._thisptr),
recovery_rate, discount_curve._thisptr, upfront_settlement_days, settles_accrual,
Expand All @@ -192,7 +192,7 @@ cdef class UpfrontCdsHelper(CdsHelper):
self._thisptr = shared_ptr[_ci.DefaultProbabilityHelper](
new _ci.UpfrontCdsHelper(
(<Quote>upfront).handle(), running_spread, deref(tenor._thisptr),
settlement_days, deref(calendar._thisptr), <Frequency>frequency,
settlement_days, calendar._thisptr, <Frequency>frequency,
<BusinessDayConvention>paymentConvention, rule,
deref(daycounter._thisptr),
recovery_rate, discount_curve._thisptr, upfront_settlement_days, settles_accrual,
Expand Down
4 changes: 2 additions & 2 deletions quantlib/termstructures/credit/flat_hazard_rate.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ cdef class FlatHazardRate(DefaultProbabilityTermStructure):
if isinstance(hazard_rate, float):
self._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _fhr.FlatHazardRate(settlement_days,
deref(calendar._thisptr),
calendar._thisptr,
<Rate>hazard_rate,
deref(day_counter._thisptr)))
elif isinstance(hazard_rate, Quote):
self._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _fhr.FlatHazardRate(
settlement_days,
deref(calendar._thisptr),
calendar._thisptr,
(<Quote>hazard_rate).handle(),
deref(day_counter._thisptr)))
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ cdef class InterpolatedHazardRateCurve(DefaultProbabilityTermStructure):
new _ihc.InterpolatedHazardRateCurve[intpl.Linear](
_dates, hazard_rates,
deref(day_counter._thisptr),
deref(cal._thisptr))
cal._thisptr)
)
elif interpolator == LogLinear:
self._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _ihc.InterpolatedHazardRateCurve[intpl.LogLinear](
_dates, hazard_rates,
deref(day_counter._thisptr),
deref(cal._thisptr))
cal._thisptr)
)
elif interpolator == BackwardFlat:
self._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _ihc.InterpolatedHazardRateCurve[intpl.BackwardFlat](
_dates, hazard_rates,
deref(day_counter._thisptr),
deref(cal._thisptr))
cal._thisptr)
)
else:
raise ValueError("interpolator needs to be any of Linear, LogLinear or BackwardFlat")
Expand Down
36 changes: 18 additions & 18 deletions quantlib/termstructures/credit/piecewise_default_curve.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -49,49 +49,49 @@ cdef class PiecewiseDefaultCurve(DefaultProbabilityTermStructure):
if interpolator == Linear:
self._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.HazardRate,_pdc.Linear](
settlement_days, deref(calendar._thisptr), instruments,
settlement_days, calendar._thisptr, instruments,
deref(daycounter._thisptr), accuracy))
elif interpolator == LogLinear:
self._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.HazardRate,_pdc.LogLinear](
settlement_days, deref(calendar._thisptr), instruments,
settlement_days, calendar._thisptr, instruments,
deref(daycounter._thisptr), accuracy))
else:
self._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.HazardRate,_pdc.BackwardFlat](
settlement_days, deref(calendar._thisptr), instruments,
settlement_days, calendar._thisptr, instruments,
deref(daycounter._thisptr), accuracy))
elif trait == DefaultDensity:
if interpolator == Linear:
self._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.DefaultDensity,_pdc.Linear](
settlement_days, deref(calendar._thisptr), instruments,
settlement_days, calendar._thisptr, instruments,
deref(daycounter._thisptr), accuracy))
elif interpolator == LogLinear:
self._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.DefaultDensity,_pdc.LogLinear](
settlement_days, deref(calendar._thisptr), instruments,
settlement_days, calendar._thisptr, instruments,
deref(daycounter._thisptr), accuracy))
else:
self._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.DefaultDensity,_pdc.BackwardFlat](
settlement_days, deref(calendar._thisptr), instruments,
settlement_days, calendar._thisptr, instruments,
deref(daycounter._thisptr), accuracy))
else:
if interpolator == Linear:
self._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.SurvivalProbability,_pdc.Linear](
settlement_days, deref(calendar._thisptr), instruments,
settlement_days, calendar._thisptr, instruments,
deref(daycounter._thisptr), accuracy))
elif interpolator == LogLinear:
self._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.SurvivalProbability,_pdc.LogLinear](
settlement_days, deref(calendar._thisptr), instruments,
settlement_days, calendar._thisptr, instruments,
deref(daycounter._thisptr), accuracy))
else:
self._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.SurvivalProbability,_pdc.BackwardFlat](
settlement_days, deref(calendar._thisptr), instruments,
settlement_days, calendar._thisptr, instruments,
deref(daycounter._thisptr), accuracy))

@classmethod
Expand All @@ -117,49 +117,49 @@ cdef class PiecewiseDefaultCurve(DefaultProbabilityTermStructure):
if interpolator == Linear:
instance._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.HazardRate,_pdc.Linear](
deref(reference_date._thisptr.get()), instruments,
deref(reference_date._thisptr), instruments,
deref(daycounter._thisptr), accuracy))
elif interpolator == LogLinear:
instance._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.HazardRate,_pdc.LogLinear](
deref(reference_date._thisptr.get()), instruments,
deref(reference_date._thisptr), instruments,
deref(daycounter._thisptr), accuracy))
else:
instance._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.HazardRate,_pdc.BackwardFlat](
deref(reference_date._thisptr.get()), instruments,
deref(reference_date._thisptr), instruments,
deref(daycounter._thisptr), accuracy))
elif trait == DefaultDensity:
if interpolator == Linear:
instance._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.DefaultDensity,_pdc.Linear](
deref(reference_date._thisptr.get()), instruments,
deref(reference_date._thisptr), instruments,
deref(daycounter._thisptr), accuracy))
elif interpolator == LogLinear:
instance._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.DefaultDensity,_pdc.LogLinear](
deref(reference_date._thisptr.get()),
deref(reference_date._thisptr),
instruments, deref(daycounter._thisptr), accuracy))
else:
instance._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.DefaultDensity,_pdc.BackwardFlat](
deref(reference_date._thisptr.get()), instruments,
deref(reference_date._thisptr), instruments,
deref(daycounter._thisptr), accuracy))
else:
if interpolator == Linear:
instance._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.SurvivalProbability,_pdc.Linear](
deref(reference_date._thisptr.get()), instruments,
deref(reference_date._thisptr), instruments,
deref(daycounter._thisptr), accuracy))
elif interpolator == LogLinear:
instance._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.SurvivalProbability,_pdc.LogLinear](
deref(reference_date._thisptr.get()),
deref(reference_date._thisptr),
instruments, deref(daycounter._thisptr), accuracy))
else:
instance._thisptr = shared_ptr[_dts.DefaultProbabilityTermStructure](
new _pdc.PiecewiseDefaultCurve[_pdc.SurvivalProbability,_pdc.BackwardFlat](
deref(reference_date._thisptr.get()), instruments,
deref(reference_date._thisptr), instruments,
deref(daycounter._thisptr), accuracy))

return instance
Expand Down
Loading

0 comments on commit 82f7a46

Please sign in to comment.