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.TermStructure.Inflation
    6   (
    7     ZeroInflationTermStructure
    8   , YoYInflationTermStructure
    9   , ZeroCouponInflationSwapHelper
   10   , YearOnYearInflationSwapHelper
   11 
   12   , CPIInterpolationType(..) -- ^re-exported from "QuantLib.Internal.Common"
   13 
   14   , zeroCouponInflationSwapHelper
   15   , yearOnYearInflationSwapHelper
   16   , zeroCouponInflationSwapHelperSwap
   17   , yearOnYearInflationSwapHelperSwap
   18 
   19   , piecewiseZeroInflationCurve
   20   , piecewiseYoYInflationCurve
   21   , interpolatedYoYInflationCurve
   22 
   23   , zeroRate
   24   , yoyRate
   25   ) where
   26 import qualified Foreign.C.Types as C2HSImp
   27 import qualified Foreign.ForeignPtr as C2HSImp
   28 import qualified Foreign.Marshal.Utils as C2HSImp
   29 import qualified Foreign.Ptr as C2HSImp
   30 
   31 
   32 import QuantLib.Internal
   33 import QuantLib.Internal.Type
   34 import QuantLib.Time.Schedule(Frequency)
   35 import QuantLib.Internal.Common
   36 import QuantLib.TermStructure.Yield(PillarChoice)
   37 
   38 
   39 
   40 
   41 
   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 -- |Bootstrap helper for a zero-coupon inflation swap, at the given (observation lag, maturity).
   68 zeroCouponInflationSwapHelper :: (GenQuote q) -- ^quote
   69  -> ((Word,TimeUnit)) -- ^swapObsLag
   70  -> (Day) -- ^maturity
   71  -> (Calendar) -> (BusinessDayConvention) -- ^paymentConvention
   72  -> (DayCounter) -> (ZeroInflationIndex) -> (CPIInterpolationType) -- ^observationInterpolation
   73  -> (PillarChoice) -- ^pillar
   74  -> (Maybe Day) -- ^customPillarDate
   75  -> IO ((ZeroCouponInflationSwapHelper))
   76 zeroCouponInflationSwapHelper a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 =
   77   withQuote a1 $ \a1' -> 
   78   let {(a2'1, a2'2) = fromEnumQuantity a2} in 
   79   withDay a3 $ \a3' -> 
   80   withCalendar a4 $ \a4' -> 
   81   let {a5' = fromEnumC a5} in 
   82   withDayCounter a6 $ \a6' -> 
   83   withZeroInflationIndex a7 $ \a7' -> 
   84   let {a8' = fromEnumC a8} in 
   85   let {a9' = (fromIntegral . fromEnum) a9} in 
   86   withMaybeDay a10 $ \a10' -> 
   87   preErrorCheck $ \a11' -> 
   88   zeroCouponInflationSwapHelper'_ a1' a2'1  a2'2 a3' a4' a5' a6' a7' a8' a9' a10' a11' >>= \res ->
   89   peekZeroCouponInflationSwapHelper res >>= \res' ->
   90   errorCheck  a11'>>
   91   return (res')
   92 
   93 
   94 
   95 -- |Bootstrap helper for a year-on-year inflation swap. Unlike 'zeroCouponInflationSwapHelper',
   96 -- also needs the nominal discount curve (the YoY swap's fixed/floating legs discount off it).
   97 yearOnYearInflationSwapHelper :: (GenQuote q) -- ^quote
   98  -> ((Word,TimeUnit)) -- ^swapObsLag
   99  -> (Day) -- ^maturity
  100  -> (Calendar) -> (BusinessDayConvention) -- ^paymentConvention
  101  -> (DayCounter) -> (YoYInflationIndex) -> (CPIInterpolationType) -- ^observationInterpolation
  102  -> (GenYieldTermStructure y) -- ^nominalTermStructure
  103  -> (PillarChoice) -- ^pillar
  104  -> (Maybe Day) -- ^customPillarDate
  105  -> IO ((YearOnYearInflationSwapHelper))
  106 yearOnYearInflationSwapHelper a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 =
  107   withQuote a1 $ \a1' -> 
  108   let {(a2'1, a2'2) = fromEnumQuantity a2} in 
  109   withDay a3 $ \a3' -> 
  110   withCalendar a4 $ \a4' -> 
  111   let {a5' = fromEnumC a5} in 
  112   withDayCounter a6 $ \a6' -> 
  113   withYoYInflationIndex a7 $ \a7' -> 
  114   let {a8' = fromEnumC a8} in 
  115   withYieldTermStructure a9 $ \a9' -> 
  116   let {a10' = (fromIntegral . fromEnum) a10} in 
  117   withMaybeDay a11 $ \a11' -> 
  118   preErrorCheck $ \a12' -> 
  119   yearOnYearInflationSwapHelper'_ a1' a2'1  a2'2 a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' >>= \res ->
  120   peekYearOnYearInflationSwapHelper res >>= \res' ->
  121   errorCheck  a12'>>
  122   return (res')
  123 
  124 
  125 
  126 -- |The underlying swap the helper builds from its quote, observation lag and maturity.
  127 zeroCouponInflationSwapHelperSwap :: (ZeroCouponInflationSwapHelper) -> IO ((ZeroCouponInflationSwap))
  128 zeroCouponInflationSwapHelperSwap a1 =
  129   withZeroCouponInflationSwapHelper a1 $ \a1' -> 
  130   preErrorCheck $ \a2' -> 
  131   zeroCouponInflationSwapHelperSwap'_ a1' a2' >>= \res ->
  132   peekZeroCouponInflationSwap res >>= \res' ->
  133   errorCheck  a2'>>
  134   return (res')
  135 
  136 
  137 
  138 -- |The underlying swap the helper builds from its quote, observation lag and maturity.
  139 yearOnYearInflationSwapHelperSwap :: (YearOnYearInflationSwapHelper) -> IO ((YearOnYearInflationSwap))
  140 yearOnYearInflationSwapHelperSwap a1 =
  141   withYearOnYearInflationSwapHelper a1 $ \a1' -> 
  142   preErrorCheck $ \a2' -> 
  143   yearOnYearInflationSwapHelperSwap'_ a1' a2' >>= \res ->
  144   peekYearOnYearInflationSwap res >>= \res' ->
  145   errorCheck  a2'>>
  146   return (res')
  147 
  148 
  149 
  150 piecewiseZeroInflationCurve :: Day -- ^referenceDate
  151   -> Day -- ^baseDate
  152   -> Frequency -> DayCounter -> [ZeroCouponInflationSwapHelper] -> Interpolation
  153   -> IO ZeroInflationTermStructure
  154 piecewiseZeroInflationCurve r b f dc h i = uncurryNested (qlPiecewiseZeroInflationCurve r b f dc h) (qlInterpolation i)
  155 -- |Bootstraps a zero-inflation term structure piecewise from a set of helpers, interpolating
  156 -- between the bootstrapped nodes with the given 'Interpolation'.
  157 qlPiecewiseZeroInflationCurve :: (Day) -> (Day) -> (Frequency) -> (DayCounter) -> ([ZeroCouponInflationSwapHelper]) -> (Int) -> (Int) -> (Int) -> IO ((ZeroInflationTermStructure))
  158 qlPiecewiseZeroInflationCurve a1 a2 a3 a4 a5 a6 a7 a8 =
  159   withDay a1 $ \a1' -> 
  160   withDay a2 $ \a2' -> 
  161   let {a3' = (fromIntegral . fromEnum) a3} in 
  162   withDayCounter a4 $ \a4' -> 
  163   withZeroCouponInflationSwapHelperArray a5 $ \(a5'1, a5'2) -> 
  164   let {a6' = fromIntegral a6} in 
  165   let {a7' = fromIntegral a7} in 
  166   let {a8' = fromIntegral a8} in 
  167   preErrorCheck $ \a9' -> 
  168   qlPiecewiseZeroInflationCurve'_ a1' a2' a3' a4' a5'1  a5'2 a6' a7' a8' a9' >>= \res ->
  169   peekZeroInflationTermStructure res >>= \res' ->
  170   errorCheck  a9'>>
  171   return (res')
  172 
  173 
  174 
  175 piecewiseYoYInflationCurve :: Day -- ^referenceDate
  176   -> Day -- ^baseDate
  177   -> Double -- ^baseYoYRate
  178   -> Frequency -> DayCounter -> [YearOnYearInflationSwapHelper] -> Interpolation
  179   -> IO YoYInflationTermStructure
  180 piecewiseYoYInflationCurve r b y f dc h i = uncurryNested (qlPiecewiseYoYInflationCurve r b y f dc h) (qlInterpolation i)
  181 -- |Bootstraps a year-on-year inflation term structure piecewise from a set of helpers,
  182 -- interpolating between the bootstrapped nodes with the given 'Interpolation'.
  183 qlPiecewiseYoYInflationCurve :: (Day) -> (Day) -> (Double) -> (Frequency) -> (DayCounter) -> ([YearOnYearInflationSwapHelper]) -> (Int) -> (Int) -> (Int) -> IO ((YoYInflationTermStructure))
  184 qlPiecewiseYoYInflationCurve a1 a2 a3 a4 a5 a6 a7 a8 a9 =
  185   withDay a1 $ \a1' -> 
  186   withDay a2 $ \a2' -> 
  187   let {a3' = realToFrac a3} in 
  188   let {a4' = (fromIntegral . fromEnum) a4} in 
  189   withDayCounter a5 $ \a5' -> 
  190   withYearOnYearInflationSwapHelperArray a6 $ \(a6'1, a6'2) -> 
  191   let {a7' = fromIntegral a7} in 
  192   let {a8' = fromIntegral a8} in 
  193   let {a9' = fromIntegral a9} in 
  194   preErrorCheck $ \a10' -> 
  195   qlPiecewiseYoYInflationCurve'_ a1' a2' a3' a4' a5' a6'1  a6'2 a7' a8' a9' a10' >>= \res ->
  196   peekYoYInflationTermStructure res >>= \res' ->
  197   errorCheck  a10'>>
  198   return (res')
  199 
  200 
  201 
  202 -- |A YoY-inflation curve interpolating directly between given (date, rate) nodes, unlike
  203 -- 'piecewiseYoYInflationCurve''s bootstrap from swap helpers -- useful when the rates are
  204 -- already known market YoY levels rather than swap quotes to calibrate against. The first
  205 -- node is the curve's own base date\/rate.
  206 interpolatedYoYInflationCurve :: Day -- ^referenceDate
  207   -> [(Day, Double)] -- ^dates, rates
  208   -> Frequency -> DayCounter -> Interpolation
  209   -> IO YoYInflationTermStructure
  210 interpolatedYoYInflationCurve r dr f dc i = uncurryNested (qlInterpolatedYoYInflationCurve r ds rs f dc) (qlInterpolation i)
  211   where (ds, rs) = unzip dr
  212 qlInterpolatedYoYInflationCurve :: (Day) -> ([Day]) -> ([Double]) -> (Frequency) -> (DayCounter) -> (Int) -> (Int) -> (Int) -> IO ((YoYInflationTermStructure))
  213 qlInterpolatedYoYInflationCurve a1 a2 a3 a4 a5 a6 a7 a8 =
  214   withDay a1 $ \a1' -> 
  215   withDayArray a2 $ \(a2'1, a2'2) -> 
  216   withDoubleArrayRaw a3 $ \a3' -> 
  217   let {a4' = (fromIntegral . fromEnum) a4} in 
  218   withDayCounter a5 $ \a5' -> 
  219   let {a6' = fromIntegral a6} in 
  220   let {a7' = fromIntegral a7} in 
  221   let {a8' = fromIntegral a8} in 
  222   preErrorCheck $ \a9' -> 
  223   qlInterpolatedYoYInflationCurve'_ a1' a2'1  a2'2 a3' a4' a5' a6' a7' a8' a9' >>= \res ->
  224   peekYoYInflationTermStructure res >>= \res' ->
  225   errorCheck  a9'>>
  226   return (res')
  227 
  228 
  229 
  230 -- |Zero-coupon inflation rate implied by the curve.
  231 zeroRate :: (ZeroInflationTermStructure) -> (Day) -> (Bool) -- ^extrapolate
  232  -> IO ((Double))
  233 zeroRate a1 a2 a3 =
  234   withGenTermStructure a1 $ \a1' -> 
  235   withDay a2 $ \a2' -> 
  236   let {a3' = C2HSImp.fromBool a3} in 
  237   preErrorCheck $ \a4' -> 
  238   zeroRate'_ a1' a2' a3' a4' >>= \res ->
  239   let {res' = realToFrac res} in
  240   errorCheck  a4'>>
  241   return (res')
  242 
  243 
  244 
  245 -- |Year-on-year inflation rate implied by the curve.
  246 yoyRate :: (YoYInflationTermStructure) -> (Day) -> (Bool) -- ^extrapolate
  247  -> IO ((Double))
  248 yoyRate a1 a2 a3 =
  249   withGenTermStructure a1 $ \a1' -> 
  250   withDay a2 $ \a2' -> 
  251   let {a3' = C2HSImp.fromBool a3} in 
  252   preErrorCheck $ \a4' -> 
  253   yoyRate'_ a1' a2' a3' a4' >>= \res ->
  254   let {res' = realToFrac res} in
  255   errorCheck  a4'>>
  256   return (res')
  257 
  258 
  259 
  260 -- vim: set ff=unix ts=8 sts=2 sw=2 et:
  261 
  262 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlZeroCouponInflationSwapHelper"
  263   zeroCouponInflationSwapHelper'_ :: ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CZeroInflationIndex')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CZeroCouponInflationSwapHelper)))))))))))))))
  264 
  265 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlYearOnYearInflationSwapHelper"
  266   yearOnYearInflationSwapHelper'_ :: ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CYoYInflationIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CYieldTermStructure')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CYearOnYearInflationSwapHelper))))))))))))))))
  267 
  268 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlZeroCouponInflationSwapHelperSwap"
  269   zeroCouponInflationSwapHelperSwap'_ :: ((C2HSImp.Ptr (CZeroCouponInflationSwapHelper)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CZeroCouponInflationSwap')))))
  270 
  271 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlYearOnYearInflationSwapHelperSwap"
  272   yearOnYearInflationSwapHelperSwap'_ :: ((C2HSImp.Ptr (CYearOnYearInflationSwapHelper)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CYearOnYearInflationSwap')))))
  273 
  274 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlPiecewiseZeroInflationCurve"
  275   qlPiecewiseZeroInflationCurve'_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CZeroCouponInflationSwapHelper))) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CZeroInflationTermStructure')))))))))))))
  276 
  277 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlPiecewiseYoYInflationCurve"
  278   qlPiecewiseYoYInflationCurve'_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CYearOnYearInflationSwapHelper))) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CYoYInflationTermStructure'))))))))))))))
  279 
  280 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlInterpolatedYoYInflationCurve"
  281   qlInterpolatedYoYInflationCurve'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CYoYInflationTermStructure')))))))))))))
  282 
  283 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlZeroInflationTermStructureZeroRate"
  284   zeroRate'_ :: ((C2HSImp.Ptr (CZeroInflationTermStructure')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))
  285 
  286 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlYoYInflationTermStructureYoYRate"
  287   yoyRate'_ :: ((C2HSImp.Ptr (CYoYInflationTermStructure')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))