InterestRateSwap#
-
class sigtech.framework.instruments.ir_otc.InterestRateSwap
Baseclasses:
InterestRateSwapBase
Implements a receiver (receives fixed, pays floating) interest rate swap where its P&L excluding cashflows is calculated from a given time series. Strike will be recorded as an entry point on the time series + transaction cost assumptions (unless specified explicitly). The name will be different depending on whether the swap will start on the next IMM contract delivery date.
The history of the swap is computed to the earliest of the pricing day and swap maturity, unless
value_post_start
is set to False, in which case the swap will only have time series from entry date until start date.If floating leg requires a spread on top of the index, it can be added as a
spread
parameters (in absolute terms, e.g. if a floating leg pays LIBOR+20bp, the 20bp should be input asspread=0.002
).Example object creation:
ir_swap = sig.InterestRateSwap( currency='USD', trade_date=dtm.date(2017, 1, 3), start_date=dtm.date(2017, 4, 14), tenor='5Y', )
This will create a 5Y USD swap, that started 3-Jan-2017, matures 3-Jan-2022, receives (fixed) fair swap rate as determined on the start date, and uses USD swap defaults - semi-annual 30/360 fixed leg vs. quarterly Act/360 (3M USD LIBOR) floating leg.
ir_swap_imm = sig.InterestRateSwap( currency='GBP', trade_date=dtm.date(2015, 4, 15), start_date=dtm.date(2015, 6, 17), fixed_rate=0.07, tenor='10Y', value_post_start=False, )
This will create an IMM (since start date is an IMM date) forward-starting 10Y GBP swap receiving 7% fixed rate (semi-annual, ACT/365), that should be traded out prior to the start date, as we don’t generate the time series for it after the start.
ir_swap = sig.InterestRateSwap( currency='EUR', trade_date=dtm.date(2017, 4, 14), start_date=dtm.date(2017, 1, 5), tenor=dtm.date(2022, 7, 5), fixed_rate=0.05, )
This will create a 5.5Y EUR swap, that started 5-Jan-2017, matures 5-Jul-2022, and receives a 5% (annual, 30/360) fixed rate.
If default swap parameters need to be changed, it can be done via the overrides dictionary as follows:
ir_swap = sig.InterestRateSwap( currency='EUR', trade_date=dtm.date(2017, 4, 14), start_date=dtm.date(2017, 7, 5), tenor=dtm.date(2022, 7, 5), fixed_rate=0.05, overrides={ 'fixed_frequency': 'S', 'discount_curve': 'EUR.F6M CURVE', 'float_day_count': 'ACT/365F' } )
This will create a 5Y EUR swap, receiving semi-annual fixed coupon, ACT365 floating leg day count, and using EUR.F6M curve for discounting its cashflows (unlike standard 5Y EUR swap that would receive annual fixed coupon, pay floating with ACT360 daycount, and would use the default EUR.D curve for discounting).
- Hereunder are some supported values for various parameters:
fixed_frequencies
: A - annual, S - semiannual, Q - quaterlyfloating_frequencies
: Tenor like string usually 3M or 6M.day_count
: ACT/365, ACT/360, ACT/365F, 30/360
- Forecast and discount curve format are the following:
forecast_curve
: CCY & ‘.F’ & tenor & ‘ CURVE’discount_curve
: CCY & ‘.d CURVE’
- For supported currencies and fixes indices:
See also
sigtech.framework.instruments.constants.SWAP_FIXES_INDICES
-
property fixed_day_count: str
Fixed day count.
-
fixed_rate: Optional[float]
-
property float_day_count: str
Floating day count.
-
property maturity
Maturity date.
-
property mx_generator_name
MX name format.
-
overrides: Optional[dict]
-
spread: Optional[float]
-
start_date: Optional[date]
-
tenor: Union[date, str]
-
trade_date: date
-
value_post_start: Optional[bool]
-
carry_roll_down(d: date, dates: Union[str, date, list[Union[str, datetime.date]]], data_point: DataPoint = None)
Compute carry and roll-down of swap by moving the valuation date forward to the requested dates, keeping discount and forecasting curves constant, i.e. discount_factor(from_original_date, for_x_number_of_days) equals discount_factor(from_the_forward_date, for_x_number_of_days), and assuming that all the forward required IBOR fixings are equal to the valuation date (d) implied fixing.
- Parameters:
d – Valuation date.
dates – String/date or a list of strings/dates for which the carry/roll-down is needed.
data_point – Data point for the original curves.
- Returns:
DataFrame of 4 columns -
carry
- cumulative cashflows fromd
to date,roll_down
- change in swap PV, and the same numbers scaled by swap PV01.
-
fair_rate(d=None, mode: str = 'mid', transaction_type: Optional[str] = None, start_date=None, overrides: Optional[dict] = None, data_point: DataPoint = None, bid_ask_to_mid_spread_override: Optional[dict] = None, **kwargs) float
Calculate the fair swap rate for a given tenor on a given date.
If no
start_date
is passed as an input, swap is assumed to start on the next IMM date, that is at least one LIBOR fixing lag apart fromd
.- Parameters:
d – Reference date to calculate fair swap rate (optional, defaults to instrument’s
trade_date
).mode – Quote to return, defaults to
'mid'
but can be'bid'
or'ask'
(optional).transaction_type – Type of transaction to assume, defaults to outright but can be set to roll (optional).
start_date – Start date of swap to assume (optional).
overrides – Swap settings overrides to provide, if any. See class docstring for examples (optional).
data_point – Data point of the underlying curves (optional).
bid_ask_to_mid_spread_override – Mid to bid/ask to use for each transaction type (optional).
- Returns:
Fair swap rate given the inputs.
-
classmethod fair_swap_rate(env: ConfiguredEnvironment, currency: str, tenor: str, d, mode: str = 'mid', transaction_type: Optional[str] = None, start_date=None, overrides: Optional[dict] = None, is_imm: bool = False, data_point: DataPoint = None, bid_ask_to_mid_spread_override: Optional[dict] = None) float deprecated
Calculate the fair swap rate for a given tenor on a given date. Deprecated, please use fair_rate instead.
If no
start_date
is passed as an input, swap is assumed to start on d + a lag depending on the currency.
-
fixing_date(start_date)
Index fixing date for the coupon starting at start_date
-
static get_calendar(currency, env: ConfiguredEnvironment)
Calendar holidays.
- Parameters:
currency – Currency.
env – Configured Environment.
- Returns:
Calendar holidays.
-
static maturity_from_tenor(env: ConfiguredEnvironment, start_date, tenor, currency, bdc='NONE_RULE')
Compute maturity date from tenor.
- Parameters:
env – Configured environment.
start_date – Start date.
tenor – Tenor.
currency – Currency.
bdc – Business day convention, e.g.
'FOLLOWING'
,'MOD_FOL'
,'PRECEDE'
.
- Returns:
Maturity date.
-
physical_cashflow(d: date)
Return a cash flow for a given date.
- Parameters:
d – Reference date.
- Returns:
Cash flow.
-
risk_ladder(d: datetime, shift_bps: float = 1.0, curves: str = 'forecasting', field: str = 'NPV', interpolation_type: str = 'CS', notional: float = 1.0) DataFrame
Return forward and zero rate shift risk ladder for specified field. Output is change in value for this field.
- Parameters:
d – Reference date to return info for.
shift_bps – Fwd and zero rate shift amount in bps (optional), 1bps used as default.
curves – Which curve to shift (optional).
'discounting'
or'forecasting'
or'both'
,'forecasting'
used as default.field – Field to calculate risk ladder for (optional).
'NPV'
or'PV01'
,'NPV'
used as default.notional – Notional (optional).
interpolation_type – Interpolation type (optional).
'FF'
,'MCF'
,'FFMCF'
or'CS'
,'CS'
used as default
- Returns:
DataFrame risk ladder for field input.
-
static schedule_stub(currency, env: ConfiguredEnvironment, group_name=None)
Schedule stub for all IR swaps.
- Parameters:
currency – Input currency.
env – Configured environment.
group_name – Group name (optional).
- Returns:
Schedule stub.
-
static spot_date(env: ConfiguredEnvironment, asof_date, currency)
Standard swap start date if traded on asof_date.
-
swap_details(d: datetime, notional: float = 1.0, as_df: bool = True) Union[dict, DataFrame]
Return swap info.
- Parameters:
d – Reference date to return info for.
notional – Notional (optional).
as_df – Return swap info as DataFrame (optional).
- Returns:
Dictionary or DataFrame of swap info.
-
static swap_info_from_currency(env: ConfiguredEnvironment, start_date, tenor: str, currency: str, rate: float = 0.0001, spread: float = 0, overrides: Optional[dict] = None)
Return standard swap info summary, for quant bridge instrument creation.
- Parameters:
env – Environment to use.
start_date – Start date to assume for the swap.
tenor – Tenor to assume for the swap.
currency – Currency to assume for the swap.
rate – Rate to assume for the swap. Is often not needed.
spread – Floating rate spread. Most of the time it is 0 and not needed.
overrides – Any overrides to pass into the method.
- Returns:
Summary of standard swap info based on inputs.
-
swap_rate_shift_details(d: datetime, shift_bps: float = 1.0, curves: str = 'forecasting', tenor: str = 'tenors', notional: float = 1.0) DataFrame
Return swap rate shift scenario analysis info.
- Parameters:
d – Reference date to return info for.
shift_bps – Swap rate shift amount in bps (optional), 1bps used as default.
curves – Which curve to shift (optional).
'discounting'
or'forecasting'
or'both'
,'forecasting'
used as default.tenor – Swap rate tenor to shift (optional), e.g.
'1Y'
,'5Y'
or'tenors'
to shift all available swap rate tenors,'tenors'
used as default.notional – Notional (optional).
- Returns:
DataFrame of scenario analysis info.
-
static swap_trading_spread(currency: str, tenor: str, d: date, transaction_type: str = 'outright') float
Get pre-defined bid/ask-mid running spread, depending on currency and tenor.
- Parameters:
currency – Currency to fetch.
tenor – Tenor to fetch.
d – Reference date to fetch spread for.
transaction_type – Transaction type (Optional, defaults to
'outright'
)
- Returns:
-
validate()
Validation procedure for this instrument.