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