-- 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" #-}
{-# LANGUAGE FlexibleInstances #-}
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
  , HasNeedsForecast(..)
  ) 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 46 "./QuantLib/Index/Inflation.chs" #-}


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


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


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


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


{-# LINE 51 "./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 53 "./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 54 "./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 55 "./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 59 "./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 62 "./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 67 "./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 70 "./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 (GenZeroInflationTermStructure z)) -> 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 81 "./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 (GenYoYInflationTermStructure yoy)) -> 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 93 "./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 :: (GenZeroInflationIndex zidx) -> (Maybe (GenYoYInflationTermStructure yoy)) -> 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 99 "./QuantLib/Index/Inflation.chs" #-}


-- |Zero and year-on-year inflation indexes; read their fixings with 'QuantLib.Index.fixing'.
class HasNeedsForecast idx where
  -- |Whether 'QuantLib.Index.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 :: idx -> Day -> IO Bool
instance HasNeedsForecast (GenZeroInflationIndex zidx) where
  needsForecast = qlZeroInflationIndexNeedsForecast
instance HasNeedsForecast (GenYoYInflationIndex yidx) where
  needsForecast :: GenYoYInflationIndex yidx -> Day -> IO Bool
needsForecast = GenYoYInflationIndex yidx -> Day -> IO Bool
forall yidx. GenYoYInflationIndex yidx -> Day -> IO Bool
qlYoYInflationIndexNeedsForecast

qlZeroInflationIndexNeedsForecast :: (GenZeroInflationIndex zidx) -> (Day) -> IO ((Bool))
qlZeroInflationIndexNeedsForecast :: forall zidx. GenZeroInflationIndex zidx -> Day -> IO Bool
qlZeroInflationIndexNeedsForecast GenZeroInflationIndex zidx
a1 Day
a2 =
  GenZeroInflationIndex zidx
-> (Ptr CZeroInflationIndex' -> IO Bool) -> IO Bool
forall zidx b.
GenZeroInflationIndex zidx
-> (Ptr CZeroInflationIndex' -> IO b) -> IO b
withZeroInflationIndex GenZeroInflationIndex zidx
a1 ((Ptr CZeroInflationIndex' -> IO Bool) -> IO Bool)
-> (Ptr CZeroInflationIndex' -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \Ptr CZeroInflationIndex'
a1' -> 
  Day -> (CInt -> IO Bool) -> IO Bool
forall a. Day -> (CInt -> IO a) -> IO a
withDay Day
a2 ((CInt -> IO Bool) -> IO Bool) -> (CInt -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \a2' -> 
  (Ptr (Ptr ()) -> IO Bool) -> IO Bool
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO Bool) -> IO Bool)
-> (Ptr (Ptr ()) -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a3' -> 
  Ptr CZeroInflationIndex' -> CInt -> Ptr (Ptr ()) -> IO CInt
qlZeroInflationIndexNeedsForecast'_ Ptr CZeroInflationIndex'
a1' CInt
a2' Ptr (Ptr ())
a3' IO CInt -> (CInt -> IO Bool) -> IO Bool
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' :: Bool
res' = CInt -> Bool
forall a. (Eq a, Num a) => a -> Bool
C2HSImp.toBool CInt
res} in
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a3'IO () -> IO Bool -> IO Bool
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
res')

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

qlYoYInflationIndexNeedsForecast :: (GenYoYInflationIndex yidx) -> (Day) -> IO ((Bool))
qlYoYInflationIndexNeedsForecast a1 a2 =
  withYoYInflationIndex a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  qlYoYInflationIndexNeedsForecast'_ a1' a2' a3' >>= \res ->
  let {res' = C2HSImp.toBool res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 115 "./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 ())) -> (IO (C2HSImp.Ptr (CZeroInflationIndex')))))

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

foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlRegion"
  region'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (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 ())) -> (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 ())) -> (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 ())) -> (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 ())) -> (IO (C2HSImp.Ptr (CYoYInflationIndex'))))))

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

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