ZCS#
- class rateslib.instruments.ZCS(*args, fixed_rate=NoInput.blank, leg2_float_spread=NoInput.blank, leg2_spread_compound_method=NoInput.blank, leg2_fixings=NoInput.blank, leg2_fixing_method=NoInput.blank, leg2_method_param=NoInput.blank, **kwargs)#
Bases:
BaseDerivative
Create a zero coupon swap (ZCS) composing a
ZeroFixedLeg
and aZeroFloatLeg
.- Parameters:
args (dict) – Required positional args to
BaseDerivative
.fixed_rate (float or None) – The fixed rate applied to the
ZeroFixedLeg
. If None will be set to mid-market when curves are provided.leg2_float_spread (float, optional) – The spread applied to the
FloatLeg
. Can be set to None and designated later, perhaps after a mid-market spread for all periods has been calculated.leg2_spread_compound_method (str, optional) – The method to use for adding a floating spread to compounded rates. Available options are {“none_simple”, “isda_compounding”, “isda_flat_compounding”}.
leg2_fixings (float, list, or Series optional) – If a float scalar, will be applied as the determined fixing for the first period. If a list of n fixings will be used as the fixings for the first n periods. If any sublist of length m is given, is used as the first m RFR fixings for that
FloatPeriod
. If a datetime indexedSeries
will use the fixings that are available in that object, and derive the rest from thecurve
.leg2_fixing_method (str, optional) – The method by which floating rates are determined, set by default. See notes.
leg2_method_param (int, optional) – A parameter that is used for the various
fixing_method
s. See notes.kwargs (dict) – Required keyword arguments to
BaseDerivative
.
Examples
Construct a curve to price the example.
In [1]: usd = Curve( ...: nodes={ ...: dt(2022, 1, 1): 1.0, ...: dt(2027, 1, 1): 0.85, ...: dt(2032, 1, 1): 0.70, ...: }, ...: id="usd" ...: ) ...:
Create the ZCS, and demonstrate the
rate()
,npv()
,analytic_delta()
, andIn [2]: zcs = ZCS( ...: effective=dt(2022, 1, 1), ...: termination="10Y", ...: frequency="Q", ...: calendar="nyc", ...: currency="usd", ...: fixed_rate=4.0, ...: convention="Act360", ...: notional=100e6, ...: curves=["usd"], ...: ) ...: In [3]: zcs.rate(curves=usd) Out[3]: 3.5307483757290647 In [4]: zcs.npv(curves=usd) Out[4]: -4825959.828579076 In [5]: zcs.analytic_delta(curve=usd) Out[5]: 105226.66099084073
A DataFrame of
cashflows()
.In [6]: zcs.cashflows(curves=usd) Out[6]: Type Period Ccy Acc Start Acc End Payment Convention DCF Notional DF Rate Spread Cashflow NPV FX Rate NPV Ccy Collateral leg1 0 ZeroFixedLeg None USD 2022-01-01 2032-01-01 2032-01-06 Act360 10.14 100000000.00 0.70 4.00 NaN -49744798.25 -34802851.16 1.00 -34802851.16 None leg2 0 ZeroFloatLeg None USD 2022-01-03 2032-01-02 2032-01-06 Act360 10.14 -100000000.00 0.70 4.22 0.00 42846903.68 29976891.34 1.00 29976891.34 None
For accurate sensitivity calculations;
delta()
andgamma()
, construct a curve model.In [7]: sofr_kws = dict( ...: effective=dt(2022, 1, 1), ...: frequency="A", ...: convention="Act360", ...: calendar="nyc", ...: currency="usd", ...: curves=["usd"] ...: ) ...: In [8]: instruments = [ ...: IRS(termination="5Y", **sofr_kws), ...: IRS(termination="10Y", **sofr_kws), ...: ] ...: In [9]: solver = Solver( ...: curves=[usd], ...: instruments=instruments, ...: s=[3.40, 3.60], ...: instrument_labels=["5Y", "10Y"], ...: id="sofr", ...: ) ...: SUCCESS: `func_tol` reached after 5 iterations (levenberg_marquardt), `f_val`: 2.2942031400260264e-15, `time`: 0.0121s In [10]: zcs.delta(solver=solver) Out[10]: local_ccy usd display_ccy usd type solver label instruments sofr 5Y -10155.74 10Y 112851.29 In [11]: zcs.gamma(solver=solver) Out[11]: type instruments solver sofr label 5Y 10Y local_ccy display_ccy type solver label usd usd instruments sofr 5Y 4.24 -23.45 10Y -23.45 -68.59
Attributes Summary
If set will also set the
fixed_rate
of the contained leg1.If set will also set the
float_spread
of contained leg1.If set will also set the
index_base
of the contained leg1.If set will also set the
fixed_rate
of the contained leg2.If set will also set the
float_spread
of contained leg2.If set will also set the
index_base
of the contained leg1.Methods Summary
analytic_delta
(*args, **kwargs)Return the analytic delta of a leg of the derivative object.
cashflows
([curves, solver, fx, base])Return the properties of all legs used in calculating cashflows.
cashflows_table
([curves, solver, fx, base])delta
(*args, **kwargs)Calculate the delta of the Instrument.
gamma
(*args, **kwargs)Calculate the gamma of the Instrument.
npv
([curves, solver, fx, base, local])Return the NPV of the derivative by summing legs.
rate
([curves, solver, fx, base])Return the mid-market rate of the ZCS.
Attributes Documentation
- fixed_rate#
If set will also set the
fixed_rate
of the contained leg1.Note
fixed_rate
,float_spread
,leg2_fixed_rate
andleg2_float_spread
are attributes only applicable to certainInstruments
. AttributeErrors are raised if calling or setting these is invalid.- Type:
float or None
- float_spread#
If set will also set the
float_spread
of contained leg1.- Type:
float or None
- index_base#
If set will also set the
index_base
of the contained leg1.Note
index_base
andleg2_index_base
are attributes only applicable to certainInstruments
. AttributeErrors are raised if calling or setting these is invalid.- Type:
float or None
- leg2_fixed_rate#
If set will also set the
fixed_rate
of the contained leg2.- Type:
float or None
- leg2_float_spread#
If set will also set the
float_spread
of contained leg2.- Type:
float or None
- leg2_index_base#
If set will also set the
index_base
of the contained leg1.Note
index_base
andleg2_index_base
are attributes only applicable to certainInstruments
. AttributeErrors are raised if calling or setting these is invalid.- Type:
float or None
Methods Documentation
- analytic_delta(*args, **kwargs)#
Return the analytic delta of a leg of the derivative object.
- cashflows(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank)#
Return the properties of all legs used in calculating cashflows.
- cashflows_table(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank)#
- delta(*args, **kwargs)#
Calculate the delta of the Instrument.
For arguments see
Sensitivities.delta()
.
- gamma(*args, **kwargs)#
Calculate the gamma of the Instrument.
For arguments see
Sensitivities.gamma()
.
- npv(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank, local=False)#
Return the NPV of the derivative by summing legs.
See
BaseDerivative.npv()
.
- rate(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank)#
Return the mid-market rate of the ZCS.
- Parameters:
curves (Curve, str or list of such) –
A single
Curve
or id or a list of such. A list defines the following curves in the order:solver (Solver, optional) –
The numerical
Solver
that constructsCurve
from calibrating instruments.Note
The arguments
fx
andbase
are unused by single currency derivatives rates calculations.
- Return type:
Notes
The arguments
fx
andbase
are unused by single currency derivatives rates calculations.The ‘irr’
fixed_rate
defines a cashflow by:\[-notional * ((1 + irr / f)^{f \times dcf} - 1)\]where \(f\) is associated with the compounding frequency.