Class Swap
- Namespace
- NanoQL.Instruments
- Assembly
- NanoQL.dll
An interest rate swap: the cash flows of a paid leg and of a received one, or of several legs.
public class Swap : Instrument
- Inheritance
-
Swap
- Derived
- Inherited Members
Remarks
Unsealed, as in QuantLib, where many swaps derive from it; a derived swap passes its legs to the multi-leg
constructor. The per-leg results that QuantLib's swap holds (legNPV, legBPS, the start and end
discounts, npvDateDiscount) are members of the SwapResults an engine returns.
Constructors
Swap(IEnumerable<ImmutableArray<CashFlow>>, IEnumerable<bool>)
Initializes a new instance of the Swap class with any number of legs.
public Swap(IEnumerable<ImmutableArray<CashFlow>> legs, IEnumerable<bool> payer)
Parameters
legsIEnumerable<ImmutableArray<CashFlow>>The legs.
payerIEnumerable<bool>For each leg, whether it is paid.
Exceptions
- ArgumentException
The two sequences differ in size.
Swap(ImmutableArray<CashFlow>, ImmutableArray<CashFlow>)
Initializes a new instance of the Swap class with a paid and a received leg.
public Swap(ImmutableArray<CashFlow> firstLeg, ImmutableArray<CashFlow> secondLeg)
Parameters
firstLegImmutableArray<CashFlow>The leg that is paid.
secondLegImmutableArray<CashFlow>The leg that is received.
Properties
Legs
Gets the legs.
public ImmutableArray<ImmutableArray<CashFlow>> Legs { get; }
Property Value
NumberOfLegs
Gets the number of legs.
public int NumberOfLegs { get; }
Property Value
Methods
FetchResults(InstrumentResults)
Reads an engine's results into the instrument's, applying any derivations the instrument makes.
public override SwapResults FetchResults(InstrumentResults results)
Parameters
resultsInstrumentResultsThe engine's results.
Returns
- SwapResults
The instrument's results.
Exceptions
- ArgumentException
The results aren't a swap's, or a per-leg result has the wrong number of legs.
IsExpired(EvaluationContext)
Whether the instrument might still have a value greater than zero.
public override bool IsExpired(EvaluationContext context)
Parameters
contextEvaluationContextThe evaluation context.
Returns
Leg(int)
The leg at an index.
public ImmutableArray<CashFlow> Leg(int j)
Parameters
jintThe index.
Returns
- ImmutableArray<CashFlow>
The leg.
Exceptions
- ArgumentException
There's no leg at the index.
MaturityDate()
The latest maturity date of the legs.
public virtual Date MaturityDate()
Returns
- Date
The maturity date.
Exceptions
- NanoQLException
The swap has no legs.
Payer(int)
Whether the leg at an index is paid.
public bool Payer(int j)
Parameters
jintThe index.
Returns
Exceptions
- ArgumentException
There's no leg at the index.
SetupExpired()
The results of an expired instrument: a zero value and error estimate, and no valuation date.
public override SwapResults SetupExpired()
Returns
- SwapResults
The expired results.
StartDate()
The earliest start date of the legs.
public virtual Date StartDate()
Returns
- Date
The start date.
Exceptions
- NanoQLException
The swap has no legs.
Validate()
Checks the instrument's terms before an engine prices it, as QuantLib's arguments do.
public override void Validate()
Exceptions
- NanoQLException
The number of legs and of multipliers differ.
WithLeg(int, ImmutableArray<CashFlow>)
A copy of the swap holding another leg at an index: SetCouponPricer<T>(T, int, FloatingRateCouponPricer?)'s step, which QuantLib does in place on the leg a built swap holds. The base's copy is memberwise, so a derived swap's terms come along; a derived swap that caches what it derives from its legs overrides it, and an override returns a copy of the same runtime type.
protected virtual Swap WithLeg(int j, ImmutableArray<CashFlow> leg)
Parameters
jintThe leg's index.
legImmutableArray<CashFlow>The new leg.
Returns
- Swap
The copy; the receiver is unchanged.
Exceptions
- ArgumentException
There's no leg at the index, or the leg holds a null cash flow.