8000 Date improvement by thrasibule · Pull Request #333 · enthought/pyql · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Date improvement #333

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

Merged
merged 4 commits into from
Mar 7, 2025
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
4 changes: 2 additions & 2 deletions quantlib/cashflow.pyx
Original file line number Diff line number Diff lin 1E79 e change
Expand Up @@ -40,13 +40,13 @@ cdef class CashFlow:
if include_ref_date is not None:
c_include_ref_date = <bool>include_ref_date
if cf:
return cf.hasOccurred(deref(ref_date._thisptr), c_include_ref_date)
return cf.hasOccurred(ref_date._thisptr, c_include_ref_date)

cdef class SimpleCashFlow(CashFlow):

def __init__(self, Real amount, Date cfdate):
self._thisptr = shared_ptr[_cf.CashFlow](
new _cf.SimpleCashFlow(amount, deref(cfdate._thisptr))
new _cf.SimpleCashFlow(amount, cfdate._thisptr)
)

def __str__(self):
Expand Down
21 changes: 10 additions & 11 deletions quantlib/cashflows/cap_floored_coupon.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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.cashflows.coupon_pricer cimport FloatingRateCouponPricer
Expand Down Expand Up @@ -82,18 +81,18 @@ cdef class CappedFlooredIborCoupon(CappedFlooredCoupon):
DayCounter day_counter=DayCounter(),
bool is_in_arrears=False):
self._thisptr = shared_ptr[CashFlow](new _cfc.CappedFlooredIborCoupon(
deref(payment_date._thisptr),
payment_date._thisptr,
nominal,
deref(start_date._thisptr),
deref(end_date._thisptr),
start_date._thisptr,
end_date._thisptr,
fixing_days,
static_pointer_cast[_ii.IborIndex](index._thisptr),
gearing,
spread,
cap,
floor,
deref(ref_period_start._thisptr),
deref(ref_period_end._thisptr),
ref_period_start._thisptr,
ref_period_end._thisptr,
deref(day_counter._thisptr),
is_in_arrears))

Expand All @@ -113,17 +112,17 @@ cdef class CappedFlooredCmsCoupon(CappedFlooredCoupon):
DayCounter day_counter=DayCounter(),
bool is_in_arrears=False):
self._thisptr = shared_ptr[CashFlow](new _cfc.CappedFlooredCmsCoupon(
deref(payment_date._thisptr),
payment_date._thisptr,
nominal,
deref(start_date._thisptr),
deref(end_date._thisptr),
start_date._thisptr,
end_date._thisptr,
fixing_days,
static_pointer_cast[_si.SwapIndex](index._thisptr),
gearing,
spread,
cap,
floor,
deref(ref_period_start._thisptr),
deref(ref_period_end._thisptr),
ref_period_start._thisptr,
ref_period_end._thisptr,
deref(day_counter._thisptr),
is_in_arrears))
16 changes: 8 additions & 8 deletions quantlib/cashflows/cashflows.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@ from ..cashflow cimport Leg
from ._cashflows cimport CashFlows

def previous_cash_flow_amount(Leg leg, bool include_settlement_date_flows, Date settlement_date=Date()):
return CashFlows.previousCashFlowAmount(leg._thisptr, include_settlement_date_flows, deref(settlement_date._thisptr))
return CashFlows.previousCashFlowAmount(leg._thisptr, include_settlement_date_flows, settlement_date._thisptr)

def next_cash_flow_amount(Leg leg, bool include_settlement_date_flows, Date settlement_date=Date()):
return CashFlows.nextCashFlowAmount(leg._thisptr, include_settlement_date_flows, deref(settlement_date._thisptr))
return CashFlows.nextCashFlowAmount(leg._thisptr, include_settlement_date_flows, settlement_date._thisptr)


def npv(Leg leg, YieldTermStructure discount_curve, bool include_settlement_date_flows,
Date settlement_date=Date, Date npv_date=Date()):
return CashFlows.npv(leg._thisptr,
deref(discount_curve.as_ptr()),
include_settlement_date_flows,
deref(settlement_date._thisptr),
deref(npv_date._thisptr))
settlement_date._thisptr,
npv_date._thisptr)

def bps(Leg leg, YieldTermStructure discount_curve, bool include_settlement_date_flows,
Date settlement_date=Date, Date npv_date=Date()):
return CashFlows.bps(leg._thisptr,
deref(discount_curve.as_ptr()),
include_settlement_date_flows,
deref(settlement_date._thisptr),
deref(npv_date._thisptr))
settlement_date._thisptr,
npv_date._thisptr)

def npvbps(Leg leg, YieldTermStructure discount_curve, bool include_settlement_date_flows,
Date settlement_date=Date, Date npv_date=Date()):
return CashFlows.npvbps(leg._thisptr,
deref(discount_curve.as_ptr()),
include_settlement_date_flows,
deref(settlement_date._thisptr),
deref(npv_date._thisptr))
settlement_date._thisptr,
npv_date._thisptr)
10 changes: 5 additions & 5 deletions quantlib/cashflows/cms_coupon.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ cdef class CmsCoupon(FloatingRateCoupon):
bool is_in_arrears=False):
self._thisptr = shared_ptr[_cf.CashFlow](
new _cc.CmsCoupon(
deref(payment_date._thisptr),
payment_date._thisptr,
nominal,
deref(start_date._thisptr),
deref(end_date._thisptr),
start_date._thisptr,
end_date._thisptr,
fixing_days,
static_pointer_cast[_si.SwapIndex](index._thisptr),
gearing,
spread,
deref(ref_period_start._thisptr),
deref(ref_period_end._thisptr),
ref_period_start._thisptr,
ref_period_end._thisptr,
deref(day_counter._thisptr),
is_in_arrears))

Expand Down
6 changes: 3 additions & 3 deletions quantlib/cashflows/coupon.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ cdef class Coupon(CashFlow):
return self._get_coupon().accrualPeriod()

def accrued_period(self, Date date):
return self._get_coupon().accruedPeriod(deref(date._thisptr))
return self._get_coupon().accruedPeriod(date._thisptr)

def accrued_days(self, Date date):
return self._get_coupon().accruedDays(deref(date._thisptr))
return self._get_coupon().accruedDays(date._thisptr)

def accrued_amount(self, Date date):
return self._get_coupon().accruedAmount(deref(date._thisptr))
return self._get_coupon().accruedAmount(date._thisptr)

@property
def rate(self):
Expand Down
15 changes: 7 additions & 8 deletions quantlib/cashflows/fixed_rate_coupon.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
include '../types.pxi'

from quantlib.types cimport Rate, Real
from cython.operator cimport dereference as deref, preincrement as preinc
from libcpp.vector cimport vector
from quantlib.compounding cimport Compounding
Expand All @@ -21,13 +20,13 @@ cdef class FixedRateCoupon(Coupon):
Date accrual_end_date not None, Date ref_period_start=Date(),
Date ref_period_end=Date(), Date ex_coupon_date=Date()):
self._thisptr = shared_ptr[_cf.CashFlow](
new _frc.FixedRateCoupon(deref(payment_date._thisptr), nominal,
new _frc.FixedRateCoupon(payment_date._thisptr, nominal,
rate, deref(day_counter._thisptr),
deref(accrual_start_date._thisptr),
deref(accrual_end_date._thisptr),
deref(ref_period_start._thisptr),
deref(ref_period_end._thisptr),
deref(ex_coupon_date._thisptr))
accrual_start_date._thisptr,
accrual_end_date._thisptr,
ref_period_start._thisptr,
ref_period_end._thisptr,
ex_coupon_date._thisptr)
)

def interest_rate(self):
Expand Down
6 changes: 3 additions & 3 deletions quantlib/cashflows/floating_rate_coupon.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ cdef class FloatingRateCoupon(Coupon):
DayCounter day_counter=DayCounter(), bool is_in_arrears=False):
self._thisptr = shared_ptr[_cf.CashFlow](
new _frc.FloatingRateCoupon(
deref(payment_date._thisptr), nominal,
deref(start_date._thisptr), deref(end_date._thisptr),
payment_date._thisptr, nominal,
start_date._thisptr, end_date._thisptr,
fixing_days,
static_pointer_cast[_iri.InterestRateIndex](index._thisptr),
gearing, spread,
deref(ref_period_start._thisptr), deref(ref_period_end._thisptr),
ref_period_start._thisptr, ref_period_end._thisptr,
deref(day_counter._thisptr), is_in_arrears)
)

Expand Down
6 changes: 3 additions & 3 deletions quantlib/cashflows/ibor_coupon.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ cdef class IborCoupon(FloatingRateCoupon):
DayCounter day_counter=DayCounter(), bool is_in_arrears=False):
self._thisptr = shared_ptr[_cf.CashFlow](
new _ic.IborCoupon(
deref(payment_date._thisptr), nominal,
deref(start_date._thisptr), deref(end_date._thisptr),
payment_date._thisptr, nominal,
start_date._thisptr, end_date._thisptr,
fixing_days,
static_pointer_cast[_ii.IborIndex](index._thisptr),
gearing, spread,
deref(ref_period_start._thisptr), deref(ref_period_end._thisptr),
ref_period_start._thisptr, ref_period_end._thisptr,
deref(day_counter._thisptr), is_in_arrears)
)
Settings = IborCouponSettings()
Expand Down
14 changes: 7 additions & 7 deletions quantlib/cashflows/overnight_indexed_coupon.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ cdef class OvernightIndexedCoupon(FloatingRateCoupon):
DayCounter day_counter=DayCounter(), bool telescopic_values= False,
RateAveraging averaging_method=RateAveraging.Compound):
self._thisptr = make_shared[_oic.OvernightIndexedCoupon](
deref(payment_date._thisptr), nominal,
deref(start_date._thisptr), deref(end_date._thisptr),
payment_date._thisptr, nominal,
start_date._thisptr, end_date._thisptr,
static_pointer_cast[_ii.OvernightIndex](index._thisptr),
gearing, spread,
deref(ref_period_start._thisptr), deref(ref_period_end._thisptr),
ref_period_start._thisptr, ref_period_end._thisptr,
deref(day_counter._thisptr), telescopic_values, averaging_method
)

Expand All @@ -38,7 +38,7 @@ cdef class OvernightIndexedCoupon(FloatingRateCoupon):

while it != (<_oic.OvernightIndexedCoupon*>self._thisptr.get()).fixingDates().end():
date = Date.__new__(Date)
date._thisptr.reset(new QlDate(deref(it)))
date._thisptr = deref(it)
l.append(date)
preinc(it)
return l
Expand All @@ -52,17 +52,17 @@ cdef class OvernightIndexedCoupon(FloatingRateCoupon):
def value_dates(self):
cdef:
vector[QlDate].const_iterator it = (<_oic.OvernightIndexedCoupon*>self._thisptr.get()).valueDates().const_begin()
QlDate d
Date date
list l = []

while it != (<_oic.OvernightIndexedCoupon*>self._thisptr.get()).valueDates().end():
date = Date.__new__(Date)
date._thisptr.reset(new QlDate(deref(it)))
date._thisptr = deref(it)
l.append(date)
preinc(it)
return l



cdef class OvernightLeg(Leg):

def __iter__(self):
Expand Down
20 changes: 10 additions & 10 deletions quantlib/experimental/coupons/cms_spread_coupon.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ cdef class CmsSpreadCoupon(FloatingRateCoupon):
bool is_in_arrears=False):
self._thisptr = shared_ptr[_cf.CashFlow](
new _csc.CmsSpreadCoupon(
deref(payment_date._thisptr),
payment_date._thisptr,
nominal,
deref(start_date._thisptr),
deref(end_date._thisptr),
start_date._thisptr,
end_date._thisptr,
fixing_days,
static_pointer_cast[_ssi.SwapSpreadIndex](index._thisptr),
gearing,
spread,
deref(ref_period_start._thisptr),
deref(ref_period_end._thisptr),
ref_period_start._thisptr,
ref_period_end._thisptr,
deref(day_counter._thisptr),
is_in_arrears))

Expand Down Expand Up @@ -65,17 +65,17 @@ cdef class CappedFlooredCmsSpreadCoupon(CappedFlooredCoupon):
bool is_in_arrears=False):
self._thisptr = shared_ptr[_cf.CashFlow](
new _csc.CappedFlooredCmsSpreadCoupon(
deref(payment_date._thisptr),
payment_date._thisptr,
nominal,
deref(start_date._thisptr),
deref(end_date._thisptr),
start_date._thisptr,
end_date._thisptr,
fixing_days,
static_pointer_cast[_ssi.SwapSpreadIndex](index._thisptr),
gearing,
spread,
cap,
floor,
deref(ref_period_start._thisptr),
deref(ref_period_end._thisptr),
ref_period_start._thisptr,
ref_period_end._thisptr,
deref(day_counter._thisptr),
is_in_arrears))
9 changes: 4 additions & 5 deletions quantlib/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""Abstract base class for indices"""
include 'types.pxi'

from cython.operator cimport dereference as deref
from cpython.datetime cimport PyDate_Check, date_year, date_month, date_day, import_datetime
from libcpp cimport bool
from libcpp.vector cimport vector
Expand Down Expand Up @@ -64,15 +63,15 @@ cdef class Index:

def is_valid_fixing_date(self, Date fixing_date not None):
return self._thisptr.get().isValidFixingDate(
deref(fixing_date._thisptr))
fixing_date._thisptr)

def fixing(self, Date fixingDate not None, bool forecast_todays_fixing=False):
return self._thisptr.get().fixing(
deref(fixingDate._thisptr), forecast_todays_fixing)
fixingDate._thisptr, forecast_todays_fixing)

def add_fixing(self, Date fixingDate not None, Real fixing, bool force_overwrite=False):
self._thisptr.get().addFixing(
deref(fixingDate._thisptr), fixing, force_overwrite
fixingDate._thisptr, fixing, force_overwrite
)

def add_fixings(self, list dates, list values, bool force_overwrite=False):
Expand All @@ -85,7 +84,7 @@ cdef class Index:
if PyDate_Check(d):
qldates.push_back(QlDate(date_day(d), <Month>date_month(d), date_year(d)))
elif isinstance(d, Date):
qldates.push_back(deref((<Date>d)._thisptr))
qldates.push_back((<Date>d)._thisptr)
else:
raise TypeError
qlvalues.push_back(<Real?>v)
Expand Down
8 changes: 4 additions & 4 deletions quantlib/indexes/interest_rate_index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ cdef class InterestRateIndex(Index):
return curr

def fixing_date(self, Date valueDate not None):
cdef _dt.Date dt = deref(valueDate._thisptr)
cdef _dt.Date dt = valueDate._thisptr
cdef _dt.Date fixing_date = get_iri(self).fixingDate(dt)
return date_from_qldate(fixing_date)


def value_date(self, Date fixingDate not None):
cdef _dt.Date dt = deref(fixingDate._thisptr)
cdef _dt.Date dt = fixingDate._thisptr
cdef _dt.Date value_date = get_iri(self).valueDate(dt)
return date_from_qldate(value_date)

def maturity_date(self, Date valueDate not None):
cdef _dt.Date dt = deref(valueDate._thisptr)
cdef _dt.Date dt = valueDate._thisptr
cdef _dt.Date maturity_date = get_iri(self).maturityDate(dt)
return date_from_qldate(maturity_date)

def forecast_fixing(self, Date fixing_date not None):
cdef _dt.Date dt = deref(fixing_date._thisptr)
cdef _dt.Date dt = fixing_date._thisptr
return get_iri(self).forecastFixing(dt)
4 changes: 2 additions & 2 deletions quantlib/indexes/swap_index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ cdef class SwapIndex(InterestRateIndex):
cdef _si.SwapIndex* swap_index = <_si.SwapIndex*>self._thisptr.get()
cdef VanillaSwap swap = VanillaSwap.__new__(VanillaSwap)
swap._thisptr = static_pointer_cast[_instrument.Instrument](
swap_index.underlyingSwap(deref(fixing_date._thisptr)))
swap_index.underlyingSwap(fixing_date._thisptr))
return swap

@property
Expand Down Expand Up @@ -118,5 +118,5 @@ cdef class OvernightIndexedSwapIndex(SwapIndex):
cdef _si.OvernightIndexedSwapIndex* swap_index = <_si.OvernightIndexedSwapIndex*>self._thisptr.get()
cdef OvernightIndexedSwap swap = OvernightIndexedSwap.__new__(OvernightIndexedSwap)
swap._thisptr = static_pointer_cast[_instrument.Instrument](
<shared_ptr[_si.OvernightIndexedSwap]>swap_index.underlyingSwap(deref(fixing_date._thisptr)))
<shared_ptr[_si.OvernightIndexedSwap]>swap_index.underlyingSwap(fixing_date._thisptr))
return swap
3 changes: 1 addition & 2 deletions quantlib/instruments/asian_options.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
""" Asian option on a single asset """
from quantlib.types cimport Real, Size
from cython.operator cimport dereference as deref
from libcpp.vector cimport vector

from quantlib.handle cimport shared_ptr, static_pointer_cast
Expand Down Expand Up @@ -67,7 +66,7 @@ cdef class DiscreteAveragingAsianOption(OneAssetOption):
# convert the list of PyQL dates into a vector of QL dates
cdef vector[_date.Date] _fixing_dates
for date in fixing_dates:
_fixing_dates.push_back(deref((<Date?>date)._thisptr))
_fixing_dates.push_back((<Date?>date)._thisptr)

if (running_accum is not None) and (past_fixings is not None):
self._thisptr = shared_ptr[_Instrument](
Expand Down
Loading
0