Record Class VanillaSwap

java.lang.Object
java.lang.Record
com.quantfinlib.rates.VanillaSwap
Record Components:
fixed - the fixed leg
floating - the floating leg

public record VanillaSwap(FixedLeg fixed, FloatLeg floating) extends Record
A fixed-for-floating swap built from two convention-driven legs: the replacement for the single-curve, annual, tau = 1 methods of the SwapPricer (removed in 4.0). Each leg carries its own frequency, day count, calendar, roll, stub and payment lag (LegConvention); the floating leg is a compounded overnight leg (OvernightLeg, with lookback, observation shift, lockout and realised fixings) or a term-rate leg (TermRateLeg).

Formal statement, per unit notional, valuation date = the discount curve's, only coupons paid after it counted:

  payer PV  = PV_float - K * A
  par rate  = PV_float / A          (the K that sets payer PV to zero)

with A the FixedLeg.annuity(DiscountCurve). A seasoned trade is valued the same way: past coupons are dropped, the current coupon combines published fixings and forecasts.

Worked example: a 5y SOFR OIS, annual both legs, ACT/360, 2-day payment lag, 2-day lookback: new VanillaSwap(new FixedLeg(s, e, k, conv), new OvernightLeg(s, e, 0, conv, new OvernightConvention(2, false, 0), fixings)); its par rate on a curve is pinned against QuantLib in the golden test.

  • Constructor Details

    • VanillaSwap

      public VanillaSwap(FixedLeg fixed, FloatLeg floating)
      Validates the fields.
  • Method Details

    • annuity

      public double annuity(DiscountCurve discount)
      Fixed-leg annuity per unit notional.
      Parameters:
      discount - discount curve
      Returns:
      the annuity
    • floatLegPv

      public double floatLegPv(DiscountCurve discount, DiscountCurve projection)
      Floating-leg PV per unit notional.
      Parameters:
      discount - discount curve
      projection - projection curve
      Returns:
      present value
    • parRate

      public double parRate(DiscountCurve discount, DiscountCurve projection)
      Par fixed rate.
      Parameters:
      discount - discount curve
      projection - projection curve
      Returns:
      the fixed rate that prices the swap at zero
    • payerPv

      public double payerPv(DiscountCurve discount, DiscountCurve projection)
      PV per unit notional of paying fixed and receiving floating.
      Parameters:
      discount - discount curve
      projection - projection curve
      Returns:
      present value
    • receiverPv

      public double receiverPv(DiscountCurve discount, DiscountCurve projection)
      PV per unit notional of receiving fixed and paying floating.
      Parameters:
      discount - discount curve
      projection - projection curve
      Returns:
      present value
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • fixed

      public FixedLeg fixed()
      Returns the value of the fixed record component.
      Returns:
      the value of the fixed record component
    • floating

      public FloatLeg floating()
      Returns the value of the floating record component.
      Returns:
      the value of the floating record component