tensorquant.flows package
Submodules
tensorquant.flows.cashflow module
- class tensorquant.flows.cashflow.CashFlow[source]
Bases:
ABCAbstract base class representing a generic cash flow.
This class provides a blueprint for creating various cash flow types, ensuring that subclasses implement the core methods for retrieving the payment date and amount.
- abstract property amount: float
Get the future value (non-discounted) of the cash flow.
Subclasses must implement this method to specify the exact amount associated with the cash flow, not taking into account any discounting.
- Returns:
The future amount of the cash flow.
- Return type:
float
- abstract property date: date
Get the payment date of the cash flow.
Subclasses must implement this property to return the specific date on which the cash flow occurs.
- Returns:
The payment date of the cash flow.
- Return type:
datetime.date
- has_occurred(ref_date: date) bool[source]
Determine if the cash flow has occurred relative to a reference date.
This method checks if the cash flow’s payment date is on or before the provided reference date.
- Parameters:
ref_date (datetime.date) – The reference date to compare against
date. (the cash flow's payment)
- Returns:
True if the cash flow’s date is on or before the reference date, otherwise False.
- Return type:
bool
tensorquant.flows.coupon module
- class tensorquant.flows.coupon.Coupon(payment_date: date, nominal: float, daycounter: DayCounter, accrual_start_date: date, accrual_end_date: date, ref_period_start: date, ref_period_end: date)[source]
Bases:
CashFlow,ABCAbstract class representing a coupon payment.
This class inherits from CashFlow and provides a foundation for different types of coupon payments. It defines necessary attributes and methods that subclasses must implement.
- property accrual_days: int
Get the number of days in the accrual period.
Uses the DayCounter to calculate the number of days between the accrual start and end dates.
- Returns:
The number of days in the accrual period.
- Return type:
int
- property accrual_end_date: date
Get the end date of the accrual period.
- Returns:
The end date of the accrual period.
- Return type:
datetime.date
- property accrual_period: float
Get the fraction of the year that represents the accrual period.
Uses the DayCounter to calculate the year fraction between the accrual start and end dates.
- Returns:
The fraction of the year that represents the accrual period.
- Return type:
float
- property accrual_start_date: date
Get the start date of the accrual period.
- Returns:
The start date of the accrual period.
- Return type:
datetime.date
- abstract accrued_amount() float[source]
Get the accrued amount of the coupon up to the current date.
Subclasses must implement this property to calculate the accrued interest for the coupon.
- Returns:
The accrued amount of the coupon.
- Return type:
float
- property accrued_days: int
Get the number of days that have accrued up to the specified date.
Uses the DayCounter to calculate the number of days between the accrual start date and the minimum of the specified date and the accrual end date.
- Parameters:
d (datetime.date) – The date up to which to calculate the accrued days.
- Returns:
The number of days that have accrued up to the specified date.
- Return type:
int
- property accrued_period: float
Get the fraction of the year that has accrued up to the specified date.
Uses the DayCounter to calculate the year fraction between the accrual start date and the minimum of the specified date and the accrual end date.
- Parameters:
d (datetime.date) – The date up to which to calculate the accrued period.
- Returns:
The fraction of the year that has accrued up to the specified date.
- Return type:
float
- property date: date
Get the payment date of the coupon.
- Returns:
The payment date of the coupon.
- Return type:
datetime.date
- property daycounter: DayCounter
Get the day counter convention used by the coupon.
- Returns:
The day counter convention used for calculating accrued interest.
- Return type:
- property nominal: float
Get the nominal (face value) amount of the coupon.
- Returns:
The nominal amount of the coupon.
- Return type:
float
- abstract property rate: float
Get the interest rate associated with the coupon.
Subclasses must implement this method to return the specific interest rate for the coupon.
- Returns:
The interest rate of the coupon.
- Return type:
float
- property ref_period_end: date
Get the end date of the reference period.
- Returns:
The end date of the reference period.
- Return type:
datetime.date
- property ref_period_start: date
Get the start date of the reference period.
- Returns:
The start date of the reference period.
- Return type:
datetime.date
tensorquant.flows.fixedcoupon module
- class tensorquant.flows.fixedcoupon.FixedCoupon(payment_date: date, nominal: float, accrual_start_date: date, accrual_end_date: date, ref_period_start: date, ref_period_end: date, r: float, daycounter: DayCounter)[source]
Bases:
CouponRepresents a fixed-rate coupon.
This class is a concrete implementation of the Coupon class for fixed-rate coupons, with methods to calculate the coupon amount, rate, and accrued amount.
- property accrual_period
Returns the fraction of the year representing the accrual period.
Uses the DayCounter to calculate the year fraction between the accrual start and end dates.
- Returns:
The fraction of the year that represents the accrual period.
- Return type:
float
- accrued_amount(d: date)[source]
Calculates the accrued coupon amount up to the given date.
- Parameters:
d (datetime.date) – The date up to which the accrued amount is calculated.
- Returns:
The accrued amount up to the specified date. If the date is before the accrual start date or after the payment date, returns 0.
- Return type:
float
- property amount: float
Returns the total coupon amount.
The amount is calculated as the nominal value multiplied by the compounded factor of the interest rate over the accrual period.
- Returns:
The total (not discounted) coupon payment amount.
- Return type:
float
- property day_counter: DayCounter
Returns the day count convention used for the coupon.
- Returns:
The day count convention for accrued interest calculation.
- Return type:
- display() DataFrame[source]
Displays a summary of the coupon details in a pandas DataFrame format.
- Returns:
A DataFrame containing the coupon’s reference period, payment date, nominal value, accrual period, day count convention, interest rate, and the coupon amount.
- Return type:
pandas.DataFrame
- property rate: InterestRate
Returns the fixed interest rate of the coupon.
- Returns:
The fixed interest rate of the coupon.
- Return type:
- class tensorquant.flows.fixedcoupon.FixedRateLeg(payment_dates: list[date], period_start_dates: list[date], period_end_dates: list[date], notionals: list[float], coupon_rates: list[float], daycounter: DayCounter, compounding: CompoundingType = CompoundingType.Simple, frequency: Frequency = Frequency.Annual)[source]
Bases:
objectRepresents a leg of fixed-rate coupon payments.
This class models a series of fixed-rate coupon payments across multiple periods. It constructs a sequence of FixedCoupon objects with specified attributes.
- property coupon_rates: list[InterestRate]
Returns a list of InterestRate objects corresponding to each coupon rate.
Each rate is associated with the day count convention, compounding, and frequency.
- Returns:
A list of InterestRate objects for the coupon rates.
- Return type:
list[InterestRate]
- display_flows() DataFrame[source]
Displays a summary of the cash flows for the fixed-rate leg.
This method concatenates the display data for each FixedCoupon in the leg into a pandas DataFrame.
- Returns:
A DataFrame summarizing the cash flows for the entire leg.
- Return type:
pandas.DataFrame
- property price: float
Get the price associated with the Leg.
- Returns:
The price of the Leg.
- Return type:
float
tensorquant.flows.floatingcoupon module
- class tensorquant.flows.floatingcoupon.FloatingCoupon(payment_date: date, nominal: float, accrual_start_date: date, accrual_end_date: date, index: IborIndex, gearing: float, spread: float, ref_period_start: date, ref_period_end: date, daycounter: DayCounter, is_in_arrears: bool = False, fixing_days: int | None = None)[source]
Bases:
CouponA concrete implementation of the Coupon class representing a floating-rate coupon.
This class models a coupon with a floating interest rate, which is typically linked to an index (e.g., LIBOR). The floating rate is adjusted by a spread and may include gearing, and it can account for whether the rate is set in advance or in arrears.
- property accrual_period: float
Returns the fraction of the year that represents the accrual period.
Uses the DayCounter to calculate the year fraction between the accrual start and end dates.
Returns:
- float
The fraction of the year that represents the accrual period.
- accrued_amount(d: date) float[source]
Calculates and returns the accrued amount of the floating coupon up to the specified date.
The accrued amount is calculated as the nominal value multiplied by the compound factor of the rate over the period from the accrual start date to the minimum of the given date and the accrual end date.
Parameters:
- d: date
The date up to which the accrued amount is calculated.
Returns:
- float
The accrued amount up to the specified date. Returns 0 if the date is outside the accrual period.
- property amount: float
Returns the total amount of the floating coupon.
The amount is pre-calculated and stored in the _amount attribute.
Returns:
- float
The total amount of the floating coupon payment.
- property day_counter: DayCounter
Returns the day count convention used by the coupon.
Returns:
- DayCounter
The day count convention used for calculating accrued interest.
- display() DataFrame[source]
Displays a summary of the floating coupon’s details in a DataFrame format.
The DataFrame includes the start and end of the reference period, payment date, nominal amount, fixing date, fixing days, index, accrual period, arrears status, gearing, spread, and day count convention.
Returns:
- pandas.DataFrame
A DataFrame summarizing the floating coupon’s details.
- property fixing_date: date
Returns the fixing date for the floating rate.
If the rate is in arrears, the fixing date is based on the accrual end date; otherwise, it is based on the accrual start date.
Returns:
- date
The date on which the rate is fixed.
- property fixing_days: int
Returns the number of days before the fixing date.
If fixing days were not provided during initialization, this property will return the default fixing days of the index. If the index is not provided, it defaults to 0.
Returns:
- int
The number of days before the fixing date.
- property index: IborIndex
Returns the index to which the floating rate is tied.
Returns:
- IborIndex
The index associated with the floating rate.
- class tensorquant.flows.floatingcoupon.FloatingRateLeg(payment_dates: list[date], period_start_dates: list[date], period_end_dates: list[date], notionals: list[float], gearings: list[float], spreads: list[float], index: IborIndex, daycounter: DayCounter, is_in_arrears: bool = False)[source]
Bases:
objectA class representing a leg of floating-rate coupon payments.
This class models a series of floating-rate coupon payments over multiple periods, constructing a sequence of FloatingCoupon objects based on the specified payment dates, notionals, gearings, spreads, and other parameters.
- display_flows() DataFrame[source]
Displays a summary of the cash flows for the entire floating-rate leg in a DataFrame format.
This method concatenates the display data of each FloatingCoupon in the leg into a single DataFrame.
Returns:
- pandas.DataFrame
A DataFrame summarizing the cash flows of the floating-rate leg.
- property price: float
Get the price associated with the Leg.
- Returns:
The price of the Leg.
- Return type:
float