tensorquant.instruments package

Submodules

tensorquant.instruments.capfloor module

class tensorquant.instruments.capfloor.Cap(leg: FloatingRateLeg, strike: float)[source]

Bases: IrOption

class tensorquant.instruments.capfloor.Collar(leg: FloatingRateLeg, strike: float)[source]

Bases: IrOption

class tensorquant.instruments.capfloor.Floor(leg: FloatingRateLeg, strike: float)[source]

Bases: IrOption

class tensorquant.instruments.capfloor.IrOption(leg: FloatingRateLeg, strike: float)[source]

Bases: Product

property atm_rate
property implied_volatility

Black implied vol

property is_expired
property maturity_date
property start_date

Get the start date of the product.

Returns:

The start date.

Return type:

datetime.date

tensorquant.instruments.deposit module

class tensorquant.instruments.deposit.Deposit(ccy: Currency, rate: float, trade_date: date, start_date: date, end_date: date, notional: int | float, day_count_convention: DayCounterConvention)[source]

Bases: Product

Represents a deposit financial product.

ccy

The currency of the deposit.

Type:

Currency

rate

The interest rate for the deposit.

Type:

float

trade_date

The trade date of the deposit.

Type:

datetime.date

start_date

The start date of the deposit.

Type:

datetime.date

end_date

The end date or maturity date of the deposit.

Type:

datetime.date

notional

The notional amount of the deposit.

Type:

float or int

day_counter

Day count convention used to calculate day fractions.

Type:

DayCounter

property day_count_convention: DayCounterConvention

Get the day count convention used for interest calculations.

Returns:

The day count convention used for this deposit.

Return type:

DayCounterConvention

property day_counter: DayCounter

Get the day count convention used for interest calculations.

Returns:

The day count convention object.

Return type:

DayCounter

property notional: float

Get the notional amount of the deposit.

Returns:

The notional amount.

Return type:

float

property rate: float
property trade_date: date

Get the trade date of the deposit.

Returns:

The trade date.

Return type:

datetime.date

tensorquant.instruments.forward module

class tensorquant.instruments.forward.Fra(ccy: Currency, start_date: date, end_date: date, notional: float, fixed_rate: float, day_count_convention: DayCounterConvention, index: IborIndex, side: SwapType = SwapType.Payer)[source]

Bases: Product

Represents a Forward Rate Agreement (FRA).

A Forward Rate Agreement (FRA) is a financial contract that allows parties to lock in an interest rate for a future period. This class models the FRA including its notional amount, start and end dates, the day count convention used for interest calculations, and the associated Ibor index.

ccy

The currency of the FRA.

Type:

Currency

start_date

The start date of the FRA.

Type:

date

end_date

The end date of the FRA.

Type:

date

notional

The notional amount of the FRA.

Type:

float

quote

The FRA quote or rate.

Type:

float

day_count_convention

The day count convention used for interest calculations.

Type:

DayCounterConvention

index

The Ibor index used for the FRA.

Type:

IborIndex

property day_count_convention: DayCounterConvention

Get the day count convention used for interest calculations.

Returns:

The day count convention.

Return type:

DayCounterConvention

property day_counter: DayCounter

Get the day count convention object used for interest calculations.

Returns:

The day count convention object.

Return type:

DayCounter

property fixed_rate: float
property fixing_date

Get the fixing date based on the start date and index.

Returns:

The fixing date.

Return type:

date

property notional: float

Get the notional amount of the FRA.

Returns:

The notional amount.

Return type:

float

property side

tensorquant.instruments.helpers module

class tensorquant.instruments.helpers.DepositGenerator(ccy: Currency, start_delay: int, roll_convention: BusinessDayConvention, day_count_convention: DayCounterConvention, notional: float, calendar: Calendar)[source]

Bases: ProductGenerator

Generator for creating deposit products.

start_delay

Number of days to delay the start of the deposit.

Type:

int

roll_convention

Business day convention for rolling.

Type:

BusinessDayConvention

day_count_convention

Day count convention for the deposit.

Type:

DayCounterConvention

calendar

Calendar used for date adjustments.

Type:

Calendar

build(trade_date: date, quote: float, term: str)[source]

Builds a deposit product based on the provided trade date, quote, and term.

Parameters:
  • trade_date (datetime.date) – The trade date for the deposit.

  • quote (float) – The quote or rate for the deposit.

  • term (str) – The term or duration of the deposit.

Returns:

The constructed deposit product.

Return type:

Deposit

class tensorquant.instruments.helpers.FraGenerator(ccy: str, start_delay: int, fixing_days: int, index_term: str, roll_convention: BusinessDayConvention, notional: float, day_count_convention: DayCounterConvention, calendar: Calendar, index: Index)[source]

Bases: ProductGenerator

Generator for creating Forward Rate Agreement (FRA) products.

start_delay

Number of days to delay the start of the FRA.

Type:

int

fixing_days

Number of days for fixing.

Type:

int

index_term

Term for the index.

Type:

str

roll_convention

Business day convention for rolling.

Type:

BusinessDayConvention

day_count_convention

Day count convention for the FRA.

Type:

DayCounterConvention

calendar

Calendar used for date adjustments.

Type:

Calendar

index

Index used for the FRA.

Type:

Index

build(trade_date: date, quote: float, term: str)[source]

Builds a FRA product based on the provided trade date, quote, and term.

Parameters:
  • trade_date (datetime.date) – The trade date for the FRA.

  • quote (float) – The quote or rate for the FRA.

  • term (str) – The term or duration of the FRA.

Returns:

The constructed FRA product.

Return type:

Fra

class tensorquant.instruments.helpers.OisGenerator(ccy: str, start_delay: int, period_fix: str, period_flt: str, roll_convention: BusinessDayConvention, notional: float, day_count_convention_fix: DayCounterConvention, day_count_convention_flt: DayCounterConvention, calendar: Calendar, index: Index)[source]

Bases: ProductGenerator

Generator for creating Overnight Index Swap (OIS) products.

start_delay

Number of days to delay the start of the OIS.

Type:

int

fixing_days

Number of days for fixing.

Type:

int

period_fix

Fixing period.

Type:

str

period_flt

Floating period.

Type:

str

roll_convention

Business day convention for rolling.

Type:

BusinessDayConvention

day_count_convention_fix

Day count convention for the fixed leg.

Type:

DayCounterConvention

day_count_convention_flt

Day count convention for the floating leg.

Type:

DayCounterConvention

calendar

Calendar used for date adjustments.

Type:

Calendar

index

Index used for the OIS.

Type:

Index

build(trade_date: date, quote: float, term: str)[source]

Builds an OIS product based on the provided trade date, quote, and term.

Parameters:
  • trade_date (datetime.date) – The trade date for the OIS.

  • quote (float) – The quote or rate for the OIS.

  • term (str) – The term or duration of the OIS.

Returns:

The constructed OIS product.

Return type:

Ois

class tensorquant.instruments.helpers.ProductGenerator(name: str, ccy: str, notional: float)[source]

Bases: ABC

Abstract base class for generating financial products.

name

The name or type of the product generator.

Type:

str

ccy

The currency of the product.

Type:

str

notional

The notional amount for the product.

Type:

float

abstract build(trade_date, quote: float, term: str)[source]

Abstract method to build a financial product.

Parameters:
  • trade_date (datetime.date) – The trade date for the product.

  • quote (float) – The quote or rate for the product.

  • term (str) – The term or duration of the product.

Returns:

The constructed financial product.

Return type:

Product

class tensorquant.instruments.helpers.SwapGenerator(ccy: Currency, start_delay: int, period_fix: str, period_flt: str, roll_convention: BusinessDayConvention, notional: float, day_count_convention_fix: DayCounterConvention, day_count_convention_flt: DayCounterConvention, calendar: Calendar, index: Index)[source]

Bases: ProductGenerator

Generator for creating Swap products.

start_delay

Number of days to delay the start of the swap.

Type:

int

period_fix

Fixing period.

Type:

str

period_flt

Floating period.

Type:

str

roll_convention

Business day convention for rolling.

Type:

BusinessDayConvention

day_count_convention_fix

Day count convention for the fixed leg.

Type:

DayCounterConvention

day_count_convention_flt

Day count convention for the floating leg.

Type:

DayCounterConvention

calendar

Calendar used for date adjustments.

Type:

Calendar

index

Index used for the swap.

Type:

Index

build(trade_date: date, quote: float, term: str)[source]

Builds a swap product based on the provided trade date, quote, and term.

Parameters:
  • trade_date (datetime.date) – The trade date for the swap.

  • quote (float) – The quote or rate for the swap.

  • term (str) – The term or duration of the swap.

Returns:

The constructed swap product.

Return type:

Swap

tensorquant.instruments.ois module

class tensorquant.instruments.ois.Ois(ccy: Currency, start_date: date, end_date: date, start_dates_fix: list[date], end_dates_fix: list[date], pay_dates_fix: list[date], start_dates_flt: list[date], end_dates_flt: list[date], pay_dates_flt: list[date], fixed_rate: float, notional: float, day_counter_fix: DayCounter, day_counter_flt: DayCounter, index: OvernightIndex, swap_type: SwapType = SwapType.Payer)[source]

Bases: Product

property discount_curve: str
property estimation_curve: str
property fixed_leg: FixedRateLeg

Get the fixed leg of the OIS.

Returns:

The fixed leg of the swap.

Return type:

FixedRateLeg

property fixed_rate
property floating_leg: FloatingRateLeg

Get the floating leg of the OIS.

Returns:

The floating leg of the swap.

Return type:

FloatingRateLeg

property notional: float

Get the notional amount for the swap.

Returns:

The notional amount.

Return type:

float

property swap_type: SwapType

Get the swap type, either Payer or Receiver.

Returns:

The type of the swap.

Return type:

SwapType

tensorquant.instruments.option module

class tensorquant.instruments.option.Option(ccy: Currency, start_date: date, end_date: date, option_type: OptionType, strike: float | list[float], exercise_type: ExerciseType, underlying: str = 'DEFAULT')[source]

Bases: Product, ABC

property exercise_type
property forward
property implied_volatility: Variable
property option_type
property strike
property underlying
class tensorquant.instruments.option.VanillaOption(ccy: Currency, start_date: date, end_date: date, option_type, strike, underlying: str = 'DEFAULT', exercise_type: ExerciseType = ExerciseType.European)[source]

Bases: Option

tensorquant.instruments.product module

class tensorquant.instruments.product.Product(ccy: Currency, start_date: date, end_date: date)[source]

Bases: ABC

Abstract base class for financial products.

ccy

The currency of the product.

Type:

Currency

start_date

The start date of the product.

Type:

datetime.date

end_date

The end date or maturity date of the product.

Type:

datetime.date

price

The price or interest rate associated with the product.

Type:

float

property ccy: Currency

Get the currency of the product.

Returns:

The currency in which the product is denominated.

Return type:

Currency

property end_date: date

Get the end or maturity date of the product.

Returns:

The end date.

Return type:

datetime.date

property price: float

Get the price associated with the product.

Returns:

The price of the product.

Return type:

float

property start_date: date

Get the start date of the product.

Returns:

The start date.

Return type:

datetime.date

tensorquant.instruments.swap module

class tensorquant.instruments.swap.Swap(ccy: Currency, start_date: date, end_date: date, start_dates_fix: list[date], end_dates_fix: list[date], pay_dates_fix: list[date], start_dates_flt: list[date], end_dates_flt: list[date], pay_dates_flt: list[date], fixed_rate: float, notional: float, day_counter_fix: DayCounter, day_counter_flt: DayCounter, index: Index, swap_type: SwapType = SwapType.Payer)[source]

Bases: Product

property discount_curve: str
property estimation_curve: str
property fixed_leg: FixedRateLeg

Get the fixed leg of the swap.

Returns:

The fixed leg of the swap.

Return type:

FixedRateLeg

property fixed_rate
property floating_leg: FloatingRateLeg

Get the floating leg of the swap.

Returns:

The floating leg of the swap.

Return type:

FloatingRateLeg

property notional: float

Get the notional principal amount of the swap.

Returns:

The notional principal amount.

Return type:

float

property swap_type: SwapType

Get the type of swap (Payer or Receiver).

Returns:

The type of the swap.

Return type:

SwapType

Module contents