Time¶
Calendars, day counters, dates, periods and schedules.
time
¶
Runtime source shim for the native itofin.time submodule.
The real itofin.time is a compiled submodule registered into
sys.modules by the extension (see crates/itofin-py/src/lib.rs); it wins
at import time, so nothing here runs. This file exists only so static type
checkers resolve from itofin.time import ... from time.pyi without
a reportMissingModuleSource warning.
Auto-generated by scripts/gen_submodule_shims.py from time.pyi; do not edit or delete by hand.
Date
¶
A calendar date with a validation guard.
Every constructor and every arithmetic result is range-checked before the core is reached, so an out-of-range date is an error rather than a panic.
Build a date from its three components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
int
|
The day of the month, within the length of that month. |
required |
month
|
int
|
The month, from 1 to 12. |
required |
year
|
int
|
The year, from 1901 to 2199. |
required |
Raises:
| Type | Description |
|---|---|
ItofinError
|
If month is outside [1, 12], year is outside [1901, 2199], or day is outside the length of that month. |
Period
¶
A signed length in one calendar unit (unit: Days, Weeks, Months, Years).
Build a period of n units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The length, which may be negative. |
required |
unit
|
str
|
One of "Days", "Weeks", "Months", "Years". |
required |
Raises:
| Type | Description |
|---|---|
ItofinError
|
If unit is not one of the four accepted strings. |
Calendar
¶
A business-day calendar.
target
staticmethod
¶
target() -> Calendar
The TARGET calendar.
Returns:
| Name | Type | Description |
|---|---|---|
Calendar |
Calendar
|
The TARGET business-day calendar. |
null_calendar
staticmethod
¶
null_calendar() -> Calendar
The calendar holding no holidays at all.
Returns:
| Name | Type | Description |
|---|---|---|
Calendar |
Calendar
|
The null calendar, on which every day is a business day. |
weekends_only
staticmethod
¶
weekends_only() -> Calendar
The weekends-only calendar: Saturdays and Sundays are holidays and no other day is. The calendar the ISDA CDS conventions roll on.
It is not substitutable by the null calendar, which holds no holidays at all, nor by a national calendar, which adds public holidays.
Returns:
| Name | Type | Description |
|---|---|---|
Calendar |
Calendar
|
The weekends-only calendar. |
united_kingdom
staticmethod
¶
united_kingdom() -> Calendar
The UK settlement calendar. Only the Settlement market is exposed: the Exchange and Metals markets share an identical business-day rule in the core and differ solely in their name.
Returns:
| Name | Type | Description |
|---|---|---|
Calendar |
Calendar
|
The UK settlement calendar. |
adjust
¶
adjust(date: Date, convention: BusinessDayConvention) -> Date
Roll a date to the nearest business day.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
Date
|
The date to roll. |
required |
convention
|
BusinessDayConvention
|
The rolling rule to apply. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Date |
Date
|
The adjusted date, unchanged when it is already a business day. |
advance
¶
advance(date: Date, n: int, unit: str, convention: BusinessDayConvention, end_of_month: bool) -> Date
Advance a date by n units and adjust the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
Date
|
The date to advance from. |
required |
n
|
int
|
The number of units to advance, which may be negative. |
required |
unit
|
str
|
One of "Days", "Weeks", "Months", "Years". |
required |
convention
|
BusinessDayConvention
|
The rule the advanced date is rolled under. |
required |
end_of_month
|
bool
|
Keep the result on the month end when the starting date is one. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Date |
Date
|
The advanced and adjusted date. |
Raises:
| Type | Description |
|---|---|
ItofinError
|
If unit is not one of the four accepted strings. |
DayCounter
¶
A year-fraction convention.
actual360
staticmethod
¶
actual360() -> DayCounter
The Actual/360 convention.
Returns:
| Name | Type | Description |
|---|---|---|
DayCounter |
DayCounter
|
An Actual/360 day counter. |
actual365_fixed
staticmethod
¶
actual365_fixed() -> DayCounter
The Actual/365 (Fixed) convention.
Returns:
| Name | Type | Description |
|---|---|---|
DayCounter |
DayCounter
|
An Actual/365 (Fixed) day counter. |
actual_actual_isda
staticmethod
¶
actual_actual_isda() -> DayCounter
The Actual/Actual (ISDA) convention.
Returns:
| Name | Type | Description |
|---|---|---|
DayCounter |
DayCounter
|
An Actual/Actual day counter on the ISDA convention. |
thirty360_bond_basis
staticmethod
¶
thirty360_bond_basis() -> DayCounter
The 30/360 (Bond Basis) convention.
Returns:
| Name | Type | Description |
|---|---|---|
DayCounter |
DayCounter
|
A 30/360 day counter on the bond-basis convention. |
year_fraction
¶
Frequency
¶
A coupon or fixing frequency.
Only the variants the ported fixtures use are surfaced; new ones are appended, so the integer values of the existing variants are unchanged.
BusinessDayConvention
¶
A holiday-rolling rule. Every core variant is covered; the four listed last are appended, so the integer values of the first three are unchanged.
DateGeneration
¶
The rule a Schedule generates its dates by.
Backward and Forward roll from one end of the range to the other; Zero keeps only the two endpoints; the ThirdWednesday and Twentieth families snap the interior dates onto an IMM Wednesday or the twentieth of the month. A Schedule builds under the three CDS rules, but SpreadCdsHelper rejects them: their maturity comes from a core routine that is not ported yet.
Schedule
¶
Schedule(start: Date, end: Date, frequency: Frequency, calendar: Calendar, convention: BusinessDayConvention, rule: DateGeneration = ..., termination_convention: BusinessDayConvention | None = None)
A sequence of coupon dates built through MakeSchedule.
termination_convention rolls the last date only, and defaults to convention. CDS conventions need the two to differ: a credit helper leaves its maturity unadjusted while paying Following.
Build the schedule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
Date
|
The effective date, which must be strictly before end. |
required |
end
|
Date
|
The termination date. |
required |
frequency
|
Frequency
|
The coupon frequency the interior dates are spaced at. |
required |
calendar
|
Calendar
|
The calendar the dates roll on. |
required |
convention
|
BusinessDayConvention
|
The rule every date but the last is rolled under. |
required |
rule
|
DateGeneration
|
The date-generation rule; defaults to Forward. |
...
|
termination_convention
|
BusinessDayConvention | None
|
The rule the last date is rolled under; None applies convention to it as well. |
None
|
Raises:
| Type | Description |
|---|---|
ItofinError
|
If start is not strictly before end. |
size
¶
The number of dates in the schedule.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The date count, one more than the number of periods. |
date
¶
date(i: int) -> Date
The i-th date in the schedule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
i
|
int
|
The zero-based index into the dates. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Date |
Date
|
The date at that index. |
Raises:
| Type | Description |
|---|---|
ItofinError
|
If i is out of range. |
is_imm_date
¶
is_imm_date(date: Date, main_cycle: bool = False) -> bool
Whether date is an IMM date.
An IMM date is the third Wednesday of the month, and of March, June, September or December only when main_cycle is set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
Date
|
The date to test. |
required |
main_cycle
|
bool
|
Restrict the test to the March/June/September/December cycle. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True when date is an IMM date under the selected cycle. |
next_imm_date
¶
The next IMM date strictly following date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
Date
|
The date to start from; the result is strictly after it. |
required |
main_cycle
|
bool
|
Restrict the result to the March/June/September/December cycle. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Date |
Date
|
The next IMM date under the selected cycle. |