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