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