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


{-# LINE 1 "./QuantLib/Index/Inflation.chs" #-}
module QuantLib.Index.Inflation
  (
    -- * Types
    -- ** Inflation index hierarchy
    GenInflationIndex
  , InflationIndex
  , GenZeroInflationIndex
  , ZeroInflationIndex
  , GenYoYInflationIndex
  , YoYInflationIndex

    -- ** Regions
  , Region
  , RegionType(..)

    -- ** Configuration
  , ZeroInflationIndexType(..)
  , YoYInflationIndexType(..)

    -- * Constructors
    -- ** Hierarchy and regions
  , asInflationIndex
  , region
  , customRegion
    -- ** Inflation indices
  , zeroInflationIndex
  , customZeroInflationIndex
  , yoyInflationIndex
  , customYoyInflationIndex
  , yoyInflationIndexFromZero

    -- * Inspectors
  , fixing
  , yoyFixing
  , needsForecast
  , yoyNeedsForecast
  ) where
import qualified Foreign.C.String as C2HSImp
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
import QuantLib.Internal.Type
import QuantLib.Time.Schedule(Frequency, TimeUnit)








{-# LINE 48 "./QuantLib/Index/Inflation.chs" #-}


{-# LINE 49 "./QuantLib/Index/Inflation.chs" #-}


{-# LINE 50 "./QuantLib/Index/Inflation.chs" #-}


{-# LINE 51 "./QuantLib/Index/Inflation.chs" #-}


{-# LINE 52 "./QuantLib/Index/Inflation.chs" #-}


{-# LINE 53 "./QuantLib/Index/Inflation.chs" #-}


data ZeroInflationIndexType = AUCPI
                            | EUHICP
                            | EUHICPXT
                            | FRHICP
                            | UKHICP
                            | UKRPI
                            | USCPI
                            | ZACPI
  deriving (Show,Eq,Read)
instance Enum ZeroInflationIndexType where
  succ AUCPI = EUHICP
  succ EUHICP = EUHICPXT
  succ EUHICPXT = FRHICP
  succ FRHICP = UKHICP
  succ UKHICP = UKRPI
  succ UKRPI = USCPI
  succ USCPI = ZACPI
  succ ZACPI = error "ZeroInflationIndexType.succ: ZACPI has no successor"

  pred EUHICP = AUCPI
  pred EUHICPXT = EUHICP
  pred FRHICP = EUHICPXT
  pred UKHICP = FRHICP
  pred UKRPI = UKHICP
  pred USCPI = UKRPI
  pred ZACPI = USCPI
  pred AUCPI = error "ZeroInflationIndexType.pred: AUCPI has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from ZACPI

  fromEnum AUCPI = 0
  fromEnum EUHICP = 1
  fromEnum EUHICPXT = 2
  fromEnum FRHICP = 3
  fromEnum UKHICP = 4
  fromEnum UKRPI = 5
  fromEnum USCPI = 6
  fromEnum ZACPI = 7

  toEnum 0 = AUCPI
  toEnum 1 = EUHICP
  toEnum 2 = EUHICPXT
  toEnum 3 = FRHICP
  toEnum 4 = UKHICP
  toEnum 5 = UKRPI
  toEnum 6 = USCPI
  toEnum 7 = ZACPI
  toEnum unmatched = error ("ZeroInflationIndexType.toEnum: Cannot match " ++ show unmatched)

{-# LINE 55 "./QuantLib/Index/Inflation.chs" #-}

data YoYInflationIndexType = YYAUCPI
                           | YYEUHICP
                           | YYEUHICPXT
                           | YYFRHICP
                           | YYUKRPI
                           | YYUSCPI
                           | YYZACPI
  deriving (Show,Eq,Read)
instance Enum YoYInflationIndexType where
  succ YYAUCPI = YYEUHICP
  succ YYEUHICP = YYEUHICPXT
  succ YYEUHICPXT = YYFRHICP
  succ YYFRHICP = YYUKRPI
  succ YYUKRPI = YYUSCPI
  succ YYUSCPI = YYZACPI
  succ YYZACPI = error "YoYInflationIndexType.succ: YYZACPI has no successor"

  pred YYEUHICP = YYAUCPI
  pred YYEUHICPXT = YYEUHICP
  pred YYFRHICP = YYEUHICPXT
  pred YYUKRPI = YYFRHICP
  pred YYUSCPI = YYUKRPI
  pred YYZACPI = YYUSCPI
  pred YYAUCPI = error "YoYInflationIndexType.pred: YYAUCPI has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from YYZACPI

  fromEnum YYAUCPI = 0
  fromEnum YYEUHICP = 1
  fromEnum YYEUHICPXT = 2
  fromEnum YYFRHICP = 3
  fromEnum YYUKRPI = 4
  fromEnum YYUSCPI = 5
  fromEnum YYZACPI = 6

  toEnum 0 = YYAUCPI
  toEnum 1 = YYEUHICP
  toEnum 2 = YYEUHICPXT
  toEnum 3 = YYFRHICP
  toEnum 4 = YYUKRPI
  toEnum 5 = YYUSCPI
  toEnum 6 = YYZACPI
  toEnum unmatched = error ("YoYInflationIndexType.toEnum: Cannot match " ++ show unmatched)

{-# LINE 56 "./QuantLib/Index/Inflation.chs" #-}

data RegionType = AustraliaRegion
                | EURegion
                | FranceRegion
                | UKRegion
                | USRegion
                | ZARegion
  deriving (Show,Eq,Read,Bounded)
instance Enum RegionType where
  succ AustraliaRegion = EURegion
  succ EURegion = FranceRegion
  succ FranceRegion = UKRegion
  succ UKRegion = USRegion
  succ USRegion = ZARegion
  succ ZARegion = error "RegionType.succ: ZARegion has no successor"

  pred EURegion = AustraliaRegion
  pred FranceRegion = EURegion
  pred UKRegion = FranceRegion
  pred USRegion = UKRegion
  pred ZARegion = USRegion
  pred AustraliaRegion = error "RegionType.pred: AustraliaRegion has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from ZARegion

  fromEnum AustraliaRegion = 0
  fromEnum EURegion = 1
  fromEnum FranceRegion = 2
  fromEnum UKRegion = 3
  fromEnum USRegion = 4
  fromEnum ZARegion = 5

  toEnum 0 = AustraliaRegion
  toEnum 1 = EURegion
  toEnum 2 = FranceRegion
  toEnum 3 = UKRegion
  toEnum 4 = USRegion
  toEnum 5 = ZARegion
  toEnum unmatched = error ("RegionType.toEnum: Cannot match " ++ show unmatched)

{-# LINE 57 "./QuantLib/Index/Inflation.chs" #-}


-- |A named zero inflation index (RPI/HICP/CPI family). Constructs with no historical
-- fixings and no linked term structure -- add fixings via 'QuantLib.Index.addFixing'.
zeroInflationIndex :: (ZeroInflationIndexType) -> IO ((ZeroInflationIndex))
zeroInflationIndex a1 =
  let {a1' = (fromIntegral . fromEnum) a1} in 
  preErrorCheck $ \a2' -> 
  zeroInflationIndex'_ a1' a2' >>= \res ->
  peekZeroInflationIndex res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 61 "./QuantLib/Index/Inflation.chs" #-}


-- |A named quoted year-on-year inflation index.
yoyInflationIndex :: (YoYInflationIndexType) -> IO ((YoYInflationIndex))
yoyInflationIndex a1 =
  let {a1' = (fromIntegral . fromEnum) a1} in 
  preErrorCheck $ \a2' -> 
  yoyInflationIndex'_ a1' a2' >>= \res ->
  peekYoYInflationIndex res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 64 "./QuantLib/Index/Inflation.chs" #-}


-- |One of the 6 named geographical/economic regions QuantLib ships (used for the pre-baked
-- named indices, e.g. 'UKRPI' uses 'UKRegion' internally). See 'region\'' for an arbitrary
-- custom region.
region :: (RegionType) -> IO ((Region))
region a1 =
  let {a1' = (fromIntegral . fromEnum) a1} in 
  preErrorCheck $ \a2' -> 
  region'_ a1' a2' >>= \res ->
  peekRegion res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 69 "./QuantLib/Index/Inflation.chs" #-}


-- |An arbitrary custom region, given its name and ISO code.
customRegion :: (String) -> (String) -> IO ((Region))
customRegion a1 a2 =
  C2HSImp.withCString a1 $ \a1' -> 
  C2HSImp.withCString a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  customRegion'_ a1' a2' a3' >>= \res ->
  peekRegion res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 72 "./QuantLib/Index/Inflation.chs" #-}


-- |A custom zero inflation index (arbitrary family name/region/currency), with no historical
-- fixings -- add fixings via 'QuantLib.Index.addFixing'.
customZeroInflationIndex :: (String) -- ^familyName
 -> (Region) -> (Bool) -- ^revised
 -> (Frequency) -> ((Int,TimeUnit)) -- ^availabilityLag
 -> (Currency) -> (Maybe ZeroInflationTermStructure) -> IO ((ZeroInflationIndex))
customZeroInflationIndex a1 a2 a3 a4 a5 a6 a7 =
  C2HSImp.withCString a1 $ \a1' -> 
  withRegion a2 $ \a2' -> 
  let {a3' = C2HSImp.fromBool a3} in 
  let {a4' = (fromIntegral . fromEnum) a4} in 
  let {(a5'1, a5'2) = fromEnumQuantity a5} in 
  withCurrency a6 $ \a6' -> 
  withMaybeZeroInflationTermStructure a7 $ \a7' -> 
  preErrorCheck $ \a8' -> 
  customZeroInflationIndex'_ a1' a2' a3' a4' a5'1  a5'2 a6' a7' a8' >>= \res ->
  peekZeroInflationIndex res >>= \res' ->
  errorCheck  a8'>>
  return (res')

{-# LINE 83 "./QuantLib/Index/Inflation.chs" #-}


-- |A custom quoted year-on-year inflation index (arbitrary family name/region/currency); needs
-- its own past fixings added via 'QuantLib.Index.addFixing'. See 'yoyInflationIndexFromZero'
-- for a YoY index defined instead as a ratio of an existing 'ZeroInflationIndex'\'s fixings.
customYoyInflationIndex :: (String) -- ^familyName
 -> (Region) -> (Bool) -- ^revised
 -> (Frequency) -> ((Int,TimeUnit)) -- ^availabilityLag
 -> (Currency) -> (Maybe YoYInflationTermStructure) -> IO ((YoYInflationIndex))
customYoyInflationIndex a1 a2 a3 a4 a5 a6 a7 =
  C2HSImp.withCString a1 $ \a1' -> 
  withRegion a2 $ \a2' -> 
  let {a3' = C2HSImp.fromBool a3} in 
  let {a4' = (fromIntegral . fromEnum) a4} in 
  let {(a5'1, a5'2) = fromEnumQuantity a5} in 
  withCurrency a6 $ \a6' -> 
  withMaybeYoYInflationTermStructure a7 $ \a7' -> 
  preErrorCheck $ \a8' -> 
  customYoyInflationIndex'_ a1' a2' a3' a4' a5'1  a5'2 a6' a7' a8' >>= \res ->
  peekYoYInflationIndex res >>= \res' ->
  errorCheck  a8'>>
  return (res')

{-# LINE 95 "./QuantLib/Index/Inflation.chs" #-}


-- |A year-on-year index defined as the ratio of an existing 'ZeroInflationIndex'\'s fixings;
-- stores no fixings of its own.
yoyInflationIndexFromZero :: (ZeroInflationIndex) -> (Maybe YoYInflationTermStructure) -> IO ((YoYInflationIndex))
yoyInflationIndexFromZero a1 a2 =
  withZeroInflationIndex a1 $ \a1' -> 
  withMaybeYoYInflationTermStructure a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  yoyInflationIndexFromZero'_ a1' a2' a3' >>= \res ->
  peekYoYInflationIndex res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 101 "./QuantLib/Index/Inflation.chs" #-}


-- |The (possibly forecast) fixing at the given date; for a date with no linked term
-- structure this returns the stored historical fixing added via 'QuantLib.Index.addFixing'.
fixing :: (ZeroInflationIndex) -> (Day) -> IO ((Double))
fixing a1 a2 =
  withZeroInflationIndex a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  fixing'_ a1' a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 105 "./QuantLib/Index/Inflation.chs" #-}


-- |The (possibly forecast) year-on-year fixing at the given date; for a date with no linked
-- term structure this returns the stored historical fixing added via 'QuantLib.Index.addFixing'.
yoyFixing :: (YoYInflationIndex) -> (Day) -> IO ((Double))
yoyFixing a1 a2 =
  withYoYInflationIndex a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  yoyFixing'_ a1' a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 109 "./QuantLib/Index/Inflation.chs" #-}


-- |Whether 'fixing' at the given date would have to be forecast rather than served from a stored
-- historical fixing -- true once the date falls after the latest period a fixing could plausibly
-- already be published for, given the index's publication lag.
-- /Warning/ It raises an exception if the index was built with a frequency outside
-- @Annual@..@Monthly@, which the inflation-period calculation does not handle.
needsForecast :: (ZeroInflationIndex) -> (Day) -> IO ((Bool))
needsForecast a1 a2 =
  withZeroInflationIndex a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  needsForecast'_ a1' a2' a3' >>= \res ->
  let {res' = C2HSImp.toBool res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 116 "./QuantLib/Index/Inflation.chs" #-}


-- |The year-on-year counterpart of 'needsForecast', for 'yoyFixing'.
-- /Warning/ It raises an exception on an unhandled frequency, as 'needsForecast' does.
yoyNeedsForecast :: (YoYInflationIndex) -> (Day) -> IO ((Bool))
yoyNeedsForecast a1 a2 =
  withYoYInflationIndex a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  yoyNeedsForecast'_ a1' a2' a3' >>= \res ->
  let {res' = C2HSImp.toBool res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 120 "./QuantLib/Index/Inflation.chs" #-}


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

foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlCreateZeroInflationIndex"
  zeroInflationIndex'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CZeroInflationIndex')))))

foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlCreateYoYInflationIndex"
  yoyInflationIndex'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CYoYInflationIndex')))))

foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlRegion"
  region'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CRegion)))))

foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlCreateRegion"
  customRegion'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CRegion))))))

foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlZeroInflationIndex"
  customZeroInflationIndex'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr (CRegion)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CZeroInflationTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CZeroInflationIndex'))))))))))))

foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlYoYInflationIndex"
  customYoyInflationIndex'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr (CRegion)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CYoYInflationTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CYoYInflationIndex'))))))))))))

foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlYoYInflationIndexFromZero"
  yoyInflationIndexFromZero'_ :: ((C2HSImp.Ptr (CZeroInflationIndex')) -> ((C2HSImp.Ptr (CYoYInflationTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CYoYInflationIndex'))))))

foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlZeroInflationIndexFixing"
  fixing'_ :: ((C2HSImp.Ptr (CZeroInflationIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlYoYInflationIndexFixing"
  yoyFixing'_ :: ((C2HSImp.Ptr (CYoYInflationIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlZeroInflationIndexNeedsForecast"
  needsForecast'_ :: ((C2HSImp.Ptr (CZeroInflationIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CInt))))

foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlYoYInflationIndexNeedsForecast"
  yoyNeedsForecast'_ :: ((C2HSImp.Ptr (CYoYInflationIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CInt))))