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 TypeFamilies, FlexibleInstances #-}
    6 module QuantLib.TermStructure
    7   (
    8     -- * Types
    9     -- ** Term-structure hierarchy
   10     GenTermStructure
   11   , TermStructure
   12 
   13     -- ** Coordinates
   14   , Reference(..)
   15   , CalendarReference(..)
   16   , TermPoint(..)
   17   , TermInterval(..)
   18   , RatePoint(..)
   19 
   20     -- * Constructors
   21   , asTermStructure
   22 
   23     -- * Mutators
   24   , setExtrapolation
   25 
   26     -- * Inspectors
   27   , HasHelperUnderlying(..)
   28   , referenceDate
   29   , maxDate
   30   , maxTime
   31   , allowsExtrapolation
   32   , timeFromReference
   33   ) where
   34 import qualified Foreign.C.Types as C2HSImp
   35 import qualified Foreign.ForeignPtr as C2HSImp
   36 import qualified Foreign.Marshal.Utils as C2HSImp
   37 import qualified Foreign.Ptr as C2HSImp
   38 
   39 
   40 import QuantLib.Internal hiding(maxDate)
   41 import QuantLib.Internal.Type
   42 
   43 
   44 
   45 
   46 
   47 
   48 
   49 
   50 
   51 
   52 
   53 
   54 
   55 
   56 
   57 
   58 
   59 
   60 
   61 
   62 
   63 
   64 
   65 
   66 
   67 
   68 
   69 
   70 
   71 
   72 
   73 
   74 
   75 
   76 -- |Bootstrap and calibration helpers that build and hold the instrument whose market quote
   77 -- they match. The class lives here, in the term-structure root module, because its instances
   78 -- span "QuantLib.TermStructure.Yield", ".Inflation" and "QuantLib.Model", and an instance must
   79 -- share a module with its class to stay non-orphan.
   80 class HasHelperUnderlying h where
   81   type HelperUnderlying h
   82   -- |The instrument the helper prices. For helpers that build it internally --
   83   -- 'QuantLib.TermStructure.Yield.fixedRateBondHelper' and
   84   -- 'QuantLib.TermStructure.Inflation.cpiBondHelper' among them -- this is the only way to reach it.
   85   helperInstrument :: h -> IO (HelperUnderlying h)
   86 
   87 instance HasHelperUnderlying BondHelper where
   88   type HelperUnderlying BondHelper = Bond
   89   helperInstrument = qlBondHelperBond
   90 instance HasHelperUnderlying SwapRateHelper where
   91   type HelperUnderlying SwapRateHelper = VanillaSwap
   92   helperInstrument = qlSwapRateHelperSwap
   93 instance HasHelperUnderlying OISRateHelper where
   94   type HelperUnderlying OISRateHelper = OvernightIndexedSwap
   95   helperInstrument = qlOISRateHelperSwap
   96 instance HasHelperUnderlying ZeroCouponInflationSwapHelper where
   97   type HelperUnderlying ZeroCouponInflationSwapHelper = ZeroCouponInflationSwap
   98   helperInstrument = qlZeroCouponInflationSwapHelperSwap
   99 instance HasHelperUnderlying YearOnYearInflationSwapHelper where
  100   type HelperUnderlying YearOnYearInflationSwapHelper = YearOnYearInflationSwap
  101   helperInstrument = qlYearOnYearInflationSwapHelperSwap
  102 -- 'QuantLib.Model.helperSwaption' reaches the swaption wrapped around this swap.
  103 instance HasHelperUnderlying SwaptionHelper where
  104   type HelperUnderlying SwaptionHelper = FixedVsFloatingSwap
  105   helperInstrument = qlSwaptionHelperUnderlying
  106 
  107 qlBondHelperBond :: (BondHelper) -> IO ((Bond))
  108 qlBondHelperBond a1 =
  109   withGenRateHelper a1 $ \a1' -> 
  110   preErrorCheck $ \a2' -> 
  111   qlBondHelperBond'_ a1' a2' >>= \res ->
  112   peekBond res >>= \res' ->
  113   errorCheck  a2'>>
  114   return (res')
  115 
  116 
  117 qlSwapRateHelperSwap :: (SwapRateHelper) -> IO ((VanillaSwap))
  118 qlSwapRateHelperSwap a1 =
  119   withGenRateHelper a1 $ \a1' -> 
  120   preErrorCheck $ \a2' -> 
  121   qlSwapRateHelperSwap'_ a1' a2' >>= \res ->
  122   peekVanillaSwap res >>= \res' ->
  123   errorCheck  a2'>>
  124   return (res')
  125 
  126 
  127 qlOISRateHelperSwap :: (OISRateHelper) -> IO ((OvernightIndexedSwap))
  128 qlOISRateHelperSwap a1 =
  129   withGenRateHelper a1 $ \a1' -> 
  130   preErrorCheck $ \a2' -> 
  131   qlOISRateHelperSwap'_ a1' a2' >>= \res ->
  132   peekOvernightIndexedSwap res >>= \res' ->
  133   errorCheck  a2'>>
  134   return (res')
  135 
  136 
  137 qlZeroCouponInflationSwapHelperSwap :: (ZeroCouponInflationSwapHelper) -> IO ((ZeroCouponInflationSwap))
  138 qlZeroCouponInflationSwapHelperSwap a1 =
  139   withZeroCouponInflationSwapHelper a1 $ \a1' -> 
  140   preErrorCheck $ \a2' -> 
  141   qlZeroCouponInflationSwapHelperSwap'_ a1' a2' >>= \res ->
  142   peekZeroCouponInflationSwap res >>= \res' ->
  143   errorCheck  a2'>>
  144   return (res')
  145 
  146 
  147 qlYearOnYearInflationSwapHelperSwap :: (YearOnYearInflationSwapHelper) -> IO ((YearOnYearInflationSwap))
  148 qlYearOnYearInflationSwapHelperSwap a1 =
  149   withYearOnYearInflationSwapHelper a1 $ \a1' -> 
  150   preErrorCheck $ \a2' -> 
  151   qlYearOnYearInflationSwapHelperSwap'_ a1' a2' >>= \res ->
  152   peekYearOnYearInflationSwap res >>= \res' ->
  153   errorCheck  a2'>>
  154   return (res')
  155 
  156 
  157 qlSwaptionHelperUnderlying :: (SwaptionHelper) -> IO ((FixedVsFloatingSwap))
  158 qlSwaptionHelperUnderlying a1 =
  159   withSwaptionHelper a1 $ \a1' -> 
  160   preErrorCheck $ \a2' -> 
  161   qlSwaptionHelperUnderlying'_ a1' a2' >>= \res ->
  162   peekFixedVsFloatingSwap res >>= \res' ->
  163   errorCheck  a2'>>
  164   return (res')
  165 
  166 
  167 
  168 -- |A term-structure reference point. 'ReferenceDate' stays fixed for the object's lifetime;
  169 -- 'SettlementDays' follows the global evaluation date using the supplied calendar.
  170 data Reference
  171   = ReferenceDate !Day
  172   | SettlementDays !Word !Calendar
  173   deriving (Eq, Show)
  174 
  175 -- |Reference-point variants for constructors that take a calendar independently in both
  176 -- upstream overloads.
  177 data CalendarReference
  178   = CalendarReferenceDate !Day
  179   | CalendarSettlementDays !Word
  180   deriving (Eq, Show)
  181 
  182 -- |A date or year-fraction coordinate measured from a term structure's reference date.
  183 data TermPoint = DatePoint !Day | TimePoint !Double
  184   deriving (Eq, Show)
  185 
  186 -- |A same-representation interval. Keeping both endpoints in one constructor prevents mixed
  187 -- date/time intervals that upstream does not accept.
  188 data TermInterval
  189   = DateInterval !Day !Day
  190   | TimeInterval !Double !Double
  191   deriving (Eq, Show)
  192 
  193 -- |A date or year-fraction coordinate where a date needs its day-counting rule.
  194 data RatePoint
  195   = RateAtDate !Day !DayCounter
  196   | RateAtTime !Double
  197   deriving (Eq, Show)
  198 
  199 -- |the date at which discount = 1.0 and/or variance = 0.0
  200 referenceDate :: (GenTermStructure t) -> IO ((Day))
  201 referenceDate a1 =
  202   withTermStructure a1 $ \a1' -> 
  203   preErrorCheck $ \a2' -> 
  204   referenceDate'_ a1' a2' >>= \res ->
  205   let {res' = toDay res} in
  206   errorCheck  a2'>>
  207   return (res')
  208 
  209 
  210 
  211 -- |the latest date for which the curve can return values
  212 maxDate :: (GenTermStructure t) -> IO ((Day))
  213 maxDate a1 =
  214   withTermStructure a1 $ \a1' -> 
  215   preErrorCheck $ \a2' -> 
  216   maxDate'_ a1' a2' >>= \res ->
  217   let {res' = toDay res} in
  218   errorCheck  a2'>>
  219   return (res')
  220 
  221 
  222 
  223 -- |'maxDate' expressed as a year fraction from the structure's reference date
  224 maxTime :: (GenTermStructure t) -> IO ((Double))
  225 maxTime a1 =
  226   withTermStructure a1 $ \a1' -> 
  227   preErrorCheck $ \a2' -> 
  228   maxTime'_ a1' a2' >>= \res ->
  229   let {res' = realToFrac res} in
  230   errorCheck  a2'>>
  231   return (res')
  232 
  233 
  234 
  235 -- |Whether calls beyond the term structure's maximum date are allowed by default.
  236 allowsExtrapolation :: (GenTermStructure t) -> IO ((Bool))
  237 allowsExtrapolation a1 =
  238   withTermStructure a1 $ \a1' -> 
  239   allowsExtrapolation'_ a1' >>= \res ->
  240   let {res' = C2HSImp.toBool res} in
  241   return (res')
  242 
  243 
  244 
  245 -- |Enable or disable default extrapolation for any term structure.
  246 setExtrapolation :: (GenTermStructure t) -> (Bool) -> IO ()
  247 setExtrapolation a1 a2 =
  248   withTermStructure a1 $ \a1' -> 
  249   let {a2' = C2HSImp.fromBool a2} in 
  250   setExtrapolation'_ a1' a2' >>
  251   return ()
  252 
  253 
  254 
  255 -- |Converts a date to a time (as a fraction of year) according to the term structure's day counter.
  256 timeFromReference :: (GenTermStructure t) -- ^term structure
  257  -> (Day) -- ^date
  258  -> IO ((Double))
  259 timeFromReference a1 a2 =
  260   withTermStructure a1 $ \a1' -> 
  261   withDay a2 $ \a2' -> 
  262   preErrorCheck $ \a3' -> 
  263   timeFromReference'_ a1' a2' a3' >>= \res ->
  264   let {res' = realToFrac res} in
  265   errorCheck  a3'>>
  266   return (res')
  267 
  268 
  269 
  270 -- vim: set ff=unix ts=8 sts=2 sw=2 et:
  271 
  272 foreign import ccall safe "QuantLib/TermStructure.chs.h qlBondHelperBond"
  273   qlBondHelperBond'_ :: ((C2HSImp.Ptr (CBondHelper')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CBond')))))
  274 
  275 foreign import ccall safe "QuantLib/TermStructure.chs.h qlSwapRateHelperSwap"
  276   qlSwapRateHelperSwap'_ :: ((C2HSImp.Ptr (CSwapRateHelper')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CVanillaSwap')))))
  277 
  278 foreign import ccall safe "QuantLib/TermStructure.chs.h qlOISRateHelperSwap"
  279   qlOISRateHelperSwap'_ :: ((C2HSImp.Ptr (COISRateHelper')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (COvernightIndexedSwap')))))
  280 
  281 foreign import ccall safe "QuantLib/TermStructure.chs.h qlZeroCouponInflationSwapHelperSwap"
  282   qlZeroCouponInflationSwapHelperSwap'_ :: ((C2HSImp.Ptr (CZeroCouponInflationSwapHelper)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CZeroCouponInflationSwap')))))
  283 
  284 foreign import ccall safe "QuantLib/TermStructure.chs.h qlYearOnYearInflationSwapHelperSwap"
  285   qlYearOnYearInflationSwapHelperSwap'_ :: ((C2HSImp.Ptr (CYearOnYearInflationSwapHelper)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CYearOnYearInflationSwap')))))
  286 
  287 foreign import ccall safe "QuantLib/TermStructure.chs.h qlSwaptionHelperUnderlying"
  288   qlSwaptionHelperUnderlying'_ :: ((C2HSImp.Ptr (CSwaptionHelper')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFixedVsFloatingSwap')))))
  289 
  290 foreign import ccall safe "QuantLib/TermStructure.chs.h qlTermStructureReferenceDate"
  291   referenceDate'_ :: ((C2HSImp.Ptr (CTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt)))
  292 
  293 foreign import ccall safe "QuantLib/TermStructure.chs.h qlTermStructureMaxDate"
  294   maxDate'_ :: ((C2HSImp.Ptr (CTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt)))
  295 
  296 foreign import ccall safe "QuantLib/TermStructure.chs.h qlTermStructureMaxTime"
  297   maxTime'_ :: ((C2HSImp.Ptr (CTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))
  298 
  299 foreign import ccall safe "QuantLib/TermStructure.chs.h qlTermStructureAllowsExtrapolation"
  300   allowsExtrapolation'_ :: ((C2HSImp.Ptr (CTermStructure')) -> (IO C2HSImp.CInt))
  301 
  302 foreign import ccall safe "QuantLib/TermStructure.chs.h qlTermStructureSetExtrapolation"
  303   setExtrapolation'_ :: ((C2HSImp.Ptr (CTermStructure')) -> (C2HSImp.CInt -> (IO ())))
  304 
  305 foreign import ccall safe "QuantLib/TermStructure.chs.h qlTermStructureTimeFromReference"
  306   timeFromReference'_ :: ((C2HSImp.Ptr (CTermStructure')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))