ZCIS#
- class rateslib.instruments.ZCIS(*args, fixed_rate=NoInput.blank, leg2_index_base=NoInput.blank, leg2_index_fixings=NoInput.blank, leg2_index_method=NoInput.blank, leg2_index_lag=NoInput.blank, **kwargs)#
Bases:
BaseDerivative
Create a zero coupon index swap (ZCIS) composing an
ZeroFixedLeg
and aZeroIndexLeg
.- 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.index_base (float or None, optional) – The base index applied to all periods.
index_fixings (float, or Series, optional) – If a float scalar, will be applied as the index fixing for the first period. If a list of n fixings will be used as the index fixings for the first n periods. If a datetime indexed
Series
will use the fixings that are available in that object, and derive the rest from thecurve
.index_method (str) – Whether the indexing uses a daily measure for settlement or the most recently monthly data taken from the first day of month.
index_lag (int, optional) – The number of months by which the index value is lagged. Used to ensure consistency between curves and forecast values. Defined by default.
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.65, ...: }, ...: id="usd", ...: ) ...: In [2]: us_cpi = IndexCurve( ...: nodes={ ...: dt(2022, 1, 1): 1.0, ...: dt(2027, 1, 1): 0.85, ...: dt(2032, 1, 1): 0.70, ...: }, ...: id="us_cpi", ...: index_base=100, ...: index_lag=3, ...: ) ...:
Create the ZCIS, and demonstrate the
rate()
,npv()
,analytic_delta()
, andIn [3]: zcis = ZCIS( ...: effective=dt(2022, 1, 1), ...: termination="10Y", ...: frequency="A", ...: calendar="nyc", ...: currency="usd", ...: fixed_rate=2.05, ...: convention="1+", ...: notional=100e6, ...: leg2_index_base=100.0, ...: leg2_index_method="monthly", ...: leg2_index_lag=3, ...: curves=["usd", "usd", "us_cpi", "usd"], ...: ) ...: In [4]: zcis.rate(curves=[usd, usd, us_cpi, usd]) Out[4]: 3.631120991031422 In [5]: zcis.npv(curves=[usd, usd, us_cpi, usd]) Out[5]: 13231298.577116087 In [6]: zcis.analytic_delta(usd, usd) Out[6]: 78012.93808671228
A DataFrame of
cashflows()
.In [7]: zcis.cashflows(curves=[usd, usd, us_cpi, usd]) Out[7]: Type Period Ccy Acc Start Acc End Payment Convention DCF Notional DF Rate Spread Cashflow NPV FX Rate NPV Ccy Collateral Real Cashflow Index Base Index Val Index Ratio leg1 0 ZeroFixedLeg None USD 2022-01-01 2032-01-01 2032-01-02 1+ 10.00 100000000.00 0.65 2.05 None -22498308.13 -14621751.99 1.00 -14621751.99 None NaN NaN NaN NaN leg2 0 ZeroIndexLeg None USD 2022-01-01 2032-01-01 2032-01-02 1 1.00 -100000000.00 0.65 100.00 None 42857142.86 27853050.57 1.00 27853050.57 None 100000000.00 100.00 142.86 1.43
For accurate sensitivity calculations;
delta()
andgamma()
, construct a curve model.In [8]: sofr_kws = dict( ...: effective=dt(2022, 1, 1), ...: frequency="A", ...: convention="Act360", ...: calendar="nyc", ...: currency="usd", ...: curves=["usd"] ...: ) ...: In [9]: cpi_kws = dict( ...: effective=dt(2022, 1, 1), ...: frequency="A", ...: convention="1+", ...: calendar="nyc", ...: leg2_index_method="monthly", ...: currency="usd", ...: curves=["usd", "usd", "us_cpi", "usd"] ...: ) ...: In [10]: instruments = [ ....: IRS(termination="5Y", **sofr_kws), ....: IRS(termination="10Y", **sofr_kws), ....: ZCIS(termination="5Y", **cpi_kws), ....: ZCIS(termination="10Y", **cpi_kws), ....: ] ....: In [11]: solver = Solver( ....: curves=[usd, us_cpi], ....: instruments=instruments, ....: s=[3.40, 3.60, 2.2, 2.05], ....: instrument_labels=["5Y", "10Y", "5Yi", "10Yi"], ....: id="us", ....: ) ....: SUCCESS: `func_tol` reached after 6 iterations (levenberg_marquardt), `f_val`: 3.5046314313449345e-17, `time`: 0.0169s In [12]: zcis.delta(solver=solver) Out[12]: local_ccy usd display_ccy usd type solver label instruments us 5Y 0.00 10Y -0.00 5Yi -0.00 10Yi 83687.51 In [13]: zcis.gamma(solver=solver) Out[13]: type instruments solver us label 5Y 10Y 5Yi 10Yi local_ccy display_ccy type solver label usd usd instruments us 5Y -0.00 0.00 -0.00 8.10 10Y 0.00 0.00 0.00 -90.49 5Yi -0.00 0.00 0.00 -0.00 10Yi 8.10 -90.49 -0.00 73.81
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[, leg])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 object by summing legs.
rate
([curves, solver, fx, base])Return the mid-market IRR rate of the ZCIS.
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
- abstract analytic_delta(*args, leg=1, **kwargs)#
Return the analytic delta of a leg of the derivative object.
- Parameters:
args – Required positional arguments supplied to
BaseLeg.analytic_delta
.leg (int in [1, 2]) – The leg identifier of which to take the analytic delta.
kwargs – Required Keyword arguments supplied to
BaseLeg.analytic_delta()
.
- Return type:
Examples
In [14]: curve = Curve({dt(2021,1,1): 1.00, dt(2025,1,1): 0.83}, id="SONIA") In [15]: fxr = FXRates({"gbpusd": 1.25}, base="usd")
In [16]: irs = IRS( ....: effective=dt(2022, 1, 1), ....: termination="6M", ....: frequency="Q", ....: currency="gbp", ....: notional=1e9, ....: fixed_rate=5.0, ....: ) ....: In [17]: irs.analytic_delta(curve, curve) Out[17]: 47156.00216054951 In [18]: irs.analytic_delta(curve, curve, fxr) Out[18]: <Dual: 58945.002701, (fx_gbpusd), [47156.0]> In [19]: irs.analytic_delta(curve, curve, fxr, "gbp") Out[19]: 47156.00216054951
- cashflows(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank)#
Return the properties of all legs used in calculating cashflows.
- Parameters:
curves (CurveType, str or list of such, optional) –
A single
Curve
,LineCurve
or id or a list of such. A list defines the following curves in the order:solver (Solver, optional) – The numerical
Solver
that constructsCurves
from calibrating instruments.fx (float, FXRates, FXForwards, optional) – The immediate settlement FX rate that will be used to convert values into another currency. A given float is used directly. If giving a
FXRates
orFXForwards
object, converts from local currency intobase
.base (str, optional) – The base currency to convert cashflows into (3-digit code). Only used if
fx
is anFXRates
orFXForwards
object. If not given defaults tofx.base
.
- Return type:
DataFrame
Notes
If only one curve is given this is used as all four curves.
If two curves are given the forecasting curve is used as the forecasting curve on both legs and the discounting curve is used as the discounting curve for both legs.
If three curves are given the single discounting curve is used as the discounting curve for both legs.
Examples
In [1]: irs.cashflows([curve], fx=fxr) Out[1]: Type Period Ccy Acc Start Acc End Payment Convention DCF Notional DF Collateral Rate Spread Cashflow NPV FX Rate NPV Ccy leg1 0 FixedPeriod Regular GBP 2022-01-01 2022-04-01 2022-04-03 ACT360 0.25 1000000000.00 0.94 None 5.00 NaN -12500000.00 -11792277.34 1.25 -14740346.67 1 FixedPeriod Regular GBP 2022-04-01 2022-07-01 2022-07-03 ACT360 0.25 1000000000.00 0.93 None 5.00 NaN -12638888.89 -11785723.74 1.25 -14732154.68 leg2 0 FloatPeriod Regular GBP 2022-01-01 2022-04-01 2022-04-03 ACT360 0.25 -1000000000.00 0.94 None 4.62 0.00 11544335.50 10890720.47 1.25 13613400.59 1 FloatPeriod Regular GBP 2022-04-01 2022-07-01 2022-07-03 ACT360 0.25 -1000000000.00 0.93 None 4.62 0.00 11673351.69 10885363.37 1.25 13606704.21
- 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 object by summing legs.
- Parameters:
curves (Curve, LineCurve, str or list of such) –
A single
Curve
,LineCurve
or id or a list of such. A list defines the following curves in the order:solver (Solver, optional) – The numerical
Solver
that constructsCurves
from calibrating instruments.fx (float, FXRates, FXForwards, optional) – The immediate settlement FX rate that will be used to convert values into another currency. A given float is used directly. If giving a
FXRates
orFXForwards
object, converts from local currency intobase
.base (str, optional) – The base currency to convert cashflows into (3-digit code). Only used if
fx
is anFXRates
orFXForwards
object. If not given defaults tofx.base
.local (bool, optional) – If True will return a dict identifying NPV by local currencies on each leg. Useful for multi-currency derivatives and for ensuring risk sensitivities are allocated to local currencies without conversion.
- Return type:
Notes
If only one curve is given this is used as all four curves.
If two curves are given the forecasting curve is used as the forecasting curve on both legs and the discounting curve is used as the discounting curve for both legs.
If three curves are given the single discounting curve is used as the discounting curve for both legs.
Examples
In [1]: irs.npv(curve) Out[1]: -1801917.2427669652 In [2]: irs.npv([curve], fx=fxr) Out[2]: <Dual: -2252396.553459, (fx_gbpusd), [-1801917.2]> In [3]: irs.npv([curve], fx=fxr, base="gbp") Out[3]: -1801917.2427669652
- rate(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank)#
Return the mid-market IRR rate of the ZCIS.
- 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.