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.InflationVolatility
    6   (
    7     YoYOptionletVolatilitySurface
    8 
    9   , constantYoYOptionletVolatility
   10   , kInterpolatedYoYOptionletVolatilitySurfaceBlack
   11   , kInterpolatedYoYOptionletVolatilitySurfaceUnitDisplacedBlack
   12   , kInterpolatedYoYOptionletVolatilitySurfaceBachelier
   13 
   14   , yoyOptionletVolatility
   15   , yoyOptionletTotalVariance
   16 
   17   , YoYCapFloorTermPriceSurface
   18   , yoyCapFloorTermPriceSurface
   19 
   20   , yoyCapFloorBaseDate
   21   , yoyCapFloorAtmYoYSwapDateRates
   22   , yoyCapFloorAtmYoYSwapRate
   23   , yoyCapFloorAtmYoYRate
   24   , yoyCapFloorStrikes
   25 
   26   , CPICapFloorTermPriceSurface
   27   , cpiCapFloorTermPriceSurface
   28 
   29   , CPIVolatilitySurface
   30   , constantCPIVolatility
   31 
   32   , cpiVolatility
   33   , cpiTotalVariance
   34   ) where
   35 import qualified Foreign.C.Types as C2HSImp
   36 import qualified Foreign.ForeignPtr as C2HSImp
   37 import qualified Foreign.Marshal.Utils as C2HSImp
   38 import qualified Foreign.Ptr as C2HSImp
   39 
   40 
   41 import QuantLib.Internal
   42 import QuantLib.Internal.Type
   43 import QuantLib.InterestRate(VolatilityType)
   44 import QuantLib.Time.Schedule(Frequency)
   45 import QuantLib.Internal.Common
   46 
   47 
   48 
   49 
   50 
   51 
   52 
   53 
   54 
   55 
   56 
   57 
   58 
   59 
   60 
   61 
   62 
   63 
   64 
   65 
   66 
   67 
   68 
   69 
   70 
   71 
   72 
   73 -- |Constant YoY-inflation optionlet vol surface, no maturity\/strike dependence. Mirrors
   74 -- 'QuantLib.TermStructure.Volatility.constantOptionletVolatility', taking a 'GenQuote' rather
   75 -- than a plain 'Double' per the @std::variant@\/overload-collapse rule (the flat case is already
   76 -- reachable via 'QuantLib.Quote.simpleQuote'). Not the only concrete leaf of this type any
   77 -- more -- see 'kInterpolatedYoYOptionletVolatilitySurfaceBlack' for the market-quote-bootstrapped
   78 -- alternative.
   79 constantYoYOptionletVolatility :: (GenQuote q) -> (Word) -- ^settlementDays
   80  -> (Calendar) -> (BusinessDayConvention) -> (DayCounter) -> ((Word,TimeUnit)) -- ^observationLag
   81  -> (Frequency) -> (Bool) -- ^indexIsInterpolated
   82  -> (Double) -- ^minStrike
   83  -> (Double) -- ^maxStrike
   84  -> (VolatilityType) -> (Double) -- ^displacement
   85  -> IO ((YoYOptionletVolatilitySurface))
   86 constantYoYOptionletVolatility a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 =
   87   withQuote a1 $ \a1' -> 
   88   let {a2' = fromIntegral a2} in 
   89   withCalendar a3 $ \a3' -> 
   90   let {a4' = fromEnumC a4} in 
   91   withDayCounter a5 $ \a5' -> 
   92   let {(a6'1, a6'2) = fromEnumQuantity a6} in 
   93   let {a7' = (fromIntegral . fromEnum) a7} in 
   94   let {a8' = C2HSImp.fromBool a8} in 
   95   let {a9' = realToFrac a9} in 
   96   let {a10' = realToFrac a10} in 
   97   let {a11' = (fromIntegral . fromEnum) a11} in 
   98   let {a12' = realToFrac a12} in 
   99   preErrorCheck $ \a13' -> 
  100   constantYoYOptionletVolatility'_ a1' a2' a3' a4' a5' a6'1  a6'2 a7' a8' a9' a10' a11' a12' a13' >>= \res ->
  101   peekYoYOptionletVolatilityStructure res >>= \res' ->
  102   errorCheck  a13'>>
  103   return (res')
  104 
  105 
  106 
  107 -- |The volatility for a given maturity date and strike, observed with the given observation
  108 -- lag (or the surface's own lag when 'Nothing').
  109 yoyOptionletVolatility :: (YoYOptionletVolatilitySurface) -> (Day) -> (Double) -- ^strike
  110  -> (Maybe (Word,TimeUnit)) -- ^obsLag
  111  -> (Bool) -- ^extrapolate
  112  -> IO ((Double))
  113 yoyOptionletVolatility a1 a2 a3 a4 a5 =
  114   withGenVolatilityTermStructure a1 $ \a1' -> 
  115   withDay a2 $ \a2' -> 
  116   let {a3' = realToFrac a3} in 
  117   let {(a4'1, a4'2) = fromMaybeEnumQuantity a4} in 
  118   let {a5' = C2HSImp.fromBool a5} in 
  119   preErrorCheck $ \a6' -> 
  120   yoyOptionletVolatility'_ a1' a2' a3' a4'1  a4'2 a5' a6' >>= \res ->
  121   let {res' = realToFrac res} in
  122   errorCheck  a6'>>
  123   return (res')
  124 
  125 
  126 
  127 -- |The total integrated variance for a given exercise date and strike -- useful because it
  128 -- scales out time from the optionlet pricing formulae. As 'yoyOptionletVolatility', a
  129 -- 'Nothing' observation lag uses the surface's own.
  130 yoyOptionletTotalVariance :: (YoYOptionletVolatilitySurface) -> (Day) -> (Double) -- ^strike
  131  -> (Maybe (Word,TimeUnit)) -- ^obsLag
  132  -> (Bool) -- ^extrapolate
  133  -> IO ((Double))
  134 yoyOptionletTotalVariance a1 a2 a3 a4 a5 =
  135   withGenVolatilityTermStructure a1 $ \a1' -> 
  136   withDay a2 $ \a2' -> 
  137   let {a3' = realToFrac a3} in 
  138   let {(a4'1, a4'2) = fromMaybeEnumQuantity a4} in 
  139   let {a5' = C2HSImp.fromBool a5} in 
  140   preErrorCheck $ \a6' -> 
  141   yoyOptionletTotalVariance'_ a1' a2' a3' a4'1  a4'2 a5' a6' >>= \res ->
  142   let {res' = realToFrac res} in
  143   errorCheck  a6'>>
  144   return (res')
  145 
  146 
  147 
  148 -- |Prices YoY cap\/floors by cap\/floor-surface intersection and put\/call parity, deriving an
  149 -- ATM YoY swap curve as a side effect. 'Interpolation2D' chooses the cap\/floor price-grid
  150 -- interpolator, 'Interpolation' the per-maturity one.
  151 yoyCapFloorTermPriceSurface :: Word -- ^fixingDays
  152   -> (Word, TimeUnit) -- ^yyLag
  153   -> YoYInflationIndex -> CPIInterpolationType -> GenYieldTermStructure y -- ^nominal
  154   -> DayCounter -> Calendar -> BusinessDayConvention
  155   -> [Double] -- ^cStrikes
  156   -> [Double] -- ^fStrikes
  157   -> [(Word, TimeUnit)] -- ^cfMaturities
  158   -> Matrix Double -- ^cPrice
  159   -> Matrix Double -- ^fPrice
  160   -> Interpolation2D -> Interpolation
  161   -> IO YoYCapFloorTermPriceSurface
  162 yoyCapFloorTermPriceSurface fixingDays yyLag yii interp nominal dc cal bdc cStrikes fStrikes cfMaturities (Matrix cr cc cd) (Matrix fr fc fd) i2d i1d =
  163   uncurryNested (qlYoYCapFloorTermPriceSurface fixingDays yyLag yii interp nominal dc cal bdc cStrikes fStrikes maturityNums maturityUnits cr cc cd fr fc fd (fromEnum i2d)) (qlInterpolation i1d)
  164   where (maturityNums, maturityUnits) = unzip cfMaturities
  165 qlYoYCapFloorTermPriceSurface :: (Word) -- ^fixingDays
  166  -> ((Word,TimeUnit)) -- ^yyLag
  167  -> (YoYInflationIndex) -> (CPIInterpolationType) -> (GenYieldTermStructure y) -- ^nominal
  168  -> (DayCounter) -> (Calendar) -> (BusinessDayConvention) -> ([Double]) -- ^cStrikes
  169  -> ([Double]) -- ^fStrikes
  170  -> ([Word]) -> ([TimeUnit]) -- ^cfMaturities
  171  -> (Word) -> (Word) -> ([Double]) -- ^cPrice
  172  -> (Word) -> (Word) -> ([Double]) -- ^fPrice
  173  -> (Int) -- ^interpolator2D
  174  -> (Int) -> (Int) -> (Int) -- ^interpolator1D, approximator, approximatorArg
  175  -> IO ((YoYCapFloorTermPriceSurface))
  176 qlYoYCapFloorTermPriceSurface a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 =
  177   let {a1' = fromIntegral a1} in 
  178   let {(a2'1, a2'2) = fromEnumQuantity a2} in 
  179   withYoYInflationIndex a3 $ \a3' -> 
  180   let {a4' = fromEnumC a4} in 
  181   withYieldTermStructure a5 $ \a5' -> 
  182   withDayCounter a6 $ \a6' -> 
  183   withCalendar a7 $ \a7' -> 
  184   let {a8' = fromEnumC a8} in 
  185   withDoubleArray a9 $ \(a9'1, a9'2) -> 
  186   withDoubleArray a10 $ \(a10'1, a10'2) -> 
  187   withIntArray a11 $ \(a11'1, a11'2) -> 
  188   withEnumArray a12 $ \(a12'1, a12'2) -> 
  189   let {a13' = fromIntegral a13} in 
  190   let {a14' = fromIntegral a14} in 
  191   withDoubleArrayRaw a15 $ \a15' -> 
  192   let {a16' = fromIntegral a16} in 
  193   let {a17' = fromIntegral a17} in 
  194   withDoubleArrayRaw a18 $ \a18' -> 
  195   let {a19' = fromIntegral a19} in 
  196   let {a20' = fromIntegral a20} in 
  197   let {a21' = fromIntegral a21} in 
  198   let {a22' = fromIntegral a22} in 
  199   preErrorCheck $ \a23' -> 
  200   qlYoYCapFloorTermPriceSurface'_ a1' a2'1  a2'2 a3' a4' a5' a6' a7' a8' a9'1  a9'2 a10'1  a10'2 a11'1  a11'2 a12'1  a12'2 a13' a14' a15' a16' a17' a18' a19' a20' a21' a22' a23' >>= \res ->
  201   peekYoYCapFloorTermPriceSurface res >>= \res' ->
  202   errorCheck  a23'>>
  203   return (res')
  204 
  205 
  206 
  207 -- |The date the surface's own YoY term structure (and hence any 'YoYOptionletVolatilitySurface'
  208 -- stripped from it) treats as its base -- referenceDate minus the observation lag, rounded to
  209 -- the containing inflation period's start.
  210 yoyCapFloorBaseDate :: (YoYCapFloorTermPriceSurface) -> IO ((Day))
  211 yoyCapFloorBaseDate a1 =
  212   withGenTermStructure a1 $ \a1' -> 
  213   preErrorCheck $ \a2' -> 
  214   yoyCapFloorBaseDate'_ a1' a2' >>= \res ->
  215   let {res' = toDay res} in
  216   errorCheck  a2'>>
  217   return (res')
  218 
  219 
  220 
  221 -- |The ATM YoY swap curve derived from cap\/floor-surface intersection, as (date, rate) pairs.
  222 yoyCapFloorAtmYoYSwapDateRates :: YoYCapFloorTermPriceSurface -> IO [(Day, Double)]
  223 yoyCapFloorAtmYoYSwapDateRates s = do
  224   (ds, rs) <- qlYoYCapFloorTermPriceSurfaceAtmYoYSwapDateRates s
  225   return $ zip ds rs
  226 qlYoYCapFloorTermPriceSurfaceAtmYoYSwapDateRates :: (YoYCapFloorTermPriceSurface) -> IO (([Day]), ([Double]))
  227 qlYoYCapFloorTermPriceSurfaceAtmYoYSwapDateRates a1 =
  228   withGenTermStructure a1 $ \a1' -> 
  229   preArray $ \(a2'1, a2'2) -> 
  230   preArray $ \(a3'1, a3'2) -> 
  231   qlYoYCapFloorTermPriceSurfaceAtmYoYSwapDateRates'_ a1' a2'1  a2'2 a3'1  a3'2 >>
  232   peekDayArray  a2'1  a2'2>>= \a2'' -> 
  233   peekDoubleArray  a3'1  a3'2>>= \a3'' -> 
  234   return (a2'', a3'')
  235 
  236 
  237 
  238 -- |The ATM YoY swap rate at the given maturity date, from put\/call parity on the surface's
  239 -- cap\/floor price data.
  240 yoyCapFloorAtmYoYSwapRate :: (YoYCapFloorTermPriceSurface) -> (Day) -> (Bool) -- ^extrapolate
  241  -> IO ((Double))
  242 yoyCapFloorAtmYoYSwapRate a1 a2 a3 =
  243   withGenTermStructure a1 $ \a1' -> 
  244   withDay a2 $ \a2' -> 
  245   let {a3' = C2HSImp.fromBool a3} in 
  246   preErrorCheck $ \a4' -> 
  247   yoyCapFloorAtmYoYSwapRate'_ a1' a2' a3' a4' >>= \res ->
  248   let {res' = realToFrac res} in
  249   errorCheck  a4'>>
  250   return (res')
  251 
  252 
  253 
  254 -- |The ATM YoY inflation rate at the given maturity date and observation lag (or the surface's
  255 -- own lag when 'Nothing'), derived from the swap-rate curve above.
  256 yoyCapFloorAtmYoYRate :: (YoYCapFloorTermPriceSurface) -> (Day) -> (Maybe (Word,TimeUnit)) -- ^obsLag
  257  -> (Bool) -- ^extrapolate
  258  -> IO ((Double))
  259 yoyCapFloorAtmYoYRate a1 a2 a3 a4 =
  260   withGenTermStructure a1 $ \a1' -> 
  261   withDay a2 $ \a2' -> 
  262   let {(a3'1, a3'2) = fromMaybeEnumQuantity a3} in 
  263   let {a4' = C2HSImp.fromBool a4} in 
  264   preErrorCheck $ \a5' -> 
  265   yoyCapFloorAtmYoYRate'_ a1' a2' a3'1  a3'2 a4' a5' >>= \res ->
  266   let {res' = realToFrac res} in
  267   errorCheck  a5'>>
  268   return (res')
  269 
  270 
  271 
  272 -- |The union of cap and floor strikes in the surface's price grid -- the strikes a stripped
  273 -- 'YoYOptionletVolatilitySurface' (via 'kInterpolatedYoYOptionletVolatilitySurfaceBlack' et al.)
  274 -- has a bootstrapped vol curve for.
  275 yoyCapFloorStrikes :: (YoYCapFloorTermPriceSurface) -> IO (([Double]))
  276 yoyCapFloorStrikes a1 =
  277   withGenTermStructure a1 $ \a1' -> 
  278   preArray $ \(a2'1, a2'2) -> 
  279   yoyCapFloorStrikes'_ a1' a2'1  a2'2 >>
  280   peekDoubleArray  a2'1  a2'2>>= \a2'' -> 
  281   return (a2'')
  282 
  283 
  284 
  285 -- |Strips a 'YoYOptionletVolatilitySurface' from a 'YoYCapFloorTermPriceSurface' by bootstrapping
  286 -- a per-strike vol curve against Black-priced YoY caps\/floors (mirrors upstream's own
  287 -- @testYoYPriceSurfaceToVol@: an @InterpolatedYoYOptionletStripper@ solving each strike's initial
  288 -- vol, then a @KInterpolatedYoYOptionletVolatilitySurface@ interpolating across strikes, both
  289 -- sharing the given 'Interpolation' -- neither is exposed as its own type, since nothing in
  290 -- upstream reaches them from outside this one bootstrap; see this function's C shim for the full
  291 -- pipeline). /index/\//nominalTermStructure/ price the null-vol engine the stripper solves
  292 -- against; /slope/ is the assumed initial caplet-vol slope for strikes past the edge of good
  293 -- price data (a negative slope for typically low\/flat short-dated extreme-strike prices, per
  294 -- upstream's own comment -- too extreme a slope can leave no arbitrage-free solution).
  295 kInterpolatedYoYOptionletVolatilitySurfaceBlack :: Word -- ^settlementDays
  296   -> Calendar -> BusinessDayConvention -> DayCounter
  297   -> YoYCapFloorTermPriceSurface -- ^capFloorPrices
  298   -> YoYInflationIndex -- ^index
  299   -> GenYieldTermStructure y -- ^nominalTermStructure
  300   -> Double -- ^slope
  301   -> Interpolation
  302   -> IO YoYOptionletVolatilitySurface
  303 kInterpolatedYoYOptionletVolatilitySurfaceBlack settlementDays cal bdc dc capFloorPrices index nominalTs slope i1d =
  304   uncurryNested (qlKInterpolatedYoYOptionletVolatilitySurfaceBlack settlementDays cal bdc dc capFloorPrices index nominalTs slope) (qlInterpolation i1d)
  305 qlKInterpolatedYoYOptionletVolatilitySurfaceBlack :: (Word) -- ^settlementDays
  306  -> (Calendar) -> (BusinessDayConvention) -> (DayCounter) -> (YoYCapFloorTermPriceSurface) -- ^capFloorPrices
  307  -> (YoYInflationIndex) -- ^index
  308  -> (GenYieldTermStructure y) -- ^nominalTermStructure
  309  -> (Double) -- ^slope
  310  -> (Int) -> (Int) -> (Int) -- ^interpolator, approximator, approximatorArg
  311  -> IO ((YoYOptionletVolatilitySurface))
  312 qlKInterpolatedYoYOptionletVolatilitySurfaceBlack a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 =
  313   let {a1' = fromIntegral a1} in 
  314   withCalendar a2 $ \a2' -> 
  315   let {a3' = fromEnumC a3} in 
  316   withDayCounter a4 $ \a4' -> 
  317   withGenTermStructure a5 $ \a5' -> 
  318   withYoYInflationIndex a6 $ \a6' -> 
  319   withYieldTermStructure a7 $ \a7' -> 
  320   let {a8' = realToFrac a8} in 
  321   let {a9' = fromIntegral a9} in 
  322   let {a10' = fromIntegral a10} in 
  323   let {a11' = fromIntegral a11} in 
  324   preErrorCheck $ \a12' -> 
  325   qlKInterpolatedYoYOptionletVolatilitySurfaceBlack'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' >>= \res ->
  326   peekYoYOptionletVolatilityStructure res >>= \res' ->
  327   errorCheck  a12'>>
  328   return (res')
  329 
  330 
  331 
  332 -- |As 'kInterpolatedYoYOptionletVolatilitySurfaceBlack', but unit-displaced Black.
  333 kInterpolatedYoYOptionletVolatilitySurfaceUnitDisplacedBlack :: Word -- ^settlementDays
  334   -> Calendar -> BusinessDayConvention -> DayCounter
  335   -> YoYCapFloorTermPriceSurface -- ^capFloorPrices
  336   -> YoYInflationIndex -- ^index
  337   -> GenYieldTermStructure y -- ^nominalTermStructure
  338   -> Double -- ^slope
  339   -> Interpolation
  340   -> IO YoYOptionletVolatilitySurface
  341 kInterpolatedYoYOptionletVolatilitySurfaceUnitDisplacedBlack settlementDays cal bdc dc capFloorPrices index nominalTs slope i1d =
  342   uncurryNested (qlKInterpolatedYoYOptionletVolatilitySurfaceUnitDisplacedBlack settlementDays cal bdc dc capFloorPrices index nominalTs slope) (qlInterpolation i1d)
  343 qlKInterpolatedYoYOptionletVolatilitySurfaceUnitDisplacedBlack :: (Word) -- ^settlementDays
  344  -> (Calendar) -> (BusinessDayConvention) -> (DayCounter) -> (YoYCapFloorTermPriceSurface) -- ^capFloorPrices
  345  -> (YoYInflationIndex) -- ^index
  346  -> (GenYieldTermStructure y) -- ^nominalTermStructure
  347  -> (Double) -- ^slope
  348  -> (Int) -> (Int) -> (Int) -- ^interpolator, approximator, approximatorArg
  349  -> IO ((YoYOptionletVolatilitySurface))
  350 qlKInterpolatedYoYOptionletVolatilitySurfaceUnitDisplacedBlack a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 =
  351   let {a1' = fromIntegral a1} in 
  352   withCalendar a2 $ \a2' -> 
  353   let {a3' = fromEnumC a3} in 
  354   withDayCounter a4 $ \a4' -> 
  355   withGenTermStructure a5 $ \a5' -> 
  356   withYoYInflationIndex a6 $ \a6' -> 
  357   withYieldTermStructure a7 $ \a7' -> 
  358   let {a8' = realToFrac a8} in 
  359   let {a9' = fromIntegral a9} in 
  360   let {a10' = fromIntegral a10} in 
  361   let {a11' = fromIntegral a11} in 
  362   preErrorCheck $ \a12' -> 
  363   qlKInterpolatedYoYOptionletVolatilitySurfaceUnitDisplacedBlack'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' >>= \res ->
  364   peekYoYOptionletVolatilityStructure res >>= \res' ->
  365   errorCheck  a12'>>
  366   return (res')
  367 
  368 
  369 
  370 -- |As 'kInterpolatedYoYOptionletVolatilitySurfaceBlack', but Bachelier (normal model).
  371 kInterpolatedYoYOptionletVolatilitySurfaceBachelier :: Word -- ^settlementDays
  372   -> Calendar -> BusinessDayConvention -> DayCounter
  373   -> YoYCapFloorTermPriceSurface -- ^capFloorPrices
  374   -> YoYInflationIndex -- ^index
  375   -> GenYieldTermStructure y -- ^nominalTermStructure
  376   -> Double -- ^slope
  377   -> Interpolation
  378   -> IO YoYOptionletVolatilitySurface
  379 kInterpolatedYoYOptionletVolatilitySurfaceBachelier settlementDays cal bdc dc capFloorPrices index nominalTs slope i1d =
  380   uncurryNested (qlKInterpolatedYoYOptionletVolatilitySurfaceBachelier settlementDays cal bdc dc capFloorPrices index nominalTs slope) (qlInterpolation i1d)
  381 qlKInterpolatedYoYOptionletVolatilitySurfaceBachelier :: (Word) -- ^settlementDays
  382  -> (Calendar) -> (BusinessDayConvention) -> (DayCounter) -> (YoYCapFloorTermPriceSurface) -- ^capFloorPrices
  383  -> (YoYInflationIndex) -- ^index
  384  -> (GenYieldTermStructure y) -- ^nominalTermStructure
  385  -> (Double) -- ^slope
  386  -> (Int) -> (Int) -> (Int) -- ^interpolator, approximator, approximatorArg
  387  -> IO ((YoYOptionletVolatilitySurface))
  388 qlKInterpolatedYoYOptionletVolatilitySurfaceBachelier a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 =
  389   let {a1' = fromIntegral a1} in 
  390   withCalendar a2 $ \a2' -> 
  391   let {a3' = fromEnumC a3} in 
  392   withDayCounter a4 $ \a4' -> 
  393   withGenTermStructure a5 $ \a5' -> 
  394   withYoYInflationIndex a6 $ \a6' -> 
  395   withYieldTermStructure a7 $ \a7' -> 
  396   let {a8' = realToFrac a8} in 
  397   let {a9' = fromIntegral a9} in 
  398   let {a10' = fromIntegral a10} in 
  399   let {a11' = fromIntegral a11} in 
  400   preErrorCheck $ \a12' -> 
  401   qlKInterpolatedYoYOptionletVolatilitySurfaceBachelier'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' >>= \res ->
  402   peekYoYOptionletVolatilityStructure res >>= \res' ->
  403   errorCheck  a12'>>
  404   return (res')
  405 
  406 
  407 
  408 -- |Prices CPI cap\/floors by interpolation and put\/call parity off a market strike\/maturity
  409 -- price grid. 'Interpolation2D' chooses the cap\/floor price-grid interpolator. @cPrice@\/
  410 -- @fPrice@ are plain price matrices (rows = strikes, columns = maturities), not quote-linked
  411 -- like 'QuantLib.TermStructure.Volatility.capFloorTermVolSurface's volatility matrix.
  412 cpiCapFloorTermPriceSurface :: Double -- ^nominal
  413   -> Double -- ^baseRate
  414   -> (Word, TimeUnit) -- ^observationLag
  415   -> Calendar -> BusinessDayConvention -> DayCounter
  416   -> ZeroInflationIndex -> CPIInterpolationType -> GenYieldTermStructure y
  417   -> [Double] -- ^cStrikes
  418   -> [Double] -- ^fStrikes
  419   -> [(Word, TimeUnit)] -- ^cfMaturities
  420   -> Matrix Double -- ^cPrice
  421   -> Matrix Double -- ^fPrice
  422   -> Interpolation2D
  423   -> IO CPICapFloorTermPriceSurface
  424 cpiCapFloorTermPriceSurface nom baseRate obsLag cal bdc dc zii interp yts cStrikes fStrikes cfMaturities (Matrix cr cc cd) (Matrix fr fc fd) i2d =
  425   qlCPICapFloorTermPriceSurface nom baseRate obsLag cal bdc dc zii interp yts cStrikes fStrikes maturityNums maturityUnits cr cc cd fr fc fd (fromEnum i2d)
  426   where (maturityNums, maturityUnits) = unzip cfMaturities
  427 qlCPICapFloorTermPriceSurface :: (Double) -> (Double) -> ((Word,TimeUnit)) -> (Calendar) -> (BusinessDayConvention) -> (DayCounter) -> (ZeroInflationIndex) -> (CPIInterpolationType) -> (GenYieldTermStructure y) -> ([Double]) -- ^cStrikes
  428  -> ([Double]) -- ^fStrikes
  429  -> ([Word]) -> ([TimeUnit]) -- ^cfMaturities
  430  -> (Word) -> (Word) -> ([Double]) -- ^cPrice
  431  -> (Word) -> (Word) -> ([Double]) -- ^fPrice
  432  -> (Int) -- ^interpolator2D
  433  -> IO ((CPICapFloorTermPriceSurface))
  434 qlCPICapFloorTermPriceSurface a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 =
  435   let {a1' = realToFrac a1} in 
  436   let {a2' = realToFrac a2} in 
  437   let {(a3'1, a3'2) = fromEnumQuantity a3} in 
  438   withCalendar a4 $ \a4' -> 
  439   let {a5' = fromEnumC a5} in 
  440   withDayCounter a6 $ \a6' -> 
  441   withZeroInflationIndex a7 $ \a7' -> 
  442   let {a8' = fromEnumC a8} in 
  443   withYieldTermStructure a9 $ \a9' -> 
  444   withDoubleArray a10 $ \(a10'1, a10'2) -> 
  445   withDoubleArray a11 $ \(a11'1, a11'2) -> 
  446   withIntArray a12 $ \(a12'1, a12'2) -> 
  447   withEnumArray a13 $ \(a13'1, a13'2) -> 
  448   let {a14' = fromIntegral a14} in 
  449   let {a15' = fromIntegral a15} in 
  450   withDoubleArrayRaw a16 $ \a16' -> 
  451   let {a17' = fromIntegral a17} in 
  452   let {a18' = fromIntegral a18} in 
  453   withDoubleArrayRaw a19 $ \a19' -> 
  454   let {a20' = fromIntegral a20} in 
  455   preErrorCheck $ \a21' -> 
  456   qlCPICapFloorTermPriceSurface'_ a1' a2' a3'1  a3'2 a4' a5' a6' a7' a8' a9' a10'1  a10'2 a11'1  a11'2 a12'1  a12'2 a13'1  a13'2 a14' a15' a16' a17' a18' a19' a20' a21' >>= \res ->
  457   peekCPICapFloorTermPriceSurface res >>= \res' ->
  458   errorCheck  a21'>>
  459   return (res')
  460 
  461 
  462 
  463 -- |Constant CPI (zero-inflation) volatility surface, no maturity\/strike dependence -- the only
  464 -- concrete leaf bound here, mirroring 'constantYoYOptionletVolatility'. No engine or coupon
  465 -- pricer consumes this in QL 1.43 (see this type's own haddock in "QuantLib.Internal.Type"), so
  466 -- it is queryable via 'cpiVolatility'\/'cpiTotalVariance' but not otherwise wired up.
  467 constantCPIVolatility :: (GenQuote q) -> (Word) -- ^settlementDays
  468  -> (Calendar) -> (BusinessDayConvention) -> (DayCounter) -> ((Word,TimeUnit)) -- ^observationLag
  469  -> (Frequency) -> (Bool) -- ^indexIsInterpolated
  470  -> IO ((CPIVolatilitySurface))
  471 constantCPIVolatility a1 a2 a3 a4 a5 a6 a7 a8 =
  472   withQuote a1 $ \a1' -> 
  473   let {a2' = fromIntegral a2} in 
  474   withCalendar a3 $ \a3' -> 
  475   let {a4' = fromEnumC a4} in 
  476   withDayCounter a5 $ \a5' -> 
  477   let {(a6'1, a6'2) = fromEnumQuantity a6} in 
  478   let {a7' = (fromIntegral . fromEnum) a7} in 
  479   let {a8' = C2HSImp.fromBool a8} in 
  480   preErrorCheck $ \a9' -> 
  481   constantCPIVolatility'_ a1' a2' a3' a4' a5' a6'1  a6'2 a7' a8' a9' >>= \res ->
  482   peekCPIVolatilitySurface res >>= \res' ->
  483   errorCheck  a9'>>
  484   return (res')
  485 
  486 
  487 
  488 -- |The volatility for a given maturity date and strike, observed with the given observation
  489 -- lag (or the surface's own lag when 'Nothing').
  490 cpiVolatility :: (CPIVolatilitySurface) -> (Day) -> (Double) -- ^strike
  491  -> (Maybe (Word,TimeUnit)) -- ^obsLag
  492  -> (Bool) -- ^extrapolate
  493  -> IO ((Double))
  494 cpiVolatility a1 a2 a3 a4 a5 =
  495   withGenVolatilityTermStructure a1 $ \a1' -> 
  496   withDay a2 $ \a2' -> 
  497   let {a3' = realToFrac a3} in 
  498   let {(a4'1, a4'2) = fromMaybeEnumQuantity a4} in 
  499   let {a5' = C2HSImp.fromBool a5} in 
  500   preErrorCheck $ \a6' -> 
  501   cpiVolatility'_ a1' a2' a3' a4'1  a4'2 a5' a6' >>= \res ->
  502   let {res' = realToFrac res} in
  503   errorCheck  a6'>>
  504   return (res')
  505 
  506 
  507 
  508 -- |The total integrated variance for a given exercise date and strike. As 'cpiVolatility', a
  509 -- 'Nothing' observation lag uses the surface's own.
  510 cpiTotalVariance :: (CPIVolatilitySurface) -> (Day) -> (Double) -- ^strike
  511  -> (Maybe (Word,TimeUnit)) -- ^obsLag
  512  -> (Bool) -- ^extrapolate
  513  -> IO ((Double))
  514 cpiTotalVariance a1 a2 a3 a4 a5 =
  515   withGenVolatilityTermStructure a1 $ \a1' -> 
  516   withDay a2 $ \a2' -> 
  517   let {a3' = realToFrac a3} in 
  518   let {(a4'1, a4'2) = fromMaybeEnumQuantity a4} in 
  519   let {a5' = C2HSImp.fromBool a5} in 
  520   preErrorCheck $ \a6' -> 
  521   cpiTotalVariance'_ a1' a2' a3' a4'1  a4'2 a5' a6' >>= \res ->
  522   let {res' = realToFrac res} in
  523   errorCheck  a6'>>
  524   return (res')
  525 
  526 
  527 
  528 foreign import ccall safe "QuantLib/TermStructure/InflationVolatility.chs.h qlConstantYoYOptionletVolatility"
  529   constantYoYOptionletVolatility'_ :: ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CYoYOptionletVolatilitySurface')))))))))))))))))
  530 
  531 foreign import ccall safe "QuantLib/TermStructure/InflationVolatility.chs.h qlYoYOptionletVolatilitySurfaceVolatility"
  532   yoyOptionletVolatility'_ :: ((C2HSImp.Ptr (CYoYOptionletVolatilitySurface')) -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))))))
  533 
  534 foreign import ccall safe "QuantLib/TermStructure/InflationVolatility.chs.h qlYoYOptionletVolatilitySurfaceTotalVariance"
  535   yoyOptionletTotalVariance'_ :: ((C2HSImp.Ptr (CYoYOptionletVolatilitySurface')) -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))))))
  536 
  537 foreign import ccall safe "QuantLib/TermStructure/InflationVolatility.chs.h qlYoYCapFloorTermPriceSurface"
  538   qlYoYCapFloorTermPriceSurface'_ :: (C2HSImp.CUInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CYoYInflationIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CYoYCapFloorTermPriceSurface')))))))))))))))))))))))))))))))
  539 
  540 foreign import ccall safe "QuantLib/TermStructure/InflationVolatility.chs.h qlYoYCapFloorTermPriceSurfaceBaseDate"
  541   yoyCapFloorBaseDate'_ :: ((C2HSImp.Ptr (CYoYCapFloorTermPriceSurface')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CInt)))
  542 
  543 foreign import ccall safe "QuantLib/TermStructure/InflationVolatility.chs.h qlYoYCapFloorTermPriceSurfaceAtmYoYSwapDateRates"
  544   qlYoYCapFloorTermPriceSurfaceAtmYoYSwapDateRates'_ :: ((C2HSImp.Ptr (CYoYCapFloorTermPriceSurface')) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CInt)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> (IO ()))))))
  545 
  546 foreign import ccall safe "QuantLib/TermStructure/InflationVolatility.chs.h qlYoYCapFloorTermPriceSurfaceAtmYoYSwapRate"
  547   yoyCapFloorAtmYoYSwapRate'_ :: ((C2HSImp.Ptr (CYoYCapFloorTermPriceSurface')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))
  548 
  549 foreign import ccall safe "QuantLib/TermStructure/InflationVolatility.chs.h qlYoYCapFloorTermPriceSurfaceAtmYoYRate"
  550   yoyCapFloorAtmYoYRate'_ :: ((C2HSImp.Ptr (CYoYCapFloorTermPriceSurface')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))))
  551 
  552 foreign import ccall safe "QuantLib/TermStructure/InflationVolatility.chs.h qlYoYCapFloorTermPriceSurfaceStrikes"
  553   yoyCapFloorStrikes'_ :: ((C2HSImp.Ptr (CYoYCapFloorTermPriceSurface')) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> (IO ()))))
  554 
  555 foreign import ccall safe "QuantLib/TermStructure/InflationVolatility.chs.h qlKInterpolatedYoYOptionletVolatilitySurfaceBlack"
  556   qlKInterpolatedYoYOptionletVolatilitySurfaceBlack'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CYoYCapFloorTermPriceSurface')) -> ((C2HSImp.Ptr (CYoYInflationIndex')) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CYoYOptionletVolatilitySurface')))))))))))))))
  557 
  558 foreign import ccall safe "QuantLib/TermStructure/InflationVolatility.chs.h qlKInterpolatedYoYOptionletVolatilitySurfaceUnitDisplacedBlack"
  559   qlKInterpolatedYoYOptionletVolatilitySurfaceUnitDisplacedBlack'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CYoYCapFloorTermPriceSurface')) -> ((C2HSImp.Ptr (CYoYInflationIndex')) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CYoYOptionletVolatilitySurface')))))))))))))))
  560 
  561 foreign import ccall safe "QuantLib/TermStructure/InflationVolatility.chs.h qlKInterpolatedYoYOptionletVolatilitySurfaceBachelier"
  562   qlKInterpolatedYoYOptionletVolatilitySurfaceBachelier'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CYoYCapFloorTermPriceSurface')) -> ((C2HSImp.Ptr (CYoYInflationIndex')) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CYoYOptionletVolatilitySurface')))))))))))))))
  563 
  564 foreign import ccall safe "QuantLib/TermStructure/InflationVolatility.chs.h qlCPICapFloorTermPriceSurface"
  565   qlCPICapFloorTermPriceSurface'_ :: (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CZeroInflationIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CYieldTermStructure')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CCPICapFloorTermPriceSurface')))))))))))))))))))))))))))))
  566 
  567 foreign import ccall safe "QuantLib/TermStructure/InflationVolatility.chs.h qlConstantCPIVolatility"
  568   constantCPIVolatility'_ :: ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CCPIVolatilitySurface')))))))))))))
  569 
  570 foreign import ccall safe "QuantLib/TermStructure/InflationVolatility.chs.h qlCPIVolatilitySurfaceVolatility"
  571   cpiVolatility'_ :: ((C2HSImp.Ptr (CCPIVolatilitySurface')) -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))))))
  572 
  573 foreign import ccall safe "QuantLib/TermStructure/InflationVolatility.chs.h qlCPIVolatilitySurfaceTotalVariance"
  574   cpiTotalVariance'_ :: ((C2HSImp.Ptr (CCPIVolatilitySurface')) -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))))))