finpricing.utils
#
Submodules#
finpricing.utils.bus_day_adj
finpricing.utils.calendar
finpricing.utils.cds_style
finpricing.utils.date
finpricing.utils.date_generator
finpricing.utils.day_count
finpricing.utils.error
finpricing.utils.frequency
finpricing.utils.holiday
finpricing.utils.instaplot
finpricing.utils.interpolator
finpricing.utils.literal
finpricing.utils.pandas_holiday
finpricing.utils.payment_schedule
finpricing.utils.tools
Package Contents#
Classes#
Generic enumeration. |
|
Generic enumeration. |
|
Generic enumeration. |
|
Generic enumeration. |
|
Generic enumeration. |
|
Generic enumeration. |
|
Generic enumeration. |
|
Generic enumeration. |
|
Generic enumeration. |
|
Generic enumeration. |
|
Generic enumeration. |
|
Generic enumeration. |
|
Generic enumeration. |
|
Generic enumeration. |
|
Generic enumeration. |
|
Generic enumeration. |
|
Literal constants |
Functions#
|
Return the string representation of a dictionary |
|
Return the string representation of a dictionary in a pretty table format where |
|
Return the string representation of a dictionary in a pretty table format |
|
|
|
- class finpricing.utils.Date(year: int, month: int, day: int)[source]#
- property is_weekend: bool#
Return True if the date is a weekend, False otherwise
Monday is 0 and Sunday is 6.
- MON = 0#
- TUE = 1#
- WED = 2#
- THU = 3#
- FRI = 4#
- SAT = 5#
- SUN = 6#
- classmethod convert_from_datetime(date: datetime.date | Date) Date [source]#
Return a Date object from a datetime.date object
- classmethod convert_from_datetimes(dates: list[datetime.date | Date]) list[Date] [source]#
Return a list of Date objects from a list of datetime.date objects
- classmethod from_datetime(date: datetime.date) Date [source]#
Return a Date object from a datetime.date object
- classmethod from_tuple(date_tuple: tuple) Date [source]#
Return a Date object from a tuple of (year, month, day)
- add_interval(time_interval: TimeInterval) Date [source]#
- class finpricing.utils.Date(year: int, month: int, day: int)[source]#
- property is_weekend: bool#
Return True if the date is a weekend, False otherwise
Monday is 0 and Sunday is 6.
- MON = 0#
- TUE = 1#
- WED = 2#
- THU = 3#
- FRI = 4#
- SAT = 5#
- SUN = 6#
- classmethod convert_from_datetime(date: datetime.date | Date) Date [source]#
Return a Date object from a datetime.date object
- classmethod convert_from_datetimes(dates: list[datetime.date | Date]) list[Date] [source]#
Return a list of Date objects from a list of datetime.date objects
- classmethod from_datetime(date: datetime.date) Date [source]#
Return a Date object from a datetime.date object
- classmethod from_tuple(date_tuple: tuple) Date [source]#
Return a Date object from a tuple of (year, month, day)
- add_interval(time_interval: TimeInterval) Date [source]#
- exception finpricing.utils.NotSupportedError[source]#
Bases:
Exception
Common base class for all non-exit exceptions.
- class finpricing.utils.DayCountTypes[source]#
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- ACT_360 = 0#
- ACT_365 = 1#
- THIRTY_360 = 2#
- ACT_ACT_ISDA = 3#
- Thirty_E_360 = 4#
- Thirty_E_360_ISDA = 5#
- class finpricing.utils.DayCount(dccType: DayCountTypes)[source]#
- year_frac#
- days_between(start_date: finpricing.utils.date.Date, end_date: finpricing.utils.date.Date, include_end=False) tuple [source]#
Return the number of days and year fraction using a specific day count convention
- Returns:
(days, fraction of year)
- Return type:
tuple
- year_fraction(start_date: finpricing.utils.date.Date | datetime.date, end_date: finpricing.utils.date.Date | datetime.date, next_coupon_date: finpricing.utils.date.Date = None) float [source]#
Return the fraction of year between two dates using a specific day count convention
The actual calculation is done in days_between() method.
- convert_dates_to_times(anchor_date: finpricing.utils.date.Date, dates: list[finpricing.utils.date.Date]) list[float] [source]#
Return a list of time fraction (year fraction) between anchor date and each date in the list
- exception finpricing.utils.NotSupportedError[source]#
Bases:
Exception
Common base class for all non-exit exceptions.
- class finpricing.utils.Date(year: int, month: int, day: int)[source]#
- property is_weekend: bool#
Return True if the date is a weekend, False otherwise
Monday is 0 and Sunday is 6.
- MON = 0#
- TUE = 1#
- WED = 2#
- THU = 3#
- FRI = 4#
- SAT = 5#
- SUN = 6#
- classmethod convert_from_datetime(date: datetime.date | Date) Date [source]#
Return a Date object from a datetime.date object
- classmethod convert_from_datetimes(dates: list[datetime.date | Date]) list[Date] [source]#
Return a list of Date objects from a list of datetime.date objects
- classmethod from_datetime(date: datetime.date) Date [source]#
Return a Date object from a datetime.date object
- classmethod from_tuple(date_tuple: tuple) Date [source]#
Return a Date object from a tuple of (year, month, day)
- add_interval(time_interval: TimeInterval) Date [source]#
- class finpricing.utils.BusDayAdjustTypes[source]#
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- NONE = 1#
- FOLLOWING = 2#
- MODIFIED_FOLLOWING = 3#
- PREVIOUS = 4#
- MODIFIED_PREVIOUS = 5#
- class finpricing.utils.Holiday(calendarType: CalendarTypes)[source]#
- is_holiday(date: finpricing.utils.date.Date) bool [source]#
- holiday_united_states(date: finpricing.utils.date.Date) bool [source]#
Return True if the date is a holiday in the United States, False otherwise
Need to verify and enhance the dates. Reference: domokane/FinancePy
- class finpricing.utils.CalendarTypes[source]#
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- NONE = 0#
- WEEKEND = 1#
- UNITED_STATES = 2#
- class finpricing.utils.DateGenRuleTypes[source]#
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- FORWARD = 1#
- BACKWARD = 2#
- class finpricing.utils.Calendar(calendarType: finpricing.utils.holiday.CalendarTypes)[source]#
- is_holiday(date: finpricing.utils.date.Date) bool [source]#
- is_business_day(date: finpricing.utils.date.Date) bool [source]#
Return True if the date is a business day
Weekend or not is determined solely by the date itself. Holiday or not is determined by the calendar.
- add_business_days(date: finpricing.utils.date.Date, num_days: int) finpricing.utils.date.Date [source]#
Return a new Date object by adding num_days business days to the date
- adjust(date: finpricing.utils.date.Date, busDayAdjType: finpricing.utils.bus_day_adj.BusDayAdjustTypes) finpricing.utils.date.Date [source]#
Return a new Date object by adjusting the date according to the Business Day Convention
For details, https://jollycontrarian.com/index.php?title=Business_Day_Convention_-_ISDA_Definition
- class finpricing.utils.FrequencyTypes[source]#
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- ANNUAL = 1#
- SEMI_ANNUAL = 2#
- QUARTERLY = 4#
- MONTHLY = 12#
- CONTINUOUS = 99#
- class finpricing.utils.BusDayAdjustTypes[source]#
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- NONE = 1#
- FOLLOWING = 2#
- MODIFIED_FOLLOWING = 3#
- PREVIOUS = 4#
- MODIFIED_PREVIOUS = 5#
- class finpricing.utils.FrequencyTypes[source]#
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- ANNUAL = 1#
- SEMI_ANNUAL = 2#
- QUARTERLY = 4#
- MONTHLY = 12#
- CONTINUOUS = 99#
- class finpricing.utils.BusDayAdjustTypes[source]#
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- NONE = 1#
- FOLLOWING = 2#
- MODIFIED_FOLLOWING = 3#
- PREVIOUS = 4#
- MODIFIED_PREVIOUS = 5#
- class finpricing.utils.CalendarTypes[source]#
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- NONE = 0#
- WEEKEND = 1#
- UNITED_STATES = 2#
- class finpricing.utils.DayCountTypes[source]#
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- ACT_360 = 0#
- ACT_365 = 1#
- THIRTY_360 = 2#
- ACT_ACT_ISDA = 3#
- Thirty_E_360 = 4#
- Thirty_E_360_ISDA = 5#
- class finpricing.utils.CDSStubType[source]#
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- NO_STUB = 'NO_STUB'#
- class finpricing.utils.CDSEffectiveDateStyle[source]#
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- PCD = 'PCD'#
- class finpricing.utils.CDSTermStyle[source]#
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- IMM_CORPORATE = 'IMM_CORPORATE'#
- class finpricing.utils.CDSAccruedStyle[source]#
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- SNAC = 'SNAC'#
- CONVENTIONAL = 'CONVENTIONAL'#
- class finpricing.utils.CDSStyleBase(name, day_count_type, frequency_type, bus_day_adj_type, cds_term_style, cds_effective_date_style, cds_stub_length, minimal_stub_period: int, eom_adj: bool, calendar_type, accrued_style)[source]#
- class finpricing.utils.CDSStyleCorpNA[source]#
Bases:
CDSStyleBase
- class finpricing.utils.Date(year: int, month: int, day: int)[source]#
- property is_weekend: bool#
Return True if the date is a weekend, False otherwise
Monday is 0 and Sunday is 6.
- MON = 0#
- TUE = 1#
- WED = 2#
- THU = 3#
- FRI = 4#
- SAT = 5#
- SUN = 6#
- classmethod convert_from_datetime(date: datetime.date | Date) Date [source]#
Return a Date object from a datetime.date object
- classmethod convert_from_datetimes(dates: list[datetime.date | Date]) list[Date] [source]#
Return a list of Date objects from a list of datetime.date objects
- classmethod from_datetime(date: datetime.date) Date [source]#
Return a Date object from a datetime.date object
- classmethod from_tuple(date_tuple: tuple) Date [source]#
Return a Date object from a tuple of (year, month, day)
- add_interval(time_interval: TimeInterval) Date [source]#
- finpricing.utils.dict_to_obj_str(d: dict) str [source]#
Return the string representation of a dictionary
- finpricing.utils.prettyTableByColumn(d: dict, align='') str [source]#
Return the string representation of a dictionary in a pretty table format where dictionary values can be either iterables for direct use or tuples where the first element is an iterable and the second is a format string.
Args: d (dict): Dictionary with data to be displayed by the table. align (str): String with column alignments. Use ‘l’ for left, ‘r’ for right, and ‘c’ for center.
Returns: str: A string representation of the table.
- finpricing.utils.prettyTableByRow(d: dict) str [source]#
Return the string representation of a dictionary in a pretty table format
The dictionary contains the row names as keys and the list of values as values.
- class finpricing.utils.Date(year: int, month: int, day: int)[source]#
- property is_weekend: bool#
Return True if the date is a weekend, False otherwise
Monday is 0 and Sunday is 6.
- MON = 0#
- TUE = 1#
- WED = 2#
- THU = 3#
- FRI = 4#
- SAT = 5#
- SUN = 6#
- classmethod convert_from_datetime(date: datetime.date | Date) Date [source]#
Return a Date object from a datetime.date object
- classmethod convert_from_datetimes(dates: list[datetime.date | Date]) list[Date] [source]#
Return a list of Date objects from a list of datetime.date objects
- classmethod from_datetime(date: datetime.date) Date [source]#
Return a Date object from a datetime.date object
- classmethod from_tuple(date_tuple: tuple) Date [source]#
Return a Date object from a tuple of (year, month, day)
- add_interval(time_interval: TimeInterval) Date [source]#
- class finpricing.utils.CDSStubType[source]#
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- NO_STUB = 'NO_STUB'#
- class finpricing.utils.CDSTermStyle[source]#
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- IMM_CORPORATE = 'IMM_CORPORATE'#
- class finpricing.utils.Calendar(calendarType: finpricing.utils.holiday.CalendarTypes)[source]#
- is_holiday(date: finpricing.utils.date.Date) bool [source]#
- is_business_day(date: finpricing.utils.date.Date) bool [source]#
Return True if the date is a business day
Weekend or not is determined solely by the date itself. Holiday or not is determined by the calendar.
- add_business_days(date: finpricing.utils.date.Date, num_days: int) finpricing.utils.date.Date [source]#
Return a new Date object by adding num_days business days to the date
- adjust(date: finpricing.utils.date.Date, busDayAdjType: finpricing.utils.bus_day_adj.BusDayAdjustTypes) finpricing.utils.date.Date [source]#
Return a new Date object by adjusting the date according to the Business Day Convention
For details, https://jollycontrarian.com/index.php?title=Business_Day_Convention_-_ISDA_Definition
- class finpricing.utils.DateGenerator[source]#
- static generate_extended(start_date: datetime.date | finpricing.utils.date.Date, maturity_date: datetime.date | finpricing.utils.date.Date, time_interval: finpricing.utils.date.TimeInterval | str, stub_at_end: bool)[source]#
generate a list of dates from start_date to maturity_date with given time_interval
Note
if stub_at_end is True, the dates will be generated from start_date and roll forward until and after maturity_date if stub_at_end is False, the dates will be generated from maturity_date and roll backward until and before start_date
- Parameters:
start_date (Union[datetime.date, Date]) – start date
maturity_date (Union[datetime.date, Date]) – maturity date
time_interval (Union[TimeInterval, str]) – time interval
stub_at_end (bool) – whether the stub is at the end of the period
- static generate_cds(start_date, maturity_date, cds_style: finpricing.utils.cds_style.CDSStyle, stub_at_end: bool = False)[source]#
generate a list of dates from start_date to maturity_date with given cds_style
Note
Most likely, the stub is at the end of the period. In a NO_STUB case, the first date will be removed. So the first date will be after start_date.
- static generate_cds_adjust(start_date, maturity_date, cds_style: finpricing.utils.cds_style.CDSStyle, stub_at_end: bool = False)[source]#
generate accrual start dates, accrual end dates, and calendar adjusted payment dates for a cds contract
NOTE only the payment dates are adjusted!
- static generate_cds_maturity_date(market_date: finpricing.utils.date.Date | datetime.date, maturity_date: finpricing.utils.date.Date | datetime.date, term_style: str = None)[source]#
return the adjusted maturity date for a cds contract by its term style
FIXME This is not effectively implemented yet. It seems IMM CORPORATE returns the same maturity date as the input.
- static generate_cds_effective_date(market_date: finpricing.utils.date.Date | datetime.date, maturity_date: finpricing.utils.date.Date | datetime.date, cds_style: finpricing.utils.cds_style.CDSStyle | str)[source]#
generate the effective date for a cds contract when market date is in between coupon dates