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.Instrument.InflationCapFloor
6 (
7 YoYInflationCapFloor
8 , yoyInflationCap
9 , yoyInflationCollar
10 , yoyInflationFloor
11 , yoyInflationCapFloorAtmRate
12 , yoyInflationCapFloorOptionlet
13
14 , CPICapFloor
15 , cpiCapFloor
16 ) where
17 import qualified Foreign.C.Types as C2HSImp
18 import qualified Foreign.ForeignPtr as C2HSImp
19 import qualified Foreign.Ptr as C2HSImp
20
21
22 import QuantLib.Internal
23 import QuantLib.Internal.Type
24 import QuantLib.Internal.Common
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 -- |Constructs a YoY-inflation cap: pays the excess of the YoY leg's rate over each exercise
48 -- rate, if positive. Unlike a nominal cap, the first optionlet is live (YoY inflation sets in
49 -- arrears, so there is no reason to omit it -- see upstream's own note on
50 -- 'YoYInflationCapFloor').
51 yoyInflationCap :: (GenLeg l) -- ^yoyLeg
52 -> ([Double]) -- ^exerciseRates
53 -> IO ((YoYInflationCapFloor))
54 yoyInflationCap a1 a2 =
55 withLeg a1 $ \a1' ->
56 withDoubleArray a2 $ \(a2'1, a2'2) ->
57 preErrorCheck $ \a3' ->
58 yoyInflationCap'_ a1' a2'1 a2'2 a3' >>= \res ->
59 peekYoYInflationCapFloor res >>= \res' ->
60 errorCheck a3'>>
61 return (res')
62
63
64
65 -- |Constructs a YoY-inflation collar: a cap struck at the cap rates combined with a floor
66 -- struck at the floor rates.
67 yoyInflationCollar :: (GenLeg l) -- ^yoyLeg
68 -> ([Double]) -- ^capRates
69 -> ([Double]) -- ^floorRates
70 -> IO ((YoYInflationCapFloor))
71 yoyInflationCollar a1 a2 a3 =
72 withLeg a1 $ \a1' ->
73 withDoubleArray a2 $ \(a2'1, a2'2) ->
74 withDoubleArray a3 $ \(a3'1, a3'2) ->
75 preErrorCheck $ \a4' ->
76 yoyInflationCollar'_ a1' a2'1 a2'2 a3'1 a3'2 a4' >>= \res ->
77 peekYoYInflationCapFloor res >>= \res' ->
78 errorCheck a4'>>
79 return (res')
80
81
82
83 -- |Constructs a YoY-inflation floor: pays the excess of each exercise rate over the YoY leg's
84 -- rate, if positive.
85 yoyInflationFloor :: (GenLeg l) -- ^yoyLeg
86 -> ([Double]) -- ^exerciseRates
87 -> IO ((YoYInflationCapFloor))
88 yoyInflationFloor a1 a2 =
89 withLeg a1 $ \a1' ->
90 withDoubleArray a2 $ \(a2'1, a2'2) ->
91 preErrorCheck $ \a3' ->
92 yoyInflationFloor'_ a1' a2'1 a2'2 a3' >>= \res ->
93 peekYoYInflationCapFloor res >>= \res' ->
94 errorCheck a3'>>
95 return (res')
96
97
98
99 -- |The fair (at-the-money) rate for the cap\/floor's underlying YoY leg, discounted on the
100 -- given curve.
101 yoyInflationCapFloorAtmRate :: (YoYInflationCapFloor) -> (GenYieldTermStructure y) -- ^discountCurve
102 -> IO ((Double))
103 yoyInflationCapFloorAtmRate a1 a2 =
104 withGenInstrument a1 $ \a1' ->
105 withYieldTermStructure a2 $ \a2' ->
106 preErrorCheck $ \a3' ->
107 yoyInflationCapFloorAtmRate'_ a1' a2' a3' >>= \res ->
108 let {res' = realToFrac res} in
109 errorCheck a3'>>
110 return (res')
111
112
113
114 -- |Returns the n-th optionlet as a new YoYInflationCapFloor with only one cash flow.
115 yoyInflationCapFloorOptionlet :: (YoYInflationCapFloor) -> (Word) -- ^n
116 -> IO ((YoYInflationCapFloor))
117 yoyInflationCapFloorOptionlet a1 a2 =
118 withGenInstrument a1 $ \a1' ->
119 let {a2' = fromIntegral a2} in
120 preErrorCheck $ \a3' ->
121 yoyInflationCapFloorOptionlet'_ a1' a2' a3' >>= \res ->
122 peekYoYInflationCapFloor res >>= \res' ->
123 errorCheck a3'>>
124 return (res')
125
126
127
128 -- |A CPI cap or floor: a single cumulative option on cumulative inflation up to maturity
129 -- (@CPI(T)\/CPI(0)@), not a strip of optionlets like 'YoYInflationCapFloor' -- similar in shape
130 -- to a ZCIIS option. No implied-volatility inspector: pricing goes purely through
131 -- 'QuantLib.PricingEngine.interpolatingCPICapFloorEngine' off a market price surface, there is
132 -- no vol-driven engine for it in QL 1.43.
133 cpiCapFloor :: (OptionType) -> (Double) -- ^nominal
134 -> (Day) -- ^startDate
135 -> (Double) -- ^baseCPI
136 -> (Day) -- ^maturity
137 -> (Calendar) -- ^fixCalendar
138 -> (BusinessDayConvention) -- ^fixConvention
139 -> (Calendar) -- ^payCalendar
140 -> (BusinessDayConvention) -- ^payConvention
141 -> (Double) -- ^strike
142 -> (ZeroInflationIndex) -> ((Word,TimeUnit)) -- ^observationLag
143 -> (CPIInterpolationType) -- ^observationInterpolation
144 -> IO ((CPICapFloor))
145 cpiCapFloor a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 =
146 let {a1' = fromEnumC a1} in
147 let {a2' = realToFrac a2} in
148 withDay a3 $ \a3' ->
149 let {a4' = realToFrac a4} in
150 withDay a5 $ \a5' ->
151 withCalendar a6 $ \a6' ->
152 let {a7' = fromEnumC a7} in
153 withCalendar a8 $ \a8' ->
154 let {a9' = fromEnumC a9} in
155 let {a10' = realToFrac a10} in
156 withZeroInflationIndex a11 $ \a11' ->
157 let {(a12'1, a12'2) = fromEnumQuantity a12} in
158 let {a13' = fromEnumC a13} in
159 preErrorCheck $ \a14' ->
160 cpiCapFloor'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12'1 a12'2 a13' a14' >>= \res ->
161 peekCPICapFloor res >>= \res' ->
162 errorCheck a14'>>
163 return (res')
164
165
166
167 -- vim: set ff=unix ts=8 sts=2 sw=2 et:
168
169 foreign import ccall safe "QuantLib/Instrument/InflationCapFloor.chs.h qlYoYInflationCap"
170 yoyInflationCap'_ :: ((C2HSImp.Ptr (CLeg')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CYoYInflationCapFloor')))))))
171
172 foreign import ccall safe "QuantLib/Instrument/InflationCapFloor.chs.h qlYoYInflationCollar"
173 yoyInflationCollar'_ :: ((C2HSImp.Ptr (CLeg')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CYoYInflationCapFloor')))))))))
174
175 foreign import ccall safe "QuantLib/Instrument/InflationCapFloor.chs.h qlYoYInflationFloor"
176 yoyInflationFloor'_ :: ((C2HSImp.Ptr (CLeg')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CYoYInflationCapFloor')))))))
177
178 foreign import ccall safe "QuantLib/Instrument/InflationCapFloor.chs.h qlYoYInflationCapFloorAtmRate"
179 yoyInflationCapFloorAtmRate'_ :: ((C2HSImp.Ptr (CYoYInflationCapFloor')) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))
180
181 foreign import ccall safe "QuantLib/Instrument/InflationCapFloor.chs.h qlYoYInflationCapFloorOptionlet"
182 yoyInflationCapFloorOptionlet'_ :: ((C2HSImp.Ptr (CYoYInflationCapFloor')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CYoYInflationCapFloor'))))))
183
184 foreign import ccall safe "QuantLib/Instrument/InflationCapFloor.chs.h qlCPICapFloor"
185 cpiCapFloor'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CZeroInflationIndex')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CCPICapFloor'))))))))))))))))))