Skip to content

feat: Implement fairSpread() for FloatFloatSwap#2411

Open
shubhamessier wants to merge 1 commit intolballabio:masterfrom
shubhamessier:master
Open

feat: Implement fairSpread() for FloatFloatSwap#2411
shubhamessier wants to merge 1 commit intolballabio:masterfrom
shubhamessier:master

Conversation

@shubhamessier
Copy link

feat: Implement fairSpread() method for FloatFloatSwap class

Add missing fairSpread() functionality to FloatFloatSwap to achieve API parity
with other swap instruments (VanillaSwap, AssetSwap, etc.). This enables
fair value calculation for basis swaps, which is essential for spread trading,
risk management, and arbitrage strategies.

Implementation Details:

  • Follows established QuantLib patterns from FixedVsFloatingSwap/AssetSwap
  • Uses standard market formula: fairSpread = currentSpread - NPV/(legBPS/basisPoint)
  • Implements proper caching mechanism with lazy evaluation
  • Includes complete lifecycle management (setupExpired, fetchResults, reset)
  • Supports both engine-calculated and fallback calculation methods

Code Changes:

  • Add fairSpread() const method declaration and implementation
  • Add fairSpread_ mutable member variable for result caching
  • Add fairSpread field to FloatFloatSwap::results class
  • Update fetchResults() with calculation logic using leg2 BPS sensitivity
  • Update setupExpired() and results::reset() for proper initialization
  • Add QL_REQUIRE validation for result availability

This enables users to calculate fair spreads for float-float swaps, which is
essential for basis trading, cross-currency swaps, and risk management
applications.

Add missing fairSpread() method to FloatFloatSwap class following the same
pattern as other swap instruments. Calculates fair spread adjustment needed
on the second floating leg to achieve zero NPV.

- Add fairSpread() method with proper caching and lifecycle management
- Update results class and fetchResults() with calculation logic
- Ensures API consistency across all swap types in QuantLib

Fixes lballabio#2403
@boring-cyborg
Copy link

boring-cyborg bot commented Dec 29, 2025

Thanks for opening this pull request! It might take a while before we look at it, so don't worry if there seems to be no feedback. We'll get to it.

@CLAassistant
Copy link

CLAassistant commented Dec 29, 2025

CLA assistant check
All committers have signed the CLA.

@lballabio
Copy link
Owner

Thanks! I'm not sure of the interface: this is a float-vs-float swap, so the spread might be on either leg. It could be something like fairSpread(int i), like the methods in the base class Swap work, or it could be a pair of methods fairSpread1() and fairSpread2() as in the rest of the methods of this class. The latter make probably more sense, since we already have spread1() and spread2().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants