Time Module¶
Date and Time¶
Date¶
- class pyquantlib.Date¶
Bases:
pybind11_objectDate class for date algebra and calendar operations.
- static isLeap(y: SupportsInt | SupportsIndex) bool¶
Whether the given year is a leap one.
- static nthWeekday(n: SupportsInt | SupportsIndex, w: Weekday, m: Month, y: SupportsInt | SupportsIndex) Date¶
The n-th given weekday in the given month and year.
- __init__(*args, **kwargs)¶
Overloaded function.
__init__() -> None
Default constructor returning a null date.
__init__(serialNumber: SupportsInt | SupportsIndex) -> None
Constructor taking a serial number as given by Excel.
__init__(d: SupportsInt | SupportsIndex, m: Month, y: SupportsInt | SupportsIndex) -> None
Constructor taking day, month, year.
__init__(arg0: object) -> None
Period¶
- class pyquantlib.Period¶
Bases:
pybind11_objectTime period represented by length and units.
- __init__(*args, **kwargs)¶
Overloaded function.
__init__() -> None
__init__(length: SupportsInt | SupportsIndex, units: TimeUnit) -> None
__init__(frequency: Frequency) -> None
__init__(arg0: str) -> None
Create Period from a string like ‘3M’, ‘2Y’, etc.
TimeGrid¶
- class pyquantlib.TimeGrid¶
Bases:
pybind11_objectTime grid for discretized models.
- __init__(*args, **kwargs)¶
Overloaded function.
__init__() -> None
Default constructor.
__init__(end: SupportsFloat | SupportsIndex, steps: SupportsInt | SupportsIndex) -> None
Constructs a regularly spaced time grid.
__init__(times: collections.abc.Sequence[SupportsFloat | SupportsIndex]) -> None
Constructs from mandatory time points.
__init__(times: collections.abc.Sequence[SupportsFloat | SupportsIndex], steps: SupportsInt | SupportsIndex) -> None
Constructs from mandatory time points with minimum steps.
- at(i: SupportsInt | SupportsIndex) float¶
Returns the time at index i with bounds checking.
- closestIndex(t: SupportsFloat | SupportsIndex) int¶
Returns the index of the time closest to t.
- closestTime(t: SupportsFloat | SupportsIndex) float¶
Returns the time on the grid closest to t.
- dt(i: SupportsInt | SupportsIndex) float¶
Returns the time step dt(i) = t(i+1) - t(i).
- index(t: SupportsFloat | SupportsIndex) int¶
Returns the index i such that grid[i] = t.
Calendars¶
Calendar¶
- class pyquantlib.Calendar¶
Bases:
pybind11_objectCalendar class for determining business days and holidays for a given market.
- adjust(d: Date, convention: BusinessDayConvention = <BusinessDayConvention.Following: 0>) Date¶
Adjusts a non-business day to the appropriate nearby business day.
- advance(*args, **kwargs)¶
Overloaded function.
advance(d: Date, n: SupportsInt | SupportsIndex, unit: TimeUnit, convention: BusinessDayConvention = <BusinessDayConvention.Following: 0>, endOfMonth: bool = False) -> Date
Advances the date by the given number of time units.
advance(d: Date, period: Period, convention: BusinessDayConvention = <BusinessDayConvention.Following: 0>, endOfMonth: bool = False) -> Date
Advances the date by the given period.
- businessDaysBetween(from_: Date, to: Date, includeFirst: bool = True, includeLast: bool = False) int¶
Calculates the number of business days between two dates.
- holidayList(from_: Date, to: Date, includeWeekEnds: bool = False) list[Date]¶
Returns the holidays between two dates.
- isEndOfMonth(d: Date) bool¶
Returns True if the date is on or after the last business day of its month.
import pyquantlib as ql
target = ql.TARGET()
us = ql.UnitedStates(ql.UnitedStates.NYSE)
date = ql.Date(25, 12, 2025)
print(target.isBusinessDay(date)) # False (Christmas)
next_bd = target.adjust(date, ql.Following)
Available Calendars¶
Region |
Calendars |
|---|---|
Multi-national |
|
Americas |
|
Europe |
|
Asia-Pacific |
|
Middle East/Africa |
|
UnitedStates Variants¶
NYSE, GovernmentBond, SOFR, FederalReserve
UnitedKingdom Variants¶
Exchange, Metals, Settlement
Day Counters¶
DayCounter¶
- class pyquantlib.DayCounter¶
Bases:
pybind11_objectDay counter base class, providing methods for time period calculations according to market conventions.
dc = ql.Actual365Fixed()
start = ql.Date(1, 6, 2025)
end = ql.Date(1, 12, 2025)
yf = dc.yearFraction(start, end) # ~0.5
Available Day Counters¶
Day Counter |
Description |
|---|---|
|
Actual/360 |
|
Actual/365 (Fixed) |
|
Actual/364 |
|
Actual/366 |
|
Actual/Actual (various conventions) |
|
30/360 (various conventions) |
|
30/365 |
|
Business/252 |
|
Returns 1 for any period |
|
Simple day counter |
Schedules¶
Schedule¶
- class pyquantlib.Schedule¶
Bases:
pybind11_objectPayment schedule for a financial instrument.
- __init__(*args, **kwargs)¶
Overloaded function.
__init__(dates: collections.abc.Sequence[Date], calendar: Calendar = <NullCalendar object at 0x7f252f3d7330>, convention: BusinessDayConvention = <BusinessDayConvention.Unadjusted: 4>, terminationDateConvention: BusinessDayConvention | None = None, tenor: Period | None = None, rule: DateGeneration.Rule | None = None, endOfMonth: bool | None = None, isRegular: collections.abc.Sequence[bool] = []) -> None
__init__(effectiveDate: Date, terminationDate: Date, tenor: Period, calendar: Calendar, convention: BusinessDayConvention, terminationDateConvention: BusinessDayConvention, rule: DateGeneration.Rule, endOfMonth: bool, firstDate: Date = <Date: null date>, nextToLastDate: Date = <Date: null date>) -> None
__init__() -> None
- at(arg0: SupportsInt | SupportsIndex) Date¶
- businessDayConvention() BusinessDayConvention¶
- date(arg0: SupportsInt | SupportsIndex) Date¶
- isRegular(*args, **kwargs)¶
Overloaded function.
isRegular(arg0: SupportsInt | SupportsIndex) -> bool
isRegular() -> list[bool]
- lower_bound(date: Date = <Date: null date>) __gnu_cxx::__normal_iterator<QuantLib::Date const*, std::vector<QuantLib::Date, std::allocator<QuantLib::Date> > >¶
- rule() DateGeneration.Rule¶
- terminationDateBusinessDayConvention() BusinessDayConvention¶
MakeSchedule¶
- class pyquantlib.MakeSchedule(effectiveDate=None, terminationDate=None, *, forwards=False, backwards=False, **kwargs)[source]¶
Bases:
Build a Schedule from keyword arguments.
- Parameters:
effectiveDate (Date, optional) – Start date of the schedule.
terminationDate (Date, optional) – End date of the schedule.
forwards (bool) – Use forward date generation.
backwards (bool) – Use backward date generation.
**kwargs – Builder options mapped to
with*methods (e.g.tenor,frequency,calendar,convention,rule, …).
- Return type:
schedule = ql.MakeSchedule() \
.fromDate(today) \
.to(today + ql.Period("5Y")) \
.withFrequency(ql.Semiannual) \
.withCalendar(ql.TARGET()) \
.withConvention(ql.ModifiedFollowing) \
.value()
Enumerations¶
TimeUnit¶
- class pyquantlib.TimeUnit¶
Bases:
pybind11_objectUnits used to describe time periods.
Members:
Days
Weeks
Months
Years
Hours
Minutes
Seconds
Milliseconds
Microseconds
- __init__(value: SupportsInt | SupportsIndex) None¶
- Days = <TimeUnit.Days: 0>¶
- Hours = <TimeUnit.Hours: 4>¶
- Microseconds = <TimeUnit.Microseconds: 8>¶
- Milliseconds = <TimeUnit.Milliseconds: 7>¶
- Minutes = <TimeUnit.Minutes: 5>¶
- Months = <TimeUnit.Months: 2>¶
- Seconds = <TimeUnit.Seconds: 6>¶
- Weeks = <TimeUnit.Weeks: 1>¶
- Years = <TimeUnit.Years: 3>¶
- TimeUnit.name -> str
- property value¶
Weekday¶
- class pyquantlib.Weekday¶
Bases:
pybind11_objectDays of the week enumeration.
Members:
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sun
Mon
Tue
Wed
Thu
Fri
Sat
- __init__(value: SupportsInt | SupportsIndex) None¶
- Fri = <Weekday.Friday: 6>¶
- Friday = <Weekday.Friday: 6>¶
- Mon = <Weekday.Monday: 2>¶
- Monday = <Weekday.Monday: 2>¶
- Sat = <Weekday.Saturday: 7>¶
- Saturday = <Weekday.Saturday: 7>¶
- Sun = <Weekday.Sunday: 1>¶
- Sunday = <Weekday.Sunday: 1>¶
- Thu = <Weekday.Thursday: 5>¶
- Thursday = <Weekday.Thursday: 5>¶
- Tue = <Weekday.Tuesday: 3>¶
- Tuesday = <Weekday.Tuesday: 3>¶
- Wed = <Weekday.Wednesday: 4>¶
- Wednesday = <Weekday.Wednesday: 4>¶
- Weekday.name -> str
- property value¶
Month¶
- class pyquantlib.Month¶
Bases:
pybind11_objectMonth names enumeration.
Members:
January
February
March
April
May
June
July
August
September
October
November
December
Jan
Feb
Mar
Apr
Jun
Jul
Aug
Sep
Oct
Nov
Dec
- __init__(value: SupportsInt | SupportsIndex) None¶
- Apr = <Month.April: 4>¶
- April = <Month.April: 4>¶
- Aug = <Month.August: 8>¶
- August = <Month.August: 8>¶
- Dec = <Month.December: 12>¶
- December = <Month.December: 12>¶
- Feb = <Month.February: 2>¶
- February = <Month.February: 2>¶
- Jan = <Month.January: 1>¶
- January = <Month.January: 1>¶
- Jul = <Month.July: 7>¶
- July = <Month.July: 7>¶
- Jun = <Month.June: 6>¶
- June = <Month.June: 6>¶
- Mar = <Month.March: 3>¶
- March = <Month.March: 3>¶
- May = <Month.May: 5>¶
- Nov = <Month.November: 11>¶
- November = <Month.November: 11>¶
- Oct = <Month.October: 10>¶
- October = <Month.October: 10>¶
- Sep = <Month.September: 9>¶
- September = <Month.September: 9>¶
- Month.name -> str
- property value¶
BusinessDayConvention¶
- class pyquantlib.BusinessDayConvention¶
Bases:
pybind11_objectConventions for adjusting dates that fall on non-business days.
Members:
Following : Choose the first business day after the given holiday.
ModifiedFollowing : Choose the first business day after the holiday unless it belongs to a different month, in which case choose the first before.
Preceding : Choose the first business day before the given holiday.
ModifiedPreceding : Choose the first business day before the holiday unless it belongs to a different month, in which case choose the first after.
Unadjusted : Do not adjust.
HalfMonthModifiedFollowing : Choose the first business day after the holiday unless that day crosses mid-month (15th) or end of month, then choose before.
Nearest : Choose the nearest business day. If equidistant, default to following.
- __init__(value: SupportsInt | SupportsIndex) None¶
- Following = <BusinessDayConvention.Following: 0>¶
- HalfMonthModifiedFollowing = <BusinessDayConvention.HalfMonthModifiedFollowing: 5>¶
- ModifiedFollowing = <BusinessDayConvention.ModifiedFollowing: 1>¶
- ModifiedPreceding = <BusinessDayConvention.ModifiedPreceding: 3>¶
- Nearest = <BusinessDayConvention.Nearest: 6>¶
- Preceding = <BusinessDayConvention.Preceding: 2>¶
- Unadjusted = <BusinessDayConvention.Unadjusted: 4>¶
- BusinessDayConvention.name -> str
- property value¶
Convention |
Description |
|---|---|
|
Do not adjust |
|
Next business day |
|
Next business day unless different month, then previous |
|
Previous business day |
|
Previous business day unless different month, then next |
DateGeneration¶
- class pyquantlib.DateGeneration¶
Bases:
pybind11_objectDate generation rules for Schedule construction.
- class Rule¶
Bases:
pybind11_objectMembers:
Backward : Backward from termination date to effective date.
Forward : Forward from effective date to termination date.
Zero : No intermediate dates between effective date and termination date.
ThirdWednesday : All dates but effective/termination are third Wednesday of their month.
ThirdWednesdayInclusive : All dates including effective/termination are third Wednesday of their month.
Twentieth : All dates but effective are the twentieth of their month (CDS in emerging markets).
TwentiethIMM : All dates but effective are the twentieth of an IMM month (CDS schedules).
OldCDS : Same as TwentiethIMM with unrestricted date ends (old CDS convention).
CDS : Credit derivatives standard rule since ‘Big Bang’ changes in 2009.
CDS2015 : Credit derivatives standard rule since December 20th, 2015.
- __init__(value: SupportsInt | SupportsIndex) None¶
- Backward = <Rule.Backward: 0>¶
- CDS = <Rule.CDS: 8>¶
- CDS2015 = <Rule.CDS2015: 9>¶
- Forward = <Rule.Forward: 1>¶
- OldCDS = <Rule.OldCDS: 7>¶
- ThirdWednesday = <Rule.ThirdWednesday: 3>¶
- ThirdWednesdayInclusive = <Rule.ThirdWednesdayInclusive: 4>¶
- Twentieth = <Rule.Twentieth: 5>¶
- TwentiethIMM = <Rule.TwentiethIMM: 6>¶
- Zero = <Rule.Zero: 2>¶
- DateGeneration.Rule.name -> str
- property value¶
- Backward = <Rule.Backward: 0>¶
- CDS = <Rule.CDS: 8>¶
- CDS2015 = <Rule.CDS2015: 9>¶
- Forward = <Rule.Forward: 1>¶
- OldCDS = <Rule.OldCDS: 7>¶
- ThirdWednesday = <Rule.ThirdWednesday: 3>¶
- ThirdWednesdayInclusive = <Rule.ThirdWednesdayInclusive: 4>¶
- Twentieth = <Rule.Twentieth: 5>¶
- TwentiethIMM = <Rule.TwentiethIMM: 6>¶
- Zero = <Rule.Zero: 2>¶
Frequency¶
- class pyquantlib.Frequency¶
Bases:
pybind11_objectFrequency of events.
Members:
NoFrequency : Null frequency
Once : Only once, e.g., a zero-coupon
Annual : Once a year
Semiannual : Twice a year
EveryFourthMonth : Every fourth month
Quarterly : Every third month
Bimonthly : Every second month
Monthly : Once a month
EveryFourthWeek : Every fourth week
Biweekly : Every second week
Weekly : Once a week
Daily : Once a day
OtherFrequency : Some other unknown frequency
- __init__(value: SupportsInt | SupportsIndex) None¶
- Annual = <Frequency.Annual: 1>¶
- Bimonthly = <Frequency.Bimonthly: 6>¶
- Biweekly = <Frequency.Biweekly: 26>¶
- Daily = <Frequency.Daily: 365>¶
- EveryFourthMonth = <Frequency.EveryFourthMonth: 3>¶
- EveryFourthWeek = <Frequency.EveryFourthWeek: 13>¶
- Monthly = <Frequency.Monthly: 12>¶
- NoFrequency = <Frequency.NoFrequency: -1>¶
- Once = <Frequency.Once: 0>¶
- OtherFrequency = <Frequency.OtherFrequency: 999>¶
- Quarterly = <Frequency.Quarterly: 4>¶
- Semiannual = <Frequency.Semiannual: 2>¶
- Weekly = <Frequency.Weekly: 52>¶
- Frequency.name -> str
- property value¶
Frequency |
Periods per year |
|---|---|
|
1 |
|
2 |
|
4 |
|
12 |
|
52 |
|
365 |