Portfolio#
- class rateslib.instruments.Portfolio(instruments)#
Bases:
Sensitivities
,Metrics
Create a collection of Instruments to group metrics
- Parameters:
instruments (list) – This should be a list of Instruments.
Notes
When using a
Portfolio
each Instrument must either have pricing parameters pre-defined using the appropriate pricing mechanisms or share common pricing parameters defined at price time.Examples
See examples for
Spread
for similar functionality.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
(*args, **kwargs)Return the properties of all legs used in calculating cashflows.
cashflows_table
([curves, solver, fx, base])Aggregate the values derived from a
cashflows()
method on an Instrument.delta
(*args, **kwargs)Calculate the delta of the Instrument.
exo_delta
(*args, **kwargs)Calculate the delta of the Instrument measured against user defined
Variable
.fixings_table
([curves, solver, fx, base, ...])Return a DataFrame of fixing exposures on the Instruments.
gamma
(*args, **kwargs)Calculate the gamma of the Instrument.
npv
([curves, solver, fx, base, local])Return the NPV of the Portfolio by summing instrument NPVs.
rate
(*args, **kwargs)Return the rate or typical price for a derivative instrument.
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.
- 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 [1]: curve = Curve({dt(2021,1,1): 1.00, dt(2025,1,1): 0.83}, id="SONIA") In [2]: fxr = FXRates({"gbpusd": 1.25}, base="usd")
In [3]: irs = IRS( ...: effective=dt(2022, 1, 1), ...: termination="6M", ...: frequency="Q", ...: currency="gbp", ...: notional=1e9, ...: fixed_rate=5.0, ...: ) ...: In [4]: irs.analytic_delta(curve, curve) Out[4]: 47156.00216054951 In [5]: irs.analytic_delta(curve, curve, fxr) Out[5]: <Dual: 58945.002701, (fx_gbpusd), [47156.0]> In [6]: irs.analytic_delta(curve, curve, fxr, "gbp") Out[6]: 47156.00216054951
- cashflows(*args, **kwargs)#
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.250000 1.000000e+09 0.943382 None 5.000000 NaN -1.250000e+07 -1.179228e+07 1.25 -1.474035e+07 1 FixedPeriod Regular GBP 2022-04-01 2022-07-01 2022-07-03 ACT360 0.252778 1.000000e+09 0.932497 None 5.000000 NaN -1.263889e+07 -1.178572e+07 1.25 -1.473215e+07 leg2 0 FloatPeriod Regular GBP 2022-01-01 2022-04-01 2022-04-03 ACT360 0.250000 -1.000000e+09 0.943382 None 4.617734 0.0 1.154434e+07 1.089072e+07 1.25 1.361340e+07 1 FloatPeriod Regular GBP 2022-04-01 2022-07-01 2022-07-03 ACT360 0.252778 -1.000000e+09 0.932497 None 4.618029 0.0 1.167335e+07 1.088536e+07 1.25 1.360670e+07
- cashflows_table(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank, **kwargs)#
Aggregate the values derived from a
cashflows()
method on an Instrument.- Parameters:
curves (CurveType, str or list of such, optional) – Argument input to the underlying
cashflows
method of the Instrument.solver (Solver, optional) – Argument input to the underlying
cashflows
method of the Instrument.fx (float, FXRates, FXForwards, optional) – Argument input to the underlying
cashflows
method of the Instrument.base (str, optional) – Argument input to the underlying
cashflows
method of the Instrument.kwargs (dict) – Additional arguments input the underlying
cashflows
method of the Instrument.
- Return type:
DataFrame
- delta(*args, **kwargs)#
Calculate the delta of the Instrument.
For arguments see
Sensitivities.delta()
.
- exo_delta(*args, **kwargs)#
Calculate the delta of the Instrument measured against user defined
Variable
.For arguments see
Sensitivities.exo_delta()
.
- fixings_table(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank, approximate=False, right=NoInput.blank)#
Return a DataFrame of fixing exposures on the Instruments.
For arguments see
XCS.fixings_table()
, and/orIRS.fixings_table()
- Return type:
DataFrame
- 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, **kwargs)#
Return the NPV of the Portfolio by summing instrument NPVs.
For arguments see
BaseDerivative.npv()
.