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 module QuantLib.Index.Inflation
    6   (
    7     -- * Types
    8     -- ** Inflation index hierarchy
    9     GenInflationIndex
   10   , InflationIndex
   11   , GenZeroInflationIndex
   12   , ZeroInflationIndex
   13   , GenYoYInflationIndex
   14   , YoYInflationIndex
   15 
   16     -- ** Regions
   17   , Region
   18   , RegionType(..)
   19 
   20     -- ** Configuration
   21   , ZeroInflationIndexType(..)
   22   , YoYInflationIndexType(..)
   23 
   24     -- * Constructors
   25     -- ** Hierarchy and regions
   26   , asInflationIndex
   27   , region
   28   , customRegion
   29     -- ** Inflation indices
   30   , zeroInflationIndex
   31   , customZeroInflationIndex
   32   , yoyInflationIndex
   33   , customYoyInflationIndex
   34   , yoyInflationIndexFromZero
   35 
   36     -- * Inspectors
   37   , fixing
   38   , yoyFixing
   39   , needsForecast
   40   , yoyNeedsForecast
   41   ) where
   42 import qualified Foreign.C.String as C2HSImp
   43 import qualified Foreign.C.Types as C2HSImp
   44 import qualified Foreign.ForeignPtr as C2HSImp
   45 import qualified Foreign.Marshal.Utils as C2HSImp
   46 import qualified Foreign.Ptr as C2HSImp
   47 
   48 
   49 import QuantLib.Internal
   50 import QuantLib.Internal.Type
   51 import QuantLib.Time.Schedule(Frequency, TimeUnit)
   52 
   53 
   54 
   55 
   56 
   57 
   58 
   59 
   60 
   61 
   62 
   63 
   64 
   65 
   66 
   67 
   68 
   69 
   70 
   71 
   72 data ZeroInflationIndexType = AUCPI
   73                             | EUHICP
   74                             | EUHICPXT
   75                             | FRHICP
   76                             | UKHICP
   77                             | UKRPI
   78                             | USCPI
   79                             | ZACPI
   80   deriving (Show,Eq,Read)
   81 instance Enum ZeroInflationIndexType where
   82   succ AUCPI = EUHICP
   83   succ EUHICP = EUHICPXT
   84   succ EUHICPXT = FRHICP
   85   succ FRHICP = UKHICP
   86   succ UKHICP = UKRPI
   87   succ UKRPI = USCPI
   88   succ USCPI = ZACPI
   89   succ ZACPI = error "ZeroInflationIndexType.succ: ZACPI has no successor"
   90 
   91   pred EUHICP = AUCPI
   92   pred EUHICPXT = EUHICP
   93   pred FRHICP = EUHICPXT
   94   pred UKHICP = FRHICP
   95   pred UKRPI = UKHICP
   96   pred USCPI = UKRPI
   97   pred ZACPI = USCPI
   98   pred AUCPI = error "ZeroInflationIndexType.pred: AUCPI has no predecessor"
   99 
  100   enumFromTo from to = go from
  101     where
  102       end = fromEnum to
  103       go v = case compare (fromEnum v) end of
  104                  LT -> v : go (succ v)
  105                  EQ -> [v]
  106                  GT -> []
  107 
  108   enumFrom from = enumFromTo from ZACPI
  109 
  110   fromEnum AUCPI = 0
  111   fromEnum EUHICP = 1
  112   fromEnum EUHICPXT = 2
  113   fromEnum FRHICP = 3
  114   fromEnum UKHICP = 4
  115   fromEnum UKRPI = 5
  116   fromEnum USCPI = 6
  117   fromEnum ZACPI = 7
  118 
  119   toEnum 0 = AUCPI
  120   toEnum 1 = EUHICP
  121   toEnum 2 = EUHICPXT
  122   toEnum 3 = FRHICP
  123   toEnum 4 = UKHICP
  124   toEnum 5 = UKRPI
  125   toEnum 6 = USCPI
  126   toEnum 7 = ZACPI
  127   toEnum unmatched = error ("ZeroInflationIndexType.toEnum: Cannot match " ++ show unmatched)
  128 
  129 
  130 data YoYInflationIndexType = YYAUCPI
  131                            | YYEUHICP
  132                            | YYEUHICPXT
  133                            | YYFRHICP
  134                            | YYUKRPI
  135                            | YYUSCPI
  136                            | YYZACPI
  137   deriving (Show,Eq,Read)
  138 instance Enum YoYInflationIndexType where
  139   succ YYAUCPI = YYEUHICP
  140   succ YYEUHICP = YYEUHICPXT
  141   succ YYEUHICPXT = YYFRHICP
  142   succ YYFRHICP = YYUKRPI
  143   succ YYUKRPI = YYUSCPI
  144   succ YYUSCPI = YYZACPI
  145   succ YYZACPI = error "YoYInflationIndexType.succ: YYZACPI has no successor"
  146 
  147   pred YYEUHICP = YYAUCPI
  148   pred YYEUHICPXT = YYEUHICP
  149   pred YYFRHICP = YYEUHICPXT
  150   pred YYUKRPI = YYFRHICP
  151   pred YYUSCPI = YYUKRPI
  152   pred YYZACPI = YYUSCPI
  153   pred YYAUCPI = error "YoYInflationIndexType.pred: YYAUCPI has no predecessor"
  154 
  155   enumFromTo from to = go from
  156     where
  157       end = fromEnum to
  158       go v = case compare (fromEnum v) end of
  159                  LT -> v : go (succ v)
  160                  EQ -> [v]
  161                  GT -> []
  162 
  163   enumFrom from = enumFromTo from YYZACPI
  164 
  165   fromEnum YYAUCPI = 0
  166   fromEnum YYEUHICP = 1
  167   fromEnum YYEUHICPXT = 2
  168   fromEnum YYFRHICP = 3
  169   fromEnum YYUKRPI = 4
  170   fromEnum YYUSCPI = 5
  171   fromEnum YYZACPI = 6
  172 
  173   toEnum 0 = YYAUCPI
  174   toEnum 1 = YYEUHICP
  175   toEnum 2 = YYEUHICPXT
  176   toEnum 3 = YYFRHICP
  177   toEnum 4 = YYUKRPI
  178   toEnum 5 = YYUSCPI
  179   toEnum 6 = YYZACPI
  180   toEnum unmatched = error ("YoYInflationIndexType.toEnum: Cannot match " ++ show unmatched)
  181 
  182 
  183 data RegionType = AustraliaRegion
  184                 | EURegion
  185                 | FranceRegion
  186                 | UKRegion
  187                 | USRegion
  188                 | ZARegion
  189   deriving (Show,Eq,Read,Bounded)
  190 instance Enum RegionType where
  191   succ AustraliaRegion = EURegion
  192   succ EURegion = FranceRegion
  193   succ FranceRegion = UKRegion
  194   succ UKRegion = USRegion
  195   succ USRegion = ZARegion
  196   succ ZARegion = error "RegionType.succ: ZARegion has no successor"
  197 
  198   pred EURegion = AustraliaRegion
  199   pred FranceRegion = EURegion
  200   pred UKRegion = FranceRegion
  201   pred USRegion = UKRegion
  202   pred ZARegion = USRegion
  203   pred AustraliaRegion = error "RegionType.pred: AustraliaRegion has no predecessor"
  204 
  205   enumFromTo from to = go from
  206     where
  207       end = fromEnum to
  208       go v = case compare (fromEnum v) end of
  209                  LT -> v : go (succ v)
  210                  EQ -> [v]
  211                  GT -> []
  212 
  213   enumFrom from = enumFromTo from ZARegion
  214 
  215   fromEnum AustraliaRegion = 0
  216   fromEnum EURegion = 1
  217   fromEnum FranceRegion = 2
  218   fromEnum UKRegion = 3
  219   fromEnum USRegion = 4
  220   fromEnum ZARegion = 5
  221 
  222   toEnum 0 = AustraliaRegion
  223   toEnum 1 = EURegion
  224   toEnum 2 = FranceRegion
  225   toEnum 3 = UKRegion
  226   toEnum 4 = USRegion
  227   toEnum 5 = ZARegion
  228   toEnum unmatched = error ("RegionType.toEnum: Cannot match " ++ show unmatched)
  229 
  230 
  231 
  232 -- |A named zero inflation index (RPI/HICP/CPI family). Constructs with no historical
  233 -- fixings and no linked term structure -- add fixings via 'QuantLib.Index.addFixing'.
  234 zeroInflationIndex :: (ZeroInflationIndexType) -> IO ((ZeroInflationIndex))
  235 zeroInflationIndex a1 =
  236   let {a1' = (fromIntegral . fromEnum) a1} in 
  237   preErrorCheck $ \a2' -> 
  238   zeroInflationIndex'_ a1' a2' >>= \res ->
  239   peekZeroInflationIndex res >>= \res' ->
  240   errorCheck  a2'>>
  241   return (res')
  242 
  243 
  244 
  245 -- |A named quoted year-on-year inflation index.
  246 yoyInflationIndex :: (YoYInflationIndexType) -> IO ((YoYInflationIndex))
  247 yoyInflationIndex a1 =
  248   let {a1' = (fromIntegral . fromEnum) a1} in 
  249   preErrorCheck $ \a2' -> 
  250   yoyInflationIndex'_ a1' a2' >>= \res ->
  251   peekYoYInflationIndex res >>= \res' ->
  252   errorCheck  a2'>>
  253   return (res')
  254 
  255 
  256 
  257 -- |One of the 6 named geographical/economic regions QuantLib ships (used for the pre-baked
  258 -- named indices, e.g. 'UKRPI' uses 'UKRegion' internally). See 'region\'' for an arbitrary
  259 -- custom region.
  260 region :: (RegionType) -> IO ((Region))
  261 region a1 =
  262   let {a1' = (fromIntegral . fromEnum) a1} in 
  263   preErrorCheck $ \a2' -> 
  264   region'_ a1' a2' >>= \res ->
  265   peekRegion res >>= \res' ->
  266   errorCheck  a2'>>
  267   return (res')
  268 
  269 
  270 
  271 -- |An arbitrary custom region, given its name and ISO code.
  272 customRegion :: (String) -> (String) -> IO ((Region))
  273 customRegion a1 a2 =
  274   C2HSImp.withCString a1 $ \a1' -> 
  275   C2HSImp.withCString a2 $ \a2' -> 
  276   preErrorCheck $ \a3' -> 
  277   customRegion'_ a1' a2' a3' >>= \res ->
  278   peekRegion res >>= \res' ->
  279   errorCheck  a3'>>
  280   return (res')
  281 
  282 
  283 
  284 -- |A custom zero inflation index (arbitrary family name/region/currency), with no historical
  285 -- fixings -- add fixings via 'QuantLib.Index.addFixing'.
  286 customZeroInflationIndex :: (String) -- ^familyName
  287  -> (Region) -> (Bool) -- ^revised
  288  -> (Frequency) -> ((Int,TimeUnit)) -- ^availabilityLag
  289  -> (Currency) -> (Maybe (GenZeroInflationTermStructure z)) -> IO ((ZeroInflationIndex))
  290 customZeroInflationIndex a1 a2 a3 a4 a5 a6 a7 =
  291   C2HSImp.withCString a1 $ \a1' -> 
  292   withRegion a2 $ \a2' -> 
  293   let {a3' = C2HSImp.fromBool a3} in 
  294   let {a4' = (fromIntegral . fromEnum) a4} in 
  295   let {(a5'1, a5'2) = fromEnumQuantity a5} in 
  296   withCurrency a6 $ \a6' -> 
  297   withMaybeZeroInflationTermStructure a7 $ \a7' -> 
  298   preErrorCheck $ \a8' -> 
  299   customZeroInflationIndex'_ a1' a2' a3' a4' a5'1  a5'2 a6' a7' a8' >>= \res ->
  300   peekZeroInflationIndex res >>= \res' ->
  301   errorCheck  a8'>>
  302   return (res')
  303 
  304 
  305 
  306 -- |A custom quoted year-on-year inflation index (arbitrary family name/region/currency); needs
  307 -- its own past fixings added via 'QuantLib.Index.addFixing'. See 'yoyInflationIndexFromZero'
  308 -- for a YoY index defined instead as a ratio of an existing 'ZeroInflationIndex'\'s fixings.
  309 customYoyInflationIndex :: (String) -- ^familyName
  310  -> (Region) -> (Bool) -- ^revised
  311  -> (Frequency) -> ((Int,TimeUnit)) -- ^availabilityLag
  312  -> (Currency) -> (Maybe (GenYoYInflationTermStructure y)) -> IO ((YoYInflationIndex))
  313 customYoyInflationIndex a1 a2 a3 a4 a5 a6 a7 =
  314   C2HSImp.withCString a1 $ \a1' -> 
  315   withRegion a2 $ \a2' -> 
  316   let {a3' = C2HSImp.fromBool a3} in 
  317   let {a4' = (fromIntegral . fromEnum) a4} in 
  318   let {(a5'1, a5'2) = fromEnumQuantity a5} in 
  319   withCurrency a6 $ \a6' -> 
  320   withMaybeYoYInflationTermStructure a7 $ \a7' -> 
  321   preErrorCheck $ \a8' -> 
  322   customYoyInflationIndex'_ a1' a2' a3' a4' a5'1  a5'2 a6' a7' a8' >>= \res ->
  323   peekYoYInflationIndex res >>= \res' ->
  324   errorCheck  a8'>>
  325   return (res')
  326 
  327 
  328 
  329 -- |A year-on-year index defined as the ratio of an existing 'ZeroInflationIndex'\'s fixings;
  330 -- stores no fixings of its own.
  331 yoyInflationIndexFromZero :: (GenZeroInflationIndex zidx) -> (Maybe (GenYoYInflationTermStructure y)) -> IO ((YoYInflationIndex))
  332 yoyInflationIndexFromZero a1 a2 =
  333   withZeroInflationIndex a1 $ \a1' -> 
  334   withMaybeYoYInflationTermStructure a2 $ \a2' -> 
  335   preErrorCheck $ \a3' -> 
  336   yoyInflationIndexFromZero'_ a1' a2' a3' >>= \res ->
  337   peekYoYInflationIndex res >>= \res' ->
  338   errorCheck  a3'>>
  339   return (res')
  340 
  341 
  342 
  343 -- |The (possibly forecast) fixing at the given date; for a date with no linked term
  344 -- structure this returns the stored historical fixing added via 'QuantLib.Index.addFixing'.
  345 fixing :: (GenZeroInflationIndex zidx) -> (Day) -> IO ((Double))
  346 fixing a1 a2 =
  347   withZeroInflationIndex a1 $ \a1' -> 
  348   withDay a2 $ \a2' -> 
  349   preErrorCheck $ \a3' -> 
  350   fixing'_ a1' a2' a3' >>= \res ->
  351   let {res' = realToFrac res} in
  352   errorCheck  a3'>>
  353   return (res')
  354 
  355 
  356 
  357 -- |The (possibly forecast) year-on-year fixing at the given date; for a date with no linked
  358 -- term structure this returns the stored historical fixing added via 'QuantLib.Index.addFixing'.
  359 yoyFixing :: (GenYoYInflationIndex yidx) -> (Day) -> IO ((Double))
  360 yoyFixing a1 a2 =
  361   withYoYInflationIndex a1 $ \a1' -> 
  362   withDay a2 $ \a2' -> 
  363   preErrorCheck $ \a3' -> 
  364   yoyFixing'_ a1' a2' a3' >>= \res ->
  365   let {res' = realToFrac res} in
  366   errorCheck  a3'>>
  367   return (res')
  368 
  369 
  370 
  371 -- |Whether 'fixing' at the given date would have to be forecast rather than served from a stored
  372 -- historical fixing -- true once the date falls after the latest period a fixing could plausibly
  373 -- already be published for, given the index's publication lag.
  374 -- /Warning/ It raises an exception if the index was built with a frequency outside
  375 -- @Annual@..@Monthly@, which the inflation-period calculation does not handle.
  376 needsForecast :: (GenZeroInflationIndex zidx) -> (Day) -> IO ((Bool))
  377 needsForecast a1 a2 =
  378   withZeroInflationIndex a1 $ \a1' -> 
  379   withDay a2 $ \a2' -> 
  380   preErrorCheck $ \a3' -> 
  381   needsForecast'_ a1' a2' a3' >>= \res ->
  382   let {res' = C2HSImp.toBool res} in
  383   errorCheck  a3'>>
  384   return (res')
  385 
  386 
  387 
  388 -- |The year-on-year counterpart of 'needsForecast', for 'yoyFixing'.
  389 -- /Warning/ It raises an exception on an unhandled frequency, as 'needsForecast' does.
  390 yoyNeedsForecast :: (GenYoYInflationIndex yidx) -> (Day) -> IO ((Bool))
  391 yoyNeedsForecast a1 a2 =
  392   withYoYInflationIndex a1 $ \a1' -> 
  393   withDay a2 $ \a2' -> 
  394   preErrorCheck $ \a3' -> 
  395   yoyNeedsForecast'_ a1' a2' a3' >>= \res ->
  396   let {res' = C2HSImp.toBool res} in
  397   errorCheck  a3'>>
  398   return (res')
  399 
  400 
  401 
  402 -- vim: set ff=unix ts=8 sts=2 sw=2 et:
  403 
  404 foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlCreateZeroInflationIndex"
  405   zeroInflationIndex'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CZeroInflationIndex')))))
  406 
  407 foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlCreateYoYInflationIndex"
  408   yoyInflationIndex'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CYoYInflationIndex')))))
  409 
  410 foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlRegion"
  411   region'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CRegion)))))
  412 
  413 foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlCreateRegion"
  414   customRegion'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CRegion))))))
  415 
  416 foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlZeroInflationIndex"
  417   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'))))))))))))
  418 
  419 foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlYoYInflationIndex"
  420   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'))))))))))))
  421 
  422 foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlYoYInflationIndexFromZero"
  423   yoyInflationIndexFromZero'_ :: ((C2HSImp.Ptr (CZeroInflationIndex')) -> ((C2HSImp.Ptr (CYoYInflationTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CYoYInflationIndex'))))))
  424 
  425 foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlZeroInflationIndexFixing"
  426   fixing'_ :: ((C2HSImp.Ptr (CZeroInflationIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
  427 
  428 foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlYoYInflationIndexFixing"
  429   yoyFixing'_ :: ((C2HSImp.Ptr (CYoYInflationIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
  430 
  431 foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlZeroInflationIndexNeedsForecast"
  432   needsForecast'_ :: ((C2HSImp.Ptr (CZeroInflationIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt))))
  433 
  434 foreign import ccall safe "QuantLib/Index/Inflation.chs.h qlYoYInflationIndexNeedsForecast"
  435   yoyNeedsForecast'_ :: ((C2HSImp.Ptr (CYoYInflationIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt))))