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, StandaloneDeriving, PatternSynonyms #-}
    6 -- suppress warnings about unused Extra_ constructors
    7 {-# OPTIONS_GHC -Wno-unused-top-binds #-}
    8 module QuantLib.Index.InterestRate
    9   (
   10     -- * Types
   11     -- ** Interest-rate index hierarchy
   12     GenInterestRateIndex
   13   , InterestRateIndex
   14   , GenIborIndex
   15   , IborIndex
   16   , GenSwapIndex
   17   , SwapIndex
   18   , BMAIndex
   19   , OvernightIborIndex
   20   , SwapSpreadIndex
   21   , OvernightIndexedSwapIndex
   22 
   23     -- * Constructors
   24     -- ** BMA indices
   25   , bmaIndex
   26 
   27     -- ** Hierarchy conversion
   28   , asInterestRateIndex
   29   , asIborIndex
   30   , asSwapIndex
   31 
   32     -- ** Overnight and swap indices
   33   , OvernightIborIndexType(..)
   34   , overnightIborIndex
   35 
   36   , LiborSwapIndexType(..)
   37   , liborSwapIndex
   38 
   39   , overnightIndexedSwapIndex
   40   , swapIndex
   41   , swapIndexWithDiscountCurve
   42   , swapSpreadIndex
   43 
   44     -- ** Ibor index catalogue
   45 
   46   -- The bundled names are the fixed-tenor shortcut pattern synonyms defined below;
   47   -- @Euribor3M@ and @Euribor (3, Months)@ are the same value, usable interchangeably
   48   -- in expressions and in patterns.
   49   , IborConstructor(.., Bbsw1M, Bbsw2M, Bbsw3M, Bbsw4M, Bbsw5M, Bbsw6M
   50                       , BiborSW, Bibor1M, Bibor2M, Bibor3M, Bibor6M, Bibor9M, Bibor1Y
   51                       , Bkbm1M, Bkbm2M, Bkbm3M, Bkbm4M, Bkbm5M, Bkbm6M
   52                       , EuriborSW, Euribor2W, Euribor3W
   53                       , Euribor1M, Euribor2M, Euribor3M, Euribor4M, Euribor5M, Euribor6M
   54                       , Euribor7M, Euribor8M, Euribor9M, Euribor10M, Euribor11M, Euribor1Y
   55                       , Euribor365_SW, Euribor365_2W, Euribor365_3W
   56                       , Euribor365_1M, Euribor365_2M, Euribor365_3M, Euribor365_4M
   57                       , Euribor365_5M, Euribor365_6M, Euribor365_7M, Euribor365_8M
   58                       , Euribor365_9M, Euribor365_10M, Euribor365_11M, Euribor365_1Y
   59                       , EurLiborSW, EurLibor2W
   60                       , EurLibor1M, EurLibor2M, EurLibor3M, EurLibor4M, EurLibor5M, EurLibor6M
   61                       , EurLibor7M, EurLibor8M, EurLibor9M, EurLibor10M, EurLibor11M, EurLibor1Y)
   62   , iborIndex
   63   , overnightIndex
   64 
   65     -- * Inspectors
   66     -- ** Index dates and conventions
   67   , fixingSchedule
   68   , forecastFixing
   69   , currency
   70   , dayCounter
   71   , fixingDays
   72   , tenor
   73   , fixingDate
   74   , valueDate
   75   , maturityDate
   76   , businessDayConvention
   77   , endOfMonth
   78 
   79     -- ** Underlying swaps and history
   80   , underlyingSwap
   81   , underlyingOis
   82 
   83   , historicalRatesAnalysis
   84   ) where
   85 import qualified Foreign.C.String as C2HSImp
   86 import qualified Foreign.C.Types as C2HSImp
   87 import qualified Foreign.ForeignPtr as C2HSImp
   88 import qualified Foreign.Marshal.Utils as C2HSImp
   89 import qualified Foreign.Ptr as C2HSImp
   90 import qualified System.IO.Unsafe as C2HSImp
   91 
   92 
   93 import QuantLib.Internal
   94 import QuantLib.Internal.Syntax
   95 import QuantLib.Internal.Common
   96 import QuantLib.Internal.Type
   97 import QuantLib.Index (historicalIndexAnalysis)
   98 -- Plain (non-c2hs) import: QuantLib.CashFlow is later in exposed-modules than
   99 -- this file, so a {#import#} here would need its .chi before it exists.
  100 -- overnightIndexedSwapIndex below marshals RateAveragingType as a plain Int
  101 -- via fromEnum instead.
  102 import QuantLib.CashFlow (RateAveragingType)
  103 -- Only for IborConstructor's Read instance below (deriveReadInstance's materializer
  104 -- table): this module already defines its own `currency`/`dayCounter` (an
  105 -- InterestRateIndex's currency/day counter, unrelated), so these come in qualified to
  106 -- avoid clashing with them.
  107 import QuantLib.Time.Calendar (calendar)
  108 import qualified QuantLib.Currency as Ccy (currency)
  109 import qualified QuantLib.Time.Schedule as Sched (dayCounter)
  110 import Data.List.NonEmpty(NonEmpty, toList)
  111 
  112 
  113 
  114 
  115 
  116 
  117 
  118 
  119 
  120 
  121 
  122 
  123 
  124 
  125 
  126 
  127 
  128 
  129 
  130 
  131 
  132 
  133 
  134 
  135 
  136 
  137 
  138 
  139 
  140 
  141 
  142 
  143 
  144 
  145 
  146 
  147 data OvernightIborIndexType = Aonia
  148                             | Eonia
  149                             | Estr
  150                             | FedFunds
  151                             | Nzocr
  152                             | Sofr
  153                             | Sonia
  154                             | Cdi
  155                             | Corra
  156                             | Kofr
  157                             | Destr
  158                             | Swestr
  159                             | Shir
  160                             | Tonar
  161                             | Saron
  162                             | Zaronia
  163   deriving (Show,Eq,Read)
  164 instance Enum OvernightIborIndexType where
  165   succ Aonia = Eonia
  166   succ Eonia = Estr
  167   succ Estr = FedFunds
  168   succ FedFunds = Nzocr
  169   succ Nzocr = Sofr
  170   succ Sofr = Sonia
  171   succ Sonia = Cdi
  172   succ Cdi = Corra
  173   succ Corra = Kofr
  174   succ Kofr = Destr
  175   succ Destr = Swestr
  176   succ Swestr = Shir
  177   succ Shir = Tonar
  178   succ Tonar = Saron
  179   succ Saron = Zaronia
  180   succ Zaronia = error "OvernightIborIndexType.succ: Zaronia has no successor"
  181 
  182   pred Eonia = Aonia
  183   pred Estr = Eonia
  184   pred FedFunds = Estr
  185   pred Nzocr = FedFunds
  186   pred Sofr = Nzocr
  187   pred Sonia = Sofr
  188   pred Cdi = Sonia
  189   pred Corra = Cdi
  190   pred Kofr = Corra
  191   pred Destr = Kofr
  192   pred Swestr = Destr
  193   pred Shir = Swestr
  194   pred Tonar = Shir
  195   pred Saron = Tonar
  196   pred Zaronia = Saron
  197   pred Aonia = error "OvernightIborIndexType.pred: Aonia has no predecessor"
  198 
  199   enumFromTo from to = go from
  200     where
  201       end = fromEnum to
  202       go v = case compare (fromEnum v) end of
  203                  LT -> v : go (succ v)
  204                  EQ -> [v]
  205                  GT -> []
  206 
  207   enumFrom from = enumFromTo from Zaronia
  208 
  209   fromEnum Aonia = 0
  210   fromEnum Eonia = 1
  211   fromEnum Estr = 2
  212   fromEnum FedFunds = 3
  213   fromEnum Nzocr = 4
  214   fromEnum Sofr = 5
  215   fromEnum Sonia = 6
  216   fromEnum Cdi = 7
  217   fromEnum Corra = 8
  218   fromEnum Kofr = 9
  219   fromEnum Destr = 10
  220   fromEnum Swestr = 11
  221   fromEnum Shir = 12
  222   fromEnum Tonar = 13
  223   fromEnum Saron = 14
  224   fromEnum Zaronia = 15
  225 
  226   toEnum 0 = Aonia
  227   toEnum 1 = Eonia
  228   toEnum 2 = Estr
  229   toEnum 3 = FedFunds
  230   toEnum 4 = Nzocr
  231   toEnum 5 = Sofr
  232   toEnum 6 = Sonia
  233   toEnum 7 = Cdi
  234   toEnum 8 = Corra
  235   toEnum 9 = Kofr
  236   toEnum 10 = Destr
  237   toEnum 11 = Swestr
  238   toEnum 12 = Shir
  239   toEnum 13 = Tonar
  240   toEnum 14 = Saron
  241   toEnum 15 = Zaronia
  242   toEnum unmatched = error ("OvernightIborIndexType.toEnum: Cannot match " ++ show unmatched)
  243 
  244 
  245 data LiborSwapIndexType = ChfLiborSwapIsdaFix
  246                         | EurLiborSwapIfrFix
  247                         | EurLiborSwapIsdaFixA
  248                         | EurLiborSwapIsdaFixB
  249                         | EuriborSwapIfrFix
  250                         | EuriborSwapIsdaFixA
  251                         | EuriborSwapIsdaFixB
  252                         | GbpLiborSwapIsdaFix
  253                         | JpyLiborSwapIsdaFixAm
  254                         | JpyLiborSwapIsdaFixPm
  255                         | UsdLiborSwapIsdaFixAm
  256                         | UsdLiborSwapIsdaFixPm
  257   deriving (Show,Eq,Read)
  258 instance Enum LiborSwapIndexType where
  259   succ ChfLiborSwapIsdaFix = EurLiborSwapIfrFix
  260   succ EurLiborSwapIfrFix = EurLiborSwapIsdaFixA
  261   succ EurLiborSwapIsdaFixA = EurLiborSwapIsdaFixB
  262   succ EurLiborSwapIsdaFixB = EuriborSwapIfrFix
  263   succ EuriborSwapIfrFix = EuriborSwapIsdaFixA
  264   succ EuriborSwapIsdaFixA = EuriborSwapIsdaFixB
  265   succ EuriborSwapIsdaFixB = GbpLiborSwapIsdaFix
  266   succ GbpLiborSwapIsdaFix = JpyLiborSwapIsdaFixAm
  267   succ JpyLiborSwapIsdaFixAm = JpyLiborSwapIsdaFixPm
  268   succ JpyLiborSwapIsdaFixPm = UsdLiborSwapIsdaFixAm
  269   succ UsdLiborSwapIsdaFixAm = UsdLiborSwapIsdaFixPm
  270   succ UsdLiborSwapIsdaFixPm = error "LiborSwapIndexType.succ: UsdLiborSwapIsdaFixPm has no successor"
  271 
  272   pred EurLiborSwapIfrFix = ChfLiborSwapIsdaFix
  273   pred EurLiborSwapIsdaFixA = EurLiborSwapIfrFix
  274   pred EurLiborSwapIsdaFixB = EurLiborSwapIsdaFixA
  275   pred EuriborSwapIfrFix = EurLiborSwapIsdaFixB
  276   pred EuriborSwapIsdaFixA = EuriborSwapIfrFix
  277   pred EuriborSwapIsdaFixB = EuriborSwapIsdaFixA
  278   pred GbpLiborSwapIsdaFix = EuriborSwapIsdaFixB
  279   pred JpyLiborSwapIsdaFixAm = GbpLiborSwapIsdaFix
  280   pred JpyLiborSwapIsdaFixPm = JpyLiborSwapIsdaFixAm
  281   pred UsdLiborSwapIsdaFixAm = JpyLiborSwapIsdaFixPm
  282   pred UsdLiborSwapIsdaFixPm = UsdLiborSwapIsdaFixAm
  283   pred ChfLiborSwapIsdaFix = error "LiborSwapIndexType.pred: ChfLiborSwapIsdaFix has no predecessor"
  284 
  285   enumFromTo from to = go from
  286     where
  287       end = fromEnum to
  288       go v = case compare (fromEnum v) end of
  289                  LT -> v : go (succ v)
  290                  EQ -> [v]
  291                  GT -> []
  292 
  293   enumFrom from = enumFromTo from UsdLiborSwapIsdaFixPm
  294 
  295   fromEnum ChfLiborSwapIsdaFix = 0
  296   fromEnum EurLiborSwapIfrFix = 1
  297   fromEnum EurLiborSwapIsdaFixA = 2
  298   fromEnum EurLiborSwapIsdaFixB = 3
  299   fromEnum EuriborSwapIfrFix = 4
  300   fromEnum EuriborSwapIsdaFixA = 5
  301   fromEnum EuriborSwapIsdaFixB = 6
  302   fromEnum GbpLiborSwapIsdaFix = 7
  303   fromEnum JpyLiborSwapIsdaFixAm = 8
  304   fromEnum JpyLiborSwapIsdaFixPm = 9
  305   fromEnum UsdLiborSwapIsdaFixAm = 10
  306   fromEnum UsdLiborSwapIsdaFixPm = 11
  307 
  308   toEnum 0 = ChfLiborSwapIsdaFix
  309   toEnum 1 = EurLiborSwapIfrFix
  310   toEnum 2 = EurLiborSwapIsdaFixA
  311   toEnum 3 = EurLiborSwapIsdaFixB
  312   toEnum 4 = EuriborSwapIfrFix
  313   toEnum 5 = EuriborSwapIsdaFixA
  314   toEnum 6 = EuriborSwapIsdaFixB
  315   toEnum 7 = GbpLiborSwapIsdaFix
  316   toEnum 8 = JpyLiborSwapIsdaFixAm
  317   toEnum 9 = JpyLiborSwapIsdaFixPm
  318   toEnum 10 = UsdLiborSwapIsdaFixAm
  319   toEnum 11 = UsdLiborSwapIsdaFixPm
  320   toEnum unmatched = error ("LiborSwapIndexType.toEnum: Cannot match " ++ show unmatched)
  321 
  322 
  323 data IborIndexType = Ibor__Bbsw
  324                    | Ibor__Bibor
  325                    | Ibor__Bkbm
  326                    | Ibor__Cdor
  327                    | Ibor__EurLibor
  328                    | Ibor__AudLibor
  329                    | Ibor__CadLibor
  330                    | Ibor__ChfLibor
  331                    | Ibor__DkkLibor
  332                    | Ibor__GbpLibor
  333                    | Ibor__JpyLibor
  334                    | Ibor__NzdLibor
  335                    | Ibor__SekLibor
  336                    | Ibor__UsdLibor
  337                    | Ibor__Euribor
  338                    | Ibor__Euribor365
  339                    | Ibor__Jibar
  340                    | Ibor__Mosprime
  341                    | Ibor__Pribor
  342                    | Ibor__Robor
  343                    | Ibor__Shibor
  344                    | Ibor__THBFIX
  345                    | Ibor__TRLibor
  346                    | Ibor__Tibor
  347                    | Ibor__Wibor
  348                    | Ibor__Zibor
  349                    | Ibor__Nibor
  350                    | Ibor__IborIndexTypeLast
  351   deriving (Show,Eq,Read)
  352 instance Enum IborIndexType where
  353   succ Ibor__Bbsw = Ibor__Bibor
  354   succ Ibor__Bibor = Ibor__Bkbm
  355   succ Ibor__Bkbm = Ibor__Cdor
  356   succ Ibor__Cdor = Ibor__EurLibor
  357   succ Ibor__EurLibor = Ibor__AudLibor
  358   succ Ibor__AudLibor = Ibor__CadLibor
  359   succ Ibor__CadLibor = Ibor__ChfLibor
  360   succ Ibor__ChfLibor = Ibor__DkkLibor
  361   succ Ibor__DkkLibor = Ibor__GbpLibor
  362   succ Ibor__GbpLibor = Ibor__JpyLibor
  363   succ Ibor__JpyLibor = Ibor__NzdLibor
  364   succ Ibor__NzdLibor = Ibor__SekLibor
  365   succ Ibor__SekLibor = Ibor__UsdLibor
  366   succ Ibor__UsdLibor = Ibor__Euribor
  367   succ Ibor__Euribor = Ibor__Euribor365
  368   succ Ibor__Euribor365 = Ibor__Jibar
  369   succ Ibor__Jibar = Ibor__Mosprime
  370   succ Ibor__Mosprime = Ibor__Pribor
  371   succ Ibor__Pribor = Ibor__Robor
  372   succ Ibor__Robor = Ibor__Shibor
  373   succ Ibor__Shibor = Ibor__THBFIX
  374   succ Ibor__THBFIX = Ibor__TRLibor
  375   succ Ibor__TRLibor = Ibor__Tibor
  376   succ Ibor__Tibor = Ibor__Wibor
  377   succ Ibor__Wibor = Ibor__Zibor
  378   succ Ibor__Zibor = Ibor__Nibor
  379   succ Ibor__Nibor = Ibor__IborIndexTypeLast
  380   succ Ibor__IborIndexTypeLast = error "IborIndexType.succ: Ibor__IborIndexTypeLast has no successor"
  381 
  382   pred Ibor__Bibor = Ibor__Bbsw
  383   pred Ibor__Bkbm = Ibor__Bibor
  384   pred Ibor__Cdor = Ibor__Bkbm
  385   pred Ibor__EurLibor = Ibor__Cdor
  386   pred Ibor__AudLibor = Ibor__EurLibor
  387   pred Ibor__CadLibor = Ibor__AudLibor
  388   pred Ibor__ChfLibor = Ibor__CadLibor
  389   pred Ibor__DkkLibor = Ibor__ChfLibor
  390   pred Ibor__GbpLibor = Ibor__DkkLibor
  391   pred Ibor__JpyLibor = Ibor__GbpLibor
  392   pred Ibor__NzdLibor = Ibor__JpyLibor
  393   pred Ibor__SekLibor = Ibor__NzdLibor
  394   pred Ibor__UsdLibor = Ibor__SekLibor
  395   pred Ibor__Euribor = Ibor__UsdLibor
  396   pred Ibor__Euribor365 = Ibor__Euribor
  397   pred Ibor__Jibar = Ibor__Euribor365
  398   pred Ibor__Mosprime = Ibor__Jibar
  399   pred Ibor__Pribor = Ibor__Mosprime
  400   pred Ibor__Robor = Ibor__Pribor
  401   pred Ibor__Shibor = Ibor__Robor
  402   pred Ibor__THBFIX = Ibor__Shibor
  403   pred Ibor__TRLibor = Ibor__THBFIX
  404   pred Ibor__Tibor = Ibor__TRLibor
  405   pred Ibor__Wibor = Ibor__Tibor
  406   pred Ibor__Zibor = Ibor__Wibor
  407   pred Ibor__Nibor = Ibor__Zibor
  408   pred Ibor__IborIndexTypeLast = Ibor__Nibor
  409   pred Ibor__Bbsw = error "IborIndexType.pred: Ibor__Bbsw has no predecessor"
  410 
  411   enumFromTo from to = go from
  412     where
  413       end = fromEnum to
  414       go v = case compare (fromEnum v) end of
  415                  LT -> v : go (succ v)
  416                  EQ -> [v]
  417                  GT -> []
  418 
  419   enumFrom from = enumFromTo from Ibor__IborIndexTypeLast
  420 
  421   fromEnum Ibor__Bbsw = 0
  422   fromEnum Ibor__Bibor = 1
  423   fromEnum Ibor__Bkbm = 2
  424   fromEnum Ibor__Cdor = 3
  425   fromEnum Ibor__EurLibor = 4
  426   fromEnum Ibor__AudLibor = 5
  427   fromEnum Ibor__CadLibor = 6
  428   fromEnum Ibor__ChfLibor = 7
  429   fromEnum Ibor__DkkLibor = 8
  430   fromEnum Ibor__GbpLibor = 9
  431   fromEnum Ibor__JpyLibor = 10
  432   fromEnum Ibor__NzdLibor = 11
  433   fromEnum Ibor__SekLibor = 12
  434   fromEnum Ibor__UsdLibor = 13
  435   fromEnum Ibor__Euribor = 14
  436   fromEnum Ibor__Euribor365 = 15
  437   fromEnum Ibor__Jibar = 16
  438   fromEnum Ibor__Mosprime = 17
  439   fromEnum Ibor__Pribor = 18
  440   fromEnum Ibor__Robor = 19
  441   fromEnum Ibor__Shibor = 20
  442   fromEnum Ibor__THBFIX = 21
  443   fromEnum Ibor__TRLibor = 22
  444   fromEnum Ibor__Tibor = 23
  445   fromEnum Ibor__Wibor = 24
  446   fromEnum Ibor__Zibor = 25
  447   fromEnum Ibor__Nibor = 26
  448   fromEnum Ibor__IborIndexTypeLast = 27
  449 
  450   toEnum 0 = Ibor__Bbsw
  451   toEnum 1 = Ibor__Bibor
  452   toEnum 2 = Ibor__Bkbm
  453   toEnum 3 = Ibor__Cdor
  454   toEnum 4 = Ibor__EurLibor
  455   toEnum 5 = Ibor__AudLibor
  456   toEnum 6 = Ibor__CadLibor
  457   toEnum 7 = Ibor__ChfLibor
  458   toEnum 8 = Ibor__DkkLibor
  459   toEnum 9 = Ibor__GbpLibor
  460   toEnum 10 = Ibor__JpyLibor
  461   toEnum 11 = Ibor__NzdLibor
  462   toEnum 12 = Ibor__SekLibor
  463   toEnum 13 = Ibor__UsdLibor
  464   toEnum 14 = Ibor__Euribor
  465   toEnum 15 = Ibor__Euribor365
  466   toEnum 16 = Ibor__Jibar
  467   toEnum 17 = Ibor__Mosprime
  468   toEnum 18 = Ibor__Pribor
  469   toEnum 19 = Ibor__Robor
  470   toEnum 20 = Ibor__Shibor
  471   toEnum 21 = Ibor__THBFIX
  472   toEnum 22 = Ibor__TRLibor
  473   toEnum 23 = Ibor__Tibor
  474   toEnum 24 = Ibor__Wibor
  475   toEnum 25 = Ibor__Zibor
  476   toEnum 26 = Ibor__Nibor
  477   toEnum 27 = Ibor__IborIndexTypeLast
  478   toEnum unmatched = error ("IborIndexType.toEnum: Cannot match " ++ show unmatched)
  479 
  480 
  481 data IborDailyTenorIndexType = Ibor__EurDailyTenorLibor
  482                              | Ibor__ChfDailyTenorLibor
  483                              | Ibor__GbpDailyTenorLibor
  484                              | Ibor__JpyDailyTenorLibor
  485                              | Ibor__UsdDailyTenorLibor
  486                              | Ibor__IborDailyTenorIndexTypeLast
  487   deriving (Show,Eq,Read)
  488 instance Enum IborDailyTenorIndexType where
  489   succ Ibor__EurDailyTenorLibor = Ibor__ChfDailyTenorLibor
  490   succ Ibor__ChfDailyTenorLibor = Ibor__GbpDailyTenorLibor
  491   succ Ibor__GbpDailyTenorLibor = Ibor__JpyDailyTenorLibor
  492   succ Ibor__JpyDailyTenorLibor = Ibor__UsdDailyTenorLibor
  493   succ Ibor__UsdDailyTenorLibor = Ibor__IborDailyTenorIndexTypeLast
  494   succ Ibor__IborDailyTenorIndexTypeLast = error "IborDailyTenorIndexType.succ: Ibor__IborDailyTenorIndexTypeLast has no successor"
  495 
  496   pred Ibor__ChfDailyTenorLibor = Ibor__EurDailyTenorLibor
  497   pred Ibor__GbpDailyTenorLibor = Ibor__ChfDailyTenorLibor
  498   pred Ibor__JpyDailyTenorLibor = Ibor__GbpDailyTenorLibor
  499   pred Ibor__UsdDailyTenorLibor = Ibor__JpyDailyTenorLibor
  500   pred Ibor__IborDailyTenorIndexTypeLast = Ibor__UsdDailyTenorLibor
  501   pred Ibor__EurDailyTenorLibor = error "IborDailyTenorIndexType.pred: Ibor__EurDailyTenorLibor has no predecessor"
  502 
  503   enumFromTo from to = go from
  504     where
  505       end = fromEnum to
  506       go v = case compare (fromEnum v) end of
  507                  LT -> v : go (succ v)
  508                  EQ -> [v]
  509                  GT -> []
  510 
  511   enumFrom from = enumFromTo from Ibor__IborDailyTenorIndexTypeLast
  512 
  513   fromEnum Ibor__EurDailyTenorLibor = 0
  514   fromEnum Ibor__ChfDailyTenorLibor = 1
  515   fromEnum Ibor__GbpDailyTenorLibor = 2
  516   fromEnum Ibor__JpyDailyTenorLibor = 3
  517   fromEnum Ibor__UsdDailyTenorLibor = 4
  518   fromEnum Ibor__IborDailyTenorIndexTypeLast = 5
  519 
  520   toEnum 0 = Ibor__EurDailyTenorLibor
  521   toEnum 1 = Ibor__ChfDailyTenorLibor
  522   toEnum 2 = Ibor__GbpDailyTenorLibor
  523   toEnum 3 = Ibor__JpyDailyTenorLibor
  524   toEnum 4 = Ibor__UsdDailyTenorLibor
  525   toEnum 5 = Ibor__IborDailyTenorIndexTypeLast
  526   toEnum unmatched = error ("IborDailyTenorIndexType.toEnum: Cannot match " ++ show unmatched)
  527 
  528 
  529 data IborONIndexType = Ibor__CadLiborON
  530                      | Ibor__EurLiborON
  531                      | Ibor__GbpLiborON
  532                      | Ibor__UsdLiborON
  533   deriving (Show,Eq,Read)
  534 instance Enum IborONIndexType where
  535   succ Ibor__CadLiborON = Ibor__EurLiborON
  536   succ Ibor__EurLiborON = Ibor__GbpLiborON
  537   succ Ibor__GbpLiborON = Ibor__UsdLiborON
  538   succ Ibor__UsdLiborON = error "IborONIndexType.succ: Ibor__UsdLiborON has no successor"
  539 
  540   pred Ibor__EurLiborON = Ibor__CadLiborON
  541   pred Ibor__GbpLiborON = Ibor__EurLiborON
  542   pred Ibor__UsdLiborON = Ibor__GbpLiborON
  543   pred Ibor__CadLiborON = error "IborONIndexType.pred: Ibor__CadLiborON has no predecessor"
  544 
  545   enumFromTo from to = go from
  546     where
  547       end = fromEnum to
  548       go v = case compare (fromEnum v) end of
  549                  LT -> v : go (succ v)
  550                  EQ -> [v]
  551                  GT -> []
  552 
  553   enumFrom from = enumFromTo from Ibor__UsdLiborON
  554 
  555   fromEnum Ibor__CadLiborON = 0
  556   fromEnum Ibor__EurLiborON = 1
  557   fromEnum Ibor__GbpLiborON = 2
  558   fromEnum Ibor__UsdLiborON = 3
  559 
  560   toEnum 0 = Ibor__CadLiborON
  561   toEnum 1 = Ibor__EurLiborON
  562   toEnum 2 = Ibor__GbpLiborON
  563   toEnum 3 = Ibor__UsdLiborON
  564   toEnum unmatched = error ("IborONIndexType.toEnum: Cannot match " ++ show unmatched)
  565 
  566 
  567 
  568 -- the fully generic, non-enum-ordinal IborConstructor cases, merged into IborConstructor by
  569 -- deriveIborConstructor below alongside the plain-tenor/daily-tenor/overnight cases generated
  570 -- straight from IborIndexType/IborDailyTenorIndexType/IborONIndexType
  571 data IborExtra =
  572       Extra__Ibor String -- ^familyName
  573       (Word, TimeUnit) -- ^tenor
  574       Word -- ^settlementDays
  575       Currency
  576       Calendar -- ^fixingCalendar
  577       BusinessDayConvention
  578       Bool -- ^endOfMonth
  579       DayCounter
  580     | Extra__Libor String (Word, TimeUnit) Word -- ^settlementDays
  581       Currency Calendar DayCounter
  582     | Extra__DailyTenorLibor String Word -- ^settlementDays
  583       Currency Calendar DayCounter
  584     | Extra__CustomIbor String -- ^familyName
  585       (Word, TimeUnit) -- ^tenor
  586       Word -- ^settlementDays
  587       Currency
  588       Calendar -- ^fixingCalendar
  589       Calendar -- ^valueCalendar
  590       Calendar -- ^maturityCalendar
  591       BusinessDayConvention
  592       Bool -- ^endOfMonth
  593       DayCounter
  594 
  595 $(deriveIborConstructor IborConstructorSpec
  596     { iborTypeName = "IborConstructor"
  597     , iborOrdinalFn = "iborIndexOrdinal"
  598     , iborTenorFn = "iborIndexTenor"
  599     , iborTenorEnum = ''IborIndexType
  600     , iborDailyTenorEnum = ''IborDailyTenorIndexType
  601     , iborOvernightEnum = ''IborONIndexType
  602     , iborExtraType = ''IborExtra
  603     })
  604 
  605 deriving instance Show IborConstructor
  606 deriving instance Eq IborConstructor
  607 
  608 -- Spliced here rather than alongside IborConstructor's declaration just above: this needs
  609 -- `calendar`/`Ccy.currency`/`Sched.dayCounter`, none of which InterestRate.chs's own
  610 -- declaration site could import without a cycle back through this module. See
  611 -- deriveReadInstance's comment in Internal/Syntax.hs for the general shape; Schedule.chs and
  612 -- Calendar.chs use the identical pattern for DayCounterConstructor/CalendarConstructor.
  613 $(deriveReadInstance ''IborConstructor
  614     [ ("Calendar", 'calendar)
  615     , ("Currency", 'Ccy.currency)
  616     , ("DayCounter", 'Sched.dayCounter)
  617     ])
  618 
  619 -- Fixed-tenor shortcuts mirroring upstream's thin @Euribor3M@-style subclasses. Bidirectional
  620 -- pattern synonyms keep family and tenor in the parameterized value instead of a second dispatch
  621 -- table that could drift.
  622 pattern Bbsw1M, Bbsw2M, Bbsw3M, Bbsw4M, Bbsw5M, Bbsw6M :: IborConstructor
  623 pattern Bbsw1M = Bbsw (1, Months)
  624 pattern Bbsw2M = Bbsw (2, Months)
  625 pattern Bbsw3M = Bbsw (3, Months)
  626 pattern Bbsw4M = Bbsw (4, Months)
  627 pattern Bbsw5M = Bbsw (5, Months)
  628 pattern Bbsw6M = Bbsw (6, Months)
  629 
  630 pattern BiborSW, Bibor1M, Bibor2M, Bibor3M, Bibor6M, Bibor9M, Bibor1Y :: IborConstructor
  631 pattern BiborSW = Bibor (1, Weeks)
  632 pattern Bibor1M = Bibor (1, Months)
  633 pattern Bibor2M = Bibor (2, Months)
  634 pattern Bibor3M = Bibor (3, Months)
  635 pattern Bibor6M = Bibor (6, Months)
  636 pattern Bibor9M = Bibor (9, Months)
  637 pattern Bibor1Y = Bibor (1, Years)
  638 
  639 pattern Bkbm1M, Bkbm2M, Bkbm3M, Bkbm4M, Bkbm5M, Bkbm6M :: IborConstructor
  640 pattern Bkbm1M = Bkbm (1, Months)
  641 pattern Bkbm2M = Bkbm (2, Months)
  642 pattern Bkbm3M = Bkbm (3, Months)
  643 pattern Bkbm4M = Bkbm (4, Months)
  644 pattern Bkbm5M = Bkbm (5, Months)
  645 pattern Bkbm6M = Bkbm (6, Months)
  646 
  647 pattern EuriborSW, Euribor2W, Euribor3W, Euribor1M, Euribor2M, Euribor3M, Euribor4M
  648   , Euribor5M, Euribor6M, Euribor7M, Euribor8M, Euribor9M, Euribor10M, Euribor11M
  649   , Euribor1Y :: IborConstructor
  650 pattern EuriborSW = Euribor (1, Weeks)
  651 pattern Euribor2W = Euribor (2, Weeks)
  652 pattern Euribor3W = Euribor (3, Weeks)
  653 pattern Euribor1M = Euribor (1, Months)
  654 pattern Euribor2M = Euribor (2, Months)
  655 pattern Euribor3M = Euribor (3, Months)
  656 pattern Euribor4M = Euribor (4, Months)
  657 pattern Euribor5M = Euribor (5, Months)
  658 pattern Euribor6M = Euribor (6, Months)
  659 pattern Euribor7M = Euribor (7, Months)
  660 pattern Euribor8M = Euribor (8, Months)
  661 pattern Euribor9M = Euribor (9, Months)
  662 pattern Euribor10M = Euribor (10, Months)
  663 pattern Euribor11M = Euribor (11, Months)
  664 pattern Euribor1Y = Euribor (1, Years)
  665 
  666 pattern Euribor365_SW, Euribor365_2W, Euribor365_3W, Euribor365_1M, Euribor365_2M
  667   , Euribor365_3M, Euribor365_4M, Euribor365_5M, Euribor365_6M, Euribor365_7M
  668   , Euribor365_8M, Euribor365_9M, Euribor365_10M, Euribor365_11M
  669   , Euribor365_1Y :: IborConstructor
  670 pattern Euribor365_SW = Euribor365 (1, Weeks)
  671 pattern Euribor365_2W = Euribor365 (2, Weeks)
  672 pattern Euribor365_3W = Euribor365 (3, Weeks)
  673 pattern Euribor365_1M = Euribor365 (1, Months)
  674 pattern Euribor365_2M = Euribor365 (2, Months)
  675 pattern Euribor365_3M = Euribor365 (3, Months)
  676 pattern Euribor365_4M = Euribor365 (4, Months)
  677 pattern Euribor365_5M = Euribor365 (5, Months)
  678 pattern Euribor365_6M = Euribor365 (6, Months)
  679 pattern Euribor365_7M = Euribor365 (7, Months)
  680 pattern Euribor365_8M = Euribor365 (8, Months)
  681 pattern Euribor365_9M = Euribor365 (9, Months)
  682 pattern Euribor365_10M = Euribor365 (10, Months)
  683 pattern Euribor365_11M = Euribor365 (11, Months)
  684 pattern Euribor365_1Y = Euribor365 (1, Years)
  685 
  686 pattern EurLiborSW, EurLibor2W, EurLibor1M, EurLibor2M, EurLibor3M, EurLibor4M
  687   , EurLibor5M, EurLibor6M, EurLibor7M, EurLibor8M, EurLibor9M, EurLibor10M
  688   , EurLibor11M, EurLibor1Y :: IborConstructor
  689 pattern EurLiborSW = EurLibor (1, Weeks)
  690 pattern EurLibor2W = EurLibor (2, Weeks)
  691 pattern EurLibor1M = EurLibor (1, Months)
  692 pattern EurLibor2M = EurLibor (2, Months)
  693 pattern EurLibor3M = EurLibor (3, Months)
  694 pattern EurLibor4M = EurLibor (4, Months)
  695 pattern EurLibor5M = EurLibor (5, Months)
  696 pattern EurLibor6M = EurLibor (6, Months)
  697 pattern EurLibor7M = EurLibor (7, Months)
  698 pattern EurLibor8M = EurLibor (8, Months)
  699 pattern EurLibor9M = EurLibor (9, Months)
  700 pattern EurLibor10M = EurLibor (10, Months)
  701 pattern EurLibor11M = EurLibor (11, Months)
  702 pattern EurLibor1Y = EurLibor (1, Years)
  703 
  704 iborIndex :: IborConstructor -> Maybe (GenYieldTermStructure y) -> IO IborIndex
  705 iborIndex (Ibor n p s cr ca bd b dc) ts = qlIborIndex n p s cr ca bd b dc ts
  706 iborIndex (Libor n p s cr ca dc) ts = qlLibor n p s cr ca dc ts
  707 iborIndex (DailyTenorLibor n c cr ca dc) ts = qlDailyTenorLibor n c cr ca dc ts
  708 iborIndex (CustomIbor n p s cr fc vc mc bd b dc) ts = qlCustomIborIndex n p s cr fc vc mc bd b dc ts
  709 iborIndex c ts = qlCreateIbor (iborIndexOrdinal c) (iborIndexTenor c) ts
  710 
  711 -- |Creates the BMA (Bond Market Association) short-term tax-exempt index, optionally linked to a forwarding curve.
  712 bmaIndex :: (Maybe (GenYieldTermStructure y)) -> IO ((BMAIndex))
  713 bmaIndex a1 =
  714   withMaybeYieldTermStructure a1 $ \a1' -> 
  715   preErrorCheck $ \a2' -> 
  716   bmaIndex'_ a1' a2' >>= \res ->
  717   peekBMAIndex res >>= \res' ->
  718   errorCheck  a2'>>
  719   return (res')
  720 
  721 
  722 
  723 -- |This method returns a schedule of fixing dates between start and end.
  724 fixingSchedule :: (BMAIndex) -> (Day) -> (Day) -> IO ((Schedule))
  725 fixingSchedule a1 a2 a3 =
  726   withBMAIndex a1 $ \a1' -> 
  727   withDay a2 $ \a2' -> 
  728   withDay a3 $ \a3' -> 
  729   preErrorCheck $ \a4' -> 
  730   fixingSchedule'_ a1' a2' a3' a4' >>= \res ->
  731   peekSchedule res >>= \res' ->
  732   errorCheck  a4'>>
  733   return (res')
  734 
  735 
  736 
  737 -- |It can be overridden to implement particular conventions.
  738 forecastFixing :: (GenInterestRateIndex ridx) -> (Day) -> IO ((Double))
  739 forecastFixing a1 a2 =
  740   withInterestRateIndex a1 $ \a1' -> 
  741   withDay a2 $ \a2' -> 
  742   preErrorCheck $ \a3' -> 
  743   forecastFixing'_ a1' a2' a3' >>= \res ->
  744   let {res' = realToFrac res} in
  745   errorCheck  a3'>>
  746   return (res')
  747 
  748 
  749 
  750 -- |Returns the index's underlying currency.
  751 currency :: (GenInterestRateIndex ridx) -> IO ((Currency))
  752 currency a1 =
  753   withInterestRateIndex a1 $ \a1' -> 
  754   preErrorCheck $ \a2' -> 
  755   currency'_ a1' a2' >>= \res ->
  756   peekCurrency res >>= \res' ->
  757   errorCheck  a2'>>
  758   return (res')
  759 
  760 
  761 
  762 -- |Returns the day counter used by the index.
  763 dayCounter :: (GenInterestRateIndex ridx) -> IO ((DayCounter))
  764 dayCounter a1 =
  765   withInterestRateIndex a1 $ \a1' -> 
  766   preErrorCheck $ \a2' -> 
  767   dayCounter'_ a1' a2' >>= \res ->
  768   peekDayCounter res >>= \res' ->
  769   errorCheck  a2'>>
  770   return (res')
  771 
  772 
  773 
  774 -- |Returns the number of business days between a fixing date and the corresponding value date.
  775 fixingDays :: (GenInterestRateIndex ridx) -> (Word)
  776 fixingDays a1 =
  777   C2HSImp.unsafePerformIO $
  778   withInterestRateIndex a1 $ \a1' -> 
  779   fixingDays'_ a1' >>= \res ->
  780   let {res' = fromIntegral res} in
  781   return (res')
  782 
  783 
  784 
  785 -- |Returns the index's tenor.
  786 tenor :: (GenInterestRateIndex ridx) -> IO ((Word), (TimeUnit))
  787 tenor a1 =
  788   withInterestRateIndex a1 $ \a1' -> 
  789   preEnum $ \a2' -> 
  790   preErrorCheck $ \a3' -> 
  791   tenor'_ a1' a2' a3' >>= \res ->
  792   let {res' = fromIntegral res} in
  793   peekEnum  a2'>>= \a2'' -> 
  794   errorCheck  a3'>>
  795   return (res', a2'')
  796 
  797 
  798 
  799 -- |Returns the fixing date corresponding to a value date, using this index's
  800 -- convention-specific business-day rules.  Concrete indexes can override the
  801 -- base calculation.
  802 fixingDate :: (GenInterestRateIndex ridx) -- ^index
  803  -> (Day) -- ^valueDate
  804  -> IO ((Day))
  805 fixingDate a1 a2 =
  806   withInterestRateIndex a1 $ \a1' -> 
  807   withDay a2 $ \a2' -> 
  808   preErrorCheck $ \a3' -> 
  809   fixingDate'_ a1' a2' a3' >>= \res ->
  810   let {res' = toDay res} in
  811   errorCheck  a3'>>
  812   return (res')
  813 
  814 
  815 
  816 -- |Returns the value date corresponding to a fixing date, using this index's
  817 -- convention-specific business-day rules.  Throws when @fixingDate@ is not a
  818 -- valid fixing day for the index.
  819 valueDate :: (GenInterestRateIndex ridx) -- ^index
  820  -> (Day) -- ^fixingDate
  821  -> IO ((Day))
  822 valueDate a1 a2 =
  823   withInterestRateIndex a1 $ \a1' -> 
  824   withDay a2 $ \a2' -> 
  825   preErrorCheck $ \a3' -> 
  826   valueDate'_ a1' a2' a3' >>= \res ->
  827   let {res' = toDay res} in
  828   errorCheck  a3'>>
  829   return (res')
  830 
  831 
  832 
  833 -- |Returns the maturity date corresponding to a value date.  This is a
  834 -- concrete-index calculation: Ibor, Libor, swap, and custom indexes can each
  835 -- apply their own tenor, calendar, and end-of-month conventions.
  836 maturityDate :: (GenInterestRateIndex ridx) -- ^index
  837  -> (Day) -- ^valueDate
  838  -> IO ((Day))
  839 maturityDate a1 a2 =
  840   withInterestRateIndex a1 $ \a1' -> 
  841   withDay a2 $ \a2' -> 
  842   preErrorCheck $ \a3' -> 
  843   maturityDate'_ a1' a2' a3' >>= \res ->
  844   let {res' = toDay res} in
  845   errorCheck  a3'>>
  846   return (res')
  847 
  848 
  849 
  850 -- |Creates one of the built-in overnight indexes (e.g. Sofr, Estr, Sonia), optionally linked to a forwarding curve.
  851 overnightIborIndex :: (OvernightIborIndexType) -> (Maybe (GenYieldTermStructure y)) -> IO ((OvernightIborIndex))
  852 overnightIborIndex a1 a2 =
  853   let {a1' = (fromIntegral . fromEnum) a1} in 
  854   withMaybeYieldTermStructure a2 $ \a2' -> 
  855   preErrorCheck $ \a3' -> 
  856   overnightIborIndex'_ a1' a2' a3' >>= \res ->
  857   peekOvernightIborIndex res >>= \res' ->
  858   errorCheck  a3'>>
  859   return (res')
  860 
  861 
  862 
  863 -- |Creates one of the built-in ISDA-fix swap-rate indexes for a given tenor, with separate forwarding and discounting curves.
  864 liborSwapIndex :: (LiborSwapIndexType) -> ((Int,TimeUnit)) -> (Maybe (GenYieldTermStructure y1)) -- ^forwarding
  865  -> (Maybe (GenYieldTermStructure y2)) -- ^discounting
  866  -> IO ((SwapIndex))
  867 liborSwapIndex a1 a2 a3 a4 =
  868   let {a1' = (fromIntegral . fromEnum) a1} in 
  869   let {(a2'1, a2'2) = fromEnumQuantity a2} in 
  870   withMaybeYieldTermStructure a3 $ \a3' -> 
  871   withMaybeYieldTermStructure a4 $ \a4' -> 
  872   preErrorCheck $ \a5' -> 
  873   liborSwapIndex'_ a1' a2'1  a2'2 a3' a4' a5' >>= \res ->
  874   peekSwapIndex res >>= \res' ->
  875   errorCheck  a5'>>
  876   return (res')
  877 
  878 
  879 
  880 -- |Construct an overnight-indexed swap index. The private binding marshals
  881 -- 'RateAveragingType' as an 'Int' to avoid a c2hs cross-module enum-import cycle.
  882 overnightIndexedSwapIndex :: String -> (Int, TimeUnit) -> Word -> Currency
  883   -> OvernightIborIndex -> Bool -> RateAveragingType -> IO OvernightIndexedSwapIndex
  884 overnightIndexedSwapIndex familyName tenr settlementDays ccy idx telescopicValueDates averagingMethod =
  885   overnightIndexedSwapIndex_ familyName tenr settlementDays ccy idx telescopicValueDates (fromEnum averagingMethod)
  886 
  887 -- |Private binding for 'overnightIndexedSwapIndex'.
  888 overnightIndexedSwapIndex_ :: (String) -> ((Int,TimeUnit)) -> (Word) -- ^settlementDays
  889  -> (Currency) -> (OvernightIborIndex) -> (Bool) -- ^telescopicValueDates
  890  -> (Int) -- ^averagingMethod
  891  -> IO ((OvernightIndexedSwapIndex))
  892 overnightIndexedSwapIndex_ a1 a2 a3 a4 a5 a6 a7 =
  893   C2HSImp.withCString a1 $ \a1' -> 
  894   let {(a2'1, a2'2) = fromEnumQuantity a2} in 
  895   let {a3' = fromIntegral a3} in 
  896   withCurrency a4 $ \a4' -> 
  897   withOvernightIborIndex a5 $ \a5' -> 
  898   let {a6' = C2HSImp.fromBool a6} in 
  899   let {a7' = fromIntegral a7} in 
  900   preErrorCheck $ \a8' -> 
  901   overnightIndexedSwapIndex_'_ a1' a2'1  a2'2 a3' a4' a5' a6' a7' a8' >>= \res ->
  902   peekOvernightIndexedSwapIndex res >>= \res' ->
  903   errorCheck  a8'>>
  904   return (res')
  905 
  906 
  907 
  908 -- |Creates a swap-rate index whose forwarding and discounting both come from the underlying ibor index's curve.
  909 swapIndex :: (String) -> ((Int,TimeUnit)) -> (Word) -- ^settlementDays
  910  -> (Currency) -> (Calendar) -> ((Int,TimeUnit)) -- ^fixedLegTenor
  911  -> (BusinessDayConvention) -> (DayCounter) -> (GenIborIndex ibor) -> IO ((SwapIndex))
  912 swapIndex a1 a2 a3 a4 a5 a6 a7 a8 a9 =
  913   C2HSImp.withCString a1 $ \a1' -> 
  914   let {(a2'1, a2'2) = fromEnumQuantity a2} in 
  915   let {a3' = fromIntegral a3} in 
  916   withCurrency a4 $ \a4' -> 
  917   withCalendar a5 $ \a5' -> 
  918   let {(a6'1, a6'2) = fromEnumQuantity a6} in 
  919   let {a7' = fromEnumC a7} in 
  920   withDayCounter a8 $ \a8' -> 
  921   withIborIndex a9 $ \a9' -> 
  922   preErrorCheck $ \a10' -> 
  923   swapIndex'_ a1' a2'1  a2'2 a3' a4' a5' a6'1  a6'2 a7' a8' a9' a10' >>= \res ->
  924   peekSwapIndex res >>= \res' ->
  925   errorCheck  a10'>>
  926   return (res')
  927 
  928 
  929 
  930 -- |Creates a swap-rate index with a discounting curve distinct from the forwarding curve of the underlying ibor index.
  931 swapIndexWithDiscountCurve :: (String) -- ^familyName
  932  -> ((Int,TimeUnit)) -- ^tenor
  933  -> (Word) -- ^settlementDays
  934  -> (Currency) -> (Calendar) -> ((Int,TimeUnit)) -- ^fixedLegTenor
  935  -> (BusinessDayConvention) -- ^fixedLegConvention
  936  -> (DayCounter) -- ^fixedLegDayCounter
  937  -> (GenIborIndex ibor) -> (GenYieldTermStructure y) -> IO ((SwapIndex))
  938 swapIndexWithDiscountCurve a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 =
  939   C2HSImp.withCString a1 $ \a1' -> 
  940   let {(a2'1, a2'2) = fromEnumQuantity a2} in 
  941   let {a3' = fromIntegral a3} in 
  942   withCurrency a4 $ \a4' -> 
  943   withCalendar a5 $ \a5' -> 
  944   let {(a6'1, a6'2) = fromEnumQuantity a6} in 
  945   let {a7' = fromEnumC a7} in 
  946   withDayCounter a8 $ \a8' -> 
  947   withIborIndex a9 $ \a9' -> 
  948   withYieldTermStructure a10 $ \a10' -> 
  949   preErrorCheck $ \a11' -> 
  950   swapIndexWithDiscountCurve'_ a1' a2'1  a2'2 a3' a4' a5' a6'1  a6'2 a7' a8' a9' a10' a11' >>= \res ->
  951   peekSwapIndex res >>= \res' ->
  952   errorCheck  a11'>>
  953   return (res')
  954 
  955 
  956 
  957 -- |Interest-rate index equal to @gearing1 * swapIndex1 + gearing2 * swapIndex2@.  It has no
  958 -- native fixing history: a historical fixing is available only when both component swap indexes
  959 -- have one.
  960 swapSpreadIndex :: (String) -- ^familyName
  961  -> (GenSwapIndex sidx1) -- ^swapIndex1
  962  -> (GenSwapIndex sidx2) -- ^swapIndex2
  963  -> (Double) -- ^gearing1
  964  -> (Double) -- ^gearing2
  965  -> IO ((SwapSpreadIndex))
  966 swapSpreadIndex a1 a2 a3 a4 a5 =
  967   C2HSImp.withCString a1 $ \a1' -> 
  968   withSwapIndex a2 $ \a2' -> 
  969   withSwapIndex a3 $ \a3' -> 
  970   let {a4' = realToFrac a4} in 
  971   let {a5' = realToFrac a5} in 
  972   preErrorCheck $ \a6' -> 
  973   swapSpreadIndex'_ a1' a2' a3' a4' a5' a6' >>= \res ->
  974   peekSwapSpreadIndex res >>= \res' ->
  975   errorCheck  a6'>>
  976   return (res')
  977 
  978 
  979 
  980 -- |Low-level glue for 'iborIndex': constructs a generic Inter-Bank-Offered-Rate index, optionally linked to a forwarding curve.
  981 qlIborIndex :: (String) -- ^familyName
  982  -> ((Word,TimeUnit)) -- ^tenor
  983  -> (Word) -- ^settlementDays
  984  -> (Currency) -> (Calendar) -> (BusinessDayConvention) -> (Bool) -- ^endOfMonth
  985  -> (DayCounter) -> (Maybe (GenYieldTermStructure y)) -> IO ((IborIndex))
  986 qlIborIndex a1 a2 a3 a4 a5 a6 a7 a8 a9 =
  987   C2HSImp.withCString a1 $ \a1' -> 
  988   let {(a2'1, a2'2) = fromEnumQuantity a2} in 
  989   let {a3' = fromIntegral a3} in 
  990   withCurrency a4 $ \a4' -> 
  991   withCalendar a5 $ \a5' -> 
  992   let {a6' = fromEnumC a6} in 
  993   let {a7' = C2HSImp.fromBool a7} in 
  994   withDayCounter a8 $ \a8' -> 
  995   withMaybeYieldTermStructure a9 $ \a9' -> 
  996   preErrorCheck $ \a10' -> 
  997   qlIborIndex'_ a1' a2'1  a2'2 a3' a4' a5' a6' a7' a8' a9' a10' >>= \res ->
  998   peekIborIndex res >>= \res' ->
  999   errorCheck  a10'>>
 1000   return (res')
 1001 
 1002 
 1003 
 1004 -- |Low-level glue for 'iborIndex': constructs an ICE LIBOR index (all currencies but EUR/O/N/S/N), optionally linked to a forwarding curve.
 1005 qlLibor :: (String) -- ^familyName
 1006  -> ((Word,TimeUnit)) -> (Word) -- settlementDays
 1007  -> (Currency) -> (Calendar) -> (DayCounter) -> (Maybe (GenYieldTermStructure y)) -> IO ((IborIndex))
 1008 qlLibor a1 a2 a3 a4 a5 a6 a7 =
 1009   C2HSImp.withCString a1 $ \a1' -> 
 1010   let {(a2'1, a2'2) = fromEnumQuantity a2} in 
 1011   let {a3' = fromIntegral a3} in 
 1012   withCurrency a4 $ \a4' -> 
 1013   withCalendar a5 $ \a5' -> 
 1014   withDayCounter a6 $ \a6' -> 
 1015   withMaybeYieldTermStructure a7 $ \a7' -> 
 1016   preErrorCheck $ \a8' -> 
 1017   qlLibor'_ a1' a2'1  a2'2 a3' a4' a5' a6' a7' a8' >>= \res ->
 1018   peekIborIndex res >>= \res' ->
 1019   errorCheck  a8'>>
 1020   return (res')
 1021 
 1022 
 1023 
 1024 -- |Low-level glue for 'iborIndex': constructs a one-day (O/N-S/N) ICE LIBOR index, optionally linked to a forwarding curve.
 1025 qlDailyTenorLibor :: (String) -- ^familyName
 1026  -> (Word) -- ^settlementDays
 1027  -> (Currency) -> (Calendar) -> (DayCounter) -> (Maybe (GenYieldTermStructure y)) -> IO ((IborIndex))
 1028 qlDailyTenorLibor a1 a2 a3 a4 a5 a6 =
 1029   C2HSImp.withCString a1 $ \a1' -> 
 1030   let {a2' = fromIntegral a2} in 
 1031   withCurrency a3 $ \a3' -> 
 1032   withCalendar a4 $ \a4' -> 
 1033   withDayCounter a5 $ \a5' -> 
 1034   withMaybeYieldTermStructure a6 $ \a6' -> 
 1035   preErrorCheck $ \a7' -> 
 1036   qlDailyTenorLibor'_ a1' a2' a3' a4' a5' a6' a7' >>= \res ->
 1037   peekIborIndex res >>= \res' ->
 1038   errorCheck  a7'>>
 1039   return (res')
 1040 
 1041 
 1042 
 1043 -- |Low-level glue for 'iborIndex': constructs a LIBOR-like index with independently specified fixing/value/maturity calendars.
 1044 qlCustomIborIndex :: (String) -- ^familyName
 1045  -> ((Word,TimeUnit)) -- ^tenor
 1046  -> (Word) -- ^settlementDays
 1047  -> (Currency) -> (Calendar) -- ^fixingCalendar
 1048  -> (Calendar) -- ^valueCalendar
 1049  -> (Calendar) -- ^maturityCalendar
 1050  -> (BusinessDayConvention) -> (Bool) -- ^endOfMonth
 1051  -> (DayCounter) -> (Maybe (GenYieldTermStructure y)) -> IO ((IborIndex))
 1052 qlCustomIborIndex a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 =
 1053   C2HSImp.withCString a1 $ \a1' -> 
 1054   let {(a2'1, a2'2) = fromEnumQuantity a2} in 
 1055   let {a3' = fromIntegral a3} in 
 1056   withCurrency a4 $ \a4' -> 
 1057   withCalendar a5 $ \a5' -> 
 1058   withCalendar a6 $ \a6' -> 
 1059   withCalendar a7 $ \a7' -> 
 1060   let {a8' = fromEnumC a8} in 
 1061   let {a9' = C2HSImp.fromBool a9} in 
 1062   withDayCounter a10 $ \a10' -> 
 1063   withMaybeYieldTermStructure a11 $ \a11' -> 
 1064   preErrorCheck $ \a12' -> 
 1065   qlCustomIborIndex'_ a1' a2'1  a2'2 a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' >>= \res ->
 1066   peekIborIndex res >>= \res' ->
 1067   errorCheck  a12'>>
 1068   return (res')
 1069 
 1070 
 1071 
 1072 -- |Low-level glue for 'iborIndex': constructs one of the built-in fixed-tenor/daily-tenor/overnight ibor indexes by ordinal, optionally linked to a forwarding curve.
 1073 qlCreateIbor :: (Int) -> ((Word,TimeUnit)) -> (Maybe (GenYieldTermStructure y)) -> IO ((IborIndex))
 1074 qlCreateIbor a1 a2 a3 =
 1075   let {a1' = fromIntegral a1} in 
 1076   let {(a2'1, a2'2) = fromEnumQuantity a2} in 
 1077   withMaybeYieldTermStructure a3 $ \a3' -> 
 1078   preErrorCheck $ \a4' -> 
 1079   qlCreateIbor'_ a1' a2'1  a2'2 a3' a4' >>= \res ->
 1080   peekIborIndex res >>= \res' ->
 1081   errorCheck  a4'>>
 1082   return (res')
 1083 
 1084 
 1085 
 1086 -- |Creates a generic overnight index, optionally linked to a forwarding curve.
 1087 overnightIndex :: (String) -> (Word) -- ^settlementDays
 1088  -> (Currency) -> (Calendar) -> (DayCounter) -> (Maybe (GenYieldTermStructure y)) -> IO ((OvernightIborIndex))
 1089 overnightIndex a1 a2 a3 a4 a5 a6 =
 1090   C2HSImp.withCString a1 $ \a1' -> 
 1091   let {a2' = fromIntegral a2} in 
 1092   withCurrency a3 $ \a3' -> 
 1093   withCalendar a4 $ \a4' -> 
 1094   withDayCounter a5 $ \a5' -> 
 1095   withMaybeYieldTermStructure a6 $ \a6' -> 
 1096   preErrorCheck $ \a7' -> 
 1097   overnightIndex'_ a1' a2' a3' a4' a5' a6' a7' >>= \res ->
 1098   peekOvernightIborIndex res >>= \res' ->
 1099   errorCheck  a7'>>
 1100   return (res')
 1101 
 1102 
 1103 
 1104 -- |Returns the business day convention used to adjust the index's value/maturity dates.
 1105 businessDayConvention :: (GenIborIndex ibor) -> (BusinessDayConvention)
 1106 businessDayConvention a1 =
 1107   C2HSImp.unsafePerformIO $
 1108   withIborIndex a1 $ \a1' -> 
 1109   businessDayConvention'_ a1' >>= \res ->
 1110   let {res' = toEnumC res} in
 1111   return (res')
 1112 
 1113 
 1114 
 1115 -- |Returns whether the index's date calculations roll to the end of the month.
 1116 endOfMonth :: (GenIborIndex ibor) -> (Bool)
 1117 endOfMonth a1 =
 1118   C2HSImp.unsafePerformIO $
 1119   withIborIndex a1 $ \a1' -> 
 1120   endOfMonth'_ a1' >>= \res ->
 1121   let {res' = C2HSImp.toBool res} in
 1122   return (res')
 1123 
 1124 
 1125 
 1126 -- |Returns the overnight-indexed swap underlying the index for a given fixing date. Relinking the index's term structure afterwards has no effect on the returned swap.
 1127 underlyingOis :: (OvernightIndexedSwapIndex) -> (Day) -> IO ((OvernightIndexedSwap))
 1128 underlyingOis a1 a2 =
 1129   withOvernightIndexedSwapIndex a1 $ \a1' -> 
 1130   withDay a2 $ \a2' -> 
 1131   preErrorCheck $ \a3' -> 
 1132   underlyingOis'_ a1' a2' a3' >>= \res ->
 1133   peekOvernightIndexedSwap res >>= \res' ->
 1134   errorCheck  a3'>>
 1135   return (res')
 1136 
 1137 
 1138 
 1139 -- |Returns the vanilla swap underlying the index for a given fixing date. Relinking the index's term structure afterwards has no effect on the returned swap.
 1140 underlyingSwap :: (GenSwapIndex sidx) -> (Day) -> IO ((VanillaSwap))
 1141 underlyingSwap a1 a2 =
 1142   withSwapIndex a1 $ \a1' -> 
 1143   withDay a2 $ \a2' -> 
 1144   preErrorCheck $ \a3' -> 
 1145   underlyingSwap'_ a1' a2' a3' >>= \res ->
 1146   peekVanillaSwap res >>= \res' ->
 1147   errorCheck  a3'>>
 1148   return (res')
 1149 
 1150 
 1151 
 1152 -- |Convenience wrapper: 'historicalIndexAnalysis' specialised to interest-rate indexes.
 1153 historicalRatesAnalysis :: Day -> Day -> (Int, TimeUnit) -> NonEmpty (GenInterestRateIndex ridx) -> IO HistoricalIndexAnalysis
 1154 historicalRatesAnalysis startDate endDate step ridxs =
 1155   mapM asIndex (toList ridxs) >>= historicalIndexAnalysis startDate endDate step
 1156 
 1157 -- vim: set ff=unix ts=8 sts=2 sw=2 et:
 1158 
 1159 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlBMAIndex"
 1160   bmaIndex'_ :: ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CBMAIndex')))))
 1161 
 1162 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlBMAIndexFixingSchedule"
 1163   fixingSchedule'_ :: ((C2HSImp.Ptr (CBMAIndex')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CSchedule)))))))
 1164 
 1165 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlInterestRateIndexForecastFixing"
 1166   forecastFixing'_ :: ((C2HSImp.Ptr (CInterestRateIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 1167 
 1168 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlInterestRateIndexCurrency"
 1169   currency'_ :: ((C2HSImp.Ptr (CInterestRateIndex')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CCurrency)))))
 1170 
 1171 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlInterestRateIndexDayCounter"
 1172   dayCounter'_ :: ((C2HSImp.Ptr (CInterestRateIndex')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CDayCounter)))))
 1173 
 1174 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlInterestRateIndexFixingDays"
 1175   fixingDays'_ :: ((C2HSImp.Ptr (CInterestRateIndex')) -> (IO C2HSImp.CUInt))
 1176 
 1177 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlInterestRateIndexTenor"
 1178   tenor'_ :: ((C2HSImp.Ptr (CInterestRateIndex')) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt))))
 1179 
 1180 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlInterestRateIndexFixingDate"
 1181   fixingDate'_ :: ((C2HSImp.Ptr (CInterestRateIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt))))
 1182 
 1183 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlInterestRateIndexValueDate"
 1184   valueDate'_ :: ((C2HSImp.Ptr (CInterestRateIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt))))
 1185 
 1186 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlInterestRateIndexMaturityDate"
 1187   maturityDate'_ :: ((C2HSImp.Ptr (CInterestRateIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt))))
 1188 
 1189 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlCreateONIndex"
 1190   overnightIborIndex'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (COvernightIndex'))))))
 1191 
 1192 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlCreateLiborSwapIndex"
 1193   liborSwapIndex'_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CSwapIndex')))))))))
 1194 
 1195 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlOvernightIndexedSwapIndex"
 1196   overnightIndexedSwapIndex_'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (COvernightIndex')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (COvernightIndexedSwapIndex'))))))))))))
 1197 
 1198 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlSwapIndex"
 1199   swapIndex'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CIborIndex')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CSwapIndex')))))))))))))))
 1200 
 1201 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlSwapIndex1"
 1202   swapIndexWithDiscountCurve'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CIborIndex')) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CSwapIndex'))))))))))))))))
 1203 
 1204 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlSwapSpreadIndex"
 1205   swapSpreadIndex'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr (CSwapIndex')) -> ((C2HSImp.Ptr (CSwapIndex')) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CSwapSpreadIndex')))))))))
 1206 
 1207 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlIborIndex"
 1208   qlIborIndex'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CIborIndex'))))))))))))))
 1209 
 1210 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlLibor"
 1211   qlLibor'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CCalendar)) -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CIborIndex'))))))))))))
 1212 
 1213 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlDailyTenorLibor"
 1214   qlDailyTenorLibor'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CCalendar)) -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CIborIndex'))))))))))
 1215 
 1216 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlCustomIborIndex"
 1217   qlCustomIborIndex'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CCalendar)) -> ((C2HSImp.Ptr (CCalendar)) -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CIborIndex'))))))))))))))))
 1218 
 1219 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlCreateIbor"
 1220   qlCreateIbor'_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CIborIndex'))))))))
 1221 
 1222 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlOvernightIndex"
 1223   overnightIndex'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CCalendar)) -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (COvernightIndex'))))))))))
 1224 
 1225 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlIborIndexBusinessDayConvention"
 1226   businessDayConvention'_ :: ((C2HSImp.Ptr (CIborIndex')) -> (IO C2HSImp.CInt))
 1227 
 1228 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlIborIndexEndOfMonth"
 1229   endOfMonth'_ :: ((C2HSImp.Ptr (CIborIndex')) -> (IO C2HSImp.CInt))
 1230 
 1231 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlOvernightIndexedSwapIndexUnderlyingSwap"
 1232   underlyingOis'_ :: ((C2HSImp.Ptr (COvernightIndexedSwapIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (COvernightIndexedSwap'))))))
 1233 
 1234 foreign import ccall safe "QuantLib/Index/InterestRate.chs.h qlSwapIndexUnderlyingSwap"
 1235   underlyingSwap'_ :: ((C2HSImp.Ptr (CSwapIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CVanillaSwap'))))))