tensorquant.index package

Submodules

tensorquant.index.curverateindex module

class tensorquant.index.curverateindex.IborIndex(fixing_calendar: Calendar, tenor: int, time_unit: TimeUnit, currency: Currency, fixing_days: int | None = None, time_series: dict | None = None)[source]

Bases: Index

Represents an Interbank Offered Rate (IBOR) index.

This class models an IBOR index, which reflects the interest rates at which banks lend to each other in the interbank market. The class extends the Index class and includes additional attributes specific to IBOR indices, such as tenor and currency.

property daycounter: DayCounter

Returns the day count convention used for the IBOR index.

Returns:

The day count convention for calculating interest accruals (e.g., Actual/360).

Return type:

DayCounter

fixing_date(value_date: date) date[source]

Calculates the fixing date based on the value date and the number of fixing days.

Parameters:

value_date (datetime.date) – The value date to calculate the fixing date from.

Returns:

The calculated fixing date.

Return type:

datetime.date

property fixing_days: int

Returns the number of fixing days for the IBOR index.

If the number of fixing days is not set, returns 0.

Returns:

The number of fixing days or 0 if not set.

Return type:

int

fixing_maturity(fixing_date: date) date[source]

Calculates the maturity date for the IBOR index based on the fixing date.

The maturity date is determined by advancing the fixing date by the tenor according to the calendar and business day conventions.

Parameters:

fixing_date (datetime.date) – The fixing date of the IBOR rate.

Returns:

The calculated maturity date.

Return type:

datetime.date

class tensorquant.index.curverateindex.OvernightIndex(fixing_calendar: Calendar, currency: Currency | None = None, fixing_days: int | None = None, time_series: dict | None = None)[source]

Bases: Index

Represents an Overnight index, typically used for short-term interest rates.

This class inherits from the abstract Index class and models an overnight index, commonly used for financial instruments with very short tenors, such as overnight lending rates.

fixing_date(value_date: date) date[source]

Calculates the fixing date based on the value date and the number of fixing days.

Parameters:

value_date (datetime.date) – The value date to calculate the fixing date from.

Returns:

The calculated fixing date.

Return type:

datetime.date

property fixing_days: int

Gets the number of fixing days for the index.

Returns:

int: The number of fixing days if set; otherwise, 0.

fixing_maturity(fixing_date: date) date[source]

Calculates the maturity date for an overnight index based on the fixing date.

The maturity date is typically one business day after the fixing date.

Parameters:

fixing_date (datetime.date) – The date of the fixing.

Returns:

The calculated maturity date.

Return type:

datetime.date

tensorquant.index.index module

class tensorquant.index.index.Index(name: str, fixing_calendar: Calendar, fixing_time_series: dict | None = None)[source]

Bases: ABC

An abstract base class representing a financial index.

This class defines a generic framework for financial indices, providing core attributes such as the index name, fixing calendar, and time series data. Specific indices (e.g., overnight or IBOR indices) should inherit from this class and implement additional logic as required.

add_fixing(fixing_date: date, value: float) None[source]

Adds a fixing for a specific date to the fixing time series.

Parameters:
  • fixing_date (datetime.date) – The date of the fixing.

  • value (float) – The fixing value for the given date.

fixing(fixing_date: date) float[source]

Retrieves the fixing value for a specific date, ensuring it is not a future date.

Parameters:

fixing_date (datetime.date) – The date for which the fixing is requested.

Returns:

The fixing value for the given date.

Return type:

float

Raises:

ValueError – If the fixing date is invalid, missing, or in the future.

property fixing_calendar: Calendar

Gets the fixing calendar for the index.

Returns:

The calendar used to determine valid fixing dates.

Return type:

Calendar

property fixing_time_series: dict

Gets the fixing time series data.

Returns:

A dictionary containing the time series of fixings.

Return type:

dict

is_valid_fixing_date(fixing_date: date) bool[source]

Checks whether the given date is a valid fixing date based on the index’s calendar.

Parameters:

fixing_date (datetime.date) – The date to check.

Returns:

True if the date is a valid fixing date, False otherwise.

Return type:

bool

Note

This method relies on the calendar’s business day determination logic.

property name: str

Gets the name of the index.

Returns:

The name of the index.

Return type:

str

past_fixing(fixing_date: date) float[source]

Retrieves the past fixing value for a specific date.

Parameters:

fixing_date (datetime.date) – The date for which the past fixing is requested.

Returns:

The fixing value for the given date.

Return type:

float

Raises:

ValueError – If the fixing date is not valid or if the fixing is missing for the given date.

tensorquant.index.inflationindex module

class tensorquant.index.inflationindex.InflationIndex(name: str, tenor: int, time_unit: TimeUnit, fixing_calendar: Calendar, frequency: Frequency = Frequency.Monthly, fixing_days: int = 0, time_series: dict | None = None, revised: bool = False)[source]

Bases: Index

Represents an Inflation index.

name

The name of the index.

Type:

str

observation_lag

The observation lag linked to the index.

Type:

int

observation_lag_period

The time unit associated with the observation lag.

Type:

TimeUnit

fixing_calendar

The calendar used for determining fixing dates.

Type:

Calendar

fixing_days

The number of days for fixing. Defaults to 0.

Type:

int, optional

time_series

A dictionary containing time series data. Defaults to None.

Type:

dict, optional

revised

Indicates whether the index is revised.

Type:

bool

frequency

The frequency at which the index is observed. Defaults to Monthly.

Type:

Frequency

Note

Inherits from Index abstract class.

fixing_date(value_date: date) date[source]

Calculate the fixing date for the given value date.

Parameters:

value_date (datetime.date) – The date for which the fixing date is required.

Returns:

The fixing date, calculated by advancing the value date backwards by the number of fixing days, based on the business day convention.

Return type:

datetime.date

property fixing_days: int

Get the number of fixing days for the index.

Returns:

The number of fixing days if set, otherwise 0.

Return type:

int

fixing_maturity(fixing_date: date) date[source]

Calculate the fixing maturity date based on the fixing date and index conventions.

Parameters:

fixing_date (datetime.date) – The fixing date.

Returns:

The maturity date for the fixing helper, calculated by advancing the fixing date by the tenor and time unit, based on the business day convention.

Return type:

datetime.date

Module contents