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     -- * Types
    8     GenZeroInflationTermStructure
    9   , ZeroInflationTermStructure
   10   , PiecewiseZeroInflationCurve
   11   , GenYoYInflationTermStructure
   12   , YoYInflationTermStructure
   13   , PiecewiseYoYInflationCurve
   14   , ZeroCouponInflationSwapHelper
   15   , YearOnYearInflationSwapHelper
   16   , CPIInterpolationType(..) -- ^re-exported from "QuantLib.Internal.Common"
   17   , InflationSwapPeriod(..)
   18     -- ** Seasonality
   19   , Seasonality(..)
   20 
   21     -- * Constructors
   22     -- ** Helpers
   23   , zeroCouponInflationSwapHelper
   24   , yearOnYearInflationSwapHelper
   25   , cpiBondHelper
   26     -- ** Curves
   27   , piecewiseZeroInflationCurve
   28   , piecewiseYoyInflationCurve
   29   , interpolatedYoyInflationCurve
   30   , interpolatedZeroInflationCurve
   31     -- ** Conversions
   32   , asZeroInflationTermStructure
   33   , asYoYInflationTermStructure
   34 
   35     -- * Inspectors
   36   , HasHelperUnderlying(..)
   37   , zeroRate
   38   , yoyRate
   39   , zeroCouponInflationSwapImpliedQuoteOn
   40   , yearOnYearInflationSwapImpliedQuoteOn
   41     -- ** Bootstrapped nodes
   42   , zeroInflationNodes
   43   , yoyInflationNodes
   44   ) where
   45 import qualified Foreign.C.Types as C2HSImp
   46 import qualified Foreign.ForeignPtr as C2HSImp
   47 import qualified Foreign.Marshal.Utils as C2HSImp
   48 import qualified Foreign.Ptr as C2HSImp
   49 
   50 
   51 import QuantLib.Internal
   52 import QuantLib.Internal.Type
   53 import QuantLib.Time.Schedule(Frequency(..))
   54 import QuantLib.Internal.Common
   55 import QuantLib.TermStructure(HasHelperUnderlying(..))
   56 import Data.List.NonEmpty(NonEmpty, toList)
   57 import QuantLib.TermStructure.Yield(PillarChoice)
   58 
   59 
   60 
   61 
   62 
   63 
   64 
   65 
   66 
   67 
   68 
   69 
   70 
   71 
   72 
   73 
   74 
   75 
   76 
   77 
   78 
   79 
   80 
   81 
   82 
   83 
   84 
   85 
   86 -- |Which dates an inflation swap helper's swap runs between. 'InflationSwapToMaturity' starts on
   87 -- the evaluation date and moves with it; 'InflationSwapBetweenDates' is fixed. The fixed form also
   88 -- takes its observation-interpolation weight from the start date rather than the maturity.
   89 data InflationSwapPeriod
   90   = InflationSwapToMaturity
   91       !Day -- ^maturity
   92   | InflationSwapBetweenDates
   93       !Day -- ^startDate
   94       !Day -- ^endDate
   95 
   96 -- |Bootstrap helper for a zero-coupon inflation swap, at the given observation lag and period.
   97 zeroCouponInflationSwapHelper :: GenQuote q -- ^quote
   98   -> (Word, TimeUnit) -- ^swapObsLag
   99   -> InflationSwapPeriod
  100   -> Calendar
  101   -> BusinessDayConvention -- ^paymentConvention
  102   -> DayCounter
  103   -> GenZeroInflationIndex zidx
  104   -> CPIInterpolationType -- ^observationInterpolation
  105   -> PillarChoice -- ^pillar
  106   -> Maybe Day -- ^customPillarDate
  107   -> IO ZeroCouponInflationSwapHelper
  108 zeroCouponInflationSwapHelper quote lag period cal conv dc zii interp pillar customPillarDate = case period of
  109   InflationSwapToMaturity m -> zeroCouponInflationSwapHelperRaw quote lag m cal conv dc zii interp pillar customPillarDate
  110   InflationSwapBetweenDates s e ->
  111     zeroCouponInflationSwapHelperBetweenDatesRaw quote lag s e cal conv dc zii interp pillar customPillarDate
  112 
  113 -- |Bootstrap helper for a year-on-year inflation swap. Unlike 'zeroCouponInflationSwapHelper',
  114 -- also needs the nominal discount curve (the YoY swap's fixed/floating legs discount off it).
  115 yearOnYearInflationSwapHelper :: GenQuote q -- ^quote
  116   -> (Word, TimeUnit) -- ^swapObsLag
  117   -> InflationSwapPeriod
  118   -> Calendar
  119   -> BusinessDayConvention -- ^paymentConvention
  120   -> DayCounter
  121   -> GenYoYInflationIndex yidx
  122   -> CPIInterpolationType -- ^observationInterpolation
  123   -> GenYieldTermStructure y -- ^nominalTermStructure
  124   -> PillarChoice -- ^pillar
  125   -> Maybe Day -- ^customPillarDate
  126   -> IO YearOnYearInflationSwapHelper
  127 yearOnYearInflationSwapHelper quote lag period cal conv dc yii interp nominal pillar customPillarDate = case period of
  128   InflationSwapToMaturity m -> yearOnYearInflationSwapHelperRaw quote lag m cal conv dc yii interp nominal pillar customPillarDate
  129   InflationSwapBetweenDates s e ->
  130     yearOnYearInflationSwapHelperBetweenDatesRaw quote lag s e cal conv dc yii interp nominal pillar customPillarDate
  131 
  132 -- Raw inflation swap helper bindings; one per 'InflationSwapPeriod' constructor for each helper.
  133 zeroCouponInflationSwapHelperRaw :: (GenQuote q) -- ^quote
  134  -> ((Word,TimeUnit)) -- ^swapObsLag
  135  -> (Day) -- ^maturity
  136  -> (Calendar) -> (BusinessDayConvention) -- ^paymentConvention
  137  -> (DayCounter) -> (GenZeroInflationIndex zidx) -> (CPIInterpolationType) -- ^observationInterpolation
  138  -> (PillarChoice) -- ^pillar
  139  -> (Maybe Day) -- ^customPillarDate
  140  -> IO ((ZeroCouponInflationSwapHelper))
  141 zeroCouponInflationSwapHelperRaw a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 =
  142   withQuote a1 $ \a1' -> 
  143   let {(a2'1, a2'2) = fromEnumQuantity a2} in 
  144   withDay a3 $ \a3' -> 
  145   withCalendar a4 $ \a4' -> 
  146   let {a5' = fromEnumC a5} in 
  147   withDayCounter a6 $ \a6' -> 
  148   withZeroInflationIndex a7 $ \a7' -> 
  149   let {a8' = fromEnumC a8} in 
  150   let {a9' = (fromIntegral . fromEnum) a9} in 
  151   withMaybeDay a10 $ \a10' -> 
  152   preErrorCheck $ \a11' -> 
  153   zeroCouponInflationSwapHelperRaw'_ a1' a2'1  a2'2 a3' a4' a5' a6' a7' a8' a9' a10' a11' >>= \res ->
  154   peekZeroCouponInflationSwapHelper res >>= \res' ->
  155   errorCheck  a11'>>
  156   return (res')
  157 
  158 
  159 
  160 zeroCouponInflationSwapHelperBetweenDatesRaw :: (GenQuote q) -- ^quote
  161  -> ((Word,TimeUnit)) -- ^swapObsLag
  162  -> (Day) -- ^startDate
  163  -> (Day) -- ^endDate
  164  -> (Calendar) -> (BusinessDayConvention) -- ^paymentConvention
  165  -> (DayCounter) -> (GenZeroInflationIndex zidx) -> (CPIInterpolationType) -- ^observationInterpolation
  166  -> (PillarChoice) -- ^pillar
  167  -> (Maybe Day) -- ^customPillarDate
  168  -> IO ((ZeroCouponInflationSwapHelper))
  169 zeroCouponInflationSwapHelperBetweenDatesRaw a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 =
  170   withQuote a1 $ \a1' -> 
  171   let {(a2'1, a2'2) = fromEnumQuantity a2} in 
  172   withDay a3 $ \a3' -> 
  173   withDay a4 $ \a4' -> 
  174   withCalendar a5 $ \a5' -> 
  175   let {a6' = fromEnumC a6} in 
  176   withDayCounter a7 $ \a7' -> 
  177   withZeroInflationIndex a8 $ \a8' -> 
  178   let {a9' = fromEnumC a9} in 
  179   let {a10' = (fromIntegral . fromEnum) a10} in 
  180   withMaybeDay a11 $ \a11' -> 
  181   preErrorCheck $ \a12' -> 
  182   zeroCouponInflationSwapHelperBetweenDatesRaw'_ a1' a2'1  a2'2 a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' >>= \res ->
  183   peekZeroCouponInflationSwapHelper res >>= \res' ->
  184   errorCheck  a12'>>
  185   return (res')
  186 
  187 
  188 
  189 yearOnYearInflationSwapHelperBetweenDatesRaw :: (GenQuote q) -- ^quote
  190  -> ((Word,TimeUnit)) -- ^swapObsLag
  191  -> (Day) -- ^startDate
  192  -> (Day) -- ^endDate
  193  -> (Calendar) -> (BusinessDayConvention) -- ^paymentConvention
  194  -> (DayCounter) -> (GenYoYInflationIndex yidx) -> (CPIInterpolationType) -- ^observationInterpolation
  195  -> (GenYieldTermStructure y) -- ^nominalTermStructure
  196  -> (PillarChoice) -- ^pillar
  197  -> (Maybe Day) -- ^customPillarDate
  198  -> IO ((YearOnYearInflationSwapHelper))
  199 yearOnYearInflationSwapHelperBetweenDatesRaw a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 =
  200   withQuote a1 $ \a1' -> 
  201   let {(a2'1, a2'2) = fromEnumQuantity a2} in 
  202   withDay a3 $ \a3' -> 
  203   withDay a4 $ \a4' -> 
  204   withCalendar a5 $ \a5' -> 
  205   let {a6' = fromEnumC a6} in 
  206   withDayCounter a7 $ \a7' -> 
  207   withYoYInflationIndex a8 $ \a8' -> 
  208   let {a9' = fromEnumC a9} in 
  209   withYieldTermStructure a10 $ \a10' -> 
  210   let {a11' = (fromIntegral . fromEnum) a11} in 
  211   withMaybeDay a12 $ \a12' -> 
  212   preErrorCheck $ \a13' -> 
  213   yearOnYearInflationSwapHelperBetweenDatesRaw'_ a1' a2'1  a2'2 a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' a13' >>= \res ->
  214   peekYearOnYearInflationSwapHelper res >>= \res' ->
  215   errorCheck  a13'>>
  216   return (res')
  217 
  218 
  219 
  220 yearOnYearInflationSwapHelperRaw :: (GenQuote q) -- ^quote
  221  -> ((Word,TimeUnit)) -- ^swapObsLag
  222  -> (Day) -- ^maturity
  223  -> (Calendar) -> (BusinessDayConvention) -- ^paymentConvention
  224  -> (DayCounter) -> (GenYoYInflationIndex yidx) -> (CPIInterpolationType) -- ^observationInterpolation
  225  -> (GenYieldTermStructure y) -- ^nominalTermStructure
  226  -> (PillarChoice) -- ^pillar
  227  -> (Maybe Day) -- ^customPillarDate
  228  -> IO ((YearOnYearInflationSwapHelper))
  229 yearOnYearInflationSwapHelperRaw a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 =
  230   withQuote a1 $ \a1' -> 
  231   let {(a2'1, a2'2) = fromEnumQuantity a2} in 
  232   withDay a3 $ \a3' -> 
  233   withCalendar a4 $ \a4' -> 
  234   let {a5' = fromEnumC a5} in 
  235   withDayCounter a6 $ \a6' -> 
  236   withYoYInflationIndex a7 $ \a7' -> 
  237   let {a8' = fromEnumC a8} in 
  238   withYieldTermStructure a9 $ \a9' -> 
  239   let {a10' = (fromIntegral . fromEnum) a10} in 
  240   withMaybeDay a11 $ \a11' -> 
  241   preErrorCheck $ \a12' -> 
  242   yearOnYearInflationSwapHelperRaw'_ a1' a2'1  a2'2 a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' >>= \res ->
  243   peekYearOnYearInflationSwapHelper res >>= \res' ->
  244   errorCheck  a12'>>
  245   return (res')
  246 
  247 
  248 
  249 -- |Bootstrap helper for a 'QuantLib.Instrument.Bond.CPIBond' -- a 'CPIBondHelper', which is a
  250 -- plain 'BondHelper' subclass with no extra methods, so it's returned as the generic
  251 -- 'BondHelper' type (same shape as 'QuantLib.TermStructure.Yield.fixedRateBondHelper').
  252 cpiBondHelper :: (GenQuote q) -> (Word) -- ^settlementDays
  253  -> (Double) -- ^faceAmount
  254  -> (Double) -- ^baseCPI
  255  -> ((Word,TimeUnit)) -- ^observationLag
  256  -> (GenZeroInflationIndex zidx) -> (CPIInterpolationType) -- ^observationInterpolation
  257  -> (Schedule) -> (NonEmpty Double) -- ^coupons
  258  -> (DayCounter) -- ^accrualDayCounter
  259  -> (BusinessDayConvention) -- ^paymentConvention
  260  -> (Maybe Day) -- ^issueDate
  261  -> (Calendar) -- ^paymentCalendar
  262  -> IO ((BondHelper))
  263 cpiBondHelper a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 =
  264   withQuote a1 $ \a1' -> 
  265   let {a2' = fromIntegral a2} in 
  266   let {a3' = realToFrac a3} in 
  267   let {a4' = realToFrac a4} in 
  268   let {(a5'1, a5'2) = fromEnumQuantity a5} in 
  269   withZeroInflationIndex a6 $ \a6' -> 
  270   let {a7' = fromEnumC a7} in 
  271   withSchedule a8 $ \a8' -> 
  272   withNonEmptyDoubleArray a9 $ \(a9'1, a9'2) -> 
  273   withDayCounter a10 $ \a10' -> 
  274   let {a11' = fromEnumC a11} in 
  275   withMaybeDay a12 $ \a12' -> 
  276   withCalendar a13 $ \a13' -> 
  277   preErrorCheck $ \a14' -> 
  278   cpiBondHelper'_ a1' a2' a3' a4' a5'1  a5'2 a6' a7' a8' a9'1  a9'2 a10' a11' a12' a13' a14' >>= \res ->
  279   peekBondHelper res >>= \res' ->
  280   errorCheck  a14'>>
  281   return (res')
  282 
  283 
  284 
  285 -- |Bootstraps a zero-inflation term structure piecewise from a set of helpers, interpolating
  286 -- between the bootstrapped nodes with the given 'Interpolation'.
  287 piecewiseZeroInflationCurve :: Day -- ^referenceDate
  288   -> Day -- ^baseDate
  289   -> Frequency -> DayCounter -> NonEmpty ZeroCouponInflationSwapHelper -> Maybe Seasonality -> Interpolation
  290   -> IO PiecewiseZeroInflationCurve
  291 piecewiseZeroInflationCurve r b f dc h s i = seasonalityArgs r s $ \sk sd sf sfs ->
  292   uncurryNested (qlPiecewiseZeroInflationCurve r b f dc (toList h) sk sd sf sfs) (qlInterpolation i)
  293 
  294 qlPiecewiseZeroInflationCurve :: (Day) -> (Day) -> (Frequency) -> (DayCounter) -> ([ZeroCouponInflationSwapHelper]) -> (Int) -> (Day) -> (Frequency) -> ([Double]) -> (Int) -> (Int) -> (Int) -> IO ((PiecewiseZeroInflationCurve))
  295 qlPiecewiseZeroInflationCurve a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 =
  296   withDay a1 $ \a1' -> 
  297   withDay a2 $ \a2' -> 
  298   let {a3' = (fromIntegral . fromEnum) a3} in 
  299   withDayCounter a4 $ \a4' -> 
  300   withZeroCouponInflationSwapHelperArray a5 $ \(a5'1, a5'2) -> 
  301   let {a6' = fromIntegral a6} in 
  302   withDay a7 $ \a7' -> 
  303   let {a8' = (fromIntegral . fromEnum) a8} in 
  304   withDoubleArray a9 $ \(a9'1, a9'2) -> 
  305   let {a10' = fromIntegral a10} in 
  306   let {a11' = fromIntegral a11} in 
  307   let {a12' = fromIntegral a12} in 
  308   preErrorCheck $ \a13' -> 
  309   qlPiecewiseZeroInflationCurve'_ a1' a2' a3' a4' a5'1  a5'2 a6' a7' a8' a9'1  a9'2 a10' a11' a12' a13' >>= \res ->
  310   peekPiecewiseZeroInflationCurve res >>= \res' ->
  311   errorCheck  a13'>>
  312   return (res')
  313 
  314 
  315 
  316 -- |Bootstraps a year-on-year inflation term structure piecewise from a set of helpers,
  317 -- interpolating between the bootstrapped nodes with the given 'Interpolation'.
  318 piecewiseYoyInflationCurve :: Day -- ^referenceDate
  319   -> Day -- ^baseDate
  320   -> Double -- ^baseYoYRate
  321   -> Frequency -> DayCounter -> NonEmpty YearOnYearInflationSwapHelper -> Maybe Seasonality -> Interpolation
  322   -> IO PiecewiseYoYInflationCurve
  323 piecewiseYoyInflationCurve r b y f dc h s i = seasonalityArgs r s $ \sk sd sf sfs ->
  324   uncurryNested (qlPiecewiseYoYInflationCurve r b y f dc (toList h) sk sd sf sfs) (qlInterpolation i)
  325 
  326 qlPiecewiseYoYInflationCurve :: (Day) -> (Day) -> (Double) -> (Frequency) -> (DayCounter) -> ([YearOnYearInflationSwapHelper]) -> (Int) -> (Day) -> (Frequency) -> ([Double]) -> (Int) -> (Int) -> (Int) -> IO ((PiecewiseYoYInflationCurve))
  327 qlPiecewiseYoYInflationCurve a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 =
  328   withDay a1 $ \a1' -> 
  329   withDay a2 $ \a2' -> 
  330   let {a3' = realToFrac a3} in 
  331   let {a4' = (fromIntegral . fromEnum) a4} in 
  332   withDayCounter a5 $ \a5' -> 
  333   withYearOnYearInflationSwapHelperArray a6 $ \(a6'1, a6'2) -> 
  334   let {a7' = fromIntegral a7} in 
  335   withDay a8 $ \a8' -> 
  336   let {a9' = (fromIntegral . fromEnum) a9} in 
  337   withDoubleArray a10 $ \(a10'1, a10'2) -> 
  338   let {a11' = fromIntegral a11} in 
  339   let {a12' = fromIntegral a12} in 
  340   let {a13' = fromIntegral a13} in 
  341   preErrorCheck $ \a14' -> 
  342   qlPiecewiseYoYInflationCurve'_ a1' a2' a3' a4' a5' a6'1  a6'2 a7' a8' a9' a10'1  a10'2 a11' a12' a13' a14' >>= \res ->
  343   peekPiecewiseYoYInflationCurve res >>= \res' ->
  344   errorCheck  a14'>>
  345   return (res')
  346 
  347 
  348 
  349 -- |A YoY-inflation curve interpolating directly between given (date, rate) nodes, unlike
  350 -- 'piecewiseYoyInflationCurve' bootstrap from swap helpers -- useful when the rates are
  351 -- already known market YoY levels rather than swap quotes to calibrate against. The first
  352 -- node is the curve's own base date\/rate.
  353 interpolatedYoyInflationCurve :: Day -- ^referenceDate
  354   -> NonEmpty (Day, Double) -- ^dates, rates
  355   -> Frequency -> DayCounter -> Maybe Seasonality -> Interpolation
  356   -> IO YoYInflationTermStructure
  357 interpolatedYoyInflationCurve r dr f dc s i = seasonalityArgs r s $ \sk sd sf sfs ->
  358   uncurryNested (qlInterpolatedYoYInflationCurve r ds rs f dc sk sd sf sfs) (qlInterpolation i)
  359   where (ds, rs) = unzip (toList dr)
  360 qlInterpolatedYoYInflationCurve :: (Day) -> ([Day]) -> ([Double]) -> (Frequency) -> (DayCounter) -> (Int) -> (Day) -> (Frequency) -> ([Double]) -> (Int) -> (Int) -> (Int) -> IO ((YoYInflationTermStructure))
  361 qlInterpolatedYoYInflationCurve a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 =
  362   withDay a1 $ \a1' -> 
  363   withDayArray a2 $ \(a2'1, a2'2) -> 
  364   withDoubleArrayRaw a3 $ \a3' -> 
  365   let {a4' = (fromIntegral . fromEnum) a4} in 
  366   withDayCounter a5 $ \a5' -> 
  367   let {a6' = fromIntegral a6} in 
  368   withDay a7 $ \a7' -> 
  369   let {a8' = (fromIntegral . fromEnum) a8} in 
  370   withDoubleArray a9 $ \(a9'1, a9'2) -> 
  371   let {a10' = fromIntegral a10} in 
  372   let {a11' = fromIntegral a11} in 
  373   let {a12' = fromIntegral a12} in 
  374   preErrorCheck $ \a13' -> 
  375   qlInterpolatedYoYInflationCurve'_ a1' a2'1  a2'2 a3' a4' a5' a6' a7' a8' a9'1  a9'2 a10' a11' a12' a13' >>= \res ->
  376   peekYoYInflationTermStructure res >>= \res' ->
  377   errorCheck  a13'>>
  378   return (res')
  379 
  380 
  381 
  382 -- |A zero-coupon inflation curve interpolating directly between given (date, rate) nodes. The
  383 -- first node is the curve's base date.
  384 interpolatedZeroInflationCurve :: Day -- ^referenceDate
  385   -> NonEmpty (Day, Double) -- ^dates, rates
  386   -> Frequency -> DayCounter -> Maybe Seasonality -> Interpolation
  387   -> IO ZeroInflationTermStructure
  388 interpolatedZeroInflationCurve r dr f dc s i = seasonalityArgs r s $ \sk sd sf sfs ->
  389   uncurryNested (qlInterpolatedZeroInflationCurve r ds rs f dc sk sd sf sfs) (qlInterpolation i)
  390   where (ds, rs) = unzip (toList dr)
  391 qlInterpolatedZeroInflationCurve :: (Day) -> ([Day]) -> ([Double]) -> (Frequency) -> (DayCounter) -> (Int) -> (Day) -> (Frequency) -> ([Double]) -> (Int) -> (Int) -> (Int) -> IO ((ZeroInflationTermStructure))
  392 qlInterpolatedZeroInflationCurve a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 =
  393   withDay a1 $ \a1' -> 
  394   withDayArray a2 $ \(a2'1, a2'2) -> 
  395   withDoubleArrayRaw a3 $ \a3' -> 
  396   let {a4' = (fromIntegral . fromEnum) a4} in 
  397   withDayCounter a5 $ \a5' -> 
  398   let {a6' = fromIntegral a6} in 
  399   withDay a7 $ \a7' -> 
  400   let {a8' = (fromIntegral . fromEnum) a8} in 
  401   withDoubleArray a9 $ \(a9'1, a9'2) -> 
  402   let {a10' = fromIntegral a10} in 
  403   let {a11' = fromIntegral a11} in 
  404   let {a12' = fromIntegral a12} in 
  405   preErrorCheck $ \a13' -> 
  406   qlInterpolatedZeroInflationCurve'_ a1' a2'1  a2'2 a3' a4' a5' a6' a7' a8' a9'1  a9'2 a10' a11' a12' a13' >>= \res ->
  407   peekZeroInflationTermStructure res >>= \res' ->
  408   errorCheck  a13'>>
  409   return (res')
  410 
  411 
  412 
  413 -- |Multiplicative price seasonality applied by an inflation curve's zero and year-on-year rates.
  414 -- Factors repeat every whole multiple of a year and are normalized to the curve's base date;
  415 -- multi-year factors inconsistent at whole years around that date make construction throw.
  416 data Seasonality
  417   = MultiplicativePriceSeasonality !Day !Frequency ![Double] -- ^seasonalityBaseDate, frequency, factors
  418   | KerkhofSeasonality !Day ![Double] -- ^seasonalityBaseDate, monthly factors
  419 
  420 -- Flattens an optional seasonality into the shims' kind, base date, frequency and factors.
  421 seasonalityArgs :: Day -> Maybe Seasonality -> (Int -> Day -> Frequency -> [Double] -> r) -> r
  422 seasonalityArgs d s k = case s of
  423   Nothing -> k (-1) d NoFrequency []
  424   Just (MultiplicativePriceSeasonality b f fs) -> k 0 b f fs
  425   Just (KerkhofSeasonality b fs) -> k 1 b Monthly fs
  426 
  427 -- |Zero-coupon inflation rate implied by the curve.
  428 zeroRate :: (GenZeroInflationTermStructure z) -> (Day) -> (Bool) -- ^extrapolate
  429  -> IO ((Double))
  430 zeroRate a1 a2 a3 =
  431   withZeroInflationTermStructure a1 $ \a1' -> 
  432   withDay a2 $ \a2' -> 
  433   let {a3' = C2HSImp.fromBool a3} in 
  434   preErrorCheck $ \a4' -> 
  435   zeroRate'_ a1' a2' a3' a4' >>= \res ->
  436   let {res' = realToFrac res} in
  437   errorCheck  a4'>>
  438   return (res')
  439 
  440 
  441 
  442 -- |The swap rate that would make a zero-coupon inflation swap helper reprice exactly on the given
  443 -- zero-inflation curve, bootstrapped from it or not.
  444 zeroCouponInflationSwapImpliedQuoteOn :: (ZeroCouponInflationSwapHelper) -> (GenZeroInflationTermStructure z) -> IO ((Double))
  445 zeroCouponInflationSwapImpliedQuoteOn a1 a2 =
  446   withZeroCouponInflationSwapHelper a1 $ \a1' -> 
  447   withZeroInflationTermStructure a2 $ \a2' -> 
  448   preErrorCheck $ \a3' -> 
  449   zeroCouponInflationSwapImpliedQuoteOn'_ a1' a2' a3' >>= \res ->
  450   let {res' = realToFrac res} in
  451   errorCheck  a3'>>
  452   return (res')
  453 
  454 
  455 
  456 -- |The swap rate that would make a year-on-year inflation swap helper reprice exactly on the given
  457 -- year-on-year curve.
  458 yearOnYearInflationSwapImpliedQuoteOn :: (YearOnYearInflationSwapHelper) -> (GenYoYInflationTermStructure y) -> IO ((Double))
  459 yearOnYearInflationSwapImpliedQuoteOn a1 a2 =
  460   withYearOnYearInflationSwapHelper a1 $ \a1' -> 
  461   withYoYInflationTermStructure a2 $ \a2' -> 
  462   preErrorCheck $ \a3' -> 
  463   yearOnYearInflationSwapImpliedQuoteOn'_ a1' a2' a3' >>= \res ->
  464   let {res' = realToFrac res} in
  465   errorCheck  a3'>>
  466   return (res')
  467 
  468 
  469 
  470 -- |Year-on-year inflation rate implied by the curve.
  471 yoyRate :: (GenYoYInflationTermStructure y) -> (Day) -> (Bool) -- ^extrapolate
  472  -> IO ((Double))
  473 yoyRate a1 a2 a3 =
  474   withYoYInflationTermStructure a1 $ \a1' -> 
  475   withDay a2 $ \a2' -> 
  476   let {a3' = C2HSImp.fromBool a3} in 
  477   preErrorCheck $ \a4' -> 
  478   yoyRate'_ a1' a2' a3' a4' >>= \res ->
  479   let {res' = realToFrac res} in
  480   errorCheck  a4'>>
  481   return (res')
  482 
  483 
  484 
  485 -- |A bootstrapped zero-inflation curve's nodes, bootstrapping it if it has not been: its base date
  486 -- first, then each helper's pillar, each with the zero inflation rate the curve interpolates, before
  487 -- seasonality. 'interpolatedZeroInflationCurve' on these nodes, with the bootstrap's interpolation,
  488 -- frequency, day counter and seasonality, is the same curve.
  489 zeroInflationNodes :: PiecewiseZeroInflationCurve -> IO [(Day, Double)]
  490 zeroInflationNodes c = zip <$> qlPiecewiseZeroInflationCurveDates c <*> qlPiecewiseZeroInflationCurveRates c
  491 qlPiecewiseZeroInflationCurveDates :: (PiecewiseZeroInflationCurve) -> IO (([Day]))
  492 qlPiecewiseZeroInflationCurveDates a1 =
  493   withPiecewiseZeroInflationCurve a1 $ \a1' -> 
  494   preIntArray $ \(a2'1, a2'2) -> 
  495   preErrorCheck $ \a3' -> 
  496   qlPiecewiseZeroInflationCurveDates'_ a1' a2'1  a2'2 a3' >>
  497   peekDayArray  a2'1  a2'2>>= \a2'' -> 
  498   errorCheck  a3'>>
  499   return (a2'')
  500 
  501 
  502 qlPiecewiseZeroInflationCurveRates :: (PiecewiseZeroInflationCurve) -> IO (([Double]))
  503 qlPiecewiseZeroInflationCurveRates a1 =
  504   withPiecewiseZeroInflationCurve a1 $ \a1' -> 
  505   preDoubleArray $ \(a2'1, a2'2) -> 
  506   preErrorCheck $ \a3' -> 
  507   qlPiecewiseZeroInflationCurveRates'_ a1' a2'1  a2'2 a3' >>
  508   peekDoubleArray  a2'1  a2'2>>= \a2'' -> 
  509   errorCheck  a3'>>
  510   return (a2'')
  511 
  512 
  513 
  514 -- |A bootstrapped year-on-year curve's nodes, bootstrapping it if it has not been: its base date
  515 -- first, then each helper's pillar, each with the year-on-year rate the curve interpolates, before
  516 -- seasonality. 'interpolatedYoyInflationCurve' on these nodes, with the bootstrap's interpolation,
  517 -- frequency, day counter and seasonality, is the same curve.
  518 yoyInflationNodes :: PiecewiseYoYInflationCurve -> IO [(Day, Double)]
  519 yoyInflationNodes c = zip <$> qlPiecewiseYoYInflationCurveDates c <*> qlPiecewiseYoYInflationCurveRates c
  520 qlPiecewiseYoYInflationCurveDates :: (PiecewiseYoYInflationCurve) -> IO (([Day]))
  521 qlPiecewiseYoYInflationCurveDates a1 =
  522   withPiecewiseYoYInflationCurve a1 $ \a1' -> 
  523   preIntArray $ \(a2'1, a2'2) -> 
  524   preErrorCheck $ \a3' -> 
  525   qlPiecewiseYoYInflationCurveDates'_ a1' a2'1  a2'2 a3' >>
  526   peekDayArray  a2'1  a2'2>>= \a2'' -> 
  527   errorCheck  a3'>>
  528   return (a2'')
  529 
  530 
  531 qlPiecewiseYoYInflationCurveRates :: (PiecewiseYoYInflationCurve) -> IO (([Double]))
  532 qlPiecewiseYoYInflationCurveRates a1 =
  533   withPiecewiseYoYInflationCurve a1 $ \a1' -> 
  534   preDoubleArray $ \(a2'1, a2'2) -> 
  535   preErrorCheck $ \a3' -> 
  536   qlPiecewiseYoYInflationCurveRates'_ a1' a2'1  a2'2 a3' >>
  537   peekDoubleArray  a2'1  a2'2>>= \a2'' -> 
  538   errorCheck  a3'>>
  539   return (a2'')
  540 
  541 
  542 
  543 -- vim: set ff=unix ts=8 sts=2 sw=2 et:
  544 
  545 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlZeroCouponInflationSwapHelper"
  546   zeroCouponInflationSwapHelperRaw'_ :: ((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 ())) -> (IO (C2HSImp.Ptr (CZeroCouponInflationSwapHelper)))))))))))))))
  547 
  548 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlZeroCouponInflationSwapHelper2"
  549   zeroCouponInflationSwapHelperBetweenDatesRaw'_ :: ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CInt -> (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 ())) -> (IO (C2HSImp.Ptr (CZeroCouponInflationSwapHelper))))))))))))))))
  550 
  551 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlYearOnYearInflationSwapHelper2"
  552   yearOnYearInflationSwapHelperBetweenDatesRaw'_ :: ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CInt -> (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 ())) -> (IO (C2HSImp.Ptr (CYearOnYearInflationSwapHelper)))))))))))))))))
  553 
  554 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlYearOnYearInflationSwapHelper"
  555   yearOnYearInflationSwapHelperRaw'_ :: ((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 ())) -> (IO (C2HSImp.Ptr (CYearOnYearInflationSwapHelper))))))))))))))))
  556 
  557 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlCPIBondHelper"
  558   cpiBondHelper'_ :: ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CUInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CZeroInflationIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CSchedule)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CCalendar)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CBondHelper')))))))))))))))))))
  559 
  560 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlPiecewiseZeroInflationCurve"
  561   qlPiecewiseZeroInflationCurve'_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CZeroCouponInflationSwapHelper))) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CPiecewiseZeroInflationCurve'))))))))))))))))))
  562 
  563 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlPiecewiseYoYInflationCurve"
  564   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.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CPiecewiseYoYInflationCurve')))))))))))))))))))
  565 
  566 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlInterpolatedYoYInflationCurve"
  567   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.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CYoYInflationTermStructure'))))))))))))))))))
  568 
  569 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlInterpolatedZeroInflationCurve"
  570   qlInterpolatedZeroInflationCurve'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CZeroInflationTermStructure'))))))))))))))))))
  571 
  572 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlZeroInflationTermStructureZeroRate"
  573   zeroRate'_ :: ((C2HSImp.Ptr (CZeroInflationTermStructure')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))
  574 
  575 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlZeroCouponInflationSwapHelperImpliedQuoteOn"
  576   zeroCouponInflationSwapImpliedQuoteOn'_ :: ((C2HSImp.Ptr (CZeroCouponInflationSwapHelper)) -> ((C2HSImp.Ptr (CZeroInflationTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
  577 
  578 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlYearOnYearInflationSwapHelperImpliedQuoteOn"
  579   yearOnYearInflationSwapImpliedQuoteOn'_ :: ((C2HSImp.Ptr (CYearOnYearInflationSwapHelper)) -> ((C2HSImp.Ptr (CYoYInflationTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
  580 
  581 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlYoYInflationTermStructureYoYRate"
  582   yoyRate'_ :: ((C2HSImp.Ptr (CYoYInflationTermStructure')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))
  583 
  584 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlPiecewiseZeroInflationCurveDates"
  585   qlPiecewiseZeroInflationCurveDates'_ :: ((C2HSImp.Ptr (CPiecewiseZeroInflationCurve')) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CInt)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
  586 
  587 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlPiecewiseZeroInflationCurveRates"
  588   qlPiecewiseZeroInflationCurveRates'_ :: ((C2HSImp.Ptr (CPiecewiseZeroInflationCurve')) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
  589 
  590 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlPiecewiseYoYInflationCurveDates"
  591   qlPiecewiseYoYInflationCurveDates'_ :: ((C2HSImp.Ptr (CPiecewiseYoYInflationCurve')) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CInt)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
  592 
  593 foreign import ccall safe "QuantLib/TermStructure/Inflation.chs.h qlPiecewiseYoYInflationCurveRates"
  594   qlPiecewiseYoYInflationCurveRates'_ :: ((C2HSImp.Ptr (CPiecewiseYoYInflationCurve')) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))