-- GENERATED by C->Haskell Compiler, version 0.28.8 Switcheroo, 25 November 2017 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "./QuantLib/TermStructure.chs" #-}
{-# LANGUAGE TypeFamilies, FlexibleInstances #-}
module QuantLib.TermStructure
  (
    -- * Types
    -- ** Term-structure hierarchy
    GenTermStructure
  , TermStructure

    -- ** Coordinates
  , Reference(..)
  , CalendarReference(..)
  , TermPoint(..)
  , TermInterval(..)
  , RatePoint(..)

    -- * Constructors
  , asTermStructure

    -- * Mutators
  , setExtrapolation

    -- * Inspectors
  , HasHelperUnderlying(..)
  , referenceDate
  , maxDate
  , maxTime
  , allowsExtrapolation
  , timeFromReference
  ) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.ForeignPtr as C2HSImp
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp


import QuantLib.Internal hiding(maxDate)
import QuantLib.Internal.Type








{-# LINE 39 "./QuantLib/TermStructure.chs" #-}


{-# LINE 40 "./QuantLib/TermStructure.chs" #-}


{-# LINE 41 "./QuantLib/TermStructure.chs" #-}


{-# LINE 42 "./QuantLib/TermStructure.chs" #-}


{-# LINE 43 "./QuantLib/TermStructure.chs" #-}


{-# LINE 44 "./QuantLib/TermStructure.chs" #-}


{-# LINE 45 "./QuantLib/TermStructure.chs" #-}


{-# LINE 46 "./QuantLib/TermStructure.chs" #-}


{-# LINE 47 "./QuantLib/TermStructure.chs" #-}


{-# LINE 48 "./QuantLib/TermStructure.chs" #-}


{-# LINE 49 "./QuantLib/TermStructure.chs" #-}


{-# LINE 50 "./QuantLib/TermStructure.chs" #-}


{-# LINE 51 "./QuantLib/TermStructure.chs" #-}


-- |Bootstrap and calibration helpers that build and hold the instrument whose market quote
-- they match. The class lives here, in the term-structure root module, because its instances
-- span "QuantLib.TermStructure.Yield", ".Inflation" and "QuantLib.Model", and an instance must
-- share a module with its class to stay non-orphan.
class HasHelperUnderlying h where
  type HelperUnderlying h
  -- |The instrument the helper prices. For helpers that build it internally --
  -- 'QuantLib.TermStructure.Yield.fixedRateBondHelper' and
  -- 'QuantLib.TermStructure.Inflation.cpiBondHelper' among them -- this is the only way to reach it.
  helperInstrument :: h -> IO (HelperUnderlying h)

instance HasHelperUnderlying BondHelper where
  type HelperUnderlying BondHelper = Bond
  helperInstrument :: BondHelper -> IO (HelperUnderlying BondHelper)
helperInstrument = BondHelper -> IO Bond
BondHelper -> IO (HelperUnderlying BondHelper)
qlBondHelperBond
instance HasHelperUnderlying SwapRateHelper where
  type HelperUnderlying SwapRateHelper = VanillaSwap
  helperInstrument :: SwapRateHelper -> IO (HelperUnderlying SwapRateHelper)
helperInstrument = SwapRateHelper -> IO VanillaSwap
SwapRateHelper -> IO (HelperUnderlying SwapRateHelper)
qlSwapRateHelperSwap
instance HasHelperUnderlying OISRateHelper where
  type HelperUnderlying OISRateHelper = OvernightIndexedSwap
  helperInstrument :: OISRateHelper -> IO (HelperUnderlying OISRateHelper)
helperInstrument = OISRateHelper -> IO OvernightIndexedSwap
OISRateHelper -> IO (HelperUnderlying OISRateHelper)
qlOISRateHelperSwap
instance HasHelperUnderlying ZeroCouponInflationSwapHelper where
  type HelperUnderlying ZeroCouponInflationSwapHelper = ZeroCouponInflationSwap
  helperInstrument :: ZeroCouponInflationSwapHelper
-> IO (HelperUnderlying ZeroCouponInflationSwapHelper)
helperInstrument = ZeroCouponInflationSwapHelper -> IO ZeroCouponInflationSwap
ZeroCouponInflationSwapHelper
-> IO (HelperUnderlying ZeroCouponInflationSwapHelper)
qlZeroCouponInflationSwapHelperSwap
instance HasHelperUnderlying YearOnYearInflationSwapHelper where
  type HelperUnderlying YearOnYearInflationSwapHelper = YearOnYearInflationSwap
  helperInstrument :: YearOnYearInflationSwapHelper
-> IO (HelperUnderlying YearOnYearInflationSwapHelper)
helperInstrument = YearOnYearInflationSwapHelper -> IO YearOnYearInflationSwap
YearOnYearInflationSwapHelper
-> IO (HelperUnderlying YearOnYearInflationSwapHelper)
qlYearOnYearInflationSwapHelperSwap
-- 'QuantLib.Model.helperSwaption' reaches the swaption wrapped around this swap.
instance HasHelperUnderlying SwaptionHelper where
  type HelperUnderlying SwaptionHelper = FixedVsFloatingSwap
  helperInstrument :: SwaptionHelper -> IO (HelperUnderlying SwaptionHelper)
helperInstrument = SwaptionHelper -> IO FixedVsFloatingSwap
SwaptionHelper -> IO (HelperUnderlying SwaptionHelper)
qlSwaptionHelperUnderlying

qlBondHelperBond :: (BondHelper) -> IO ((Bond))
qlBondHelperBond :: BondHelper -> IO Bond
qlBondHelperBond BondHelper
a1 =
  BondHelper -> (Ptr CBondHelper' -> IO Bond) -> IO Bond
forall rh b.
GenRateHelper (ForeignPtr rh) -> (Ptr rh -> IO b) -> IO b
withGenRateHelper BondHelper
a1 ((Ptr CBondHelper' -> IO Bond) -> IO Bond)
-> (Ptr CBondHelper' -> IO Bond) -> IO Bond
forall a b. (a -> b) -> a -> b
$ \Ptr CBondHelper'
a1' -> 
  (Ptr (Ptr CChar) -> IO Bond) -> IO Bond
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO Bond) -> IO Bond)
-> (Ptr (Ptr CChar) -> IO Bond) -> IO Bond
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a2' -> 
  Ptr CBondHelper' -> Ptr (Ptr CChar) -> IO (Ptr CBond')
qlBondHelperBond'_ Ptr CBondHelper'
a1' Ptr (Ptr CChar)
a2' IO (Ptr CBond') -> (Ptr CBond' -> IO Bond) -> IO Bond
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CBond'
res ->
  Ptr CBond' -> IO Bond
peekBond Ptr CBond'
res IO Bond -> (Bond -> IO Bond) -> IO Bond
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bond
res' ->
  Ptr (Ptr CChar) -> IO ()
errorCheck  Ptr (Ptr CChar)
a2'IO () -> IO Bond -> IO Bond
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Bond -> IO Bond
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bond
res')

{-# LINE 84 "./QuantLib/TermStructure.chs" #-}

qlSwapRateHelperSwap :: (SwapRateHelper) -> IO ((VanillaSwap))
qlSwapRateHelperSwap a1 =
  withGenRateHelper a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  qlSwapRateHelperSwap'_ a1' a2' >>= \res ->
  peekVanillaSwap res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 85 "./QuantLib/TermStructure.chs" #-}

qlOISRateHelperSwap :: (OISRateHelper) -> IO ((OvernightIndexedSwap))
qlOISRateHelperSwap a1 =
  withGenRateHelper a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  qlOISRateHelperSwap'_ a1' a2' >>= \res ->
  peekOvernightIndexedSwap res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 86 "./QuantLib/TermStructure.chs" #-}

qlZeroCouponInflationSwapHelperSwap :: (ZeroCouponInflationSwapHelper) -> IO ((ZeroCouponInflationSwap))
qlZeroCouponInflationSwapHelperSwap a1 =
  withZeroCouponInflationSwapHelper a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  qlZeroCouponInflationSwapHelperSwap'_ a1' a2' >>= \res ->
  peekZeroCouponInflationSwap res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 87 "./QuantLib/TermStructure.chs" #-}

qlYearOnYearInflationSwapHelperSwap :: (YearOnYearInflationSwapHelper) -> IO ((YearOnYearInflationSwap))
qlYearOnYearInflationSwapHelperSwap a1 =
  withYearOnYearInflationSwapHelper a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  qlYearOnYearInflationSwapHelperSwap'_ a1' a2' >>= \res ->
  peekYearOnYearInflationSwap res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 88 "./QuantLib/TermStructure.chs" #-}

qlSwaptionHelperUnderlying :: (SwaptionHelper) -> IO ((FixedVsFloatingSwap))
qlSwaptionHelperUnderlying a1 =
  withSwaptionHelper a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  qlSwaptionHelperUnderlying'_ a1' a2' >>= \res ->
  peekFixedVsFloatingSwap res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 89 "./QuantLib/TermStructure.chs" #-}


-- |A term-structure reference point. 'ReferenceDate' stays fixed for the object's lifetime;
-- 'SettlementDays' follows the global evaluation date using the supplied calendar.
data Reference
  = ReferenceDate !Day
  | SettlementDays !Word !Calendar
  deriving (Eq, Show)

-- |Reference-point variants for constructors that take a calendar independently in both
-- upstream overloads.
data CalendarReference
  = CalendarReferenceDate !Day
  | CalendarSettlementDays !Word
  deriving (CalendarReference -> CalendarReference -> Bool
(CalendarReference -> CalendarReference -> Bool)
-> (CalendarReference -> CalendarReference -> Bool)
-> Eq CalendarReference
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CalendarReference -> CalendarReference -> Bool
== :: CalendarReference -> CalendarReference -> Bool
$c/= :: CalendarReference -> CalendarReference -> Bool
/= :: CalendarReference -> CalendarReference -> Bool
Eq, Int -> CalendarReference -> ShowS
[CalendarReference] -> ShowS
CalendarReference -> String
(Int -> CalendarReference -> ShowS)
-> (CalendarReference -> String)
-> ([CalendarReference] -> ShowS)
-> Show CalendarReference
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CalendarReference -> ShowS
showsPrec :: Int -> CalendarReference -> ShowS
$cshow :: CalendarReference -> String
show :: CalendarReference -> String
$cshowList :: [CalendarReference] -> ShowS
showList :: [CalendarReference] -> ShowS
Show)

-- |A date or year-fraction coordinate measured from a term structure's reference date.
data TermPoint = DatePoint !Day | TimePoint !Double
  deriving (TermPoint -> TermPoint -> Bool
(TermPoint -> TermPoint -> Bool)
-> (TermPoint -> TermPoint -> Bool) -> Eq TermPoint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TermPoint -> TermPoint -> Bool
== :: TermPoint -> TermPoint -> Bool
$c/= :: TermPoint -> TermPoint -> Bool
/= :: TermPoint -> TermPoint -> Bool
Eq, Int -> TermPoint -> ShowS
[TermPoint] -> ShowS
TermPoint -> String
(Int -> TermPoint -> ShowS)
-> (TermPoint -> String)
-> ([TermPoint] -> ShowS)
-> Show TermPoint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TermPoint -> ShowS
showsPrec :: Int -> TermPoint -> ShowS
$cshow :: TermPoint -> String
show :: TermPoint -> String
$cshowList :: [TermPoint] -> ShowS
showList :: [TermPoint] -> ShowS
Show)

-- |A same-representation interval. Keeping both endpoints in one constructor prevents mixed
-- date/time intervals that upstream does not accept.
data TermInterval
  = DateInterval !Day !Day
  | TimeInterval !Double !Double
  deriving (TermInterval -> TermInterval -> Bool
(TermInterval -> TermInterval -> Bool)
-> (TermInterval -> TermInterval -> Bool) -> Eq TermInterval
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TermInterval -> TermInterval -> Bool
== :: TermInterval -> TermInterval -> Bool
$c/= :: TermInterval -> TermInterval -> Bool
/= :: TermInterval -> TermInterval -> Bool
Eq, Int -> TermInterval -> ShowS
[TermInterval] -> ShowS
TermInterval -> String
(Int -> TermInterval -> ShowS)
-> (TermInterval -> String)
-> ([TermInterval] -> ShowS)
-> Show TermInterval
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TermInterval -> ShowS
showsPrec :: Int -> TermInterval -> ShowS
$cshow :: TermInterval -> String
show :: TermInterval -> String
$cshowList :: [TermInterval] -> ShowS
showList :: [TermInterval] -> ShowS
Show)

-- |A date or year-fraction coordinate where a date needs its day-counting rule.
data RatePoint
  = RateAtDate !Day !DayCounter
  | RateAtTime !Double
  deriving (RatePoint -> RatePoint -> Bool
(RatePoint -> RatePoint -> Bool)
-> (RatePoint -> RatePoint -> Bool) -> Eq RatePoint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RatePoint -> RatePoint -> Bool
== :: RatePoint -> RatePoint -> Bool
$c/= :: RatePoint -> RatePoint -> Bool
/= :: RatePoint -> RatePoint -> Bool
Eq, Int -> RatePoint -> ShowS
[RatePoint] -> ShowS
RatePoint -> String
(Int -> RatePoint -> ShowS)
-> (RatePoint -> String)
-> ([RatePoint] -> ShowS)
-> Show RatePoint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RatePoint -> ShowS
showsPrec :: Int -> RatePoint -> ShowS
$cshow :: RatePoint -> String
show :: RatePoint -> String
$cshowList :: [RatePoint] -> ShowS
showList :: [RatePoint] -> ShowS
Show)

-- |the date at which discount = 1.0 and/or variance = 0.0
referenceDate :: (GenTermStructure t) -> IO ((Day))
referenceDate :: forall t. GenTermStructure t -> IO Day
referenceDate GenTermStructure t
a1 =
  GenTermStructure t -> (Ptr CTermStructure' -> IO Day) -> IO Day
forall t b.
GenTermStructure t -> (Ptr CTermStructure' -> IO b) -> IO b
withTermStructure GenTermStructure t
a1 ((Ptr CTermStructure' -> IO Day) -> IO Day)
-> (Ptr CTermStructure' -> IO Day) -> IO Day
forall a b. (a -> b) -> a -> b
$ \Ptr CTermStructure'
a1' -> 
  (Ptr (Ptr CChar) -> IO Day) -> IO Day
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO Day) -> IO Day)
-> (Ptr (Ptr CChar) -> IO Day) -> IO Day
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a2' -> 
  Ptr CTermStructure' -> Ptr (Ptr CChar) -> IO CInt
referenceDate'_ Ptr CTermStructure'
a1' Ptr (Ptr CChar)
a2' IO CInt -> (CInt -> IO Day) -> IO Day
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CInt
res ->
  let {res' :: Day
res' = CInt -> Day
toDay CInt
res} in
  Ptr (Ptr CChar) -> IO ()
errorCheck  Ptr (Ptr CChar)
a2'IO () -> IO Day -> IO Day
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Day -> IO Day
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Day
res')

{-# LINE 123 "./QuantLib/TermStructure.chs" #-}


-- |the latest date for which the curve can return values
maxDate :: (GenTermStructure t) -> IO ((Day))
maxDate a1 =
  withTermStructure a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  maxDate'_ a1' a2' >>= \res ->
  let {res' = toDay res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 126 "./QuantLib/TermStructure.chs" #-}


-- |'maxDate' expressed as a year fraction from the structure's reference date
maxTime :: (GenTermStructure t) -> IO ((Double))
maxTime a1 =
  withTermStructure a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  maxTime'_ a1' a2' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 129 "./QuantLib/TermStructure.chs" #-}


-- |Whether calls beyond the term structure's maximum date are allowed by default.
allowsExtrapolation :: (GenTermStructure t) -> IO ((Bool))
allowsExtrapolation a1 =
  withTermStructure a1 $ \a1' -> 
  allowsExtrapolation'_ a1' >>= \res ->
  let {res' = C2HSImp.toBool res} in
  return (res')

{-# LINE 132 "./QuantLib/TermStructure.chs" #-}


-- |Enable or disable default extrapolation for any term structure.
setExtrapolation :: (GenTermStructure t) -> (Bool) -> IO ()
setExtrapolation a1 a2 =
  withTermStructure a1 $ \a1' -> 
  let {a2' = C2HSImp.fromBool a2} in 
  setExtrapolation'_ a1' a2' >>
  return ()

{-# LINE 135 "./QuantLib/TermStructure.chs" #-}


-- |Converts a date to a time (as a fraction of year) according to the term structure's day counter.
timeFromReference :: (GenTermStructure t) -- ^term structure
 -> (Day) -- ^date
 -> IO ((Double))
timeFromReference a1 a2 =
  withTermStructure a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  timeFromReference'_ a1' a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 140 "./QuantLib/TermStructure.chs" #-}


-- vim: set ff=unix ts=8 sts=2 sw=2 et:

foreign import ccall safe "QuantLib/TermStructure.chs.h qlBondHelperBond"
  qlBondHelperBond'_ :: ((C2HSImp.Ptr (CBondHelper')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CBond')))))

foreign import ccall safe "QuantLib/TermStructure.chs.h qlSwapRateHelperSwap"
  qlSwapRateHelperSwap'_ :: ((C2HSImp.Ptr (CSwapRateHelper')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CVanillaSwap')))))

foreign import ccall safe "QuantLib/TermStructure.chs.h qlOISRateHelperSwap"
  qlOISRateHelperSwap'_ :: ((C2HSImp.Ptr (COISRateHelper')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (COvernightIndexedSwap')))))

foreign import ccall safe "QuantLib/TermStructure.chs.h qlZeroCouponInflationSwapHelperSwap"
  qlZeroCouponInflationSwapHelperSwap'_ :: ((C2HSImp.Ptr (CZeroCouponInflationSwapHelper)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CZeroCouponInflationSwap')))))

foreign import ccall safe "QuantLib/TermStructure.chs.h qlYearOnYearInflationSwapHelperSwap"
  qlYearOnYearInflationSwapHelperSwap'_ :: ((C2HSImp.Ptr (CYearOnYearInflationSwapHelper)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CYearOnYearInflationSwap')))))

foreign import ccall safe "QuantLib/TermStructure.chs.h qlSwaptionHelperUnderlying"
  qlSwaptionHelperUnderlying'_ :: ((C2HSImp.Ptr (CSwaptionHelper')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CFixedVsFloatingSwap')))))

foreign import ccall safe "QuantLib/TermStructure.chs.h qlTermStructureReferenceDate"
  referenceDate'_ :: ((C2HSImp.Ptr (CTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CInt)))

foreign import ccall safe "QuantLib/TermStructure.chs.h qlTermStructureMaxDate"
  maxDate'_ :: ((C2HSImp.Ptr (CTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CInt)))

foreign import ccall safe "QuantLib/TermStructure.chs.h qlTermStructureMaxTime"
  maxTime'_ :: ((C2HSImp.Ptr (CTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))

foreign import ccall safe "QuantLib/TermStructure.chs.h qlTermStructureAllowsExtrapolation"
  allowsExtrapolation'_ :: ((C2HSImp.Ptr (CTermStructure')) -> (IO C2HSImp.CInt))

foreign import ccall safe "QuantLib/TermStructure.chs.h qlTermStructureSetExtrapolation"
  setExtrapolation'_ :: ((C2HSImp.Ptr (CTermStructure')) -> (C2HSImp.CInt -> (IO ())))

foreign import ccall safe "QuantLib/TermStructure.chs.h qlTermStructureTimeFromReference"
  timeFromReference'_ :: ((C2HSImp.Ptr (CTermStructure')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))