Time Module

Date and Time

Date

class pyquantlib.Date

Bases: pybind11_object

Date class for date algebra and calendar operations.

static endOfMonth(d: Date) Date

Last day of the month to which the given date belongs.

static from_date(arg0: object) Date
static isEndOfMonth(d: Date) bool

Whether a date is the last day of its month.

static isLeap(y: SupportsInt | SupportsIndex) bool

Whether the given year is a leap one.

static isStartOfMonth(d: Date) bool

Whether a date is the first day of its month.

static maxDate() Date

Latest allowed date.

static minDate() Date

Earliest allowed date.

static nextWeekday(d: Date, w: Weekday) Date

Next given weekday following the given date.

static nthWeekday(n: SupportsInt | SupportsIndex, w: Weekday, m: Month, y: SupportsInt | SupportsIndex) Date

The n-th given weekday in the given month and year.

static startOfMonth(d: Date) Date

First day of the month to which the given date belongs.

static todaysDate() Date

Today’s date.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__() -> None

Default constructor returning a null date.

  1. __init__(serialNumber: SupportsInt | SupportsIndex) -> None

Constructor taking a serial number as given by Excel.

  1. __init__(d: SupportsInt | SupportsIndex, m: Month, y: SupportsInt | SupportsIndex) -> None

Constructor taking day, month, year.

  1. __init__(arg0: object) -> None

dayOfMonth() int
dayOfYear() int
month() Month
serialNumber() int
to_date() object
weekday() Weekday
year() int

Period

class pyquantlib.Period

Bases: pybind11_object

Time period represented by length and units.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__() -> None

  2. __init__(length: SupportsInt | SupportsIndex, units: TimeUnit) -> None

  3. __init__(frequency: Frequency) -> None

  4. __init__(arg0: str) -> None

Create Period from a string like ‘3M’, ‘2Y’, etc.

frequency() Frequency
length() int
normalize() None
normalized() Period
units() TimeUnit

TimeGrid

class pyquantlib.TimeGrid

Bases: pybind11_object

Time grid for discretized models.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__() -> None

Default constructor.

  1. __init__(end: SupportsFloat | SupportsIndex, steps: SupportsInt | SupportsIndex) -> None

Constructs a regularly spaced time grid.

  1. __init__(times: collections.abc.Sequence[SupportsFloat | SupportsIndex]) -> None

Constructs from mandatory time points.

  1. __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.

back() float

Returns the last time.

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).

empty() bool

Returns true if the grid is empty.

front() float

Returns the first time (t=0).

index(t: SupportsFloat | SupportsIndex) int

Returns the index i such that grid[i] = t.

mandatoryTimes() list[float]

Returns the mandatory time points.

size() int

Returns the number of time points.

Calendars

Calendar

class pyquantlib.Calendar

Bases: pybind11_object

Calendar class for determining business days and holidays for a given market.

__init__() None
addHoliday(d: Date) None

Adds a date to the set of holidays for the given calendar.

addedHolidays() set[Date]

Returns the set of added holidays for the given calendar.

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.

  1. 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.

  1. advance(d: Date, period: Period, convention: BusinessDayConvention = <BusinessDayConvention.Following: 0>, endOfMonth: bool = False) -> Date

Advances the date by the given period.

businessDayList(from_: Date, to: Date) list[Date]

Returns the business days between two dates.

businessDaysBetween(from_: Date, to: Date, includeFirst: bool = True, includeLast: bool = False) int

Calculates the number of business days between two dates.

empty() bool

Returns whether or not the calendar is initialized.

endOfMonth(d: Date) Date

Last business day of the month to which the given date belongs.

holidayList(from_: Date, to: Date, includeWeekEnds: bool = False) list[Date]

Returns the holidays between two dates.

isBusinessDay(d: Date) bool

Returns True if the date is a business day.

isEndOfMonth(d: Date) bool

Returns True if the date is on or after the last business day of its month.

isHoliday(d: Date) bool

Returns True if the date is a holiday.

isStartOfMonth(d: Date) bool

Returns True if the date is on or before the first business day of its month.

isWeekend(w: Weekday) bool

Returns True if the weekday is part of the weekend.

name() str

Returns the name of the calendar.

removeHoliday(d: Date) None

Removes a date from the set of holidays for the given calendar.

removedHolidays() set[Date]

Returns the set of removed holidays for the given calendar.

resetAddedAndRemovedHolidays() None

Clear the set of added and removed holidays.

startOfMonth(d: Date) Date

First business day of the month to which the given date belongs.

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

TARGET, WeekendsOnly, NullCalendar, JointCalendar, BespokeCalendar

Americas

UnitedStates, Canada, Brazil, Mexico, Argentina, Chile

Europe

UnitedKingdom, Germany, France, Italy, Switzerland, Sweden, Norway, Denmark, Finland, Poland, CzechRepublic, Hungary, Romania, Russia, Ukraine, Turkey, Iceland, Austria, Slovakia

Asia-Pacific

Japan, China, HongKong, Singapore, Australia, NewZealand, India, SouthKorea, Taiwan, Indonesia, Thailand

Middle East/Africa

SaudiArabia, Israel, SouthAfrica, Botswana

UnitedStates Variants

NYSE, GovernmentBond, SOFR, FederalReserve

UnitedKingdom Variants

Exchange, Metals, Settlement

Day Counters

DayCounter

class pyquantlib.DayCounter

Bases: pybind11_object

Day counter base class, providing methods for time period calculations according to market conventions.

__init__() None

Default (null) day counter constructor.

dayCount(d1: Date, d2: Date) int

Returns the number of days between two dates.

empty() bool

Returns True if the day counter is not initialized.

name() str

Returns the name of the day counter.

yearFraction(d1: Date, d2: Date, refPeriodStart: Date = <Date: null date>, refPeriodEnd: Date = <Date: null date>) float

Returns the period between two dates as a fraction of year.

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

Actual360

Actual/360

Actual365Fixed

Actual/365 (Fixed)

Actual364

Actual/364

Actual366

Actual/366

ActualActual

Actual/Actual (various conventions)

Thirty360

30/360 (various conventions)

Thirty365

30/365

Business252

Business/252

OneDayCounter

Returns 1 for any period

SimpleDayCounter

Simple day counter

Schedules

Schedule

class pyquantlib.Schedule

Bases: pybind11_object

Payment schedule for a financial instrument.

__init__(*args, **kwargs)

Overloaded function.

  1. __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

  2. __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

  3. __init__() -> None

after(arg0: Date) Schedule
at(arg0: SupportsInt | SupportsIndex) Date
back() Date
businessDayConvention() BusinessDayConvention
calendar() Calendar
date(arg0: SupportsInt | SupportsIndex) Date
dates() list[Date]
empty() bool
endDate() Date
endOfMonth() bool
front() Date
hasEndOfMonth() bool
hasIsRegular() bool
hasRule() bool
hasTenor() bool
hasTerminationDateBusinessDayConvention() bool
isRegular(*args, **kwargs)

Overloaded function.

  1. isRegular(arg0: SupportsInt | SupportsIndex) -> bool

  2. 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> > >
nextDate(arg0: Date) Date
previousDate(arg0: Date) Date
rule() DateGeneration.Rule
startDate() Date
tenor() Period
terminationDateBusinessDayConvention() BusinessDayConvention
until(arg0: Date) Schedule

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

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_object

Units 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_object

Days 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_object

Month 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_object

Conventions 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

Unadjusted

Do not adjust

Following

Next business day

ModifiedFollowing

Next business day unless different month, then previous

Preceding

Previous business day

ModifiedPreceding

Previous business day unless different month, then next

DateGeneration

class pyquantlib.DateGeneration

Bases: pybind11_object

Date generation rules for Schedule construction.

class Rule

Bases: pybind11_object

Members:

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
__init__() 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>

Frequency

class pyquantlib.Frequency

Bases: pybind11_object

Frequency 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

Annual

1

Semiannual

2

Quarterly

4

Monthly

12

Weekly

52

Daily

365