never executed always true always false
    1 -- GENERATED by C->Haskell Compiler, version 0.28.8 Switcheroo, 25 November 2017 (Haskell)
    2 -- Edit the ORIGNAL .chs file instead!
    3 
    4 
    5 {-# LANGUAGE TemplateHaskell, FlexibleInstances, TypeFamilies #-}
    6 module QuantLib.Instrument.Swap
    7   (
    8     -- * Types
    9     -- ** Swap hierarchy
   10     GenSwap
   11   , Swap
   12   , GenFixedVsFloatingSwap
   13   , FixedVsFloatingSwap
   14   , VanillaSwap
   15   , OvernightIndexedSwap
   16   , NonstandardSwap
   17   , IrregularSwap
   18   , FloatFloatSwap
   19   , AssetSwap
   20   , BMASwap
   21   , ZeroCouponInflationSwap
   22   , YearOnYearInflationSwap
   23   , CPISwap
   24   , ZeroCouponSwap
   25   , EquityTotalReturnSwap
   26   , VarianceSwap
   27   , GenConstNotionalCrossCurrencySwap
   28   , ConstNotionalCrossCurrencySwap
   29   , ConstNotionalCrossCurrencyBasisSwap
   30   , MtMCrossCurrencyBasisSwap
   31   , ConstNotionalCrossCurrencyFixedVsFloatingSwap
   32 
   33     -- ** Swaptions and variance options
   34   , Swaption
   35   , IrregularSwaption
   36   , NonstandardSwaption
   37   , FloatFloatSwaption
   38   , VarianceOption
   39 
   40     -- ** Configuration
   41   , SwapType(..)
   42   , SwaptionPriceType(..)
   43   , IrregularSettlementType(..)
   44   , CPIInterpolationType(..)
   45   , CalibrationBasketType(..)
   46   , FloatFloatSwapOpts(..)
   47   , defaultFloatFloatSwapOpts
   48   , FloatFloatSwapVaryingOpts(..)
   49   , defaultFloatFloatSwapVaryingOpts
   50   , ConstNotionalCrossCurrencyBasisSwapOpts(..)
   51   , MtmCrossCurrencySwapType(..)
   52   , MtMCrossCurrencyBasisSwapOpts(..)
   53   , defaultMtmCrossCurrencyBasisSwapOpts
   54   , defaultConstNotionalCrossCurrencyBasisSwapOpts
   55   , OvernightObservation(..)
   56   , defaultOvernightObservation
   57 
   58   , StubIndexSelection(..)
   59 
   60     -- * Constructors
   61     -- ** Hierarchy conversion
   62   , asSwap
   63 
   64     -- ** Swaps
   65   , swapFromLegs
   66   , swap
   67   , bmaSwap
   68   , vanillaSwap
   69   , nonstandardSwapFromVanilla
   70   , nonstandardSwap
   71   , nonstandardSwapFromGearingsAndSpreads
   72   , floatFloatSwap
   73   , floatFloatSwapFromNominals
   74   , makeVanillaSwap
   75   , makeCms
   76   , zeroCouponInflationSwap
   77   , yearOnYearInflationSwap
   78   , cpiSwap
   79   , zeroCouponSwap
   80   , zeroCouponSwapFromRate
   81   , equityTotalReturnSwapIbor
   82   , equityTotalReturnSwapOvernight
   83   , varianceSwap
   84   , varianceOption
   85 
   86     -- ** Cross-currency swaps
   87   , constNotionalCrossCurrencySwap
   88   , constNotionalCrossCurrencySwapFromLegs
   89   , constNotionalCrossCurrencyBasisSwap
   90   , mtmCrossCurrencyBasisSwap
   91   , mtmCrossCurrencyBasisSwapWithOptions
   92   , constNotionalCrossCurrencyFixedVsFloatingSwap
   93 
   94     -- ** Overnight-indexed and asset swaps
   95   , overnightIndexedSwap
   96   , overnightIndexedSwapFromNominals
   97   , assetSwap
   98 
   99     -- ** Swaptions
  100   , swaption
  101   , irregularSwaption
  102   , irregularSwap
  103   , nonstandardSwaptionFromSwaption
  104   , nonstandardSwaption
  105   , floatFloatSwaption
  106 
  107     -- * Inspectors
  108   , HasCrossCurrencyResults(..)
  109   , HasFairLegSpreads(..)
  110   , fairFxBaseSpread
  111   , fairFxQuoteSpread
  112   , fxResetRates
  113   , fxResetNotionals
  114     -- ** Common swap inspectors
  115   , HasFixedLeg(..)
  116   , HasFloatingLeg(..)
  117   , HasFairRate(..)
  118   , HasFairSpread(..)
  119   , HasInstrumentUnderlying(..)
  120   , impliedVolatility
  121   , endDiscounts
  122   , leg
  123   , numberOfLegs
  124   , legBps
  125   , legNpv
  126   , maturityDate
  127   , npvDateDiscount
  128   , startDate
  129   , startDiscounts
  130   , nonstandardSwapFixedRate
  131 
  132     -- ** Cross-currency swaps
  133 
  134     -- ** BMA swaps
  135   , bmaLeg
  136   , bmaLegBps
  137   , bmaLegNpv
  138   , fairLiborFraction
  139   , fairLiborSpread
  140   , liborFraction
  141   , liborLeg
  142   , liborLegBps
  143   , liborLegNpv
  144 
  145     -- ** Swaption calibration baskets
  146   , calibrationBasket
  147   , floatFloatSwaptionCalibrationBasket
  148 
  149     -- ** Asset swaps
  150   , bondLeg
  151   , cleanPrice
  152   , fairCleanPrice
  153   , fairNonParRepayment
  154   , nonParRepayment
  155   , parSwap
  156   , payBondCoupon
  157 
  158     -- ** Float-float swaps
  159   , firstLegFairSpread
  160   , secondLegFairSpread
  161 
  162     -- ** Zero-coupon, equity and variance swaps
  163   , fairFixedPayment
  164   , fairFixedRate
  165   , equityLegNpv
  166   , interestRateLegNpv
  167   , fairMargin
  168   , variance
  169 
  170     -- ** Overnight-indexed swaps
  171   , overnightLeg
  172   , overnightLegBps
  173   , overnightLegNpv
  174 
  175   ) where
  176 import qualified Foreign.C.Types as C2HSImp
  177 import qualified Foreign.ForeignPtr as C2HSImp
  178 import qualified Foreign.Marshal.Utils as C2HSImp
  179 import qualified Foreign.Ptr as C2HSImp
  180 
  181 
  182 import Language.Haskell.TH(mkName, varT)
  183 import Data.Maybe(fromMaybe)
  184 import QuantLib.Internal.Syntax(deriveOptionsRecord)
  185 import QuantLib.Internal
  186 import QuantLib.Instrument
  187 
  188 import QuantLib.InterestRate(VolatilityType)
  189 import QuantLib.CashFlow(RateAveragingType(..))
  190 import QuantLib.CashFlow(cmsLeg, iborLeg)
  191 import QuantLib.Time.Calendar(adjust, advance)
  192 import QuantLib.Internal.Type
  193 import QuantLib.Internal.Common
  194 import Data.List.NonEmpty(NonEmpty((:|)))
  195 import QuantLib.Time.Schedule(schedule, DateGenerationRule(..))
  196 import QuantLib.Time.Date(addPeriod)
  197 import QuantLib.Context(evaluationDate)
  198 import QuantLib.Index(fixingCalendar)
  199 import QuantLib.Index.InterestRate(tenor, dayCounter, businessDayConvention)
  200 
  201 
  202 
  203 
  204 
  205 
  206 
  207 
  208 
  209 
  210 
  211 
  212 
  213 
  214 
  215 
  216 
  217 
  218 
  219 
  220 
  221 
  222 
  223 
  224 
  225 
  226 
  227 
  228 
  229 
  230 
  231 
  232 
  233 
  234 
  235 
  236 
  237 
  238 
  239 
  240 
  241 
  242 
  243 
  244 
  245 
  246 
  247 
  248 
  249 
  250 
  251 
  252 
  253 
  254 
  255 
  256 
  257 
  258 
  259 
  260 
  261 
  262 
  263 
  264 
  265 
  266 
  267 
  268 
  269 
  270 
  271 
  272 
  273 
  274 
  275 
  276 
  277 
  278 
  279 
  280 
  281 
  282 data SwapType = Receiver
  283               | Payer
  284   deriving (Show,Eq,Read)
  285 instance Enum SwapType where
  286   succ Receiver = Payer
  287   succ Payer = error "SwapType.succ: Payer has no successor"
  288 
  289   pred Payer = Receiver
  290   pred Receiver = error "SwapType.pred: Receiver has no predecessor"
  291 
  292   enumFromTo from to = go from
  293     where
  294       end = fromEnum to
  295       go v = case compare (fromEnum v) end of
  296                  LT -> v : go (succ v)
  297                  EQ -> [v]
  298                  GT -> []
  299 
  300   enumFrom from = enumFromTo from Payer
  301 
  302   fromEnum Receiver = (-1)
  303   fromEnum Payer = 1
  304 
  305   toEnum (-1) = Receiver
  306   toEnum 1 = Payer
  307   toEnum unmatched = error ("SwapType.toEnum: Cannot match " ++ show unmatched)
  308 
  309 
  310 data SwaptionPriceType = SwaptionSpot
  311                        | SwaptionForward
  312   deriving (Enum,Show,Eq,Read)
  313 
  314 
  315 data IrregularSettlementType = IrregularPhysical
  316                              | IrregularCash
  317   deriving (Show,Eq,Read)
  318 instance Enum IrregularSettlementType where
  319   succ IrregularPhysical = IrregularCash
  320   succ IrregularCash = error "IrregularSettlementType.succ: IrregularCash has no successor"
  321 
  322   pred IrregularCash = IrregularPhysical
  323   pred IrregularPhysical = error "IrregularSettlementType.pred: IrregularPhysical has no predecessor"
  324 
  325   enumFromTo from to = go from
  326     where
  327       end = fromEnum to
  328       go v = case compare (fromEnum v) end of
  329                  LT -> v : go (succ v)
  330                  EQ -> [v]
  331                  GT -> []
  332 
  333   enumFrom from = enumFromTo from IrregularCash
  334 
  335   fromEnum IrregularPhysical = 0
  336   fromEnum IrregularCash = 1
  337 
  338   toEnum 0 = IrregularPhysical
  339   toEnum 1 = IrregularCash
  340   toEnum unmatched = error ("IrregularSettlementType.toEnum: Cannot match " ++ show unmatched)
  341 
  342 
  343 
  344 -- FloatFloatSwapOpts/FloatFloatSwapVaryingOpts bundle every trailing param of FloatFloatSwap's
  345 -- two constructors (floatfloatswap.hpp) -- 12 trailing defaulted params each, past the
  346 -- options-record threshold (see the add-quantlib-options-record skill). Two separate records
  347 -- (not one shared) since the scalar ctor's gearing/spread/cappedRate/flooredRate are plain
  348 -- Double/Maybe Double while the vector ctor's are [Double]. This splice must stay textually
  349 -- before every {#fun#}-generated binding in this file -- see OISRateHelperOpts in
  350 -- QuantLib/TermStructure/Yield.chs for why (c2hs always appends its raw foreign-import stubs at
  351 -- the physical end of the generated module regardless of where in the .chs a {#fun#} hook
  352 -- appears, so a top-level TH splice in between would split the file into declaration groups
  353 -- that can't see each other).
  354 -- |Direction of the FX-base currency leg, independent of the resettable-leg choice.
  355 data MtmCrossCurrencySwapType = PayFxBaseCurrency | ReceiveFxBaseCurrency deriving (Eq, Show, Read)
  356 
  357 $(deriveOptionsRecord "MtMCrossCurrencyBasisSwapOpts" ["ibor3", "ibor4"]
  358   [ ("mtmFxResetFixingDays", [t|Word|], [|0|])
  359   , ("mtmFxResetFixingCalendar", [t|Maybe Calendar|], [|Nothing|])
  360   , ("mtmFxBasePaymentLag", [t|Int|], [|0|])
  361   , ("mtmFxQuotePaymentLag", [t|Int|], [|0|])
  362   , ("mtmFxBasePaymentConvention", [t|BusinessDayConvention|], [|Following|])
  363   , ("mtmFxQuotePaymentConvention", [t|BusinessDayConvention|], [|Following|])
  364   , ("mtmFxBaseCompoundSpread", [t|Bool|], [|False|])
  365   , ("mtmFxBaseObservation", [t|OvernightObservation|], [|defaultOvernightObservation|])
  366   , ("mtmFxBaseAveragingMethod", [t|RateAveragingType|], [|AveragingCompound|])
  367   , ("mtmFxQuoteCompoundSpread", [t|Bool|], [|False|])
  368   , ("mtmFxQuoteObservation", [t|OvernightObservation|], [|defaultOvernightObservation|])
  369   , ("mtmFxQuoteAveragingMethod", [t|RateAveragingType|], [|AveragingCompound|])
  370   , ("mtmTelescopicValueDates", [t|Bool|], [|False|])
  371   , ("mtmUseIndexedCoupons", [t|Maybe Bool|], [|Nothing|])
  372   , ("mtmFxBaseStubIndexSelection", [t|Maybe (StubIndexSelection $(varT (mkName "ibor3")))|], [|Nothing|])
  373   , ("mtmFxQuoteStubIndexSelection", [t|Maybe (StubIndexSelection $(varT (mkName "ibor4")))|], [|Nothing|])
  374   ])
  375 
  376 $(deriveOptionsRecord "FloatFloatSwapOpts" []
  377   [ ("ffsIntermediateCapitalExchange", [t|Bool|], [|False|])
  378   , ("ffsFinalCapitalExchange", [t|Bool|], [|False|])
  379   , ("ffsFirstLegGearing", [t|Double|], [|1.0|])
  380   , ("ffsFirstLegSpread", [t|Double|], [|0.0|])
  381   , ("ffsFirstLegCappedRate", [t|Maybe Double|], [|Nothing|])
  382   , ("ffsFirstLegFlooredRate", [t|Maybe Double|], [|Nothing|])
  383   , ("ffsSecondLegGearing", [t|Double|], [|1.0|])
  384   , ("ffsSecondLegSpread", [t|Double|], [|0.0|])
  385   , ("ffsSecondLegCappedRate", [t|Maybe Double|], [|Nothing|])
  386   , ("ffsSecondLegFlooredRate", [t|Maybe Double|], [|Nothing|])
  387   , ("ffsFirstLegPaymentConvention", [t|Maybe BusinessDayConvention|], [|Nothing|])
  388   , ("ffsSecondLegPaymentConvention", [t|Maybe BusinessDayConvention|], [|Nothing|])
  389   ])
  390 $(deriveOptionsRecord "FloatFloatSwapVaryingOpts" []
  391   [ ("ffsvIntermediateCapitalExchange", [t|Bool|], [|False|])
  392   , ("ffsvFinalCapitalExchange", [t|Bool|], [|False|])
  393   , ("ffsvFirstLegGearing", [t|[Double]|], [|[]|])
  394   , ("ffsvFirstLegSpread", [t|[Double]|], [|[]|])
  395   , ("ffsvFirstLegCappedRate", [t|[Double]|], [|[]|])
  396   , ("ffsvFirstLegFlooredRate", [t|[Double]|], [|[]|])
  397   , ("ffsvSecondLegGearing", [t|[Double]|], [|[]|])
  398   , ("ffsvSecondLegSpread", [t|[Double]|], [|[]|])
  399   , ("ffsvSecondLegCappedRate", [t|[Double]|], [|[]|])
  400   , ("ffsvSecondLegFlooredRate", [t|[Double]|], [|[]|])
  401   , ("ffsvFirstLegPaymentConvention", [t|Maybe BusinessDayConvention|], [|Nothing|])
  402   , ("ffsvSecondLegPaymentConvention", [t|Maybe BusinessDayConvention|], [|Nothing|])
  403   ])
  404 
  405 -- ConstNotionalCrossCurrencyBasisSwapOpts bundles ConstNotionalCrossCurrencyBasisSwap's 13
  406 -- trailing defaulted params (per-leg OIS-only payment lag, compound-spread, lookback,
  407 -- observation shift, lockout, averaging method, plus a shared telescopicValueDates), past the
  408 -- options-record threshold -- see FloatFloatSwapOpts above for why this splice must stay
  409 -- textually before every {#fun#} in this file. ConstNotionalCrossCurrencyFixedVsFloatingSwap's
  410 -- constructor has only 4 trailing defaults (under the threshold), so it's widened in place
  411 -- instead -- see 'constNotionalCrossCurrencyFixedVsFloatingSwap' below.
  412 $(deriveOptionsRecord "ConstNotionalCrossCurrencyBasisSwapOpts" ["ibor3", "ibor4"]
  413   [ ("cccbsPayPaymentLag", [t|Int|], [|0|])
  414   , ("cccbsRecPaymentLag", [t|Int|], [|0|])
  415   , ("cccbsPayCompoundSpread", [t|Bool|], [|False|])
  416   , ("cccbsPayObservation", [t|OvernightObservation|], [|defaultOvernightObservation|])
  417   , ("cccbsPayAveragingMethod", [t|RateAveragingType|], [|AveragingCompound|])
  418   , ("cccbsRecCompoundSpread", [t|Bool|], [|False|])
  419   , ("cccbsRecObservation", [t|OvernightObservation|], [|defaultOvernightObservation|])
  420   , ("cccbsRecAveragingMethod", [t|RateAveragingType|], [|AveragingCompound|])
  421   , ("cccbsTelescopicValueDates", [t|Bool|], [|False|])
  422   , ("cccbsUseIndexedCoupons", [t|Maybe Bool|], [|Nothing|])
  423   , ("cccbsPaymentLagOnNotionalExchanges", [t|Bool|], [|False|])
  424   , ("cccbsPayStubIndexSelection", [t|Maybe (StubIndexSelection $(varT (mkName "ibor3")))|], [|Nothing|])
  425   , ("cccbsRecStubIndexSelection", [t|Maybe (StubIndexSelection $(varT (mkName "ibor4")))|], [|Nothing|])
  426   ])
  427 
  428 -- |implied volatility
  429 impliedVolatility :: (Swaption) -> (Double) -- ^price
  430  -> (GenYieldTermStructure y) -> (Double) -- ^guess
  431  -> (Double) -- ^accuracy
  432  -> (Word) -- ^maxEvaluations
  433  -> (Double) -- ^minVol
  434  -> (Double) -- ^maxVol
  435  -> (VolatilityType) -- ^type
  436  -> (Double) -- ^displacement
  437  -> (SwaptionPriceType) -- ^priceType
  438  -> IO ((Double))
  439 impliedVolatility a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 =
  440   withSwaption a1 $ \a1' -> 
  441   let {a2' = realToFrac a2} in 
  442   withYieldTermStructure a3 $ \a3' -> 
  443   let {a4' = realToFrac a4} in 
  444   let {a5' = realToFrac a5} in 
  445   let {a6' = fromIntegral a6} in 
  446   let {a7' = realToFrac a7} in 
  447   let {a8' = realToFrac a8} in 
  448   let {a9' = (fromIntegral . fromEnum) a9} in 
  449   let {a10' = realToFrac a10} in 
  450   let {a11' = (fromIntegral . fromEnum) a11} in 
  451   preErrorCheck $ \a12' -> 
  452   impliedVolatility'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' >>= \res ->
  453   let {res' = realToFrac res} in
  454   errorCheck  a12'>>
  455   return (res')
  456 
  457 
  458 
  459 -- |Multi leg constructor.
  460 swapFromLegs :: [(GenLeg l, Bool)] -- ^(legs, payer)
  461   -> IO Swap
  462 swapFromLegs = (uncurry qlSwap1) . unzip
  463 qlSwap1 :: ([GenLeg l]) -> ([Bool]) -> IO ((Swap))
  464 qlSwap1 a1 a2 =
  465   withLegArray a1 $ \(a1'1, a1'2) -> 
  466   withBoolArray a2 $ \(a2'1, a2'2) -> 
  467   preErrorCheck $ \a3' -> 
  468   qlSwap1'_ a1'1  a1'2 a2'1  a2'2 a3' >>= \res ->
  469   peekSwap res >>= \res' ->
  470   errorCheck  a3'>>
  471   return (res')
  472 
  473 
  474 
  475 -- |Swap paying Libor against BMA coupons
  476 bmaSwap :: (SwapType) -> (Double) -- ^nominal
  477  -> (Schedule) -- ^liborSchedule
  478  -> (Double) -- ^liborFraction
  479  -> (Double) -- ^liborSpread
  480  -> (GenIborIndex ibor) -> (DayCounter) -- ^liborDayCount
  481  -> (Schedule) -- ^bmaSchedule
  482  -> (BMAIndex) -> (DayCounter) -- ^bmaDayCount
  483  -> IO ((BMASwap))
  484 bmaSwap a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 =
  485   let {a1' = (fromIntegral . fromEnum) a1} in 
  486   let {a2' = realToFrac a2} in 
  487   withSchedule a3 $ \a3' -> 
  488   let {a4' = realToFrac a4} in 
  489   let {a5' = realToFrac a5} in 
  490   withIborIndex a6 $ \a6' -> 
  491   withDayCounter a7 $ \a7' -> 
  492   withSchedule a8 $ \a8' -> 
  493   withBMAIndex a9 $ \a9' -> 
  494   withDayCounter a10 $ \a10' -> 
  495   preErrorCheck $ \a11' -> 
  496   bmaSwap'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' >>= \res ->
  497   peekBMASwap res >>= \res' ->
  498   errorCheck  a11'>>
  499   return (res')
  500 
  501 
  502 
  503 -- |Fixed-rate vs floating-rate (Ibor) swap; if no payment convention is given, the floating leg's is used.
  504 vanillaSwap :: (SwapType) -> (Double) -- ^nominal
  505  -> (Schedule) -- ^fixedSchedule
  506  -> (Double) -- ^fixedRate
  507  -> (DayCounter) -- ^fixedDayCount
  508  -> (Schedule) -- ^floatSchedule
  509  -> (GenIborIndex ibor) -> (Double) -- ^spread
  510  -> (DayCounter) -- ^floatingDayCount
  511  -> (Maybe BusinessDayConvention) -- ^paymentConvention
  512  -> (Maybe Bool) -- ^useIndexedCoupons
  513  -> IO ((VanillaSwap))
  514 vanillaSwap a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 =
  515   let {a1' = (fromIntegral . fromEnum) a1} in 
  516   let {a2' = realToFrac a2} in 
  517   withSchedule a3 $ \a3' -> 
  518   let {a4' = realToFrac a4} in 
  519   withDayCounter a5 $ \a5' -> 
  520   withSchedule a6 $ \a6' -> 
  521   withIborIndex a7 $ \a7' -> 
  522   let {a8' = realToFrac a8} in 
  523   withDayCounter a9 $ \a9' -> 
  524   let {a10' = fromMaybeEnum a10} in 
  525   let {a11' = fromMaybeBool a11} in 
  526   preErrorCheck $ \a12' -> 
  527   vanillaSwap'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' >>= \res ->
  528   peekVanillaSwap res >>= \res' ->
  529   errorCheck  a12'>>
  530   return (res')
  531 
  532 
  533 
  534 -- |Converts an existing 'FixedVsFloatingSwap' (e.g. a 'VanillaSwap') into a 'NonstandardSwap'
  535 -- (upstream's own conversion constructor, @NonstandardSwap(const FixedVsFloatingSwap&)@).
  536 -- An 'OvernightIndexedSwap' keeps its compounded coupons, payment lag and observation
  537 -- conventions; converting one requires QuantLib 1.44.
  538 nonstandardSwapFromVanilla :: (GenFixedVsFloatingSwap f) -> IO ((NonstandardSwap))
  539 nonstandardSwapFromVanilla a1 =
  540   withFixedVsFloatingSwap a1 $ \a1' -> 
  541   preErrorCheck $ \a2' -> 
  542   nonstandardSwapFromVanilla'_ a1' a2' >>= \res ->
  543   peekNonstandardSwap res >>= \res' ->
  544   errorCheck  a2'>>
  545   return (res')
  546 
  547 
  548 
  549 -- |'VanillaSwap' generalized to per-period fixed/floating nominals and fixed rates, plus
  550 -- optional intermediate\/final notional exchange -- a single 'Double' gearing\/spread shared
  551 -- across all floating periods. See 'nonstandardSwapFromGearingsAndSpreads' for per-period gearing\/spread.
  552 -- QuantLib 1.44 builds compounded coupons for an overnight index; 1.43 builds Ibor coupons.
  553 nonstandardSwap :: (SwapType) -> ([Double]) -- ^fixedNominal
  554  -> ([Double]) -- ^floatingNominal
  555  -> (Schedule) -- ^fixedSchedule
  556  -> ([Double]) -- ^fixedRate
  557  -> (DayCounter) -- ^fixedDayCount
  558  -> (Schedule) -- ^floatingSchedule
  559  -> (GenIborIndex ibor) -> (Double) -- ^gearing
  560  -> (Double) -- ^spread
  561  -> (DayCounter) -- ^floatingDayCount
  562  -> (Bool) -- ^intermediateCapitalExchange
  563  -> (Bool) -- ^finalCapitalExchange
  564  -> (Maybe BusinessDayConvention) -- ^paymentConvention
  565  -> (Int) -- ^paymentLag (1.44; QuantLib 1.43 requires 0)
  566  -> (Maybe Calendar) -- ^paymentCalendar, 'Nothing' for each leg's schedule calendar (1.44; QuantLib 1.43 requires 'Nothing')
  567  -> IO ((NonstandardSwap))
  568 nonstandardSwap a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 =
  569   let {a1' = (fromIntegral . fromEnum) a1} in 
  570   withDoubleArray a2 $ \(a2'1, a2'2) -> 
  571   withDoubleArray a3 $ \(a3'1, a3'2) -> 
  572   withSchedule a4 $ \a4' -> 
  573   withDoubleArray a5 $ \(a5'1, a5'2) -> 
  574   withDayCounter a6 $ \a6' -> 
  575   withSchedule a7 $ \a7' -> 
  576   withIborIndex a8 $ \a8' -> 
  577   let {a9' = realToFrac a9} in 
  578   let {a10' = realToFrac a10} in 
  579   withDayCounter a11 $ \a11' -> 
  580   let {a12' = C2HSImp.fromBool a12} in 
  581   let {a13' = C2HSImp.fromBool a13} in 
  582   let {a14' = fromMaybeEnum a14} in 
  583   let {a15' = fromIntegral a15} in 
  584   withMaybeCalendar a16 $ \a16' -> 
  585   preErrorCheck $ \a17' -> 
  586   nonstandardSwap'_ a1' a2'1  a2'2 a3'1  a3'2 a4' a5'1  a5'2 a6' a7' a8' a9' a10' a11' a12' a13' a14' a15' a16' a17' >>= \res ->
  587   peekNonstandardSwap res >>= \res' ->
  588   errorCheck  a17'>>
  589   return (res')
  590 
  591 
  592 
  593 -- |As 'nonstandardSwap', but with a per-period gearing and spread instead of one shared value.
  594 nonstandardSwapFromGearingsAndSpreads :: (SwapType) -> ([Double]) -- ^fixedNominal
  595  -> ([Double]) -- ^floatingNominal
  596  -> (Schedule) -- ^fixedSchedule
  597  -> ([Double]) -- ^fixedRate
  598  -> (DayCounter) -- ^fixedDayCount
  599  -> (Schedule) -- ^floatingSchedule
  600  -> (GenIborIndex ibor) -> ([Double]) -- ^gearing
  601  -> ([Double]) -- ^spread
  602  -> (DayCounter) -- ^floatingDayCount
  603  -> (Bool) -- ^intermediateCapitalExchange
  604  -> (Bool) -- ^finalCapitalExchange
  605  -> (Maybe BusinessDayConvention) -- ^paymentConvention
  606  -> (Int) -- ^paymentLag (1.44; QuantLib 1.43 requires 0)
  607  -> (Maybe Calendar) -- ^paymentCalendar, 'Nothing' for each leg's schedule calendar (1.44; QuantLib 1.43 requires 'Nothing')
  608  -> IO ((NonstandardSwap))
  609 nonstandardSwapFromGearingsAndSpreads a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 =
  610   let {a1' = (fromIntegral . fromEnum) a1} in 
  611   withDoubleArray a2 $ \(a2'1, a2'2) -> 
  612   withDoubleArray a3 $ \(a3'1, a3'2) -> 
  613   withSchedule a4 $ \a4' -> 
  614   withDoubleArray a5 $ \(a5'1, a5'2) -> 
  615   withDayCounter a6 $ \a6' -> 
  616   withSchedule a7 $ \a7' -> 
  617   withIborIndex a8 $ \a8' -> 
  618   withDoubleArray a9 $ \(a9'1, a9'2) -> 
  619   withDoubleArray a10 $ \(a10'1, a10'2) -> 
  620   withDayCounter a11 $ \a11' -> 
  621   let {a12' = C2HSImp.fromBool a12} in 
  622   let {a13' = C2HSImp.fromBool a13} in 
  623   let {a14' = fromMaybeEnum a14} in 
  624   let {a15' = fromIntegral a15} in 
  625   withMaybeCalendar a16 $ \a16' -> 
  626   preErrorCheck $ \a17' -> 
  627   nonstandardSwapFromGearingsAndSpreads'_ a1' a2'1  a2'2 a3'1  a3'2 a4' a5'1  a5'2 a6' a7' a8' a9'1  a9'2 a10'1  a10'2 a11' a12' a13' a14' a15' a16' a17' >>= \res ->
  628   peekNonstandardSwap res >>= \res' ->
  629   errorCheck  a17'>>
  630   return (res')
  631 
  632 
  633 
  634 -- |Per-period fixed rate, one entry per fixed-leg accrual period. For a swap built via
  635 -- 'nonstandardSwap'\/'nonstandardSwapFromGearingsAndSpreads', this simply echoes the constructor's @fixedRate@; for
  636 -- one built via 'nonstandardSwapFromVanilla' it is derived from the underlying vanilla swap's
  637 -- fixed leg coupons.
  638 nonstandardSwapFixedRate :: (NonstandardSwap) -> IO (([Double]))
  639 nonstandardSwapFixedRate a1 =
  640   withNonstandardSwap a1 $ \a1' -> 
  641   preDoubleArray $ \(a2'1, a2'2) -> 
  642   preErrorCheck $ \a3' -> 
  643   nonstandardSwapFixedRate'_ a1' a2'1  a2'2 a3' >>
  644   peekDoubleArray  a2'1  a2'2>>= \a2'' -> 
  645   errorCheck  a3'>>
  646   return (a2'')
  647 
  648 
  649 
  650 -- |Swap exchanging capped\/floored Libor or CMS coupons with a single flat nominal on each leg.
  651 -- 'FloatFloatSwapOpts' bundles every trailing param the C++ constructor defaults (gearing\/
  652 -- spread\/cap\/floor per leg, capital exchange, payment conventions); override only what's
  653 -- needed via record-update syntax on 'defaultFloatFloatSwapOpts'. See 'floatFloatSwapFromNominals' for the
  654 -- per-period-nominal overload.
  655 floatFloatSwap :: SwapType -> Double -> Double -> Schedule -> GenInterestRateIndex ridx1
  656   -> DayCounter -> Schedule -> GenInterestRateIndex ridx2 -> DayCounter -> FloatFloatSwapOpts
  657   -> IO FloatFloatSwap
  658 floatFloatSwap ty nominal1 nominal2 schedule1 index1 dayCount1 schedule2 index2 dayCount2 opts =
  659   floatFloatSwap_ ty nominal1 nominal2 schedule1 index1 dayCount1 schedule2 index2 dayCount2
  660     (ffsIntermediateCapitalExchange opts) (ffsFinalCapitalExchange opts)
  661     (ffsFirstLegGearing opts) (ffsFirstLegSpread opts) (ffsFirstLegCappedRate opts) (ffsFirstLegFlooredRate opts)
  662     (ffsSecondLegGearing opts) (ffsSecondLegSpread opts) (ffsSecondLegCappedRate opts) (ffsSecondLegFlooredRate opts)
  663     (ffsFirstLegPaymentConvention opts) (ffsSecondLegPaymentConvention opts)
  664 
  665 floatFloatSwap_ :: (SwapType) -> (Double) -- ^nominal1
  666  -> (Double) -- ^nominal2
  667  -> (Schedule) -- ^schedule1
  668  -> (GenInterestRateIndex ridx1) -> (DayCounter) -- ^dayCount1
  669  -> (Schedule) -- ^schedule2
  670  -> (GenInterestRateIndex ridx2) -> (DayCounter) -- ^dayCount2
  671  -> (Bool) -- ^intermediateCapitalExchange
  672  -> (Bool) -- ^finalCapitalExchange
  673  -> (Double) -- ^gearing1
  674  -> (Double) -- ^spread1
  675  -> (Maybe Double) -- ^cappedRate1
  676  -> (Maybe Double) -- ^flooredRate1
  677  -> (Double) -- ^gearing2
  678  -> (Double) -- ^spread2
  679  -> (Maybe Double) -- ^cappedRate2
  680  -> (Maybe Double) -- ^flooredRate2
  681  -> (Maybe BusinessDayConvention) -- ^paymentConvention1
  682  -> (Maybe BusinessDayConvention) -- ^paymentConvention2
  683  -> IO ((FloatFloatSwap))
  684 floatFloatSwap_ a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 =
  685   let {a1' = (fromIntegral . fromEnum) a1} in 
  686   let {a2' = realToFrac a2} in 
  687   let {a3' = realToFrac a3} in 
  688   withSchedule a4 $ \a4' -> 
  689   withInterestRateIndex a5 $ \a5' -> 
  690   withDayCounter a6 $ \a6' -> 
  691   withSchedule a7 $ \a7' -> 
  692   withInterestRateIndex a8 $ \a8' -> 
  693   withDayCounter a9 $ \a9' -> 
  694   let {a10' = C2HSImp.fromBool a10} in 
  695   let {a11' = C2HSImp.fromBool a11} in 
  696   let {a12' = realToFrac a12} in 
  697   let {a13' = realToFrac a13} in 
  698   let {a14' = fromMaybeDouble a14} in 
  699   let {a15' = fromMaybeDouble a15} in 
  700   let {a16' = realToFrac a16} in 
  701   let {a17' = realToFrac a17} in 
  702   let {a18' = fromMaybeDouble a18} in 
  703   let {a19' = fromMaybeDouble a19} in 
  704   let {a20' = fromMaybeEnum a20} in 
  705   let {a21' = fromMaybeEnum a21} in 
  706   preErrorCheck $ \a22' -> 
  707   floatFloatSwap_'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' a13' a14' a15' a16' a17' a18' a19' a20' a21' a22' >>= \res ->
  708   peekFloatFloatSwap res >>= \res' ->
  709   errorCheck  a22'>>
  710   return (res')
  711 
  712 
  713 
  714 -- |As 'floatFloatSwap', but with per-period nominals on each leg. 'FloatFloatSwapVaryingOpts'
  715 -- also supplies the per-period gearings, spreads, caps, and floors for both legs.
  716 floatFloatSwapFromNominals :: SwapType -> [Double] -> [Double] -> Schedule -> GenInterestRateIndex ridx1
  717   -> DayCounter -> Schedule -> GenInterestRateIndex ridx2 -> DayCounter
  718   -> FloatFloatSwapVaryingOpts -> IO FloatFloatSwap
  719 floatFloatSwapFromNominals ty nominal1 nominal2 schedule1 index1 dayCount1 schedule2 index2 dayCount2 opts =
  720   floatFloatSwap2_ ty nominal1 nominal2 schedule1 index1 dayCount1 schedule2 index2 dayCount2
  721     (ffsvIntermediateCapitalExchange opts) (ffsvFinalCapitalExchange opts)
  722     (ffsvFirstLegGearing opts) (ffsvFirstLegSpread opts) (ffsvFirstLegCappedRate opts) (ffsvFirstLegFlooredRate opts)
  723     (ffsvSecondLegGearing opts) (ffsvSecondLegSpread opts) (ffsvSecondLegCappedRate opts) (ffsvSecondLegFlooredRate opts)
  724     (ffsvFirstLegPaymentConvention opts) (ffsvSecondLegPaymentConvention opts)
  725 
  726 floatFloatSwap2_ :: (SwapType) -> ([Double]) -- ^nominal1
  727  -> ([Double]) -- ^nominal2
  728  -> (Schedule) -- ^schedule1
  729  -> (GenInterestRateIndex ridx1) -> (DayCounter) -- ^dayCount1
  730  -> (Schedule) -- ^schedule2
  731  -> (GenInterestRateIndex ridx2) -> (DayCounter) -- ^dayCount2
  732  -> (Bool) -- ^intermediateCapitalExchange
  733  -> (Bool) -- ^finalCapitalExchange
  734  -> ([Double]) -- ^gearing1
  735  -> ([Double]) -- ^spread1
  736  -> ([Double]) -- ^cappedRate1
  737  -> ([Double]) -- ^flooredRate1
  738  -> ([Double]) -- ^gearing2
  739  -> ([Double]) -- ^spread2
  740  -> ([Double]) -- ^cappedRate2
  741  -> ([Double]) -- ^flooredRate2
  742  -> (Maybe BusinessDayConvention) -- ^paymentConvention1
  743  -> (Maybe BusinessDayConvention) -- ^paymentConvention2
  744  -> IO ((FloatFloatSwap))
  745 floatFloatSwap2_ a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 =
  746   let {a1' = (fromIntegral . fromEnum) a1} in 
  747   withDoubleArray a2 $ \(a2'1, a2'2) -> 
  748   withDoubleArray a3 $ \(a3'1, a3'2) -> 
  749   withSchedule a4 $ \a4' -> 
  750   withInterestRateIndex a5 $ \a5' -> 
  751   withDayCounter a6 $ \a6' -> 
  752   withSchedule a7 $ \a7' -> 
  753   withInterestRateIndex a8 $ \a8' -> 
  754   withDayCounter a9 $ \a9' -> 
  755   let {a10' = C2HSImp.fromBool a10} in 
  756   let {a11' = C2HSImp.fromBool a11} in 
  757   withDoubleArray a12 $ \(a12'1, a12'2) -> 
  758   withDoubleArray a13 $ \(a13'1, a13'2) -> 
  759   withDoubleArray a14 $ \(a14'1, a14'2) -> 
  760   withDoubleArray a15 $ \(a15'1, a15'2) -> 
  761   withDoubleArray a16 $ \(a16'1, a16'2) -> 
  762   withDoubleArray a17 $ \(a17'1, a17'2) -> 
  763   withDoubleArray a18 $ \(a18'1, a18'2) -> 
  764   withDoubleArray a19 $ \(a19'1, a19'2) -> 
  765   let {a20' = fromMaybeEnum a20} in 
  766   let {a21' = fromMaybeEnum a21} in 
  767   preErrorCheck $ \a22' -> 
  768   floatFloatSwap2_'_ a1' a2'1  a2'2 a3'1  a3'2 a4' a5' a6' a7' a8' a9' a10' a11' a12'1  a12'2 a13'1  a13'2 a14'1  a14'2 a15'1  a15'2 a16'1  a16'2 a17'1  a17'2 a18'1  a18'2 a19'1  a19'2 a20' a21' a22' >>= \res ->
  769   peekFloatFloatSwap res >>= \res' ->
  770   errorCheck  a22'>>
  771   return (res')
  772 
  773 
  774 
  775 -- |The spread on leg 1 that would make the swap's NPV zero.
  776 firstLegFairSpread :: (FloatFloatSwap) -> IO ((Double))
  777 firstLegFairSpread a1 =
  778   withFloatFloatSwap a1 $ \a1' -> 
  779   preErrorCheck $ \a2' -> 
  780   firstLegFairSpread'_ a1' a2' >>= \res ->
  781   let {res' = realToFrac res} in
  782   errorCheck  a2'>>
  783   return (res')
  784 
  785 
  786 
  787 -- |The spread on leg 2 that would make the swap's NPV zero.
  788 secondLegFairSpread :: (FloatFloatSwap) -> IO ((Double))
  789 secondLegFairSpread a1 =
  790   withFloatFloatSwap a1 $ \a1' -> 
  791   preErrorCheck $ \a2' -> 
  792   secondLegFairSpread'_ a1' a2' >>= \res ->
  793   let {res' = realToFrac res} in
  794   errorCheck  a2'>>
  795   return (res')
  796 
  797 
  798 
  799 -- | Haskell equivalent of QuantLib's fluent @MakeVanillaSwap@ builder -- a
  800 -- single function with 'Maybe'-wrapped optional parameters instead of
  801 -- chained @.with*@ calls, covering the subset of @makevanillaswap.hpp@'s
  802 -- fields named in the parameters below. Not covered at all (no parameter):
  803 -- explicit effective\/termination date overrides, a settlement calendar
  804 -- distinct from the floating-leg one, floating-leg tenor\/convention\/
  805 -- termination convention\/day count overrides (always taken from the
  806 -- index, matching upstream's own defaults), @withRule@ variants (always
  807 -- @DateGeneration::Backward@), end-of-month\/first-date\/next-to-last-date
  808 -- overrides, a floating-leg spread other than @0@, a discounting term
  809 -- structure or custom pricing engine (use 'setPricingEngine' on the
  810 -- result instead), indexed\/at-par coupon overrides, and payment
  811 -- convention (always the floating leg's, matching upstream's own default
  812 -- when unset). @fixedLegTenor@\/@fixedLegDayCount@ are required arguments
  813 -- here rather than optional with upstream's currency-based inference. A
  814 -- 'Nothing' @settlementDays@ behaves as @Just 0@, rather than replicating
  815 -- upstream's index-@valueDate@-based spot-date convention.
  816 makeVanillaSwap
  817   :: (Word, TimeUnit)             -- ^swapTenor
  818   -> GenIborIndex ibor
  819   -> Double                       -- ^fixedRate
  820   -> (Int, TimeUnit)              -- ^forwardStart
  821   -> Maybe Int                    -- ^settlementDays
  822   -> (Word, TimeUnit)             -- ^fixedLegTenor
  823   -> DayCounter                   -- ^fixedLegDayCount
  824   -> Maybe BusinessDayConvention  -- ^fixedLegConvention
  825   -> Maybe BusinessDayConvention  -- ^fixedLegTerminationDateConvention
  826   -> Maybe Calendar               -- ^fixedLegCalendar
  827   -> Maybe Calendar               -- ^floatingLegCalendar
  828   -> Maybe Double                 -- ^nominal
  829   -> Maybe SwapType
  830   -> IO VanillaSwap
  831 makeVanillaSwap (swLen, swUnit) index fixedRate forwardStart mSettlementDays
  832     fixedTenor fixedDayCount mFixedConvention mFixedTerminationConvention mFixedCalendar
  833     mFloatCalendar mNominal mType = do
  834   idxCalendar <- fixingCalendar index
  835   floatTenor <- tenor index
  836   floatDayCount <- dayCounter index
  837   refDate <- evaluationDate
  838   let floatConv = businessDayConvention index
  839       floatCalendar = fromMaybe idxCalendar mFloatCalendar
  840       fixedCalendar = fromMaybe idxCalendar mFixedCalendar
  841       fixedConvention = fromMaybe ModifiedFollowing mFixedConvention
  842       fixedTerminationConvention = fromMaybe ModifiedFollowing mFixedTerminationConvention
  843       settlementDays = fromMaybe 0 mSettlementDays
  844       nominal = fromMaybe 1.0 mNominal
  845       swapType = fromMaybe Payer mType
  846       (fsLen, _) = forwardStart
  847   spotDate <- advance floatCalendar refDate (settlementDays, Days) Following False
  848   startDate0 <- addPeriod spotDate forwardStart
  849   swapStartDate <- case compare fsLen 0 of
  850     LT -> adjust floatCalendar startDate0 Preceding
  851     GT -> adjust floatCalendar startDate0 Following
  852     EQ -> pure startDate0
  853   endDate <- addPeriod swapStartDate (fromIntegral swLen, swUnit)
  854   fixedSchedule <- schedule (Just swapStartDate) endDate fixedTenor fixedCalendar
  855     fixedConvention fixedTerminationConvention Backward False Nothing Nothing
  856   floatSchedule <- schedule (Just swapStartDate) endDate floatTenor floatCalendar
  857     floatConv floatConv Backward False Nothing Nothing
  858   vanillaSwap swapType nominal fixedSchedule fixedRate fixedDayCount
  859     floatSchedule index 0.0 floatDayCount (Just floatConv) Nothing
  860 
  861 -- |Haskell equivalent of QuantLib's fluent @MakeCms@ builder, in the style of
  862 -- 'makeVanillaSwap' above -- not a binding of the @MakeCms@ C++ class at all, but a plain
  863 -- function composing already-bound primitives ('QuantLib.Time.Schedule.schedule',
  864 -- 'QuantLib.CashFlow.cmsLeg', 'QuantLib.CashFlow.iborLeg', 'swapFromLegs'). The result is a plain
  865 -- 'Swap' (a CMS swap has no calc\/getter of its own beyond generic 'Swap''s), with no
  866 -- 'FloatingRateCouponPricer' attached -- attach one to the CMS leg afterwards via
  867 -- @setCouponPricer =<< 'leg' result 0@ ('swapFromLegs' is used instead of 'swap' precisely so the
  868 -- CMS leg is always leg 0, regardless of 'SwapType') and 'QuantLib.CashFlow.setCouponPricer'
  869 -- before pricing.
  870 --
  871 -- Unlike @MakeCms@, @cmsLegTenor@\/@cmsLegDayCount@ are required arguments here rather than
  872 -- defaulted (upstream hardcodes 3 Months\/@Actual360@); pass those literals to reproduce
  873 -- @MakeCms@'s own defaults. Not covered at all (no parameter): an explicit effective date
  874 -- override, CMS-leg\/floating-leg termination-date-convention\/rule\/end-of-month\/
  875 -- first-date\/next-to-last-date overrides (always @ModifiedFollowing@\/@Backward@\/@False@\/
  876 -- unset, matching @MakeCms@'s own defaults for the CMS leg), CMS coupon gearing\/caps\/floors
  877 -- (use 'QuantLib.CashFlow.cmsLegWithOptions' and 'swap' directly for those), an ATM-spread lookup, a
  878 -- discounting term structure or custom pricing engine (use 'QuantLib.Instrument.setPricingEngine'
  879 -- on the result instead). A 'Nothing' @settlementDays@ behaves as @Just 0@, rather than
  880 -- replicating upstream's index-@valueDate@-based spot-date convention (matching
  881 -- 'makeVanillaSwap''s own choice here).
  882 makeCms
  883   :: (Word, TimeUnit)             -- ^swapTenor
  884   -> GenSwapIndex sidx            -- ^cms index
  885   -> GenIborIndex ibor            -- ^floating-leg index
  886   -> Double                       -- ^floating-leg spread
  887   -> (Int, TimeUnit)              -- ^forwardStart
  888   -> Maybe Int                    -- ^settlementDays
  889   -> (Word, TimeUnit)             -- ^cmsLegTenor
  890   -> DayCounter                   -- ^cmsLegDayCount
  891   -> Maybe Calendar               -- ^cmsLegCalendar
  892   -> Maybe Calendar               -- ^floatingLegCalendar
  893   -> Maybe Double                 -- ^nominal
  894   -> Maybe SwapType                -- ^'Payer' pays the CMS leg (receives floating); 'Receiver' the reverse
  895   -> IO Swap
  896 makeCms (swLen, swUnit) swapIndex iborIndex iborSpread forwardStart mSettlementDays
  897     cmsTenor cmsDayCount mCmsCalendar mFloatCalendar mNominal mType = do
  898   idxCalendar <- fixingCalendar swapIndex
  899   floatTenor <- tenor iborIndex
  900   floatDayCount <- dayCounter iborIndex
  901   refDate <- evaluationDate
  902   let floatConv = businessDayConvention iborIndex
  903       floatCalendar = fromMaybe idxCalendar mFloatCalendar
  904       cmsCalendar = fromMaybe idxCalendar mCmsCalendar
  905       settlementDays = fromMaybe 0 mSettlementDays
  906       nominal = fromMaybe 1.0 mNominal
  907       swapType = fromMaybe Payer mType
  908       (fsLen, _) = forwardStart
  909   spotDate <- advance floatCalendar refDate (settlementDays, Days) Following False
  910   startDate0 <- addPeriod spotDate forwardStart
  911   swapStartDate <- case compare fsLen 0 of
  912     LT -> adjust floatCalendar startDate0 Preceding
  913     GT -> adjust floatCalendar startDate0 Following
  914     EQ -> pure startDate0
  915   endDate <- addPeriod swapStartDate (fromIntegral swLen, swUnit)
  916   cmsSchedule <- schedule (Just swapStartDate) endDate cmsTenor cmsCalendar
  917     ModifiedFollowing ModifiedFollowing Backward False Nothing Nothing
  918   floatSchedule <- schedule (Just swapStartDate) endDate floatTenor floatCalendar
  919     floatConv floatConv Backward False Nothing Nothing
  920   cmsLegResult <- cmsLeg cmsSchedule swapIndex (nominal :| []) cmsDayCount ModifiedFollowing
  921     [] [] [] [] [] False False
  922   floatLegResult <- iborLeg floatSchedule iborIndex (nominal :| []) floatDayCount floatConv
  923     [] [] [iborSpread] [] [] False False
  924   -- 'swapFromLegs' (not 'swap') so the CMS leg is always leg 0 of the result regardless of
  925   -- 'SwapType' -- attach a pricer via @setCouponPricer =<< 'leg' result 0@ before pricing.
  926   swapFromLegs [(cmsLegResult, swapType == Payer), (floatLegResult, swapType == Receiver)]
  927 
  928 -- |The cash flows belonging to the first leg are paid; the ones belonging to the second leg are received.
  929 swap :: (GenLeg l1) -> (GenLeg l2) -> IO ((Swap))
  930 swap a1 a2 =
  931   withLeg a1 $ \a1' -> 
  932   withLeg a2 $ \a2' -> 
  933   preErrorCheck $ \a3' -> 
  934   swap'_ a1' a2' a3' >>= \res ->
  935   peekSwap res >>= \res' ->
  936   errorCheck  a3'>>
  937   return (res')
  938 
  939 
  940 
  941 -- |Discount factor at leg j's end date.
  942 endDiscounts :: (GenSwap s) -> (Word) -> IO ((Double))
  943 endDiscounts a1 a2 =
  944   withSwap a1 $ \a1' -> 
  945   let {a2' = fromIntegral a2} in 
  946   preErrorCheck $ \a3' -> 
  947   endDiscounts'_ a1' a2' a3' >>= \res ->
  948   let {res' = realToFrac res} in
  949   errorCheck  a3'>>
  950   return (res')
  951 
  952 
  953 
  954 -- |How many legs this swap has; leg indexes run from 0 to one less than this.
  955 numberOfLegs :: (GenSwap s) -> IO ((Word))
  956 numberOfLegs a1 =
  957   withSwap a1 $ \a1' -> 
  958   preErrorCheck $ \a2' -> 
  959   numberOfLegs'_ a1' a2' >>= \res ->
  960   let {res' = fromIntegral res} in
  961   errorCheck  a2'>>
  962   return (res')
  963 
  964 
  965 
  966 -- |The j-th leg's cash flows.
  967 leg :: (GenSwap s) -> (Word) -> IO ((Leg))
  968 leg a1 a2 =
  969   withSwap a1 $ \a1' -> 
  970   let {a2' = fromIntegral a2} in 
  971   preErrorCheck $ \a3' -> 
  972   leg'_ a1' a2' a3' >>= \res ->
  973   peekLeg res >>= \res' ->
  974   errorCheck  a3'>>
  975   return (res')
  976 
  977 
  978 
  979 -- |Basis-point sensitivity of leg j.
  980 legBps :: (GenSwap s) -> (Word) -> IO ((Double))
  981 legBps a1 a2 =
  982   withSwap a1 $ \a1' -> 
  983   let {a2' = fromIntegral a2} in 
  984   preErrorCheck $ \a3' -> 
  985   legBps'_ a1' a2' a3' >>= \res ->
  986   let {res' = realToFrac res} in
  987   errorCheck  a3'>>
  988   return (res')
  989 
  990 
  991 
  992 -- |NPV of leg j.
  993 legNpv :: (GenSwap s) -> (Word) -> IO ((Double))
  994 legNpv a1 a2 =
  995   withSwap a1 $ \a1' -> 
  996   let {a2' = fromIntegral a2} in 
  997   preErrorCheck $ \a3' -> 
  998   legNpv'_ a1' a2' a3' >>= \res ->
  999   let {res' = realToFrac res} in
 1000   errorCheck  a3'>>
 1001   return (res')
 1002 
 1003 
 1004 
 1005 -- |Discount factor at leg j's start date.
 1006 startDiscounts :: (GenSwap s) -> (Word) -> IO ((Double))
 1007 startDiscounts a1 a2 =
 1008   withSwap a1 $ \a1' -> 
 1009   let {a2' = fromIntegral a2} in 
 1010   preErrorCheck $ \a3' -> 
 1011   startDiscounts'_ a1' a2' a3' >>= \res ->
 1012   let {res' = realToFrac res} in
 1013   errorCheck  a3'>>
 1014   return (res')
 1015 
 1016 
 1017 
 1018 -- |Constructs a cross-currency swap from two legs and their currencies; the first leg is paid, the second received.
 1019 constNotionalCrossCurrencySwap :: (GenLeg l1) -> (Currency) -- ^firstLegCcy
 1020  -> (GenLeg l2) -> (Currency) -- ^secondLegCcy
 1021  -> IO ((ConstNotionalCrossCurrencySwap))
 1022 constNotionalCrossCurrencySwap a1 a2 a3 a4 =
 1023   withLeg a1 $ \a1' -> 
 1024   withCurrency a2 $ \a2' -> 
 1025   withLeg a3 $ \a3' -> 
 1026   withCurrency a4 $ \a4' -> 
 1027   preErrorCheck $ \a5' -> 
 1028   constNotionalCrossCurrencySwap'_ a1' a2' a3' a4' a5' >>= \res ->
 1029   peekConstNotionalCrossCurrencySwap res >>= \res' ->
 1030   errorCheck  a5'>>
 1031   return (res')
 1032 
 1033 
 1034 
 1035 -- |Multi-leg constructor.
 1036 constNotionalCrossCurrencySwapFromLegs :: [(GenLeg l, Bool)] -- ^(legs, payer)
 1037   -> [Currency] -> IO ConstNotionalCrossCurrencySwap
 1038 constNotionalCrossCurrencySwapFromLegs legsPayer = qlConstNotionalCrossCurrencySwap1 legs payer
 1039   where (legs, payer) = unzip legsPayer
 1040 qlConstNotionalCrossCurrencySwap1 :: ([GenLeg l]) -> ([Bool]) -> ([Currency]) -> IO ((ConstNotionalCrossCurrencySwap))
 1041 qlConstNotionalCrossCurrencySwap1 a1 a2 a3 =
 1042   withLegArray a1 $ \(a1'1, a1'2) -> 
 1043   withBoolArray a2 $ \(a2'1, a2'2) -> 
 1044   withCurrencyArray a3 $ \(a3'1, a3'2) -> 
 1045   preErrorCheck $ \a4' -> 
 1046   qlConstNotionalCrossCurrencySwap1'_ a1'1  a1'2 a2'1  a2'2 a3'1  a3'2 a4' >>= \res ->
 1047   peekConstNotionalCrossCurrencySwap res >>= \res' ->
 1048   errorCheck  a4'>>
 1049   return (res')
 1050 
 1051 
 1052 
 1053 -- |Leg j's currency.
 1054 constNotionalLegCurrency :: (GenConstNotionalCrossCurrencySwap x) -> (Word) -> IO ((Currency))
 1055 constNotionalLegCurrency a1 a2 =
 1056   withConstNotionalCrossCurrencySwap a1 $ \a1' -> 
 1057   let {a2' = fromIntegral a2} in 
 1058   preErrorCheck $ \a3' -> 
 1059   constNotionalLegCurrency'_ a1' a2' a3' >>= \res ->
 1060   peekCurrency res >>= \res' ->
 1061   errorCheck  a3'>>
 1062   return (res')
 1063 
 1064 
 1065 
 1066 -- |Basis-point sensitivity of leg j, expressed in the leg's own currency (contrast 'legBps', in the swap's NPV currency).
 1067 constNotionalInCcyLegBPS :: (GenConstNotionalCrossCurrencySwap x) -> (Word) -> IO ((Double))
 1068 constNotionalInCcyLegBPS a1 a2 =
 1069   withConstNotionalCrossCurrencySwap a1 $ \a1' -> 
 1070   let {a2' = fromIntegral a2} in 
 1071   preErrorCheck $ \a3' -> 
 1072   constNotionalInCcyLegBPS'_ a1' a2' a3' >>= \res ->
 1073   let {res' = realToFrac res} in
 1074   errorCheck  a3'>>
 1075   return (res')
 1076 
 1077 
 1078 
 1079 -- |NPV of leg j, expressed in the leg's own currency (contrast 'legNpv', in the swap's NPV currency).
 1080 constNotionalInCcyLegNPV :: (GenConstNotionalCrossCurrencySwap x) -> (Word) -> IO ((Double))
 1081 constNotionalInCcyLegNPV a1 a2 =
 1082   withConstNotionalCrossCurrencySwap a1 $ \a1' -> 
 1083   let {a2' = fromIntegral a2} in 
 1084   preErrorCheck $ \a3' -> 
 1085   constNotionalInCcyLegNPV'_ a1' a2' a3' >>= \res ->
 1086   let {res' = realToFrac res} in
 1087   errorCheck  a3'>>
 1088   return (res')
 1089 
 1090 
 1091 
 1092 -- |Discount factor at the instrument's NPV date, for leg j.
 1093 constNotionalNpvDateDiscounts :: (GenConstNotionalCrossCurrencySwap x) -> (Word) -> IO ((Double))
 1094 constNotionalNpvDateDiscounts a1 a2 =
 1095   withConstNotionalCrossCurrencySwap a1 $ \a1' -> 
 1096   let {a2' = fromIntegral a2} in 
 1097   preErrorCheck $ \a3' -> 
 1098   constNotionalNpvDateDiscounts'_ a1' a2' a3' >>= \res ->
 1099   let {res' = realToFrac res} in
 1100   errorCheck  a3'>>
 1101   return (res')
 1102 
 1103 
 1104 
 1105 -- |Cross-currency basis swap: pay-currency cashflows on leg 0, receive-currency on leg 1.
 1106 -- 'ConstNotionalCrossCurrencyBasisSwapOpts' bundles every trailing param the C++ constructor
 1107 -- defaults (OIS payment lag, compound-spread, lookback, observation shift, lockout,
 1108 -- averaging method per leg, plus a shared telescopic-value-dates flag; ignored for a plain Ibor
 1109 -- 'payIndex'\/'recIndex'). Indexed coupons, lagged notional exchanges and stub selections are
 1110 -- available on QuantLib 1.44; 1.43 accepts only their defaults. Override only what's needed on
 1111 -- 'defaultConstNotionalCrossCurrencyBasisSwapOpts'.
 1112 constNotionalCrossCurrencyBasisSwap :: Double -> Currency -> Schedule -> GenIborIndex ibor1 -> Double -> Double
 1113   -> Double -> Currency -> Schedule -> GenIborIndex ibor2 -> Double -> Double
 1114   -> ConstNotionalCrossCurrencyBasisSwapOpts ibor3 ibor4 -> IO ConstNotionalCrossCurrencyBasisSwap
 1115 constNotionalCrossCurrencyBasisSwap payNominal payCurrency paySchedule payIndex paySpread payGearing
 1116     recNominal recCurrency recSchedule recIndex recSpread recGearing opts =
 1117   constNotionalCrossCurrencyBasisSwap_ payNominal payCurrency paySchedule payIndex paySpread payGearing
 1118     recNominal recCurrency recSchedule recIndex recSpread recGearing
 1119     (cccbsPayPaymentLag opts) (cccbsRecPaymentLag opts)
 1120     (cccbsPayCompoundSpread opts) (lookbackDays payObs) (applyObservationShift payObs)
 1121     (lockoutDays payObs) (cccbsPayAveragingMethod opts)
 1122     (cccbsRecCompoundSpread opts) (lookbackDays recObs) (applyObservationShift recObs)
 1123     (lockoutDays recObs) (cccbsRecAveragingMethod opts)
 1124     (cccbsTelescopicValueDates opts)
 1125     (cccbsUseIndexedCoupons opts) (cccbsPaymentLagOnNotionalExchanges opts)
 1126     (cccbsPayStubIndexSelection opts) (cccbsRecStubIndexSelection opts)
 1127   where payObs = cccbsPayObservation opts
 1128         recObs = cccbsRecObservation opts
 1129 
 1130 constNotionalCrossCurrencyBasisSwap_ :: (Double) -- ^payNominal
 1131  -> (Currency) -- ^payCurrency
 1132  -> (Schedule) -- ^paySchedule
 1133  -> (GenIborIndex ibor1) -- ^payIndex
 1134  -> (Double) -- ^paySpread
 1135  -> (Double) -- ^payGearing
 1136  -> (Double) -- ^recNominal
 1137  -> (Currency) -- ^recCurrency
 1138  -> (Schedule) -- ^recSchedule
 1139  -> (GenIborIndex ibor2) -- ^recIndex
 1140  -> (Double) -- ^recSpread
 1141  -> (Double) -- ^recGearing
 1142  -> (Int) -- ^payPaymentLag
 1143  -> (Int) -- ^recPaymentLag
 1144  -> (Bool) -- ^payCompoundSpread
 1145  -> (Maybe Word) -- ^payLookbackDays
 1146  -> (Bool) -- ^payObservationShift
 1147  -> (Word) -- ^payLockoutDays
 1148  -> (RateAveragingType) -- ^payAveragingMethod
 1149  -> (Bool) -- ^recCompoundSpread
 1150  -> (Maybe Word) -- ^recLookbackDays
 1151  -> (Bool) -- ^recObservationShift
 1152  -> (Word) -- ^recLockoutDays
 1153  -> (RateAveragingType) -- ^recAveragingMethod
 1154  -> (Bool) -- ^telescopicValueDates
 1155  -> (Maybe Bool) -- ^useIndexedCoupons (1.44; QuantLib 1.43 requires 'Nothing')
 1156  -> (Bool) -- ^paymentLagOnNotionalExchanges (1.44; QuantLib 1.43 requires 'False')
 1157  -> (Maybe (StubIndexSelection ibor3)) -- ^payStub (1.44; QuantLib 1.43 requires 'Nothing')
 1158  -> (Maybe (StubIndexSelection ibor4)) -- ^recStub (1.44; QuantLib 1.43 requires 'Nothing')
 1159  -> IO ((ConstNotionalCrossCurrencyBasisSwap))
 1160 constNotionalCrossCurrencyBasisSwap_ a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28 a29 =
 1161   let {a1' = realToFrac a1} in 
 1162   withCurrency a2 $ \a2' -> 
 1163   withSchedule a3 $ \a3' -> 
 1164   withIborIndex a4 $ \a4' -> 
 1165   let {a5' = realToFrac a5} in 
 1166   let {a6' = realToFrac a6} in 
 1167   let {a7' = realToFrac a7} in 
 1168   withCurrency a8 $ \a8' -> 
 1169   withSchedule a9 $ \a9' -> 
 1170   withIborIndex a10 $ \a10' -> 
 1171   let {a11' = realToFrac a11} in 
 1172   let {a12' = realToFrac a12} in 
 1173   let {a13' = fromIntegral a13} in 
 1174   let {a14' = fromIntegral a14} in 
 1175   let {a15' = C2HSImp.fromBool a15} in 
 1176   let {a16' = fromMaybeInt a16} in 
 1177   let {a17' = C2HSImp.fromBool a17} in 
 1178   let {a18' = fromIntegral a18} in 
 1179   let {a19' = (fromIntegral . fromEnum) a19} in 
 1180   let {a20' = C2HSImp.fromBool a20} in 
 1181   let {a21' = fromMaybeInt a21} in 
 1182   let {a22' = C2HSImp.fromBool a22} in 
 1183   let {a23' = fromIntegral a23} in 
 1184   let {a24' = (fromIntegral . fromEnum) a24} in 
 1185   let {a25' = C2HSImp.fromBool a25} in 
 1186   let {a26' = fromMaybeBool a26} in 
 1187   let {a27' = C2HSImp.fromBool a27} in 
 1188   withStubIndexSelection a28 $ \a28' -> 
 1189   withStubIndexSelection a29 $ \a29' -> 
 1190   preErrorCheck $ \a30' -> 
 1191   constNotionalCrossCurrencyBasisSwap_'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' a13' a14' a15' a16' a17' a18' a19' a20' a21' a22' a23' a24' a25' a26' a27' a28' a29' a30' >>= \res ->
 1192   peekConstNotionalCrossCurrencyBasisSwap res >>= \res' ->
 1193   errorCheck  a30'>>
 1194   return (res')
 1195 
 1196 
 1197 
 1198 -- |The pay-leg spread that would make the swap's NPV zero.
 1199 constNotionalFairPaySpread :: (ConstNotionalCrossCurrencyBasisSwap) -> IO ((Double))
 1200 constNotionalFairPaySpread a1 =
 1201   withConstNotionalCrossCurrencyBasisSwap a1 $ \a1' -> 
 1202   preErrorCheck $ \a2' -> 
 1203   constNotionalFairPaySpread'_ a1' a2' >>= \res ->
 1204   let {res' = realToFrac res} in
 1205   errorCheck  a2'>>
 1206   return (res')
 1207 
 1208 
 1209 
 1210 -- |The receive-leg spread that would make the swap's NPV zero.
 1211 constNotionalFairRecSpread :: (ConstNotionalCrossCurrencyBasisSwap) -> IO ((Double))
 1212 constNotionalFairRecSpread a1 =
 1213   withConstNotionalCrossCurrencyBasisSwap a1 $ \a1' -> 
 1214   preErrorCheck $ \a2' -> 
 1215   constNotionalFairRecSpread'_ a1' a2' >>= \res ->
 1216   let {res' = realToFrac res} in
 1217   errorCheck  a2'>>
 1218   return (res')
 1219 
 1220 
 1221 
 1222 -- |Cross-currency fixed-vs-floating swap: 'Payer' pays the fixed leg (leg 0) and receives the
 1223 -- floating leg (leg 1); 'Receiver' the reverse. Every trailing defaulted param of the upstream
 1224 -- constructor is a required argument here (only 4 trailing defaults, under the options-record
 1225 -- threshold -- see 'ConstNotionalCrossCurrencyBasisSwapOpts' above) -- pass @False@\/@False@\/
 1226 -- 'defaultOvernightObservation'\/'AveragingCompound' to reproduce upstream's own defaults; the
 1227 -- OIS-only ones are ignored for a plain Ibor 'floatIndex'.
 1228 --
 1229 -- Upstream declares the three observation parameters as
 1230 -- @floatLookbackDays, floatObservationShift, floatLockoutDays@, inverting the order every
 1231 -- other overnight-leg producer uses; 'OvernightObservation' hides that.
 1232 constNotionalCrossCurrencyFixedVsFloatingSwap :: SwapType
 1233   -> Double -- ^fixedNominal
 1234   -> Currency -- ^fixedCurrency
 1235   -> Schedule -- ^fixedSchedule
 1236   -> Double -- ^fixedRate
 1237   -> DayCounter -- ^fixedDayCount
 1238   -> BusinessDayConvention -- ^fixedPaymentBdc
 1239   -> Word -- ^fixedPaymentLag
 1240   -> Calendar -- ^fixedPaymentCalendar
 1241   -> Double -- ^floatNominal
 1242   -> Currency -- ^floatCurrency
 1243   -> Schedule -- ^floatSchedule
 1244   -> GenIborIndex ibor -- ^floatIndex
 1245   -> Double -- ^floatSpread
 1246   -> BusinessDayConvention -- ^floatPaymentBdc
 1247   -> Word -- ^floatPaymentLag
 1248   -> Calendar -- ^floatPaymentCalendar
 1249   -> Bool -- ^telescopicValueDates
 1250   -> Bool -- ^floatCompoundSpread
 1251   -> OvernightObservation -- ^floatObservation
 1252   -> RateAveragingType -- ^floatAveragingMethod
 1253   -> Maybe Bool -- ^useIndexedCoupons (1.44; QuantLib 1.43 requires 'Nothing')
 1254   -> Maybe (StubIndexSelection ibor2) -- ^floatStubIndexSelection (1.44; QuantLib 1.43 requires 'Nothing')
 1255   -> IO ConstNotionalCrossCurrencyFixedVsFloatingSwap
 1256 constNotionalCrossCurrencyFixedVsFloatingSwap t fxN fxC fxS fxR fxDc fxBdc fxLag fxCal
 1257   flN flC flS flIdx flSprd flBdc flLag flCal telescopic compound obs avg indexed stub =
 1258   constNotionalCrossCurrencyFixedVsFloatingSwapRaw t fxN fxC fxS fxR fxDc fxBdc fxLag fxCal
 1259     flN flC flS flIdx flSprd flBdc flLag flCal telescopic compound
 1260     (lookbackDays obs) (applyObservationShift obs) (lockoutDays obs) avg indexed stub
 1261 
 1262 constNotionalCrossCurrencyFixedVsFloatingSwapRaw :: (SwapType) -> (Double) -- ^fixedNominal
 1263  -> (Currency) -- ^fixedCurrency
 1264  -> (Schedule) -- ^fixedSchedule
 1265  -> (Double) -- ^fixedRate
 1266  -> (DayCounter) -- ^fixedDayCount
 1267  -> (BusinessDayConvention) -- ^fixedPaymentBdc
 1268  -> (Word) -- ^fixedPaymentLag
 1269  -> (Calendar) -- ^fixedPaymentCalendar
 1270  -> (Double) -- ^floatNominal
 1271  -> (Currency) -- ^floatCurrency
 1272  -> (Schedule) -- ^floatSchedule
 1273  -> (GenIborIndex ibor) -- ^floatIndex
 1274  -> (Double) -- ^floatSpread
 1275  -> (BusinessDayConvention) -- ^floatPaymentBdc
 1276  -> (Word) -- ^floatPaymentLag
 1277  -> (Calendar) -- ^floatPaymentCalendar
 1278  -> (Bool) -- ^telescopicValueDates
 1279  -> (Bool) -- ^floatCompoundSpread
 1280  -> (Maybe Word) -- ^floatLookbackDays
 1281  -> (Bool) -- ^floatObservationShift
 1282  -> (Word) -- ^floatLockoutDays
 1283  -> (RateAveragingType) -- ^floatAveragingMethod
 1284  -> (Maybe Bool) -- ^useIndexedCoupons (1.44; QuantLib 1.43 requires 'Nothing')
 1285  -> (Maybe (StubIndexSelection ibor2)) -- ^floatStub (1.44; QuantLib 1.43 requires 'Nothing')
 1286  -> IO ((ConstNotionalCrossCurrencyFixedVsFloatingSwap))
 1287 constNotionalCrossCurrencyFixedVsFloatingSwapRaw a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 =
 1288   let {a1' = (fromIntegral . fromEnum) a1} in 
 1289   let {a2' = realToFrac a2} in 
 1290   withCurrency a3 $ \a3' -> 
 1291   withSchedule a4 $ \a4' -> 
 1292   let {a5' = realToFrac a5} in 
 1293   withDayCounter a6 $ \a6' -> 
 1294   let {a7' = fromEnumC a7} in 
 1295   let {a8' = fromIntegral a8} in 
 1296   withCalendar a9 $ \a9' -> 
 1297   let {a10' = realToFrac a10} in 
 1298   withCurrency a11 $ \a11' -> 
 1299   withSchedule a12 $ \a12' -> 
 1300   withIborIndex a13 $ \a13' -> 
 1301   let {a14' = realToFrac a14} in 
 1302   let {a15' = fromEnumC a15} in 
 1303   let {a16' = fromIntegral a16} in 
 1304   withCalendar a17 $ \a17' -> 
 1305   let {a18' = C2HSImp.fromBool a18} in 
 1306   let {a19' = C2HSImp.fromBool a19} in 
 1307   let {a20' = fromMaybeInt a20} in 
 1308   let {a21' = C2HSImp.fromBool a21} in 
 1309   let {a22' = fromIntegral a22} in 
 1310   let {a23' = (fromIntegral . fromEnum) a23} in 
 1311   let {a24' = fromMaybeBool a24} in 
 1312   withStubIndexSelection a25 $ \a25' -> 
 1313   preErrorCheck $ \a26' -> 
 1314   constNotionalCrossCurrencyFixedVsFloatingSwapRaw'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' a13' a14' a15' a16' a17' a18' a19' a20' a21' a22' a23' a24' a25' a26' >>= \res ->
 1315   peekConstNotionalCrossCurrencyFixedVsFloatingSwap res >>= \res' ->
 1316   errorCheck  a26'>>
 1317   return (res')
 1318 
 1319 
 1320 
 1321 -- |The fixed rate that would make the swap's NPV zero.
 1322 qlConstNotionalCrossCurrencyFixedVsFloatingSwapFairRate :: (ConstNotionalCrossCurrencyFixedVsFloatingSwap) -> IO ((Double))
 1323 qlConstNotionalCrossCurrencyFixedVsFloatingSwapFairRate a1 =
 1324   withConstNotionalCrossCurrencyFixedVsFloatingSwap a1 $ \a1' -> 
 1325   preErrorCheck $ \a2' -> 
 1326   qlConstNotionalCrossCurrencyFixedVsFloatingSwapFairRate'_ a1' a2' >>= \res ->
 1327   let {res' = realToFrac res} in
 1328   errorCheck  a2'>>
 1329   return (res')
 1330 
 1331 
 1332 
 1333 instance HasFairRate ConstNotionalCrossCurrencyFixedVsFloatingSwap where
 1334   fairRate = qlConstNotionalCrossCurrencyFixedVsFloatingSwapFairRate
 1335 instance HasFairSpread ConstNotionalCrossCurrencyFixedVsFloatingSwap where
 1336   fairSpread = qlConstNotionalCrossCurrencyFixedVsFloatingSwapFairSpread
 1337 qlConstNotionalCrossCurrencyFixedVsFloatingSwapFairSpread :: (ConstNotionalCrossCurrencyFixedVsFloatingSwap) -> IO ((Double))
 1338 qlConstNotionalCrossCurrencyFixedVsFloatingSwapFairSpread a1 =
 1339   withConstNotionalCrossCurrencyFixedVsFloatingSwap a1 $ \a1' -> 
 1340   preErrorCheck $ \a2' -> 
 1341   qlConstNotionalCrossCurrencyFixedVsFloatingSwapFairSpread'_ a1' a2' >>= \res ->
 1342   let {res' = realToFrac res} in
 1343   errorCheck  a2'>>
 1344   return (res')
 1345 
 1346 
 1347 
 1348 -- |An option on a 'VanillaSwap' or an 'OvernightIndexedSwap'; the latter requires QuantLib 1.44.
 1349 -- The Gaussian1d swaption engines then compound overnight coupons exactly, approximate lookback
 1350 -- without observation shift and lockout, and do not support arithmetic averaging.
 1351 swaption :: (GenFixedVsFloatingSwap f) -> (Exercise) -> (SettlementType) -> (SettlementMethod) -> IO ((Swaption))
 1352 swaption a1 a2 a3 a4 =
 1353   withFixedVsFloatingSwap a1 $ \a1' -> 
 1354   withExercise a2 $ \a2' -> 
 1355   let {a3' = (fromIntegral . fromEnum) a3} in 
 1356   let {a4' = (fromIntegral . fromEnum) a4} in 
 1357   preErrorCheck $ \a5' -> 
 1358   swaption'_ a1' a2' a3' a4' a5' >>= \res ->
 1359   peekSwaption res >>= \res' ->
 1360   errorCheck  a5'>>
 1361   return (res')
 1362 
 1363 
 1364 
 1365 -- |A priceable option on an 'IrregularSwap'.  Use 'haganIrregularSwaptionEngine'
 1366 -- as its pricing engine; QuantLib has no corresponding stock IrregularSwap engine.
 1367 irregularSwaption :: (IrregularSwap) -> (Exercise) -> (IrregularSettlementType) -> IO ((IrregularSwaption))
 1368 irregularSwaption a1 a2 a3 =
 1369   withIrregularSwap a1 $ \a1' -> 
 1370   withExercise a2 $ \a2' -> 
 1371   let {a3' = fromEnumC a3} in 
 1372   preErrorCheck $ \a4' -> 
 1373   irregularSwaption'_ a1' a2' a3' a4' >>= \res ->
 1374   peekIrregularSwaption res >>= \res' ->
 1375   errorCheck  a4'>>
 1376   return (res')
 1377 
 1378 
 1379 irregularSwap :: (SwapType) -> (GenLeg fixed) -> (GenLeg float) -> IO ((IrregularSwap))
 1380 irregularSwap a1 a2 a3 =
 1381   let {a1' = (fromIntegral . fromEnum) a1} in 
 1382   withLeg a2 $ \a2' -> 
 1383   withLeg a3 $ \a3' -> 
 1384   preErrorCheck $ \a4' -> 
 1385   irregularSwap'_ a1' a2' a3' a4' >>= \res ->
 1386   peekIrregularSwap res >>= \res' ->
 1387   errorCheck  a4'>>
 1388   return (res')
 1389 
 1390 
 1391 qlIrregularSwapFairRate :: (IrregularSwap) -> IO ((Double))
 1392 qlIrregularSwapFairRate a1 =
 1393   withIrregularSwap a1 $ \a1' -> 
 1394   preErrorCheck $ \a2' -> 
 1395   qlIrregularSwapFairRate'_ a1' a2' >>= \res ->
 1396   let {res' = realToFrac res} in
 1397   errorCheck  a2'>>
 1398   return (res')
 1399 
 1400 
 1401 qlIrregularSwapFairSpread :: (IrregularSwap) -> IO ((Double))
 1402 qlIrregularSwapFairSpread a1 =
 1403   withIrregularSwap a1 $ \a1' -> 
 1404   preErrorCheck $ \a2' -> 
 1405   qlIrregularSwapFairSpread'_ a1' a2' >>= \res ->
 1406   let {res' = realToFrac res} in
 1407   errorCheck  a2'>>
 1408   return (res')
 1409 
 1410 
 1411 
 1412 -- |Converts an existing 'Swaption' into a 'NonstandardSwaption' (upstream's own conversion
 1413 -- constructor).
 1414 nonstandardSwaptionFromSwaption :: (Swaption) -> IO ((NonstandardSwaption))
 1415 nonstandardSwaptionFromSwaption a1 =
 1416   withSwaption a1 $ \a1' -> 
 1417   preErrorCheck $ \a2' -> 
 1418   nonstandardSwaptionFromSwaption'_ a1' a2' >>= \res ->
 1419   peekNonstandardSwaption res >>= \res' ->
 1420   errorCheck  a2'>>
 1421   return (res')
 1422 
 1423 
 1424 
 1425 -- |An option on a 'NonstandardSwap'.
 1426 nonstandardSwaption :: (NonstandardSwap) -> (Exercise) -> (SettlementType) -> (SettlementMethod) -> IO ((NonstandardSwaption))
 1427 nonstandardSwaption a1 a2 a3 a4 =
 1428   withNonstandardSwap a1 $ \a1' -> 
 1429   withExercise a2 $ \a2' -> 
 1430   let {a3' = (fromIntegral . fromEnum) a3} in 
 1431   let {a4' = (fromIntegral . fromEnum) a4} in 
 1432   preErrorCheck $ \a5' -> 
 1433   nonstandardSwaption'_ a1' a2' a3' a4' a5' >>= \res ->
 1434   peekNonstandardSwaption res >>= \res' ->
 1435   errorCheck  a5'>>
 1436   return (res')
 1437 
 1438 
 1439 
 1440 -- |Auto-generates a basket of plain 'Swaption's used to calibrate a model to price a
 1441 -- 'NonstandardSwaption' -- either ATM swaptions adapted to the exercise dates ('Naive') or
 1442 -- swaptions whose maturity\/strike\/nominal match the underlying's NPV, delta and gamma at each
 1443 -- exercise date ('MaturityStrikeByDeltaGamma').
 1444 calibrationBasket :: (NonstandardSwaption) -> (GenSwapIndex sidx) -- ^standardSwapBase
 1445  -> (GenSwaptionVolatilityStructure sv) -- ^swaptionVolatility
 1446  -> (CalibrationBasketType) -> IO (([BlackCalibrationHelper]))
 1447 calibrationBasket a1 a2 a3 a4 =
 1448   withNonstandardSwaption a1 $ \a1' -> 
 1449   withSwapIndex a2 $ \a2' -> 
 1450   withSwaptionVolatilityStructure a3 $ \a3' -> 
 1451   let {a4' = fromEnumC a4} in 
 1452   preBlackCalibrationHelperArray $ \(a5'1, a5'2) -> 
 1453   preErrorCheck $ \a6' -> 
 1454   calibrationBasket'_ a1' a2' a3' a4' a5'1  a5'2 a6' >>
 1455   peekBlackCalibrationHelperArray  a5'1  a5'2>>= \a5'' -> 
 1456   errorCheck  a6'>>
 1457   return (a5'')
 1458 
 1459 
 1460 
 1461 -- |An option on a 'FloatFloatSwap'.
 1462 floatFloatSwaption :: (FloatFloatSwap) -> (Exercise) -> (SettlementType) -> (SettlementMethod) -> IO ((FloatFloatSwaption))
 1463 floatFloatSwaption a1 a2 a3 a4 =
 1464   withFloatFloatSwap a1 $ \a1' -> 
 1465   withExercise a2 $ \a2' -> 
 1466   let {a3' = (fromIntegral . fromEnum) a3} in 
 1467   let {a4' = (fromIntegral . fromEnum) a4} in 
 1468   preErrorCheck $ \a5' -> 
 1469   floatFloatSwaption'_ a1' a2' a3' a4' a5' >>= \res ->
 1470   peekFloatFloatSwaption res >>= \res' ->
 1471   errorCheck  a5'>>
 1472   return (res')
 1473 
 1474 
 1475 
 1476 -- |As 'calibrationBasket', for a 'FloatFloatSwaption'.
 1477 floatFloatSwaptionCalibrationBasket :: (FloatFloatSwaption) -> (GenSwapIndex sidx) -- ^standardSwapBase
 1478  -> (GenSwaptionVolatilityStructure sv) -- ^swaptionVolatility
 1479  -> (CalibrationBasketType) -> IO (([BlackCalibrationHelper]))
 1480 floatFloatSwaptionCalibrationBasket a1 a2 a3 a4 =
 1481   withFloatFloatSwaption a1 $ \a1' -> 
 1482   withSwapIndex a2 $ \a2' -> 
 1483   withSwaptionVolatilityStructure a3 $ \a3' -> 
 1484   let {a4' = fromEnumC a4} in 
 1485   preBlackCalibrationHelperArray $ \(a5'1, a5'2) -> 
 1486   preErrorCheck $ \a6' -> 
 1487   floatFloatSwaptionCalibrationBasket'_ a1' a2' a3' a4' a5'1  a5'2 a6' >>
 1488   peekBlackCalibrationHelperArray  a5'1  a5'2>>= \a5'' -> 
 1489   errorCheck  a6'>>
 1490   return (a5'')
 1491 
 1492 
 1493 
 1494 -- |Bullet bond vs Libor swap (par or market asset swap, per /parAssetSwap/).
 1495 assetSwap :: (Bool) -- ^payBondCoupon
 1496  -> (GenBond b) -> (Double) -- ^bondCleanPrice
 1497  -> (GenIborIndex ibor) -> (Double) -- spread
 1498  -> (Schedule) -- ^floatSchedule
 1499  -> (DayCounter) -- ^floatingDayCount
 1500  -> (Bool) -- ^parAssetSwap
 1501  -> (Double) -- ^gearing
 1502  -> (Maybe Double) -- ^nonParRepayment
 1503  -> (Maybe Day) -- ^dealMaturity
 1504  -> IO ((AssetSwap))
 1505 assetSwap a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 =
 1506   let {a1' = C2HSImp.fromBool a1} in 
 1507   withBond a2 $ \a2' -> 
 1508   let {a3' = realToFrac a3} in 
 1509   withIborIndex a4 $ \a4' -> 
 1510   let {a5' = realToFrac a5} in 
 1511   withSchedule a6 $ \a6' -> 
 1512   withDayCounter a7 $ \a7' -> 
 1513   let {a8' = C2HSImp.fromBool a8} in 
 1514   let {a9' = realToFrac a9} in 
 1515   let {a10' = fromMaybeDouble a10} in 
 1516   withMaybeDay a11 $ \a11' -> 
 1517   preErrorCheck $ \a12' -> 
 1518   assetSwap'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' >>= \res ->
 1519   peekAssetSwap res >>= \res' ->
 1520   errorCheck  a12'>>
 1521   return (res')
 1522 
 1523 
 1524 
 1525 -- |Fixed vs compounded-overnight-rate swap, with a single flat nominal for both legs.
 1526 overnightIndexedSwap :: SwapType
 1527   -> Double -- ^nominal
 1528   -> Schedule
 1529   -> Double -- ^fixedRate
 1530   -> DayCounter -- ^fixedDC
 1531   -> OvernightIborIndex
 1532   -> Double -- ^spread
 1533   -> Int -- ^paymentLag
 1534   -> BusinessDayConvention -- ^paymentAdjustment
 1535   -> Calendar -- ^paymentCalendar
 1536   -> Bool -- ^telescopicValueDates
 1537   -> RateAveragingType -- ^averagingMethod
 1538   -> OvernightObservation
 1539   -> Maybe Int -- ^roundingPrecision (1.44; QuantLib 1.43 requires 'Nothing')
 1540   -> IO OvernightIndexedSwap
 1541 overnightIndexedSwap t n sch r dc idx sprd lag adj cal telescopic avg obs precision =
 1542   overnightIndexedSwapRaw t n sch r dc idx sprd lag adj cal telescopic avg
 1543     (lookbackDays obs) (lockoutDays obs) (applyObservationShift obs) precision
 1544 
 1545 overnightIndexedSwapRaw :: (SwapType) -> (Double) -- ^nominal
 1546  -> (Schedule) -> (Double) -- ^fixedRate
 1547  -> (DayCounter) -- ^fixedDC
 1548  -> (OvernightIborIndex) -> (Double) -- ^spread
 1549  -> (Int) -- ^paymentLag
 1550  -> (BusinessDayConvention) -- ^paymentAdjustment
 1551  -> (Calendar) -- ^paymentCalendar
 1552  -> (Bool) -- ^telescopicValueDates
 1553  -> (RateAveragingType) -- ^averagingMethod
 1554  -> (Maybe Word) -- ^lookbackDays
 1555  -> (Word) -- ^lockoutDays
 1556  -> (Bool) -- ^applyObservationShift
 1557  -> (Maybe Int) -- ^roundingPrecision (1.44; QuantLib 1.43 requires 'Nothing')
 1558  -> IO ((OvernightIndexedSwap))
 1559 overnightIndexedSwapRaw a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 =
 1560   let {a1' = (fromIntegral . fromEnum) a1} in 
 1561   let {a2' = realToFrac a2} in 
 1562   withSchedule a3 $ \a3' -> 
 1563   let {a4' = realToFrac a4} in 
 1564   withDayCounter a5 $ \a5' -> 
 1565   withOvernightIborIndex a6 $ \a6' -> 
 1566   let {a7' = realToFrac a7} in 
 1567   let {a8' = fromIntegral a8} in 
 1568   let {a9' = fromEnumC a9} in 
 1569   withCalendar a10 $ \a10' -> 
 1570   let {a11' = C2HSImp.fromBool a11} in 
 1571   let {a12' = (fromIntegral . fromEnum) a12} in 
 1572   let {a13' = fromMaybeInt a13} in 
 1573   let {a14' = fromIntegral a14} in 
 1574   let {a15' = C2HSImp.fromBool a15} in 
 1575   let {a16' = fromMaybeInt a16} in 
 1576   preErrorCheck $ \a17' -> 
 1577   overnightIndexedSwapRaw'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' a13' a14' a15' a16' a17' >>= \res ->
 1578   peekOvernightIndexedSwap res >>= \res' ->
 1579   errorCheck  a17'>>
 1580   return (res')
 1581 
 1582 
 1583 
 1584 -- |As 'overnightIndexedSwap', but with a per-period nominal schedule instead of a single flat nominal.
 1585 overnightIndexedSwapFromNominals :: SwapType
 1586   -> [Double] -- ^nominals
 1587   -> Schedule
 1588   -> Double -- ^fixedRate
 1589   -> DayCounter -- ^fixedDC
 1590   -> OvernightIborIndex
 1591   -> Double -- ^spread
 1592   -> Int -- ^paymentLag
 1593   -> BusinessDayConvention -- ^paymentAdjustment
 1594   -> Calendar -- ^paymentCalendar
 1595   -> Bool -- ^telescopicValueDates
 1596   -> RateAveragingType -- ^averagingMethod
 1597   -> OvernightObservation
 1598   -> Maybe Int -- ^roundingPrecision (1.44; QuantLib 1.43 requires 'Nothing')
 1599   -> IO OvernightIndexedSwap
 1600 overnightIndexedSwapFromNominals t ns sch r dc idx sprd lag adj cal telescopic avg obs precision =
 1601   overnightIndexedSwapFromNominalsRaw t ns sch r dc idx sprd lag adj cal telescopic avg
 1602     (lookbackDays obs) (lockoutDays obs) (applyObservationShift obs) precision
 1603 
 1604 overnightIndexedSwapFromNominalsRaw :: (SwapType) -> ([Double]) -- ^nominals
 1605  -> (Schedule) -- ^schedule
 1606  -> (Double) -- ^fixedRate
 1607  -> (DayCounter) -- ^fixedDC
 1608  -> (OvernightIborIndex) -> (Double) -- ^spread
 1609  -> (Int) -- ^paymentLag
 1610  -> (BusinessDayConvention) -- ^paymentAdjustment
 1611  -> (Calendar) -- ^paymentCalendar
 1612  -> (Bool) -- ^telescopicValueDates
 1613  -> (RateAveragingType) -- ^averagingMethod
 1614  -> (Maybe Word) -- ^lookbackDays
 1615  -> (Word) -- ^lockoutDays
 1616  -> (Bool) -- ^applyObservationShift
 1617  -> (Maybe Int) -- ^roundingPrecision (1.44; QuantLib 1.43 requires 'Nothing')
 1618  -> IO ((OvernightIndexedSwap))
 1619 overnightIndexedSwapFromNominalsRaw a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 =
 1620   let {a1' = (fromIntegral . fromEnum) a1} in 
 1621   withDoubleArray a2 $ \(a2'1, a2'2) -> 
 1622   withSchedule a3 $ \a3' -> 
 1623   let {a4' = realToFrac a4} in 
 1624   withDayCounter a5 $ \a5' -> 
 1625   withOvernightIborIndex a6 $ \a6' -> 
 1626   let {a7' = realToFrac a7} in 
 1627   let {a8' = fromIntegral a8} in 
 1628   let {a9' = fromEnumC a9} in 
 1629   withCalendar a10 $ \a10' -> 
 1630   let {a11' = C2HSImp.fromBool a11} in 
 1631   let {a12' = (fromIntegral . fromEnum) a12} in 
 1632   let {a13' = fromMaybeInt a13} in 
 1633   let {a14' = fromIntegral a14} in 
 1634   let {a15' = C2HSImp.fromBool a15} in 
 1635   let {a16' = fromMaybeInt a16} in 
 1636   preErrorCheck $ \a17' -> 
 1637   overnightIndexedSwapFromNominalsRaw'_ a1' a2'1  a2'2 a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' a13' a14' a15' a16' a17' >>= \res ->
 1638   peekOvernightIndexedSwap res >>= \res' ->
 1639   errorCheck  a17'>>
 1640   return (res')
 1641 
 1642 
 1643 
 1644 -- |The swap's maturity date, or 'Nothing' if the swap has no legs.
 1645 maturityDate :: (GenSwap s) -> IO (((Maybe Day)))
 1646 maturityDate a1 =
 1647   withSwap a1 $ \a1' -> 
 1648   preErrorCheck $ \a2' -> 
 1649   maturityDate'_ a1' a2' >>= \res ->
 1650   let {res' = toMaybeDay res} in
 1651   errorCheck  a2'>>
 1652   return (res')
 1653 
 1654 
 1655 
 1656 -- |The swap's start date, or 'Nothing' if the swap has no legs.
 1657 startDate :: (GenSwap s) -> IO (((Maybe Day)))
 1658 startDate a1 =
 1659   withSwap a1 $ \a1' -> 
 1660   preErrorCheck $ \a2' -> 
 1661   startDate'_ a1' a2' >>= \res ->
 1662   let {res' = toMaybeDay res} in
 1663   errorCheck  a2'>>
 1664   return (res')
 1665 
 1666 
 1667 
 1668 -- |Discount factor at the instrument's NPV date.
 1669 npvDateDiscount :: (GenSwap s) -> IO ((Double))
 1670 npvDateDiscount a1 =
 1671   withSwap a1 $ \a1' -> 
 1672   preErrorCheck $ \a2' -> 
 1673   npvDateDiscount'_ a1' a2' >>= \res ->
 1674   let {res' = realToFrac res} in
 1675   errorCheck  a2'>>
 1676   return (res')
 1677 
 1678 
 1679 
 1680 -- |The BMA leg's cash flows.
 1681 bmaLeg :: (BMASwap) -> IO ((Leg))
 1682 bmaLeg a1 =
 1683   withBMASwap a1 $ \a1' -> 
 1684   preErrorCheck $ \a2' -> 
 1685   bmaLeg'_ a1' a2' >>= \res ->
 1686   peekLeg res >>= \res' ->
 1687   errorCheck  a2'>>
 1688   return (res')
 1689 
 1690 
 1691 
 1692 -- |Basis-point sensitivity of the BMA leg.
 1693 bmaLegBps :: (BMASwap) -> IO ((Double))
 1694 bmaLegBps a1 =
 1695   withBMASwap a1 $ \a1' -> 
 1696   preErrorCheck $ \a2' -> 
 1697   bmaLegBps'_ a1' a2' >>= \res ->
 1698   let {res' = realToFrac res} in
 1699   errorCheck  a2'>>
 1700   return (res')
 1701 
 1702 
 1703 
 1704 -- |NPV of the BMA leg.
 1705 bmaLegNpv :: (BMASwap) -> IO ((Double))
 1706 bmaLegNpv a1 =
 1707   withBMASwap a1 $ \a1' -> 
 1708   preErrorCheck $ \a2' -> 
 1709   bmaLegNpv'_ a1' a2' >>= \res ->
 1710   let {res' = realToFrac res} in
 1711   errorCheck  a2'>>
 1712   return (res')
 1713 
 1714 
 1715 
 1716 -- |The Libor fraction that would make the swap's NPV zero.
 1717 fairLiborFraction :: (BMASwap) -> IO ((Double))
 1718 fairLiborFraction a1 =
 1719   withBMASwap a1 $ \a1' -> 
 1720   preErrorCheck $ \a2' -> 
 1721   fairLiborFraction'_ a1' a2' >>= \res ->
 1722   let {res' = realToFrac res} in
 1723   errorCheck  a2'>>
 1724   return (res')
 1725 
 1726 
 1727 
 1728 -- |The Libor spread that would make the swap's NPV zero.
 1729 fairLiborSpread :: (BMASwap) -> IO ((Double))
 1730 fairLiborSpread a1 =
 1731   withBMASwap a1 $ \a1' -> 
 1732   preErrorCheck $ \a2' -> 
 1733   fairLiborSpread'_ a1' a2' >>= \res ->
 1734   let {res' = realToFrac res} in
 1735   errorCheck  a2'>>
 1736   return (res')
 1737 
 1738 
 1739 
 1740 -- |The fraction of the Libor rate paid on the Libor leg.
 1741 liborFraction :: (BMASwap) -> IO ((Double))
 1742 liborFraction a1 =
 1743   withBMASwap a1 $ \a1' -> 
 1744   preErrorCheck $ \a2' -> 
 1745   liborFraction'_ a1' a2' >>= \res ->
 1746   let {res' = realToFrac res} in
 1747   errorCheck  a2'>>
 1748   return (res')
 1749 
 1750 
 1751 
 1752 -- |The Libor leg's cash flows.
 1753 liborLeg :: (BMASwap) -> IO ((Leg))
 1754 liborLeg a1 =
 1755   withBMASwap a1 $ \a1' -> 
 1756   preErrorCheck $ \a2' -> 
 1757   liborLeg'_ a1' a2' >>= \res ->
 1758   peekLeg res >>= \res' ->
 1759   errorCheck  a2'>>
 1760   return (res')
 1761 
 1762 
 1763 
 1764 -- |Basis-point sensitivity of the Libor leg.
 1765 liborLegBps :: (BMASwap) -> IO ((Double))
 1766 liborLegBps a1 =
 1767   withBMASwap a1 $ \a1' -> 
 1768   preErrorCheck $ \a2' -> 
 1769   liborLegBps'_ a1' a2' >>= \res ->
 1770   let {res' = realToFrac res} in
 1771   errorCheck  a2'>>
 1772   return (res')
 1773 
 1774 
 1775 
 1776 -- |NPV of the Libor leg.
 1777 liborLegNpv :: (BMASwap) -> IO ((Double))
 1778 liborLegNpv a1 =
 1779   withBMASwap a1 $ \a1' -> 
 1780   preErrorCheck $ \a2' -> 
 1781   liborLegNpv'_ a1' a2' >>= \res ->
 1782   let {res' = realToFrac res} in
 1783   errorCheck  a2'>>
 1784   return (res')
 1785 
 1786 
 1787 
 1788 -- |The underlying bond's cash flows.
 1789 bondLeg :: (AssetSwap) -> IO ((Leg))
 1790 bondLeg a1 =
 1791   withAssetSwap a1 $ \a1' -> 
 1792   preErrorCheck $ \a2' -> 
 1793   bondLeg'_ a1' a2' >>= \res ->
 1794   peekLeg res >>= \res' ->
 1795   errorCheck  a2'>>
 1796   return (res')
 1797 
 1798 
 1799 
 1800 -- |The bond's clean price, as passed to the constructor.
 1801 cleanPrice :: (AssetSwap) -> IO ((Double))
 1802 cleanPrice a1 =
 1803   withAssetSwap a1 $ \a1' -> 
 1804   preErrorCheck $ \a2' -> 
 1805   cleanPrice'_ a1' a2' >>= \res ->
 1806   let {res' = realToFrac res} in
 1807   errorCheck  a2'>>
 1808   return (res')
 1809 
 1810 
 1811 
 1812 -- |The clean price that would make the swap's NPV zero.
 1813 fairCleanPrice :: (AssetSwap) -> IO ((Double))
 1814 fairCleanPrice a1 =
 1815   withAssetSwap a1 $ \a1' -> 
 1816   preErrorCheck $ \a2' -> 
 1817   fairCleanPrice'_ a1' a2' >>= \res ->
 1818   let {res' = realToFrac res} in
 1819   errorCheck  a2'>>
 1820   return (res')
 1821 
 1822 
 1823 
 1824 -- |The non-par repayment that would make the swap's NPV zero.
 1825 fairNonParRepayment :: (AssetSwap) -> IO ((Double))
 1826 fairNonParRepayment a1 =
 1827   withAssetSwap a1 $ \a1' -> 
 1828   preErrorCheck $ \a2' -> 
 1829   fairNonParRepayment'_ a1' a2' >>= \res ->
 1830   let {res' = realToFrac res} in
 1831   errorCheck  a2'>>
 1832   return (res')
 1833 
 1834 
 1835 
 1836 -- |The non-par repayment, as passed to the constructor.
 1837 nonParRepayment :: (AssetSwap) -> IO ((Double))
 1838 nonParRepayment a1 =
 1839   withAssetSwap a1 $ \a1' -> 
 1840   preErrorCheck $ \a2' -> 
 1841   nonParRepayment'_ a1' a2' >>= \res ->
 1842   let {res' = realToFrac res} in
 1843   errorCheck  a2'>>
 1844   return (res')
 1845 
 1846 
 1847 
 1848 -- |Whether this is a par asset swap.
 1849 parSwap :: (AssetSwap) -> IO ((Bool))
 1850 parSwap a1 =
 1851   withAssetSwap a1 $ \a1' -> 
 1852   preErrorCheck $ \a2' -> 
 1853   parSwap'_ a1' a2' >>= \res ->
 1854   let {res' = C2HSImp.toBool res} in
 1855   errorCheck  a2'>>
 1856   return (res')
 1857 
 1858 
 1859 
 1860 -- |Whether the bond coupon is paid (rather than netted against the floating leg).
 1861 payBondCoupon :: (AssetSwap) -> IO ((Bool))
 1862 payBondCoupon a1 =
 1863   withAssetSwap a1 $ \a1' -> 
 1864   preErrorCheck $ \a2' -> 
 1865   payBondCoupon'_ a1' a2' >>= \res ->
 1866   let {res' = C2HSImp.toBool res} in
 1867   errorCheck  a2'>>
 1868   return (res')
 1869 
 1870 
 1871 
 1872 -- |The overnight leg's cash flows.
 1873 overnightLeg :: (OvernightIndexedSwap) -> IO ((Leg))
 1874 overnightLeg a1 =
 1875   withOvernightIndexedSwap a1 $ \a1' -> 
 1876   preErrorCheck $ \a2' -> 
 1877   overnightLeg'_ a1' a2' >>= \res ->
 1878   peekLeg res >>= \res' ->
 1879   errorCheck  a2'>>
 1880   return (res')
 1881 
 1882 
 1883 
 1884 -- |Basis-point sensitivity of the overnight leg.
 1885 overnightLegBps :: (OvernightIndexedSwap) -> IO ((Double))
 1886 overnightLegBps a1 =
 1887   withOvernightIndexedSwap a1 $ \a1' -> 
 1888   preErrorCheck $ \a2' -> 
 1889   overnightLegBps'_ a1' a2' >>= \res ->
 1890   let {res' = realToFrac res} in
 1891   errorCheck  a2'>>
 1892   return (res')
 1893 
 1894 
 1895 
 1896 -- |NPV of the overnight leg.
 1897 overnightLegNpv :: (OvernightIndexedSwap) -> IO ((Double))
 1898 overnightLegNpv a1 =
 1899   withOvernightIndexedSwap a1 $ \a1' -> 
 1900   preErrorCheck $ \a2' -> 
 1901   overnightLegNpv'_ a1' a2' >>= \res ->
 1902   let {res' = realToFrac res} in
 1903   errorCheck  a2'>>
 1904   return (res')
 1905 
 1906 
 1907 
 1908 -- |A zero-coupon inflation-indexed swap (ZCIIS): a single fixed-vs-CPI-ratio exchange at
 1909 -- maturity. Per-leg NPV\/BPS use the generic 'leg'\/'legNpv'\/'legBps' (leg 0 = fixed, leg 1 =
 1910 -- inflation).
 1911 zeroCouponInflationSwap :: (SwapType) -> (Double) -- ^nominal
 1912  -> (Day) -- ^startDate
 1913  -> (Day) -- ^maturity
 1914  -> (Calendar) -> (BusinessDayConvention) -- ^paymentConvention
 1915  -> (DayCounter) -> (Double) -- ^fixedRate
 1916  -> (GenZeroInflationIndex zidx) -> ((Word,TimeUnit)) -- ^observationLag
 1917  -> (CPIInterpolationType) -- ^observationInterpolation
 1918  -> (Bool) -- ^adjustInfObsDates
 1919  -> (Calendar) -- ^infCalendar
 1920  -> (BusinessDayConvention) -- ^infConvention
 1921  -> IO ((ZeroCouponInflationSwap))
 1922 zeroCouponInflationSwap a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 =
 1923   let {a1' = (fromIntegral . fromEnum) a1} in 
 1924   let {a2' = realToFrac a2} in 
 1925   withDay a3 $ \a3' -> 
 1926   withDay a4 $ \a4' -> 
 1927   withCalendar a5 $ \a5' -> 
 1928   let {a6' = fromEnumC a6} in 
 1929   withDayCounter a7 $ \a7' -> 
 1930   let {a8' = realToFrac a8} in 
 1931   withZeroInflationIndex a9 $ \a9' -> 
 1932   let {(a10'1, a10'2) = fromEnumQuantity a10} in 
 1933   let {a11' = fromEnumC a11} in 
 1934   let {a12' = C2HSImp.fromBool a12} in 
 1935   withCalendar a13 $ \a13' -> 
 1936   let {a14' = fromEnumC a14} in 
 1937   preErrorCheck $ \a15' -> 
 1938   zeroCouponInflationSwap'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10'1  a10'2 a11' a12' a13' a14' a15' >>= \res ->
 1939   peekZeroCouponInflationSwap res >>= \res' ->
 1940   errorCheck  a15'>>
 1941   return (res')
 1942 
 1943 
 1944 
 1945 -- |The fixed rate that would make the swap's NPV zero.
 1946 qlZeroCouponInflationSwapFairRate :: (ZeroCouponInflationSwap) -> IO ((Double))
 1947 qlZeroCouponInflationSwapFairRate a1 =
 1948   withZeroCouponInflationSwap a1 $ \a1' -> 
 1949   preErrorCheck $ \a2' -> 
 1950   qlZeroCouponInflationSwapFairRate'_ a1' a2' >>= \res ->
 1951   let {res' = realToFrac res} in
 1952   errorCheck  a2'>>
 1953   return (res')
 1954 
 1955 
 1956 
 1957 -- |A year-on-year inflation-indexed swap: fixed leg vs a YoY-inflation-linked leg. Per-leg
 1958 -- NPV\/BPS use the generic 'leg'\/'legNpv'\/'legBps' (leg 0 = fixed, leg 1 = YoY).
 1959 yearOnYearInflationSwap :: (SwapType) -> (Double) -- ^nominal
 1960  -> (Schedule) -- ^fixedSchedule
 1961  -> (Double) -- ^fixedRate
 1962  -> (DayCounter) -- ^fixedDayCount
 1963  -> (Schedule) -- ^yoySchedule
 1964  -> (GenYoYInflationIndex yidx) -> ((Word,TimeUnit)) -- ^observationLag
 1965  -> (CPIInterpolationType) -- ^interpolation
 1966  -> (Double) -- ^spread
 1967  -> (DayCounter) -- ^yoyDayCount
 1968  -> (Calendar) -- ^paymentCalendar
 1969  -> (BusinessDayConvention) -- ^paymentConvention
 1970  -> IO ((YearOnYearInflationSwap))
 1971 yearOnYearInflationSwap a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 =
 1972   let {a1' = (fromIntegral . fromEnum) a1} in 
 1973   let {a2' = realToFrac a2} in 
 1974   withSchedule a3 $ \a3' -> 
 1975   let {a4' = realToFrac a4} in 
 1976   withDayCounter a5 $ \a5' -> 
 1977   withSchedule a6 $ \a6' -> 
 1978   withYoYInflationIndex a7 $ \a7' -> 
 1979   let {(a8'1, a8'2) = fromEnumQuantity a8} in 
 1980   let {a9' = fromEnumC a9} in 
 1981   let {a10' = realToFrac a10} in 
 1982   withDayCounter a11 $ \a11' -> 
 1983   withCalendar a12 $ \a12' -> 
 1984   let {a13' = fromEnumC a13} in 
 1985   preErrorCheck $ \a14' -> 
 1986   yearOnYearInflationSwap'_ a1' a2' a3' a4' a5' a6' a7' a8'1  a8'2 a9' a10' a11' a12' a13' a14' >>= \res ->
 1987   peekYearOnYearInflationSwap res >>= \res' ->
 1988   errorCheck  a14'>>
 1989   return (res')
 1990 
 1991 
 1992 
 1993 -- |The fixed rate that would make the swap's NPV zero.
 1994 qlYearOnYearInflationSwapFairRate :: (YearOnYearInflationSwap) -> IO ((Double))
 1995 qlYearOnYearInflationSwapFairRate a1 =
 1996   withYearOnYearInflationSwap a1 $ \a1' -> 
 1997   preErrorCheck $ \a2' -> 
 1998   qlYearOnYearInflationSwapFairRate'_ a1' a2' >>= \res ->
 1999   let {res' = realToFrac res} in
 2000   errorCheck  a2'>>
 2001   return (res')
 2002 
 2003 
 2004 
 2005 -- |The spread that would make the swap's NPV zero.
 2006 qlYearOnYearInflationSwapFairSpread :: (YearOnYearInflationSwap) -> IO ((Double))
 2007 qlYearOnYearInflationSwapFairSpread a1 =
 2008   withYearOnYearInflationSwap a1 $ \a1' -> 
 2009   preErrorCheck $ \a2' -> 
 2010   qlYearOnYearInflationSwapFairSpread'_ a1' a2' >>= \res ->
 2011   let {res' = realToFrac res} in
 2012   errorCheck  a2'>>
 2013   return (res')
 2014 
 2015 
 2016 
 2017 -- |A fixed-x-CPI-ratio leg (subtracting the inflation notional if
 2018 -- /subtractInflationNominal/) vs a float+spread leg -- QuantLib's general-purpose inflation
 2019 -- swap, also usable to replicate a single-cashflow ZCIIS (see 'zeroCouponInflationSwap').
 2020 -- Per-leg NPV\/BPS use the generic 'leg'\/'legNpv'\/'legBps' (leg 0 = CPI, leg 1 = float).
 2021 cpiSwap :: (SwapType) -> (Double) -- ^nominal
 2022  -> (Bool) -- ^subtractInflationNominal
 2023  -> (Double) -- ^spread
 2024  -> (DayCounter) -- ^floatDayCount
 2025  -> (Schedule) -- ^floatSchedule
 2026  -> (BusinessDayConvention) -- ^floatRoll
 2027  -> (Word) -- ^fixingDays
 2028  -> (GenIborIndex ibor) -- ^floatIndex
 2029  -> (Double) -- ^fixedRate
 2030  -> (Double) -- ^baseCPI
 2031  -> (DayCounter) -- ^fixedDayCount
 2032  -> (Schedule) -- ^fixedSchedule
 2033  -> (BusinessDayConvention) -- ^fixedRoll
 2034  -> ((Word,TimeUnit)) -- ^observationLag
 2035  -> (GenZeroInflationIndex zidx) -- ^fixedIndex
 2036  -> (CPIInterpolationType) -- ^observationInterpolation
 2037  -> (Maybe Double) -- ^inflationNominal
 2038  -> IO ((CPISwap))
 2039 cpiSwap a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 =
 2040   let {a1' = (fromIntegral . fromEnum) a1} in 
 2041   let {a2' = realToFrac a2} in 
 2042   let {a3' = C2HSImp.fromBool a3} in 
 2043   let {a4' = realToFrac a4} in 
 2044   withDayCounter a5 $ \a5' -> 
 2045   withSchedule a6 $ \a6' -> 
 2046   let {a7' = fromEnumC a7} in 
 2047   let {a8' = fromIntegral a8} in 
 2048   withIborIndex a9 $ \a9' -> 
 2049   let {a10' = realToFrac a10} in 
 2050   let {a11' = realToFrac a11} in 
 2051   withDayCounter a12 $ \a12' -> 
 2052   withSchedule a13 $ \a13' -> 
 2053   let {a14' = fromEnumC a14} in 
 2054   let {(a15'1, a15'2) = fromEnumQuantity a15} in 
 2055   withZeroInflationIndex a16 $ \a16' -> 
 2056   let {a17' = fromEnumC a17} in 
 2057   let {a18' = fromMaybeDouble a18} in 
 2058   preErrorCheck $ \a19' -> 
 2059   cpiSwap'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' a13' a14' a15'1  a15'2 a16' a17' a18' a19' >>= \res ->
 2060   peekCPISwap res >>= \res' ->
 2061   errorCheck  a19'>>
 2062   return (res')
 2063 
 2064 
 2065 
 2066 -- |The fixed rate that would make the swap's NPV zero.
 2067 qlCPISwapFairRate :: (CPISwap) -> IO ((Double))
 2068 qlCPISwapFairRate a1 =
 2069   withCPISwap a1 $ \a1' -> 
 2070   preErrorCheck $ \a2' -> 
 2071   qlCPISwapFairRate'_ a1' a2' >>= \res ->
 2072   let {res' = realToFrac res} in
 2073   errorCheck  a2'>>
 2074   return (res')
 2075 
 2076 
 2077 
 2078 -- |The spread that would make the swap's NPV zero.
 2079 qlCPISwapFairSpread :: (CPISwap) -> IO ((Double))
 2080 qlCPISwapFairSpread a1 =
 2081   withCPISwap a1 $ \a1' -> 
 2082   preErrorCheck $ \a2' -> 
 2083   qlCPISwapFairSpread'_ a1' a2' >>= \res ->
 2084   let {res' = realToFrac res} in
 2085   errorCheck  a2'>>
 2086   return (res')
 2087 
 2088 
 2089 
 2090 -- |Zero-coupon swap quoted in terms of a known fixed cash flow. \"payer\"\/\"receiver\" refer to
 2091 -- the fixed leg. Per-leg NPV uses the generic 'leg'\/'legNpv' (leg 0 = fixed, leg 1 = floating).
 2092 zeroCouponSwap :: (SwapType) -> (Double) -- ^baseNominal
 2093  -> (Day) -- ^startDate
 2094  -> (Day) -- ^maturityDate
 2095  -> (Double) -- ^fixedPayment
 2096  -> (GenIborIndex ibor) -> (Calendar) -- ^paymentCalendar
 2097  -> (BusinessDayConvention) -- ^paymentConvention
 2098  -> (Word) -- ^paymentDelay
 2099  -> IO ((ZeroCouponSwap))
 2100 zeroCouponSwap a1 a2 a3 a4 a5 a6 a7 a8 a9 =
 2101   let {a1' = (fromIntegral . fromEnum) a1} in 
 2102   let {a2' = realToFrac a2} in 
 2103   withDay a3 $ \a3' -> 
 2104   withDay a4 $ \a4' -> 
 2105   let {a5' = realToFrac a5} in 
 2106   withIborIndex a6 $ \a6' -> 
 2107   withCalendar a7 $ \a7' -> 
 2108   let {a8' = fromEnumC a8} in 
 2109   let {a9' = fromIntegral a9} in 
 2110   preErrorCheck $ \a10' -> 
 2111   zeroCouponSwap'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' >>= \res ->
 2112   peekZeroCouponSwap res >>= \res' ->
 2113   errorCheck  a10'>>
 2114   return (res')
 2115 
 2116 
 2117 
 2118 -- |Zero-coupon swap quoted in terms of a fixed rate.
 2119 zeroCouponSwapFromRate :: (SwapType) -> (Double) -- ^baseNominal
 2120  -> (Day) -- ^startDate
 2121  -> (Day) -- ^maturityDate
 2122  -> (Double) -- ^fixedRate
 2123  -> (DayCounter) -- ^fixedDayCounter
 2124  -> (GenIborIndex ibor) -> (Calendar) -- ^paymentCalendar
 2125  -> (BusinessDayConvention) -- ^paymentConvention
 2126  -> (Word) -- ^paymentDelay
 2127  -> IO ((ZeroCouponSwap))
 2128 zeroCouponSwapFromRate a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 =
 2129   let {a1' = (fromIntegral . fromEnum) a1} in 
 2130   let {a2' = realToFrac a2} in 
 2131   withDay a3 $ \a3' -> 
 2132   withDay a4 $ \a4' -> 
 2133   let {a5' = realToFrac a5} in 
 2134   withDayCounter a6 $ \a6' -> 
 2135   withIborIndex a7 $ \a7' -> 
 2136   withCalendar a8 $ \a8' -> 
 2137   let {a9' = fromEnumC a9} in 
 2138   let {a10' = fromIntegral a10} in 
 2139   preErrorCheck $ \a11' -> 
 2140   zeroCouponSwapFromRate'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' >>= \res ->
 2141   peekZeroCouponSwap res >>= \res' ->
 2142   errorCheck  a11'>>
 2143   return (res')
 2144 
 2145 
 2146 
 2147 -- |The fixed payment that would make the swap's NPV zero.
 2148 fairFixedPayment :: (ZeroCouponSwap) -> IO ((Double))
 2149 fairFixedPayment a1 =
 2150   withZeroCouponSwap a1 $ \a1' -> 
 2151   preErrorCheck $ \a2' -> 
 2152   fairFixedPayment'_ a1' a2' >>= \res ->
 2153   let {res' = realToFrac res} in
 2154   errorCheck  a2'>>
 2155   return (res')
 2156 
 2157 
 2158 
 2159 -- |The fixed rate, under the given day counter, that would make the swap's NPV zero.
 2160 fairFixedRate :: (ZeroCouponSwap) -> (DayCounter) -> IO ((Double))
 2161 fairFixedRate a1 a2 =
 2162   withZeroCouponSwap a1 $ \a1' -> 
 2163   withDayCounter a2 $ \a2' -> 
 2164   preErrorCheck $ \a3' -> 
 2165   fairFixedRate'_ a1' a2' a3' >>= \res ->
 2166   let {res' = realToFrac res} in
 2167   errorCheck  a3'>>
 2168   return (res')
 2169 
 2170 
 2171 
 2172 -- |Exchanges the total return of an 'EquityIndex' for a set of floating cash flows linked to an
 2173 -- 'IborIndex'. /type/ (payer\/receiver) refers to the equity leg.
 2174 equityTotalReturnSwapIbor :: (SwapType) -> (Double) -- ^nominal
 2175  -> (Schedule) -> (EquityIndex) -> (GenIborIndex ibor) -- ^interestRateIndex
 2176  -> (DayCounter) -> (Double) -- ^margin
 2177  -> (Double) -- ^gearing
 2178  -> (Calendar) -- ^paymentCalendar
 2179  -> (BusinessDayConvention) -- ^paymentConvention
 2180  -> (Word) -- ^paymentDelay
 2181  -> IO ((EquityTotalReturnSwap))
 2182 equityTotalReturnSwapIbor a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 =
 2183   let {a1' = (fromIntegral . fromEnum) a1} in 
 2184   let {a2' = realToFrac a2} in 
 2185   withSchedule a3 $ \a3' -> 
 2186   withEquityIndex a4 $ \a4' -> 
 2187   withIborIndex a5 $ \a5' -> 
 2188   withDayCounter a6 $ \a6' -> 
 2189   let {a7' = realToFrac a7} in 
 2190   let {a8' = realToFrac a8} in 
 2191   withCalendar a9 $ \a9' -> 
 2192   let {a10' = fromEnumC a10} in 
 2193   let {a11' = fromIntegral a11} in 
 2194   preErrorCheck $ \a12' -> 
 2195   equityTotalReturnSwapIbor'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' >>= \res ->
 2196   peekEquityTotalReturnSwap res >>= \res' ->
 2197   errorCheck  a12'>>
 2198   return (res')
 2199 
 2200 
 2201 
 2202 -- |As 'equityTotalReturnSwapIbor', but with the floating leg linked to an overnight index instead
 2203 -- -- fixings are compounded over the accrual period.
 2204 equityTotalReturnSwapOvernight :: (SwapType) -> (Double) -- ^nominal
 2205  -> (Schedule) -> (EquityIndex) -> (OvernightIborIndex) -- ^interestRateIndex
 2206  -> (DayCounter) -> (Double) -- ^margin
 2207  -> (Double) -- ^gearing
 2208  -> (Calendar) -- ^paymentCalendar
 2209  -> (BusinessDayConvention) -- ^paymentConvention
 2210  -> (Word) -- ^paymentDelay
 2211  -> IO ((EquityTotalReturnSwap))
 2212 equityTotalReturnSwapOvernight a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 =
 2213   let {a1' = (fromIntegral . fromEnum) a1} in 
 2214   let {a2' = realToFrac a2} in 
 2215   withSchedule a3 $ \a3' -> 
 2216   withEquityIndex a4 $ \a4' -> 
 2217   withOvernightIborIndex a5 $ \a5' -> 
 2218   withDayCounter a6 $ \a6' -> 
 2219   let {a7' = realToFrac a7} in 
 2220   let {a8' = realToFrac a8} in 
 2221   withCalendar a9 $ \a9' -> 
 2222   let {a10' = fromEnumC a10} in 
 2223   let {a11' = fromIntegral a11} in 
 2224   preErrorCheck $ \a12' -> 
 2225   equityTotalReturnSwapOvernight'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' >>= \res ->
 2226   peekEquityTotalReturnSwap res >>= \res' ->
 2227   errorCheck  a12'>>
 2228   return (res')
 2229 
 2230 
 2231 
 2232 -- |NPV of the equity total-return leg.
 2233 equityLegNpv :: (EquityTotalReturnSwap) -> IO ((Double))
 2234 equityLegNpv a1 =
 2235   withEquityTotalReturnSwap a1 $ \a1' -> 
 2236   preErrorCheck $ \a2' -> 
 2237   equityLegNpv'_ a1' a2' >>= \res ->
 2238   let {res' = realToFrac res} in
 2239   errorCheck  a2'>>
 2240   return (res')
 2241 
 2242 
 2243 
 2244 -- |NPV of the interest-rate leg.
 2245 interestRateLegNpv :: (EquityTotalReturnSwap) -> IO ((Double))
 2246 interestRateLegNpv a1 =
 2247   withEquityTotalReturnSwap a1 $ \a1' -> 
 2248   preErrorCheck $ \a2' -> 
 2249   interestRateLegNpv'_ a1' a2' >>= \res ->
 2250   let {res' = realToFrac res} in
 2251   errorCheck  a2'>>
 2252   return (res')
 2253 
 2254 
 2255 
 2256 -- |The margin that would make the swap's NPV zero.
 2257 fairMargin :: (EquityTotalReturnSwap) -> IO ((Double))
 2258 fairMargin a1 =
 2259   withEquityTotalReturnSwap a1 $ \a1' -> 
 2260   preErrorCheck $ \a2' -> 
 2261   fairMargin'_ a1' a2' >>= \res ->
 2262   let {res' = realToFrac res} in
 2263   errorCheck  a2'>>
 2264   return (res')
 2265 
 2266 
 2267 
 2268 class HasFixedLeg a where
 2269   fixedLeg :: a -> IO Leg
 2270   fixedLegBps :: a -> IO Double
 2271   fixedLegNpv :: a -> IO Double
 2272 instance HasFixedLeg (GenFixedVsFloatingSwap f) where
 2273   fixedLeg = qlFixedVsFloatingSwapFixedLeg
 2274   fixedLegBps = qlFixedVsFloatingSwapFixedLegBPS
 2275   fixedLegNpv = qlFixedVsFloatingSwapFixedLegNPV
 2276 
 2277 class HasFairRate a where
 2278   fairRate :: a -> IO Double
 2279 instance HasFairRate (GenFixedVsFloatingSwap f) where
 2280   fairRate = qlFixedVsFloatingSwapFairRate
 2281 instance HasFairRate IrregularSwap where
 2282   fairRate = qlIrregularSwapFairRate
 2283 instance HasFairRate ZeroCouponInflationSwap where
 2284   fairRate = qlZeroCouponInflationSwapFairRate
 2285 instance HasFairRate YearOnYearInflationSwap where
 2286   fairRate = qlYearOnYearInflationSwapFairRate
 2287 instance HasFairRate CPISwap where
 2288   fairRate = qlCPISwapFairRate
 2289 
 2290 class HasFairSpread a where
 2291   fairSpread :: a -> IO Double
 2292 instance HasFairSpread (GenFixedVsFloatingSwap f) where
 2293   fairSpread = qlFixedVsFloatingSwapFairSpread
 2294 instance HasFairSpread AssetSwap where
 2295   fairSpread = qlAssetSwapFairSpread
 2296 instance HasFairSpread CreditDefaultSwap where
 2297   fairSpread = qlCreditDefaultSwapFairSpread
 2298 instance HasFairSpread YearOnYearInflationSwap where
 2299   fairSpread = qlYearOnYearInflationSwapFairSpread
 2300 instance HasFairSpread CPISwap where
 2301   fairSpread = qlCPISwapFairSpread
 2302 instance HasFairSpread IrregularSwap where
 2303   fairSpread = qlIrregularSwapFairSpread
 2304 
 2305 -- |Options that hold the swap they are written on. 'CdsOption' is constructed in
 2306 -- "QuantLib.Instrument.Credit"; import this module as well to reach its underlying swap.
 2307 class HasInstrumentUnderlying a where
 2308   type InstrumentUnderlying a
 2309   underlyingSwap :: a -> IO (InstrumentUnderlying a)
 2310 instance HasInstrumentUnderlying Swaption where
 2311   type InstrumentUnderlying Swaption = FixedVsFloatingSwap
 2312   underlyingSwap = qlSwaptionUnderlying
 2313 instance HasInstrumentUnderlying NonstandardSwaption where
 2314   type InstrumentUnderlying NonstandardSwaption = NonstandardSwap
 2315   underlyingSwap = qlNonstandardSwaptionUnderlyingSwap
 2316 instance HasInstrumentUnderlying FloatFloatSwaption where
 2317   type InstrumentUnderlying FloatFloatSwaption = FloatFloatSwap
 2318   underlyingSwap = qlFloatFloatSwaptionUnderlyingSwap
 2319 instance HasInstrumentUnderlying IrregularSwaption where
 2320   type InstrumentUnderlying IrregularSwaption = IrregularSwap
 2321   underlyingSwap = qlIrregularSwaptionUnderlyingSwap
 2322 instance HasInstrumentUnderlying CdsOption where
 2323   type InstrumentUnderlying CdsOption = CreditDefaultSwap
 2324   underlyingSwap = qlCdsOptionUnderlyingSwap
 2325 
 2326 qlSwaptionUnderlying :: (Swaption) -> IO ((FixedVsFloatingSwap))
 2327 qlSwaptionUnderlying a1 =
 2328   withSwaption a1 $ \a1' -> 
 2329   preErrorCheck $ \a2' -> 
 2330   qlSwaptionUnderlying'_ a1' a2' >>= \res ->
 2331   peekFixedVsFloatingSwap res >>= \res' ->
 2332   errorCheck  a2'>>
 2333   return (res')
 2334 
 2335 
 2336 qlNonstandardSwaptionUnderlyingSwap :: (NonstandardSwaption) -> IO ((NonstandardSwap))
 2337 qlNonstandardSwaptionUnderlyingSwap a1 =
 2338   withNonstandardSwaption a1 $ \a1' -> 
 2339   preErrorCheck $ \a2' -> 
 2340   qlNonstandardSwaptionUnderlyingSwap'_ a1' a2' >>= \res ->
 2341   peekNonstandardSwap res >>= \res' ->
 2342   errorCheck  a2'>>
 2343   return (res')
 2344 
 2345 
 2346 qlFloatFloatSwaptionUnderlyingSwap :: (FloatFloatSwaption) -> IO ((FloatFloatSwap))
 2347 qlFloatFloatSwaptionUnderlyingSwap a1 =
 2348   withFloatFloatSwaption a1 $ \a1' -> 
 2349   preErrorCheck $ \a2' -> 
 2350   qlFloatFloatSwaptionUnderlyingSwap'_ a1' a2' >>= \res ->
 2351   peekFloatFloatSwap res >>= \res' ->
 2352   errorCheck  a2'>>
 2353   return (res')
 2354 
 2355 
 2356 qlIrregularSwaptionUnderlyingSwap :: (IrregularSwaption) -> IO ((IrregularSwap))
 2357 qlIrregularSwaptionUnderlyingSwap a1 =
 2358   withIrregularSwaption a1 $ \a1' -> 
 2359   preErrorCheck $ \a2' -> 
 2360   qlIrregularSwaptionUnderlyingSwap'_ a1' a2' >>= \res ->
 2361   peekIrregularSwap res >>= \res' ->
 2362   errorCheck  a2'>>
 2363   return (res')
 2364 
 2365 
 2366 qlCdsOptionUnderlyingSwap :: (CdsOption) -> IO ((CreditDefaultSwap))
 2367 qlCdsOptionUnderlyingSwap a1 =
 2368   withCdsOption a1 $ \a1' -> 
 2369   preErrorCheck $ \a2' -> 
 2370   qlCdsOptionUnderlyingSwap'_ a1' a2' >>= \res ->
 2371   peekCreditDefaultSwap res >>= \res' ->
 2372   errorCheck  a2'>>
 2373   return (res')
 2374 
 2375 
 2376 
 2377 class HasFloatingLeg a where
 2378   floatingLeg :: a -> IO Leg
 2379   floatingLegBps :: a -> IO Double
 2380   floatingLegNpv :: a -> IO Double
 2381 instance HasFloatingLeg (GenFixedVsFloatingSwap f) where
 2382   floatingLeg = qlFixedVsFloatingSwapFloatingLeg
 2383   floatingLegBps = qlFixedVsFloatingSwapFloatingLegBPS
 2384   floatingLegNpv = qlFixedVsFloatingSwapFloatingLegNPV
 2385 instance HasFloatingLeg AssetSwap where
 2386   floatingLeg = qlAssetSwapFloatingLeg
 2387   floatingLegBps = qlAssetSwapFloatingLegBPS
 2388   floatingLegNpv = qlAssetSwapFloatingLegNPV
 2389 
 2390 -- |The spread that would make the swap's NPV zero.
 2391 qlFixedVsFloatingSwapFairSpread :: (GenFixedVsFloatingSwap f) -> IO ((Double))
 2392 qlFixedVsFloatingSwapFairSpread a1 =
 2393   withFixedVsFloatingSwap a1 $ \a1' -> 
 2394   preErrorCheck $ \a2' -> 
 2395   qlFixedVsFloatingSwapFairSpread'_ a1' a2' >>= \res ->
 2396   let {res' = realToFrac res} in
 2397   errorCheck  a2'>>
 2398   return (res')
 2399 
 2400 
 2401 
 2402 -- |The spread that would make the swap's NPV zero.
 2403 qlAssetSwapFairSpread :: (AssetSwap) -> IO ((Double))
 2404 qlAssetSwapFairSpread a1 =
 2405   withAssetSwap a1 $ \a1' -> 
 2406   preErrorCheck $ \a2' -> 
 2407   qlAssetSwapFairSpread'_ a1' a2' >>= \res ->
 2408   let {res' = realToFrac res} in
 2409   errorCheck  a2'>>
 2410   return (res')
 2411 
 2412 
 2413 
 2414 -- |The fixed rate that would make the swap's NPV zero.
 2415 qlFixedVsFloatingSwapFairRate :: (GenFixedVsFloatingSwap f) -> IO ((Double))
 2416 qlFixedVsFloatingSwapFairRate a1 =
 2417   withFixedVsFloatingSwap a1 $ \a1' -> 
 2418   preErrorCheck $ \a2' -> 
 2419   qlFixedVsFloatingSwapFairRate'_ a1' a2' >>= \res ->
 2420   let {res' = realToFrac res} in
 2421   errorCheck  a2'>>
 2422   return (res')
 2423 
 2424 
 2425 
 2426 -- |The fixed leg's cash flows.
 2427 qlFixedVsFloatingSwapFixedLeg :: (GenFixedVsFloatingSwap f) -> IO ((Leg))
 2428 qlFixedVsFloatingSwapFixedLeg a1 =
 2429   withFixedVsFloatingSwap a1 $ \a1' -> 
 2430   preErrorCheck $ \a2' -> 
 2431   qlFixedVsFloatingSwapFixedLeg'_ a1' a2' >>= \res ->
 2432   peekLeg res >>= \res' ->
 2433   errorCheck  a2'>>
 2434   return (res')
 2435 
 2436 
 2437 
 2438 -- |Basis-point sensitivity of the fixed leg.
 2439 qlFixedVsFloatingSwapFixedLegBPS :: (GenFixedVsFloatingSwap f) -> IO ((Double))
 2440 qlFixedVsFloatingSwapFixedLegBPS a1 =
 2441   withFixedVsFloatingSwap a1 $ \a1' -> 
 2442   preErrorCheck $ \a2' -> 
 2443   qlFixedVsFloatingSwapFixedLegBPS'_ a1' a2' >>= \res ->
 2444   let {res' = realToFrac res} in
 2445   errorCheck  a2'>>
 2446   return (res')
 2447 
 2448 
 2449 
 2450 -- |NPV of the fixed leg.
 2451 qlFixedVsFloatingSwapFixedLegNPV :: (GenFixedVsFloatingSwap f) -> IO ((Double))
 2452 qlFixedVsFloatingSwapFixedLegNPV a1 =
 2453   withFixedVsFloatingSwap a1 $ \a1' -> 
 2454   preErrorCheck $ \a2' -> 
 2455   qlFixedVsFloatingSwapFixedLegNPV'_ a1' a2' >>= \res ->
 2456   let {res' = realToFrac res} in
 2457   errorCheck  a2'>>
 2458   return (res')
 2459 
 2460 
 2461 
 2462 -- |Returns the running spread that, given the quoted recovery rate, will make the running-only CDS have an NPV of 0.This calculation does not take any upfront into account, even if one was given.
 2463 qlCreditDefaultSwapFairSpread :: (CreditDefaultSwap) -> IO ((Double))
 2464 qlCreditDefaultSwapFairSpread a1 =
 2465   withGenInstrument a1 $ \a1' -> 
 2466   preErrorCheck $ \a2' -> 
 2467   qlCreditDefaultSwapFairSpread'_ a1' a2' >>= \res ->
 2468   let {res' = realToFrac res} in
 2469   errorCheck  a2'>>
 2470   return (res')
 2471 
 2472 
 2473 
 2474 -- |The floating leg's cash flows.
 2475 qlFixedVsFloatingSwapFloatingLeg :: (GenFixedVsFloatingSwap f) -> IO ((Leg))
 2476 qlFixedVsFloatingSwapFloatingLeg a1 =
 2477   withFixedVsFloatingSwap a1 $ \a1' -> 
 2478   preErrorCheck $ \a2' -> 
 2479   qlFixedVsFloatingSwapFloatingLeg'_ a1' a2' >>= \res ->
 2480   peekLeg res >>= \res' ->
 2481   errorCheck  a2'>>
 2482   return (res')
 2483 
 2484 
 2485 
 2486 -- |Basis-point sensitivity of the floating leg.
 2487 qlFixedVsFloatingSwapFloatingLegBPS :: (GenFixedVsFloatingSwap f) -> IO ((Double))
 2488 qlFixedVsFloatingSwapFloatingLegBPS a1 =
 2489   withFixedVsFloatingSwap a1 $ \a1' -> 
 2490   preErrorCheck $ \a2' -> 
 2491   qlFixedVsFloatingSwapFloatingLegBPS'_ a1' a2' >>= \res ->
 2492   let {res' = realToFrac res} in
 2493   errorCheck  a2'>>
 2494   return (res')
 2495 
 2496 
 2497 
 2498 -- |NPV of the floating leg.
 2499 qlFixedVsFloatingSwapFloatingLegNPV :: (GenFixedVsFloatingSwap f) -> IO ((Double))
 2500 qlFixedVsFloatingSwapFloatingLegNPV a1 =
 2501   withFixedVsFloatingSwap a1 $ \a1' -> 
 2502   preErrorCheck $ \a2' -> 
 2503   qlFixedVsFloatingSwapFloatingLegNPV'_ a1' a2' >>= \res ->
 2504   let {res' = realToFrac res} in
 2505   errorCheck  a2'>>
 2506   return (res')
 2507 
 2508 
 2509 
 2510 -- |The floating leg's cash flows.
 2511 qlAssetSwapFloatingLeg :: (AssetSwap) -> IO ((Leg))
 2512 qlAssetSwapFloatingLeg a1 =
 2513   withAssetSwap a1 $ \a1' -> 
 2514   preErrorCheck $ \a2' -> 
 2515   qlAssetSwapFloatingLeg'_ a1' a2' >>= \res ->
 2516   peekLeg res >>= \res' ->
 2517   errorCheck  a2'>>
 2518   return (res')
 2519 
 2520 
 2521 
 2522 -- |Basis-point sensitivity of the floating leg.
 2523 qlAssetSwapFloatingLegBPS :: (AssetSwap) -> IO ((Double))
 2524 qlAssetSwapFloatingLegBPS a1 =
 2525   withAssetSwap a1 $ \a1' -> 
 2526   preErrorCheck $ \a2' -> 
 2527   qlAssetSwapFloatingLegBPS'_ a1' a2' >>= \res ->
 2528   let {res' = realToFrac res} in
 2529   errorCheck  a2'>>
 2530   return (res')
 2531 
 2532 
 2533 
 2534 -- |NPV of the floating leg.
 2535 qlAssetSwapFloatingLegNPV :: (AssetSwap) -> IO ((Double))
 2536 qlAssetSwapFloatingLegNPV a1 =
 2537   withAssetSwap a1 $ \a1' -> 
 2538   preErrorCheck $ \a2' -> 
 2539   qlAssetSwapFloatingLegNPV'_ a1' a2' >>= \res ->
 2540   let {res' = realToFrac res} in
 2541   errorCheck  a2'>>
 2542   return (res')
 2543 
 2544 
 2545 
 2546 
 2547 
 2548 
 2549 -- |Variance swap: pays off the difference between realized and strike variance, scaled by notional. This class does not manage seasoned variance swaps.
 2550 varianceSwap :: (PositionType) -> (Double) -- ^strike
 2551  -> (Double) -- ^notional
 2552  -> (Day) -- ^startDate
 2553  -> (Day) -- ^maturityDate
 2554  -> IO ((VarianceSwap))
 2555 varianceSwap a1 a2 a3 a4 a5 =
 2556   let {a1' = fromEnumC a1} in 
 2557   let {a2' = realToFrac a2} in 
 2558   let {a3' = realToFrac a3} in 
 2559   withDay a4 $ \a4' -> 
 2560   withDay a5 $ \a5' -> 
 2561   preErrorCheck $ \a6' -> 
 2562   varianceSwap'_ a1' a2' a3' a4' a5' a6' >>= \res ->
 2563   peekVarianceSwap res >>= \res' ->
 2564   errorCheck  a6'>>
 2565   return (res')
 2566 
 2567 
 2568 
 2569 -- |Realized variance -- requires a pricing engine to be set first
 2570 variance :: (VarianceSwap) -> IO ((Double))
 2571 variance a1 =
 2572   withGenInstrument a1 $ \a1' -> 
 2573   preErrorCheck $ \a2' -> 
 2574   variance'_ a1' a2' >>= \res ->
 2575   let {res' = realToFrac res} in
 2576   errorCheck  a2'>>
 2577   return (res')
 2578 
 2579 
 2580 
 2581 
 2582 
 2583 
 2584 
 2585 
 2586 -- |Variance option: an option on realized variance, priced (e.g. via 'integralHestonVarianceOptionEngine')
 2587 -- against a payoff on the variance level rather than the underlying price. This class does not
 2588 -- manage seasoned variance options.
 2589 varianceOption :: (Payoff) -> (Double) -- ^notional
 2590  -> (Day) -- ^startDate
 2591  -> (Day) -- ^maturityDate
 2592  -> IO ((VarianceOption))
 2593 varianceOption a1 a2 a3 a4 =
 2594   withPayoff a1 $ \a1' -> 
 2595   let {a2' = realToFrac a2} in 
 2596   withDay a3 $ \a3' -> 
 2597   withDay a4 $ \a4' -> 
 2598   preErrorCheck $ \a5' -> 
 2599   varianceOption'_ a1' a2' a3' a4' a5' >>= \res ->
 2600   peekVarianceOption res >>= \res' ->
 2601   errorCheck  a5'>>
 2602   return (res')
 2603 
 2604 
 2605 
 2606 -- |Native MTM product construction.
 2607 mtmCrossCurrencyBasisSwapRaw :: (Int) -- ^type
 2608  -> (Double) -- ^fxBaseNominal
 2609  -> (Currency) -- ^fxBaseCurrency
 2610  -> (Schedule) -- ^fxBaseSchedule
 2611  -> (GenIborIndex ibor1) -- ^fxBaseIndex
 2612  -> (Double) -- ^fxBaseSpread
 2613  -> (Double) -- ^fxBaseGearing
 2614  -> (Double) -- ^fxQuoteNominal
 2615  -> (Currency) -- ^fxQuoteCurrency
 2616  -> (Schedule) -- ^fxQuoteSchedule
 2617  -> (GenIborIndex ibor2) -- ^fxQuoteIndex
 2618  -> (Double) -- ^fxQuoteSpread
 2619  -> (Double) -- ^fxQuoteGearing
 2620  -> (Bool) -- ^isFxBaseCurrencyLegResettable
 2621  -> (Word) -- ^fxResetFixingDays
 2622  -> (Maybe Calendar) -- ^fxResetFixingCalendar
 2623  -> (Int) -- ^fxBasePaymentLag
 2624  -> (Int) -- ^fxQuotePaymentLag
 2625  -> (BusinessDayConvention) -- ^fxBasePaymentConvention
 2626  -> (BusinessDayConvention) -- ^fxQuotePaymentConvention
 2627  -> (Bool) -- ^fxBaseCompoundSpread
 2628  -> (Maybe Word) -- ^fxBaseLookbackDays
 2629  -> (Bool) -- ^fxBaseObservationShift
 2630  -> (Word) -- ^fxBaseLockoutDays
 2631  -> (RateAveragingType) -- ^fxBaseAveragingMethod
 2632  -> (Bool) -- ^fxQuoteCompoundSpread
 2633  -> (Maybe Word) -- ^fxQuoteLookbackDays
 2634  -> (Bool) -- ^fxQuoteObservationShift
 2635  -> (Word) -- ^fxQuoteLockoutDays
 2636  -> (RateAveragingType) -- ^fxQuoteAveragingMethod
 2637  -> (Bool) -- ^telescopicValueDates
 2638  -> (Maybe Bool) -- ^useIndexedCoupons
 2639  -> (Maybe (StubIndexSelection ibor3)) -- ^fxBaseStubIndexSelection
 2640  -> (Maybe (StubIndexSelection ibor4)) -- ^fxQuoteStubIndexSelection
 2641  -> IO ((MtMCrossCurrencyBasisSwap))
 2642 mtmCrossCurrencyBasisSwapRaw a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 a32 a33 a34 =
 2643   let {a1' = fromIntegral a1} in 
 2644   let {a2' = realToFrac a2} in 
 2645   withCurrency a3 $ \a3' -> 
 2646   withSchedule a4 $ \a4' -> 
 2647   withIborIndex a5 $ \a5' -> 
 2648   let {a6' = realToFrac a6} in 
 2649   let {a7' = realToFrac a7} in 
 2650   let {a8' = realToFrac a8} in 
 2651   withCurrency a9 $ \a9' -> 
 2652   withSchedule a10 $ \a10' -> 
 2653   withIborIndex a11 $ \a11' -> 
 2654   let {a12' = realToFrac a12} in 
 2655   let {a13' = realToFrac a13} in 
 2656   let {a14' = C2HSImp.fromBool a14} in 
 2657   let {a15' = fromIntegral a15} in 
 2658   withMaybeCalendar a16 $ \a16' -> 
 2659   let {a17' = fromIntegral a17} in 
 2660   let {a18' = fromIntegral a18} in 
 2661   let {a19' = fromEnumC a19} in 
 2662   let {a20' = fromEnumC a20} in 
 2663   let {a21' = C2HSImp.fromBool a21} in 
 2664   let {a22' = fromMaybeInt a22} in 
 2665   let {a23' = C2HSImp.fromBool a23} in 
 2666   let {a24' = fromIntegral a24} in 
 2667   let {a25' = (fromIntegral . fromEnum) a25} in 
 2668   let {a26' = C2HSImp.fromBool a26} in 
 2669   let {a27' = fromMaybeInt a27} in 
 2670   let {a28' = C2HSImp.fromBool a28} in 
 2671   let {a29' = fromIntegral a29} in 
 2672   let {a30' = (fromIntegral . fromEnum) a30} in 
 2673   let {a31' = C2HSImp.fromBool a31} in 
 2674   let {a32' = fromMaybeBool a32} in 
 2675   withStubIndexSelection a33 $ \a33' -> 
 2676   withStubIndexSelection a34 $ \a34' -> 
 2677   preErrorCheck $ \a35' -> 
 2678   mtmCrossCurrencyBasisSwapRaw'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' a13' a14' a15' a16' a17' a18' a19' a20' a21' a22' a23' a24' a25' a26' a27' a28' a29' a30' a31' a32' a33' a34' a35' >>= \res ->
 2679   peekMtMCrossCurrencyBasisSwap res >>= \res' ->
 2680   errorCheck  a35'>>
 2681   return (res')
 2682 
 2683 
 2684 
 2685 -- |Resetting-notional cross-currency basis swap with upstream defaults (1.44).
 2686 -- Base is leg 0 and quote is leg 1. The Bool chooses whether base resets.
 2687 mtmCrossCurrencyBasisSwap :: MtmCrossCurrencySwapType -- ^Pay/receive FX base currency; base is leg 0, quote leg 1
 2688   -> Double -- ^FX base nominal
 2689   -> Currency -- ^FX base currency
 2690   -> Schedule -- ^FX base schedule
 2691   -> GenIborIndex ibor1 -- ^FX base IBOR or overnight index
 2692   -> Double -- ^FX base spread
 2693   -> Double -- ^FX base gearing
 2694   -> Double -- ^FX quote nominal
 2695   -> Currency -- ^FX quote currency
 2696   -> Schedule -- ^FX quote schedule
 2697   -> GenIborIndex ibor2 -- ^FX quote IBOR or overnight index
 2698   -> Double -- ^FX quote spread
 2699   -> Double -- ^FX quote gearing
 2700   -> Bool -- ^True resets the FX base leg; False resets the FX quote leg
 2701   -> IO MtMCrossCurrencyBasisSwap
 2702 mtmCrossCurrencyBasisSwap direction fxBaseNominal fxBaseCurrency fxBaseSchedule fxBaseIndex fxBaseSpread fxBaseGearing fxQuoteNominal fxQuoteCurrency fxQuoteSchedule fxQuoteIndex fxQuoteSpread fxQuoteGearing resetBase =
 2703   mtmCrossCurrencyBasisSwapWithOptions direction fxBaseNominal fxBaseCurrency fxBaseSchedule fxBaseIndex fxBaseSpread fxBaseGearing fxQuoteNominal fxQuoteCurrency fxQuoteSchedule fxQuoteIndex fxQuoteSpread fxQuoteGearing resetBase defaultMtmCrossCurrencyBasisSwapOpts
 2704 
 2705 -- |Full MTM construction (1.44). Payment lags affect coupons, not principal exchanges.
 2706 -- Empty FX fixing calendars use the resetting schedule calendar when the fixing lag is nonzero.
 2707 mtmCrossCurrencyBasisSwapWithOptions :: MtmCrossCurrencySwapType -- ^Pay/receive FX base currency; base is leg 0, quote leg 1
 2708   -> Double -- ^FX base nominal
 2709   -> Currency -- ^FX base currency
 2710   -> Schedule -- ^FX base schedule
 2711   -> GenIborIndex ibor1 -- ^FX base IBOR or overnight index
 2712   -> Double -- ^FX base spread
 2713   -> Double -- ^FX base gearing
 2714   -> Double -- ^FX quote nominal
 2715   -> Currency -- ^FX quote currency
 2716   -> Schedule -- ^FX quote schedule
 2717   -> GenIborIndex ibor2 -- ^FX quote IBOR or overnight index
 2718   -> Double -- ^FX quote spread
 2719   -> Double -- ^FX quote gearing
 2720   -> Bool -- ^True resets the FX base leg; False resets the FX quote leg
 2721   -> MtMCrossCurrencyBasisSwapOpts ibor3 ibor4 -- ^Payment, reset, overnight and stub options
 2722   -> IO MtMCrossCurrencyBasisSwap
 2723 mtmCrossCurrencyBasisSwapWithOptions direction fxBaseNominal fxBaseCurrency fxBaseSchedule fxBaseIndex fxBaseSpread fxBaseGearing fxQuoteNominal fxQuoteCurrency fxQuoteSchedule fxQuoteIndex fxQuoteSpread fxQuoteGearing resetBase opts =
 2724   mtmCrossCurrencyBasisSwapRaw (case direction of PayFxBaseCurrency -> 0; ReceiveFxBaseCurrency -> 1)
 2725     fxBaseNominal fxBaseCurrency fxBaseSchedule fxBaseIndex fxBaseSpread fxBaseGearing fxQuoteNominal fxQuoteCurrency fxQuoteSchedule fxQuoteIndex fxQuoteSpread fxQuoteGearing resetBase
 2726     (mtmFxResetFixingDays opts) (mtmFxResetFixingCalendar opts)
 2727     (mtmFxBasePaymentLag opts) (mtmFxQuotePaymentLag opts)
 2728     (mtmFxBasePaymentConvention opts) (mtmFxQuotePaymentConvention opts)
 2729     (mtmFxBaseCompoundSpread opts) (lookbackDays baseObs) (applyObservationShift baseObs) (lockoutDays baseObs) (mtmFxBaseAveragingMethod opts)
 2730     (mtmFxQuoteCompoundSpread opts) (lookbackDays quoteObs) (applyObservationShift quoteObs) (lockoutDays quoteObs) (mtmFxQuoteAveragingMethod opts)
 2731     (mtmTelescopicValueDates opts) (mtmUseIndexedCoupons opts)
 2732     (mtmFxBaseStubIndexSelection opts) (mtmFxQuoteStubIndexSelection opts)
 2733   where baseObs = mtmFxBaseObservation opts
 2734         quoteObs = mtmFxQuoteObservation opts
 2735 
 2736 -- |Currency-denominated results shared by cross-currency swaps.
 2737 class HasCrossCurrencyResults s where
 2738   -- |Currency of a leg, selected by zero-based index.
 2739   legCurrency :: s -> Word -> IO Currency
 2740   -- |Signed basis-point sensitivity in the leg currency.
 2741   inCcyLegBps :: s -> Word -> IO Double
 2742   -- |Signed NPV in the leg currency.
 2743   inCcyLegNpv :: s -> Word -> IO Double
 2744   -- |Discount factor at the NPV date for the selected currency.
 2745   npvDateDiscounts :: s -> Word -> IO Double
 2746 
 2747 instance HasCrossCurrencyResults (GenConstNotionalCrossCurrencySwap x) where
 2748   legCurrency = constNotionalLegCurrency
 2749   inCcyLegBps = constNotionalInCcyLegBPS
 2750   inCcyLegNpv = constNotionalInCcyLegNPV
 2751   npvDateDiscounts = constNotionalNpvDateDiscounts
 2752 
 2753 instance HasCrossCurrencyResults MtMCrossCurrencyBasisSwap where
 2754   legCurrency = mtmLegCurrency
 2755   inCcyLegBps = mtmInCcyLegBPS
 2756   inCcyLegNpv = mtmInCcyLegNPV
 2757   npvDateDiscounts = mtmNpvDateDiscounts
 2758 
 2759 -- |MTM legCurrency (1.44).
 2760 mtmLegCurrency :: (MtMCrossCurrencyBasisSwap) -- ^swap
 2761  -> (Word) -- ^legIndex
 2762  -> IO ((Currency))
 2763 mtmLegCurrency a1 a2 =
 2764   withMtMCrossCurrencyBasisSwap a1 $ \a1' -> 
 2765   let {a2' = fromIntegral a2} in 
 2766   preErrorCheck $ \a3' -> 
 2767   mtmLegCurrency'_ a1' a2' a3' >>= \res ->
 2768   peekCurrency res >>= \res' ->
 2769   errorCheck  a3'>>
 2770   return (res')
 2771 
 2772 
 2773 
 2774 -- |MTM inCcyLegBPS (1.44).
 2775 mtmInCcyLegBPS :: (MtMCrossCurrencyBasisSwap) -- ^swap
 2776  -> (Word) -- ^legIndex
 2777  -> IO ((Double))
 2778 mtmInCcyLegBPS a1 a2 =
 2779   withMtMCrossCurrencyBasisSwap a1 $ \a1' -> 
 2780   let {a2' = fromIntegral a2} in 
 2781   preErrorCheck $ \a3' -> 
 2782   mtmInCcyLegBPS'_ a1' a2' a3' >>= \res ->
 2783   let {res' = realToFrac res} in
 2784   errorCheck  a3'>>
 2785   return (res')
 2786 
 2787 
 2788 
 2789 -- |MTM inCcyLegNPV (1.44).
 2790 mtmInCcyLegNPV :: (MtMCrossCurrencyBasisSwap) -- ^swap
 2791  -> (Word) -- ^legIndex
 2792  -> IO ((Double))
 2793 mtmInCcyLegNPV a1 a2 =
 2794   withMtMCrossCurrencyBasisSwap a1 $ \a1' -> 
 2795   let {a2' = fromIntegral a2} in 
 2796   preErrorCheck $ \a3' -> 
 2797   mtmInCcyLegNPV'_ a1' a2' a3' >>= \res ->
 2798   let {res' = realToFrac res} in
 2799   errorCheck  a3'>>
 2800   return (res')
 2801 
 2802 
 2803 
 2804 -- |MTM npvDateDiscounts (1.44).
 2805 mtmNpvDateDiscounts :: (MtMCrossCurrencyBasisSwap) -- ^swap
 2806  -> (Word) -- ^legIndex
 2807  -> IO ((Double))
 2808 mtmNpvDateDiscounts a1 a2 =
 2809   withMtMCrossCurrencyBasisSwap a1 $ \a1' -> 
 2810   let {a2' = fromIntegral a2} in 
 2811   preErrorCheck $ \a3' -> 
 2812   mtmNpvDateDiscounts'_ a1' a2' a3' >>= \res ->
 2813   let {res' = realToFrac res} in
 2814   errorCheck  a3'>>
 2815   return (res')
 2816 
 2817 
 2818 
 2819 -- |Native NPV/BPS par spread (1.44).
 2820 -- Compounded overnight spreads can leave a repricing residual.
 2821 fairFxBaseSpread :: (MtMCrossCurrencyBasisSwap) -- ^swap
 2822  -> IO ((Double))
 2823 fairFxBaseSpread a1 =
 2824   withMtMCrossCurrencyBasisSwap a1 $ \a1' -> 
 2825   preErrorCheck $ \a2' -> 
 2826   fairFxBaseSpread'_ a1' a2' >>= \res ->
 2827   let {res' = realToFrac res} in
 2828   errorCheck  a2'>>
 2829   return (res')
 2830 
 2831 
 2832 
 2833 -- |Native NPV/BPS par spread (1.44).
 2834 -- Compounded overnight spreads can leave a repricing residual.
 2835 fairFxQuoteSpread :: (MtMCrossCurrencyBasisSwap) -- ^swap
 2836  -> IO ((Double))
 2837 fairFxQuoteSpread a1 =
 2838   withMtMCrossCurrencyBasisSwap a1 $ \a1' -> 
 2839   preErrorCheck $ \a2' -> 
 2840   fairFxQuoteSpread'_ a1' a2' >>= \res ->
 2841   let {res' = realToFrac res} in
 2842   errorCheck  a2'>>
 2843   return (res')
 2844 
 2845 
 2846 
 2847 -- |Native NPV/BPS par spread (1.44).
 2848 -- Compounded overnight spreads can leave a repricing residual.
 2849 mtmFairPaySpread :: (MtMCrossCurrencyBasisSwap) -- ^swap
 2850  -> IO ((Double))
 2851 mtmFairPaySpread a1 =
 2852   withMtMCrossCurrencyBasisSwap a1 $ \a1' -> 
 2853   preErrorCheck $ \a2' -> 
 2854   mtmFairPaySpread'_ a1' a2' >>= \res ->
 2855   let {res' = realToFrac res} in
 2856   errorCheck  a2'>>
 2857   return (res')
 2858 
 2859 
 2860 
 2861 -- |Native NPV/BPS par spread (1.44).
 2862 -- Compounded overnight spreads can leave a repricing residual.
 2863 mtmFairRecSpread :: (MtMCrossCurrencyBasisSwap) -- ^swap
 2864  -> IO ((Double))
 2865 mtmFairRecSpread a1 =
 2866   withMtMCrossCurrencyBasisSwap a1 $ \a1' -> 
 2867   preErrorCheck $ \a2' -> 
 2868   mtmFairRecSpread'_ a1' a2' >>= \res ->
 2869   let {res' = realToFrac res} in
 2870   errorCheck  a2'>>
 2871   return (res')
 2872 
 2873 
 2874 
 2875 -- |Native NPV/BPS par spreads for paid and received legs of basis swaps.
 2876 -- Compounded overnight spreads can leave a repricing residual.
 2877 class HasFairLegSpreads s where
 2878   -- |Par spread of the paid leg.
 2879   fairPaySpread :: s -> IO Double
 2880   -- |Par spread of the received leg.
 2881   fairRecSpread :: s -> IO Double
 2882 instance HasFairLegSpreads ConstNotionalCrossCurrencyBasisSwap where
 2883   fairPaySpread = constNotionalFairPaySpread
 2884   fairRecSpread = constNotionalFairRecSpread
 2885 instance HasFairLegSpreads MtMCrossCurrencyBasisSwap where
 2886   fairPaySpread = mtmFairPaySpread
 2887   fairRecSpread = mtmFairRecSpread
 2888 
 2889 -- |Calculated reset rates for non-occurred coupons in leg order (1.44).
 2890 fxResetRates :: (MtMCrossCurrencyBasisSwap) -- ^swap
 2891  -> IO ((RealVector))
 2892 fxResetRates a1 =
 2893   withMtMCrossCurrencyBasisSwap a1 $ \a1' -> 
 2894   preDoubleArray $ \(a2'1, a2'2) -> 
 2895   preErrorCheck $ \a3' -> 
 2896   fxResetRates'_ a1' a2'1  a2'2 a3' >>
 2897   peekRealVector  a2'1  a2'2>>= \a2'' -> 
 2898   errorCheck  a3'>>
 2899   return (a2'')
 2900 
 2901 
 2902 
 2903 -- |Calculated reset notionals for non-occurred coupons in leg order (1.44).
 2904 fxResetNotionals :: (MtMCrossCurrencyBasisSwap) -- ^swap
 2905  -> IO ((RealVector))
 2906 fxResetNotionals a1 =
 2907   withMtMCrossCurrencyBasisSwap a1 $ \a1' -> 
 2908   preDoubleArray $ \(a2'1, a2'2) -> 
 2909   preErrorCheck $ \a3' -> 
 2910   fxResetNotionals'_ a1' a2'1  a2'2 a3' >>
 2911   peekRealVector  a2'1  a2'2>>= \a2'' -> 
 2912   errorCheck  a3'>>
 2913   return (a2'')
 2914 
 2915 
 2916 
 2917 -- |Upstream defaults for MTM cross-currency construction.
 2918 defaultMtmCrossCurrencyBasisSwapOpts :: MtMCrossCurrencyBasisSwapOpts ibor3 ibor4
 2919 defaultMtmCrossCurrencyBasisSwapOpts = defaultMtMCrossCurrencyBasisSwapOpts
 2920 
 2921 -- vim: set ff=unix ts=8 sts=2 sw=2 et:
 2922 
 2923 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlSwaptionImpliedVolatility"
 2924   impliedVolatility'_ :: ((C2HSImp.Ptr (CSwaption')) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CYieldTermStructure')) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))))))))))
 2925 
 2926 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlSwap1"
 2927   qlSwap1'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CLeg'))) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CSwap'))))))))
 2928 
 2929 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlBMASwap"
 2930   bmaSwap'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CSchedule)) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CIborIndex')) -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CSchedule)) -> ((C2HSImp.Ptr (CBMAIndex')) -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CBMASwap'))))))))))))))
 2931 
 2932 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlVanillaSwap"
 2933   vanillaSwap'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CSchedule)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CSchedule)) -> ((C2HSImp.Ptr (CIborIndex')) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CVanillaSwap')))))))))))))))
 2934 
 2935 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlNonstandardSwap1"
 2936   nonstandardSwapFromVanilla'_ :: ((C2HSImp.Ptr (CFixedVsFloatingSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CNonstandardSwap')))))
 2937 
 2938 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlNonstandardSwap"
 2939   nonstandardSwap'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CSchedule)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CSchedule)) -> ((C2HSImp.Ptr (CIborIndex')) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CCalendar)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CNonstandardSwap')))))))))))))))))))))))
 2940 
 2941 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlNonstandardSwap2"
 2942   nonstandardSwapFromGearingsAndSpreads'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CSchedule)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CSchedule)) -> ((C2HSImp.Ptr (CIborIndex')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CCalendar)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CNonstandardSwap')))))))))))))))))))))))))
 2943 
 2944 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlNonstandardSwapFixedRate"
 2945   nonstandardSwapFixedRate'_ :: ((C2HSImp.Ptr (CNonstandardSwap')) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
 2946 
 2947 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlFloatFloatSwap"
 2948   floatFloatSwap_'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CSchedule)) -> ((C2HSImp.Ptr (CInterestRateIndex')) -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CSchedule)) -> ((C2HSImp.Ptr (CInterestRateIndex')) -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFloatFloatSwap')))))))))))))))))))))))))
 2949 
 2950 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlFloatFloatSwap2"
 2951   floatFloatSwap2_'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CSchedule)) -> ((C2HSImp.Ptr (CInterestRateIndex')) -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CSchedule)) -> ((C2HSImp.Ptr (CInterestRateIndex')) -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFloatFloatSwap')))))))))))))))))))))))))))))))))))
 2952 
 2953 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlFloatFloatSwapFairSpread1"
 2954   firstLegFairSpread'_ :: ((C2HSImp.Ptr (CFloatFloatSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 2955 
 2956 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlFloatFloatSwapFairSpread2"
 2957   secondLegFairSpread'_ :: ((C2HSImp.Ptr (CFloatFloatSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 2958 
 2959 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlSwap"
 2960   swap'_ :: ((C2HSImp.Ptr (CLeg')) -> ((C2HSImp.Ptr (CLeg')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CSwap'))))))
 2961 
 2962 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlSwapEndDiscounts"
 2963   endDiscounts'_ :: ((C2HSImp.Ptr (CSwap')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 2964 
 2965 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlSwapNumberOfLegs"
 2966   numberOfLegs'_ :: ((C2HSImp.Ptr (CSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CUInt)))
 2967 
 2968 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlSwapLeg"
 2969   leg'_ :: ((C2HSImp.Ptr (CSwap')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CLeg'))))))
 2970 
 2971 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlSwapLegBPS"
 2972   legBps'_ :: ((C2HSImp.Ptr (CSwap')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 2973 
 2974 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlSwapLegNPV"
 2975   legNpv'_ :: ((C2HSImp.Ptr (CSwap')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 2976 
 2977 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlSwapStartDiscounts"
 2978   startDiscounts'_ :: ((C2HSImp.Ptr (CSwap')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 2979 
 2980 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlConstNotionalCrossCurrencySwap"
 2981   constNotionalCrossCurrencySwap'_ :: ((C2HSImp.Ptr (CLeg')) -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CLeg')) -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CConstNotionalCrossCurrencySwap'))))))))
 2982 
 2983 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlConstNotionalCrossCurrencySwap1"
 2984   qlConstNotionalCrossCurrencySwap1'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CLeg'))) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CCurrency))) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CConstNotionalCrossCurrencySwap'))))))))))
 2985 
 2986 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlConstNotionalCrossCurrencySwapLegCurrency"
 2987   constNotionalLegCurrency'_ :: ((C2HSImp.Ptr (CConstNotionalCrossCurrencySwap')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CCurrency))))))
 2988 
 2989 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlConstNotionalCrossCurrencySwapInCcyLegBPS"
 2990   constNotionalInCcyLegBPS'_ :: ((C2HSImp.Ptr (CConstNotionalCrossCurrencySwap')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 2991 
 2992 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlConstNotionalCrossCurrencySwapInCcyLegNPV"
 2993   constNotionalInCcyLegNPV'_ :: ((C2HSImp.Ptr (CConstNotionalCrossCurrencySwap')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 2994 
 2995 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlConstNotionalCrossCurrencySwapNpvDateDiscounts"
 2996   constNotionalNpvDateDiscounts'_ :: ((C2HSImp.Ptr (CConstNotionalCrossCurrencySwap')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 2997 
 2998 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlConstNotionalCrossCurrencyBasisSwap"
 2999   constNotionalCrossCurrencyBasisSwap_'_ :: (C2HSImp.CDouble -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CSchedule)) -> ((C2HSImp.Ptr (CIborIndex')) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CSchedule)) -> ((C2HSImp.Ptr (CIborIndex')) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((QlStubIndexSelection) -> ((QlStubIndexSelection) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CConstNotionalCrossCurrencyBasisSwap')))))))))))))))))))))))))))))))))
 3000 
 3001 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlConstNotionalCrossCurrencyBasisSwapFairPaySpread"
 3002   constNotionalFairPaySpread'_ :: ((C2HSImp.Ptr (CConstNotionalCrossCurrencyBasisSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3003 
 3004 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlConstNotionalCrossCurrencyBasisSwapFairRecSpread"
 3005   constNotionalFairRecSpread'_ :: ((C2HSImp.Ptr (CConstNotionalCrossCurrencyBasisSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3006 
 3007 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlConstNotionalCrossCurrencyFixedVsFloatingSwap"
 3008   constNotionalCrossCurrencyFixedVsFloatingSwapRaw'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CSchedule)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CSchedule)) -> ((C2HSImp.Ptr (CIborIndex')) -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((QlStubIndexSelection) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CConstNotionalCrossCurrencyFixedVsFloatingSwap')))))))))))))))))))))))))))))
 3009 
 3010 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlConstNotionalCrossCurrencyFixedVsFloatingSwapFairRate"
 3011   qlConstNotionalCrossCurrencyFixedVsFloatingSwapFairRate'_ :: ((C2HSImp.Ptr (CConstNotionalCrossCurrencyFixedVsFloatingSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3012 
 3013 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlConstNotionalCrossCurrencyFixedVsFloatingSwapFairSpread"
 3014   qlConstNotionalCrossCurrencyFixedVsFloatingSwapFairSpread'_ :: ((C2HSImp.Ptr (CConstNotionalCrossCurrencyFixedVsFloatingSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3015 
 3016 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlSwaption"
 3017   swaption'_ :: ((C2HSImp.Ptr (CFixedVsFloatingSwap')) -> ((QlExercise) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CSwaption'))))))))
 3018 
 3019 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlIrregularSwaption"
 3020   irregularSwaption'_ :: ((C2HSImp.Ptr (CIrregularSwap')) -> ((QlExercise) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CIrregularSwaption')))))))
 3021 
 3022 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlIrregularSwap"
 3023   irregularSwap'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (CLeg')) -> ((C2HSImp.Ptr (CLeg')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CIrregularSwap')))))))
 3024 
 3025 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlIrregularSwapFairRate"
 3026   qlIrregularSwapFairRate'_ :: ((C2HSImp.Ptr (CIrregularSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3027 
 3028 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlIrregularSwapFairSpread"
 3029   qlIrregularSwapFairSpread'_ :: ((C2HSImp.Ptr (CIrregularSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3030 
 3031 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlNonstandardSwaption1"
 3032   nonstandardSwaptionFromSwaption'_ :: ((C2HSImp.Ptr (CSwaption')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CNonstandardSwaption')))))
 3033 
 3034 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlNonstandardSwaption"
 3035   nonstandardSwaption'_ :: ((C2HSImp.Ptr (CNonstandardSwap')) -> ((QlExercise) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CNonstandardSwaption'))))))))
 3036 
 3037 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlNonstandardSwaptionCalibrationBasket"
 3038   calibrationBasket'_ :: ((C2HSImp.Ptr (CNonstandardSwaption')) -> ((C2HSImp.Ptr (CSwapIndex')) -> ((C2HSImp.Ptr (CSwaptionVolatilityStructure')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr (C2HSImp.Ptr (CBlackCalibrationHelper')))) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))))
 3039 
 3040 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlFloatFloatSwaption"
 3041   floatFloatSwaption'_ :: ((C2HSImp.Ptr (CFloatFloatSwap')) -> ((QlExercise) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFloatFloatSwaption'))))))))
 3042 
 3043 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlFloatFloatSwaptionCalibrationBasket"
 3044   floatFloatSwaptionCalibrationBasket'_ :: ((C2HSImp.Ptr (CFloatFloatSwaption')) -> ((C2HSImp.Ptr (CSwapIndex')) -> ((C2HSImp.Ptr (CSwaptionVolatilityStructure')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr (C2HSImp.Ptr (CBlackCalibrationHelper')))) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))))
 3045 
 3046 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlAssetSwap"
 3047   assetSwap'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (CBond')) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CIborIndex')) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CSchedule)) -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CAssetSwap')))))))))))))))
 3048 
 3049 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlOvernightIndexedSwap"
 3050   overnightIndexedSwapRaw'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CSchedule)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (COvernightIndex')) -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (COvernightIndexedSwap'))))))))))))))))))))
 3051 
 3052 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlOvernightIndexedSwap1"
 3053   overnightIndexedSwapFromNominalsRaw'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CSchedule)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (COvernightIndex')) -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (COvernightIndexedSwap')))))))))))))))))))))
 3054 
 3055 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlSwapMaturityDate"
 3056   maturityDate'_ :: ((C2HSImp.Ptr (CSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt)))
 3057 
 3058 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlSwapStartDate"
 3059   startDate'_ :: ((C2HSImp.Ptr (CSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt)))
 3060 
 3061 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlSwapNpvDateDiscount"
 3062   npvDateDiscount'_ :: ((C2HSImp.Ptr (CSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3063 
 3064 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlBMASwapBmaLeg"
 3065   bmaLeg'_ :: ((C2HSImp.Ptr (CBMASwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CLeg')))))
 3066 
 3067 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlBMASwapBmaLegBPS"
 3068   bmaLegBps'_ :: ((C2HSImp.Ptr (CBMASwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3069 
 3070 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlBMASwapBmaLegNPV"
 3071   bmaLegNpv'_ :: ((C2HSImp.Ptr (CBMASwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3072 
 3073 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlBMASwapFairLiborFraction"
 3074   fairLiborFraction'_ :: ((C2HSImp.Ptr (CBMASwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3075 
 3076 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlBMASwapFairLiborSpread"
 3077   fairLiborSpread'_ :: ((C2HSImp.Ptr (CBMASwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3078 
 3079 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlBMASwapLiborFraction"
 3080   liborFraction'_ :: ((C2HSImp.Ptr (CBMASwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3081 
 3082 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlBMASwapLiborLeg"
 3083   liborLeg'_ :: ((C2HSImp.Ptr (CBMASwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CLeg')))))
 3084 
 3085 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlBMASwapLiborLegBPS"
 3086   liborLegBps'_ :: ((C2HSImp.Ptr (CBMASwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3087 
 3088 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlBMASwapLiborLegNPV"
 3089   liborLegNpv'_ :: ((C2HSImp.Ptr (CBMASwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3090 
 3091 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlAssetSwapBondLeg"
 3092   bondLeg'_ :: ((C2HSImp.Ptr (CAssetSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CLeg')))))
 3093 
 3094 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlAssetSwapCleanPrice"
 3095   cleanPrice'_ :: ((C2HSImp.Ptr (CAssetSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3096 
 3097 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlAssetSwapFairCleanPrice"
 3098   fairCleanPrice'_ :: ((C2HSImp.Ptr (CAssetSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3099 
 3100 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlAssetSwapFairNonParRepayment"
 3101   fairNonParRepayment'_ :: ((C2HSImp.Ptr (CAssetSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3102 
 3103 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlAssetSwapNonParRepayment"
 3104   nonParRepayment'_ :: ((C2HSImp.Ptr (CAssetSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3105 
 3106 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlAssetSwapParSwap"
 3107   parSwap'_ :: ((C2HSImp.Ptr (CAssetSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt)))
 3108 
 3109 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlAssetSwapPayBondCoupon"
 3110   payBondCoupon'_ :: ((C2HSImp.Ptr (CAssetSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt)))
 3111 
 3112 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlOvernightIndexedSwapOvernightLeg"
 3113   overnightLeg'_ :: ((C2HSImp.Ptr (COvernightIndexedSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CLeg')))))
 3114 
 3115 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlOvernightIndexedSwapOvernightLegBPS"
 3116   overnightLegBps'_ :: ((C2HSImp.Ptr (COvernightIndexedSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3117 
 3118 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlOvernightIndexedSwapOvernightLegNPV"
 3119   overnightLegNpv'_ :: ((C2HSImp.Ptr (COvernightIndexedSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3120 
 3121 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlZeroCouponInflationSwap"
 3122   zeroCouponInflationSwap'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CZeroInflationIndex')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CZeroCouponInflationSwap')))))))))))))))))))
 3123 
 3124 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlZeroCouponInflationSwapFairRate"
 3125   qlZeroCouponInflationSwapFairRate'_ :: ((C2HSImp.Ptr (CZeroCouponInflationSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3126 
 3127 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlYearOnYearInflationSwap"
 3128   yearOnYearInflationSwap'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CSchedule)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CSchedule)) -> ((C2HSImp.Ptr (CYoYInflationIndex')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CYearOnYearInflationSwap'))))))))))))))))))
 3129 
 3130 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlYearOnYearInflationSwapFairRate"
 3131   qlYearOnYearInflationSwapFairRate'_ :: ((C2HSImp.Ptr (CYearOnYearInflationSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3132 
 3133 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlYearOnYearInflationSwapFairSpread"
 3134   qlYearOnYearInflationSwapFairSpread'_ :: ((C2HSImp.Ptr (CYearOnYearInflationSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3135 
 3136 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlCPISwap"
 3137   cpiSwap'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CSchedule)) -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CIborIndex')) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CSchedule)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CZeroInflationIndex')) -> (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CCPISwap')))))))))))))))))))))))
 3138 
 3139 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlCPISwapFairRate"
 3140   qlCPISwapFairRate'_ :: ((C2HSImp.Ptr (CCPISwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3141 
 3142 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlCPISwapFairSpread"
 3143   qlCPISwapFairSpread'_ :: ((C2HSImp.Ptr (CCPISwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3144 
 3145 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlZeroCouponSwap"
 3146   zeroCouponSwap'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CIborIndex')) -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CZeroCouponSwap')))))))))))))
 3147 
 3148 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlZeroCouponSwap1"
 3149   zeroCouponSwapFromRate'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CIborIndex')) -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CZeroCouponSwap'))))))))))))))
 3150 
 3151 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlZeroCouponSwapFairFixedPayment"
 3152   fairFixedPayment'_ :: ((C2HSImp.Ptr (CZeroCouponSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3153 
 3154 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlZeroCouponSwapFairFixedRate"
 3155   fairFixedRate'_ :: ((C2HSImp.Ptr (CZeroCouponSwap')) -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 3156 
 3157 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlEquityTotalReturnSwapIbor"
 3158   equityTotalReturnSwapIbor'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CSchedule)) -> ((C2HSImp.Ptr (CEquityIndex')) -> ((C2HSImp.Ptr (CIborIndex')) -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CEquityTotalReturnSwap')))))))))))))))
 3159 
 3160 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlEquityTotalReturnSwapOvernight"
 3161   equityTotalReturnSwapOvernight'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CSchedule)) -> ((C2HSImp.Ptr (CEquityIndex')) -> ((C2HSImp.Ptr (COvernightIndex')) -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CEquityTotalReturnSwap')))))))))))))))
 3162 
 3163 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlEquityTotalReturnSwapEquityLegNPV"
 3164   equityLegNpv'_ :: ((C2HSImp.Ptr (CEquityTotalReturnSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3165 
 3166 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlEquityTotalReturnSwapInterestRateLegNPV"
 3167   interestRateLegNpv'_ :: ((C2HSImp.Ptr (CEquityTotalReturnSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3168 
 3169 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlEquityTotalReturnSwapFairMargin"
 3170   fairMargin'_ :: ((C2HSImp.Ptr (CEquityTotalReturnSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3171 
 3172 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlSwaptionUnderlying"
 3173   qlSwaptionUnderlying'_ :: ((C2HSImp.Ptr (CSwaption')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFixedVsFloatingSwap')))))
 3174 
 3175 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlNonstandardSwaptionUnderlyingSwap"
 3176   qlNonstandardSwaptionUnderlyingSwap'_ :: ((C2HSImp.Ptr (CNonstandardSwaption')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CNonstandardSwap')))))
 3177 
 3178 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlFloatFloatSwaptionUnderlyingSwap"
 3179   qlFloatFloatSwaptionUnderlyingSwap'_ :: ((C2HSImp.Ptr (CFloatFloatSwaption')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFloatFloatSwap')))))
 3180 
 3181 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlIrregularSwaptionUnderlyingSwap"
 3182   qlIrregularSwaptionUnderlyingSwap'_ :: ((C2HSImp.Ptr (CIrregularSwaption')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CIrregularSwap')))))
 3183 
 3184 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlCdsOptionUnderlyingSwap"
 3185   qlCdsOptionUnderlyingSwap'_ :: ((C2HSImp.Ptr (CCdsOption')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CCreditDefaultSwap')))))
 3186 
 3187 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlFixedVsFloatingSwapFairSpread"
 3188   qlFixedVsFloatingSwapFairSpread'_ :: ((C2HSImp.Ptr (CFixedVsFloatingSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3189 
 3190 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlAssetSwapFairSpread"
 3191   qlAssetSwapFairSpread'_ :: ((C2HSImp.Ptr (CAssetSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3192 
 3193 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlFixedVsFloatingSwapFairRate"
 3194   qlFixedVsFloatingSwapFairRate'_ :: ((C2HSImp.Ptr (CFixedVsFloatingSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3195 
 3196 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlFixedVsFloatingSwapFixedLeg"
 3197   qlFixedVsFloatingSwapFixedLeg'_ :: ((C2HSImp.Ptr (CFixedVsFloatingSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CLeg')))))
 3198 
 3199 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlFixedVsFloatingSwapFixedLegBPS"
 3200   qlFixedVsFloatingSwapFixedLegBPS'_ :: ((C2HSImp.Ptr (CFixedVsFloatingSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3201 
 3202 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlFixedVsFloatingSwapFixedLegNPV"
 3203   qlFixedVsFloatingSwapFixedLegNPV'_ :: ((C2HSImp.Ptr (CFixedVsFloatingSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3204 
 3205 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlCreditDefaultSwapFairSpread"
 3206   qlCreditDefaultSwapFairSpread'_ :: ((C2HSImp.Ptr (CCreditDefaultSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3207 
 3208 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlFixedVsFloatingSwapFloatingLeg"
 3209   qlFixedVsFloatingSwapFloatingLeg'_ :: ((C2HSImp.Ptr (CFixedVsFloatingSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CLeg')))))
 3210 
 3211 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlFixedVsFloatingSwapFloatingLegBPS"
 3212   qlFixedVsFloatingSwapFloatingLegBPS'_ :: ((C2HSImp.Ptr (CFixedVsFloatingSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3213 
 3214 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlFixedVsFloatingSwapFloatingLegNPV"
 3215   qlFixedVsFloatingSwapFloatingLegNPV'_ :: ((C2HSImp.Ptr (CFixedVsFloatingSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3216 
 3217 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlAssetSwapFloatingLeg"
 3218   qlAssetSwapFloatingLeg'_ :: ((C2HSImp.Ptr (CAssetSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CLeg')))))
 3219 
 3220 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlAssetSwapFloatingLegBPS"
 3221   qlAssetSwapFloatingLegBPS'_ :: ((C2HSImp.Ptr (CAssetSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3222 
 3223 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlAssetSwapFloatingLegNPV"
 3224   qlAssetSwapFloatingLegNPV'_ :: ((C2HSImp.Ptr (CAssetSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3225 
 3226 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlVarianceSwap"
 3227   varianceSwap'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CVarianceSwap')))))))))
 3228 
 3229 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlVarianceSwapVariance"
 3230   variance'_ :: ((C2HSImp.Ptr (CVarianceSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3231 
 3232 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlVarianceOption"
 3233   varianceOption'_ :: ((QlPayoff) -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CVarianceOption'))))))))
 3234 
 3235 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlMtMCrossCurrencyBasisSwap"
 3236   mtmCrossCurrencyBasisSwapRaw'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CSchedule)) -> ((C2HSImp.Ptr (CIborIndex')) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CSchedule)) -> ((C2HSImp.Ptr (CIborIndex')) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((QlStubIndexSelection) -> ((QlStubIndexSelection) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CMtMCrossCurrencyBasisSwap'))))))))))))))))))))))))))))))))))))))
 3237 
 3238 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlMtMLegCurrency"
 3239   mtmLegCurrency'_ :: ((C2HSImp.Ptr (CMtMCrossCurrencyBasisSwap')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CCurrency))))))
 3240 
 3241 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlMtMInCcyLegBPS"
 3242   mtmInCcyLegBPS'_ :: ((C2HSImp.Ptr (CMtMCrossCurrencyBasisSwap')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 3243 
 3244 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlMtMInCcyLegNPV"
 3245   mtmInCcyLegNPV'_ :: ((C2HSImp.Ptr (CMtMCrossCurrencyBasisSwap')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 3246 
 3247 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlMtMNpvDateDiscounts"
 3248   mtmNpvDateDiscounts'_ :: ((C2HSImp.Ptr (CMtMCrossCurrencyBasisSwap')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 3249 
 3250 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlMtMFairFxBaseSpread"
 3251   fairFxBaseSpread'_ :: ((C2HSImp.Ptr (CMtMCrossCurrencyBasisSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3252 
 3253 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlMtMFairFxQuoteSpread"
 3254   fairFxQuoteSpread'_ :: ((C2HSImp.Ptr (CMtMCrossCurrencyBasisSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3255 
 3256 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlMtMFairPaySpread"
 3257   mtmFairPaySpread'_ :: ((C2HSImp.Ptr (CMtMCrossCurrencyBasisSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3258 
 3259 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlMtMFairRecSpread"
 3260   mtmFairRecSpread'_ :: ((C2HSImp.Ptr (CMtMCrossCurrencyBasisSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
 3261 
 3262 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlMtMFxResetRates"
 3263   fxResetRates'_ :: ((C2HSImp.Ptr (CMtMCrossCurrencyBasisSwap')) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
 3264 
 3265 foreign import ccall safe "QuantLib/Instrument/Swap.chs.h qlMtMFxResetNotionals"
 3266   fxResetNotionals'_ :: ((C2HSImp.Ptr (CMtMCrossCurrencyBasisSwap')) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))