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.Forward
6 (
7 Forward
8 , asForward
9 , ForwardRateAgreement
10 , BondForward
11 , FxForward
12
13 , forwardRateAgreement
14 , bondForward
15 , fxForward
16 , fxForward'
17
18 , cleanForwardPrice
19 , forwardPrice
20 , forwardValue
21 , impliedYield
22 , settlementDate
23 , spotIncome
24 , spotValue
25
26 , forwardRate
27 , fairForwardRate
28 , npvSourceCurrency
29 , npvTargetCurrency
30 ) where
31 import qualified Foreign.C.Types as C2HSImp
32 import qualified Foreign.ForeignPtr as C2HSImp
33 import qualified Foreign.Marshal.Utils as C2HSImp
34 import qualified Foreign.Ptr as C2HSImp
35
36
37 import QuantLib.Internal
38 import QuantLib.Internal.Common
39 import QuantLib.Internal.Type
40 import QuantLib.InterestRate
41
42
43
44
45
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 -- |FRA with a par-rate approximation: the forward rate is forecast from valueDate to maturityDate by the index's forecast curve (useIndexedCoupon=false).
71 forwardRateAgreement :: (GenIborIndex ibor) -> (Day) -- ^valueDate
72 -> (Day) -- ^maturityDate
73 -> (PositionType) -> (Double) -- ^strikeForwardRate
74 -> (Double) -- ^notionalAmount
75 -> (Maybe (GenYieldTermStructure y)) -- ^discountCurve
76 -> IO ((ForwardRateAgreement))
77 forwardRateAgreement a1 a2 a3 a4 a5 a6 a7 =
78 withIborIndex a1 $ \a1' ->
79 withDay a2 $ \a2' ->
80 withDay a3 $ \a3' ->
81 let {a4' = fromEnumC a4} in
82 let {a5' = realToFrac a5} in
83 let {a6' = realToFrac a6} in
84 withMaybeYieldTermStructure a7 $ \a7' ->
85 preErrorCheck $ \a8' ->
86 forwardRateAgreement'_ a1' a2' a3' a4' a5' a6' a7' a8' >>= \res ->
87 peekForwardRateAgreement res >>= \res' ->
88 errorCheck a8'>>
89 return (res')
90
91
92
93 -- |If strike is given in the constructor, can calculate the NPV of the contract via NPV().If strike/forward price is desired, it can be obtained via forwardPrice(). In this case, the strike variable in the constructor is irrelevant and will be ignored.
94 bondForward :: (Day) -- ^valueDate
95 -> (Day) -- ^maturityDate
96 -> (PositionType) -> (Double) -- ^strike
97 -> (Word) -- ^settlementDays
98 -> (DayCounter) -> (Calendar) -> (BusinessDayConvention) -> (GenBond b) -> (Maybe (GenYieldTermStructure y1)) -- ^discountCurve
99 -> (Maybe (GenYieldTermStructure y2)) -- ^incomeDiscountCurve
100 -> IO ((BondForward))
101 bondForward a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 =
102 withDay a1 $ \a1' ->
103 withDay a2 $ \a2' ->
104 let {a3' = fromEnumC a3} in
105 let {a4' = realToFrac a4} in
106 let {a5' = fromIntegral a5} in
107 withDayCounter a6 $ \a6' ->
108 withCalendar a7 $ \a7' ->
109 let {a8' = fromEnumC a8} in
110 withBond a9 $ \a9' ->
111 withMaybeYieldTermStructure a10 $ \a10' ->
112 withMaybeYieldTermStructure a11 $ \a11' ->
113 preErrorCheck $ \a12' ->
114 bondForward'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' >>= \res ->
115 peekBondForward res >>= \res' ->
116 errorCheck a12'>>
117 return (res')
118
119
120
121 -- |(dirty) forward bond price minus accrued on bond at delivery
122 cleanForwardPrice :: (BondForward) -> IO ((Double))
123 cleanForwardPrice a1 =
124 withBondForward a1 $ \a1' ->
125 preErrorCheck $ \a2' ->
126 cleanForwardPrice'_ a1' a2' >>= \res ->
127 let {res' = realToFrac res} in
128 errorCheck a2'>>
129 return (res')
130
131
132
133 -- |(dirty) forward bond price
134 forwardPrice :: (BondForward) -> IO ((Double))
135 forwardPrice a1 =
136 withBondForward a1 $ \a1' ->
137 preErrorCheck $ \a2' ->
138 forwardPrice'_ a1' a2' >>= \res ->
139 let {res' = realToFrac res} in
140 errorCheck a2'>>
141 return (res')
142
143
144
145 -- |forward value/price of underlying, discounting income/dividends
146 -- if this is a bond forward price, is must be a dirty forward price.
147 forwardValue :: (GenForward f) -> IO ((Double))
148 forwardValue a1 =
149 withForward a1 $ \a1' ->
150 preErrorCheck $ \a2' ->
151 forwardValue'_ a1' a2' >>= \res ->
152 let {res' = realToFrac res} in
153 errorCheck a2'>>
154 return (res')
155
156
157
158 -- |Simple yield calculation based on underlying spot and forward values, taking into account underlying income. When $ t>0 $, call with: underlyingSpotValue=spotValue(t), forwardValue=strikePrice, to get current yield. For a repo, if $ t=0 $, impliedYield should reproduce the spot repo rate. For FRA's, this should reproduce the relevant zero rate at the FRA's maturityDate_;
159 impliedYield :: (GenForward f) -> (Double) -- ^underlyingSpotValue
160 -> (Double) -- ^forwarValue
161 -> (Day) -- ^settlementDate
162 -> (Compounding) -> (DayCounter) -> IO ((InterestRate))
163 impliedYield a1 a2 a3 a4 a5 a6 =
164 withForward a1 $ \a1' ->
165 let {a2' = realToFrac a2} in
166 let {a3' = realToFrac a3} in
167 withDay a4 $ \a4' ->
168 let {a5' = (fromIntegral . fromEnum) a5} in
169 withDayCounter a6 $ \a6' ->
170 preErrorCheck $ \a7' ->
171 impliedYield'_ a1' a2' a3' a4' a5' a6' a7' >>= \res ->
172 peekInterestRate res >>= \res' ->
173 errorCheck a7'>>
174 return (res')
175
176
177
178 -- |Date on which the forward contract settles.
179 settlementDate :: (GenForward f) -> IO ((Day))
180 settlementDate a1 =
181 withForward a1 $ \a1' ->
182 preErrorCheck $ \a2' ->
183 settlementDate'_ a1' a2' >>= \res ->
184 let {res' = toDay res} in
185 errorCheck a2'>>
186 return (res')
187
188
189
190 -- |NPV of income/dividends/storage-costs etc. of underlying instrument.
191 spotIncome :: (GenForward f) -> (GenYieldTermStructure y) -> IO ((Double))
192 spotIncome a1 a2 =
193 withForward a1 $ \a1' ->
194 withYieldTermStructure a2 $ \a2' ->
195 preErrorCheck $ \a3' ->
196 spotIncome'_ a1' a2' a3' >>= \res ->
197 let {res' = realToFrac res} in
198 errorCheck a3'>>
199 return (res')
200
201
202
203 -- |returns spot value/price of an underlying financial instrument
204 spotValue :: (GenForward f) -> IO ((Double))
205 spotValue a1 =
206 withForward a1 $ \a1' ->
207 preErrorCheck $ \a2' ->
208 spotValue'_ a1' a2' >>= \res ->
209 let {res' = realToFrac res} in
210 errorCheck a2'>>
211 return (res')
212
213
214
215 -- |Returns the relevant forward rate associated with the FRA term.
216 forwardRate :: (ForwardRateAgreement) -> IO ((InterestRate))
217 forwardRate a1 =
218 withGenInstrument a1 $ \a1' ->
219 preErrorCheck $ \a2' ->
220 forwardRate'_ a1' a2' >>= \res ->
221 peekInterestRate res >>= \res' ->
222 errorCheck a2'>>
223 return (res')
224
225
226
227 -- |FX forward using nominal amounts in both currencies.
228 fxForward :: (Double) -- ^sourceNominal
229 -> (Currency) -- ^sourceCurrency
230 -> (Double) -- ^targetNominal
231 -> (Currency) -- ^targetCurrency
232 -> (Day) -- ^maturityDate
233 -> (Bool) -- ^paySourceCurrency
234 -> (Word) -- ^settlementDays
235 -> (Calendar) -- ^paymentCalendar
236 -> IO ((FxForward))
237 fxForward a1 a2 a3 a4 a5 a6 a7 a8 =
238 let {a1' = realToFrac a1} in
239 withCurrency a2 $ \a2' ->
240 let {a3' = realToFrac a3} in
241 withCurrency a4 $ \a4' ->
242 withDay a5 $ \a5' ->
243 let {a6' = C2HSImp.fromBool a6} in
244 let {a7' = fromIntegral a7} in
245 withCalendar a8 $ \a8' ->
246 preErrorCheck $ \a9' ->
247 fxForward'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' >>= \res ->
248 peekFxForward res >>= \res' ->
249 errorCheck a9'>>
250 return (res')
251
252
253
254 -- |FX forward using a source nominal amount and a contracted forward rate (target/source).
255 fxForward' :: (Double) -- ^sourceNominal
256 -> (Currency) -- ^sourceCurrency
257 -> (Currency) -- ^targetCurrency
258 -> (Double) -- ^forwardRate
259 -> (Day) -- ^maturityDate
260 -> (Bool) -- ^paySourceCurrency
261 -> (Word) -- ^settlementDays
262 -> (Calendar) -- ^paymentCalendar
263 -> IO ((FxForward))
264 fxForward' a1 a2 a3 a4 a5 a6 a7 a8 =
265 let {a1' = realToFrac a1} in
266 withCurrency a2 $ \a2' ->
267 withCurrency a3 $ \a3' ->
268 let {a4' = realToFrac a4} in
269 withDay a5 $ \a5' ->
270 let {a6' = C2HSImp.fromBool a6} in
271 let {a7' = fromIntegral a7} in
272 withCalendar a8 $ \a8' ->
273 preErrorCheck $ \a9' ->
274 fxForward''_ a1' a2' a3' a4' a5' a6' a7' a8' a9' >>= \res ->
275 peekFxForward res >>= \res' ->
276 errorCheck a9'>>
277 return (res')
278
279
280
281 -- |The market-implied fair forward rate, computed by the pricing engine.
282 fairForwardRate :: (FxForward) -> IO ((Double))
283 fairForwardRate a1 =
284 withGenInstrument a1 $ \a1' ->
285 preErrorCheck $ \a2' ->
286 fairForwardRate'_ a1' a2' >>= \res ->
287 let {res' = realToFrac res} in
288 errorCheck a2'>>
289 return (res')
290
291
292
293 -- |NPV in source currency terms.
294 npvSourceCurrency :: (FxForward) -> IO ((Double))
295 npvSourceCurrency a1 =
296 withGenInstrument a1 $ \a1' ->
297 preErrorCheck $ \a2' ->
298 npvSourceCurrency'_ a1' a2' >>= \res ->
299 let {res' = realToFrac res} in
300 errorCheck a2'>>
301 return (res')
302
303
304
305 -- |NPV in target currency terms.
306 npvTargetCurrency :: (FxForward) -> IO ((Double))
307 npvTargetCurrency a1 =
308 withGenInstrument a1 $ \a1' ->
309 preErrorCheck $ \a2' ->
310 npvTargetCurrency'_ a1' a2' >>= \res ->
311 let {res' = realToFrac res} in
312 errorCheck a2'>>
313 return (res')
314
315
316
317 -- vim: set ff=unix ts=8 sts=2 sw=2 et:
318
319 foreign import ccall safe "QuantLib/Instrument/Forward.chs.h qlForwardRateAgreement"
320 forwardRateAgreement'_ :: ((C2HSImp.Ptr (CIborIndex')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CForwardRateAgreement')))))))))))
321
322 foreign import ccall safe "QuantLib/Instrument/Forward.chs.h qlBondForward"
323 bondForward'_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CBond')) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CBondForward')))))))))))))))
324
325 foreign import ccall safe "QuantLib/Instrument/Forward.chs.h qlBondForwardCleanForwardPrice"
326 cleanForwardPrice'_ :: ((C2HSImp.Ptr (CBondForward')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
327
328 foreign import ccall safe "QuantLib/Instrument/Forward.chs.h qlBondForwardForwardPrice"
329 forwardPrice'_ :: ((C2HSImp.Ptr (CBondForward')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
330
331 foreign import ccall safe "QuantLib/Instrument/Forward.chs.h qlForwardForwardValue"
332 forwardValue'_ :: ((C2HSImp.Ptr (CForward')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
333
334 foreign import ccall safe "QuantLib/Instrument/Forward.chs.h qlForwardImpliedYield"
335 impliedYield'_ :: ((C2HSImp.Ptr (CForward')) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CInterestRate))))))))))
336
337 foreign import ccall safe "QuantLib/Instrument/Forward.chs.h qlForwardSettlementDate"
338 settlementDate'_ :: ((C2HSImp.Ptr (CForward')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CInt)))
339
340 foreign import ccall safe "QuantLib/Instrument/Forward.chs.h qlForwardSpotIncome"
341 spotIncome'_ :: ((C2HSImp.Ptr (CForward')) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))
342
343 foreign import ccall safe "QuantLib/Instrument/Forward.chs.h qlForwardSpotValue"
344 spotValue'_ :: ((C2HSImp.Ptr (CForward')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
345
346 foreign import ccall safe "QuantLib/Instrument/Forward.chs.h qlForwardRateAgreementForwardRate"
347 forwardRate'_ :: ((C2HSImp.Ptr (CForwardRateAgreement')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CInterestRate)))))
348
349 foreign import ccall safe "QuantLib/Instrument/Forward.chs.h qlFxForward"
350 fxForward'_ :: (C2HSImp.CDouble -> ((C2HSImp.Ptr (CCurrency)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CCurrency)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCalendar)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CFxForward'))))))))))))
351
352 foreign import ccall safe "QuantLib/Instrument/Forward.chs.h qlFxForward1"
353 fxForward''_ :: (C2HSImp.CDouble -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CCurrency)) -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCalendar)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CFxForward'))))))))))))
354
355 foreign import ccall safe "QuantLib/Instrument/Forward.chs.h qlFxForwardFairForwardRate"
356 fairForwardRate'_ :: ((C2HSImp.Ptr (CFxForward')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
357
358 foreign import ccall safe "QuantLib/Instrument/Forward.chs.h qlFxForwardNpvSourceCurrency"
359 npvSourceCurrency'_ :: ((C2HSImp.Ptr (CFxForward')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
360
361 foreign import ccall safe "QuantLib/Instrument/Forward.chs.h qlFxForwardNpvTargetCurrency"
362 npvTargetCurrency'_ :: ((C2HSImp.Ptr (CFxForward')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))