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

closer to upstream constructor #319

Merged
merged 1 commit into from
Feb 27, 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
4 changes: 4 additions & 0 deletions quantlib/time/calendars/null_calendar.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from quantlib.time.calendar cimport Calendar

cdef class NullCalendar(Calendar):
pass
7 changes: 2 additions & 5 deletions quantlib/time/calendars/null_calendar.pyx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
cimport quantlib.time.calendars._null_calendar as _nc
from quantlib.time.calendar cimport Calendar


cdef class NullCalendar(Calendar):
'''Calendar for reproducing theoretical calculations.
This calendar has no holidays. It ensures that dates at whole-month

This calendar has no holidays. It ensures that dates at whole-month
distances have the same day of month.

'''

def __cinit__(self):
self._thisptr = _nc.NullCalendar()

69 changes: 38 additions & 31 deletions quantlib/time/schedule.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ cimport cython
import numpy as np
cimport numpy as np
np.import_array()
from .businessdayconvention cimport Following, BusinessDayConvention
from .businessdayconvention cimport Following, Unadjusted, BusinessDayConvention
from .dategeneration cimport DateGeneration

from .calendar cimport Calendar
from .calendars.null_calendar cimport NullCalendar
from .date cimport date_from_qldate, Date, Period

import warnings
Expand All @@ -25,51 +26,57 @@ cdef class Schedule:
BusinessDayConvention business_day_convention=Following,
BusinessDayConvention termination_date_convention=Following,
DateGeneration date_generation_rule=DateGeneration.Forward, bool end_of_month=False,
from_classmethod=False
):

if not from_classmethod:
warnings.warn("Deprecated: use class method from_rule instead",
DeprecationWarning)

self._thisptr = new _schedule.Schedule(
deref(effective_date._thisptr),
deref(termination_date._thisptr),
deref(tenor._thisptr),
calendar._thisptr,
business_day_convention,
termination_date_convention,
date_generation_rule, end_of_month,
_date.Date(), _date.Date()
)
else:
pass
warnings.warn("Deprecated: use class method from_rule instead",
DeprecationWarning)

self._thisptr = new _schedule.Schedule(
deref(effective_date._thisptr),
deref(termination_date._thisptr),
deref(tenor._thisptr),
calendar._thisptr,
business_day_convention,
termination_date_convention,
date_generation_rule, end_of_month,
_date.Date(), _date.Date()
)

@classmethod
def from_dates(cls, dates, Calendar calendar not None,
BusinessDayConvention business_day_convention=Following,
BusinessDayConvention termination_date_convention=Following,
def from_dates(cls, dates, Calendar calendar=NullCalendar(),
BusinessDayConvention business_day_convention=Unadjusted,
termination_date_convention=None,
Period tenor=None,
DateGeneration date_generation_rule=DateGeneration.Forward, bool end_of_month=False,
rule=None,
end_of_month=None,
vector[bool] is_regular=[]):
# convert lists to vectors
cdef vector[_date.Date] _dates = vector[_date.Date]()
cdef vector[_date.Date] _dates
cdef Date date
for date in dates:
_dates.push_back(deref((<Date>date)._thisptr))
_dates.push_back(deref(date._thisptr))

cdef Schedule instance = cls.__new__(cls)
cdef Schedule instance = Schedule.__new__(Schedule)
cdef optional[BusinessDayConvention] opt_termination_convention
cdef optional[_calendar.Period] opt_tenor
cdef optional[DateGeneration] opt_rule
cdef optional[bool] opt_end_of_month
if tenor is not None:
opt_tenor = deref(tenor._thisptr)
cdef optional[BusinessDayConvention] opt_termination_convention = termination_date_convention
if termination_date_convention is not None:
opt_termination_convention = <BusinessDayConvention>termination_date_convention
if rule is not None:
opt_rule = <DateGeneration>rule
if end_of_month is not None:
opt_end_of_month = <bool>end_of_month
instance._thisptr = new _schedule.Schedule(
_dates,
calendar._thisptr,
business_day_convention,
opt_termination_convention,
opt_tenor,
optional[DateGeneration](date_generation_rule),
optional[bool](end_of_month),
opt_rule,
opt_end_of_month,
is_regular
)

Expand All @@ -81,18 +88,18 @@ cdef class Schedule:
Period tenor not None, Calendar calendar not None,
BusinessDayConvention business_day_convention=Following,
BusinessDayConvention termination_date_convention=Following,
DateGeneration date_generation_rule=DateGeneration.Forward, bool end_of_month=False,
DateGeneration rule=DateGeneration.Forward, bool end_of_month=False,
Date first_date=Date(), Date next_to_lastdate=Date()):

cdef Schedule instance = cls.__new__(cls)
cdef Schedule instance = Schedule.__new__(Schedule)
instance._thisptr = new _schedule.Schedule(
deref(effective_date._thisptr),
deref(termination_date._thisptr),
deref(tenor._thisptr),
calendar._thisptr,
business_day_convention,
termination_date_convention,
date_generation_rule, end_of_month,
rule, end_of_month,
deref(first_date._thisptr), deref(next_to_lastdate._thisptr)
)
return instance
Expand Down
Loading