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.CapFloor
6 (
7 -- * Types
8 CapFloor
9
10 -- * Constructors
11 , cap
12 , collar
13 , floor
14 , optionlet
15
16 -- * Inspectors
17 , atmRate
18 , impliedVolatility
19 ) where
20 import qualified Foreign.C.Types as C2HSImp
21 import qualified Foreign.ForeignPtr as C2HSImp
22 import qualified Foreign.Ptr as C2HSImp
23
24
25 import Prelude hiding(floor)
26
27 import QuantLib.Internal
28 import QuantLib.Internal.Type
29 import Data.List.NonEmpty(NonEmpty)
30 import QuantLib.InterestRate(VolatilityType)
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 -- |constructs a cap: pays the excess of the floating leg's rate over each exercise rate, if positive
46 cap :: (GenLeg l) -- ^floatingLeg
47 -> (NonEmpty Double) -- ^exerciseRates
48 -> IO ((CapFloor))
49 cap a1 a2 =
50 withLeg a1 $ \a1' ->
51 withNonEmptyDoubleArray a2 $ \(a2'1, a2'2) ->
52 preErrorCheck $ \a3' ->
53 cap'_ a1' a2'1 a2'2 a3' >>= \res ->
54 peekCapFloor res >>= \res' ->
55 errorCheck a3'>>
56 return (res')
57
58
59
60 -- |constructs a collar: a cap struck at the cap rates combined with a floor struck at the floor rates
61 collar :: (GenLeg l) -- ^floatingLeg
62 -> (NonEmpty Double) -- ^capRates
63 -> (NonEmpty Double) -- ^floorRates
64 -> IO ((CapFloor))
65 collar a1 a2 a3 =
66 withLeg a1 $ \a1' ->
67 withNonEmptyDoubleArray a2 $ \(a2'1, a2'2) ->
68 withNonEmptyDoubleArray a3 $ \(a3'1, a3'2) ->
69 preErrorCheck $ \a4' ->
70 collar'_ a1' a2'1 a2'2 a3'1 a3'2 a4' >>= \res ->
71 peekCapFloor res >>= \res' ->
72 errorCheck a4'>>
73 return (res')
74
75
76
77 -- |constructs a floor: pays the excess of each exercise rate over the floating leg's rate, if positive
78 floor :: (GenLeg l) -- ^floatingLeg
79 -> (NonEmpty Double) -- ^exerciseRates
80 -> IO ((CapFloor))
81 floor a1 a2 =
82 withLeg a1 $ \a1' ->
83 withNonEmptyDoubleArray a2 $ \(a2'1, a2'2) ->
84 preErrorCheck $ \a3' ->
85 floor'_ a1' a2'1 a2'2 a3' >>= \res ->
86 peekCapFloor res >>= \res' ->
87 errorCheck a3'>>
88 return (res')
89
90
91
92 -- |returns the fair (at-the-money) rate for the cap/floor's underlying floating leg, discounted on the given curve
93 atmRate :: (CapFloor) -> (GenYieldTermStructure y) -- ^discountCurve
94 -> IO ((Double))
95 atmRate a1 a2 =
96 withGenInstrument a1 $ \a1' ->
97 withYieldTermStructure a2 $ \a2' ->
98 preErrorCheck $ \a3' ->
99 atmRate'_ a1' a2' a3' >>= \res ->
100 let {res' = realToFrac res} in
101 errorCheck a3'>>
102 return (res')
103
104
105
106 -- |implied term volatility
107 impliedVolatility :: (CapFloor) -> (Double) -- ^price
108 -> (GenYieldTermStructure y) -- ^disc
109 -> (Double) -- ^guess
110 -> (Double) -- ^accuracy
111 -> (Word) -- ^maxEvaluations
112 -> (Double) -- ^minVol
113 -> (Double) -- ^maxVol
114 -> (VolatilityType) -- ^type
115 -> (Double) -- ^displacement
116 -> IO ((Double))
117 impliedVolatility a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 =
118 withGenInstrument a1 $ \a1' ->
119 let {a2' = realToFrac a2} in
120 withYieldTermStructure a3 $ \a3' ->
121 let {a4' = realToFrac a4} in
122 let {a5' = realToFrac a5} in
123 let {a6' = fromIntegral a6} in
124 let {a7' = realToFrac a7} in
125 let {a8' = realToFrac a8} in
126 let {a9' = (fromIntegral . fromEnum) a9} in
127 let {a10' = realToFrac a10} in
128 preErrorCheck $ \a11' ->
129 impliedVolatility'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' >>= \res ->
130 let {res' = realToFrac res} in
131 errorCheck a11'>>
132 return (res')
133
134
135
136 -- |Returns the n-th optionlet as a new CapFloor with only one cash flow.
137 optionlet :: (CapFloor) -> (Word) -- ^n
138 -> IO ((CapFloor))
139 optionlet a1 a2 =
140 withGenInstrument a1 $ \a1' ->
141 let {a2' = fromIntegral a2} in
142 preErrorCheck $ \a3' ->
143 optionlet'_ a1' a2' a3' >>= \res ->
144 peekCapFloor res >>= \res' ->
145 errorCheck a3'>>
146 return (res')
147
148
149
150 -- vim: set ff=unix ts=8 sts=2 sw=2 et:
151
152 foreign import ccall safe "QuantLib/Instrument/CapFloor.chs.h qlCap"
153 cap'_ :: ((C2HSImp.Ptr (CLeg')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CCapFloor')))))))
154
155 foreign import ccall safe "QuantLib/Instrument/CapFloor.chs.h qlCollar"
156 collar'_ :: ((C2HSImp.Ptr (CLeg')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CCapFloor')))))))))
157
158 foreign import ccall safe "QuantLib/Instrument/CapFloor.chs.h qlFloor"
159 floor'_ :: ((C2HSImp.Ptr (CLeg')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CCapFloor')))))))
160
161 foreign import ccall safe "QuantLib/Instrument/CapFloor.chs.h qlCapFloorAtmRate"
162 atmRate'_ :: ((C2HSImp.Ptr (CCapFloor')) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
163
164 foreign import ccall safe "QuantLib/Instrument/CapFloor.chs.h qlCapFloorImpliedVolatility"
165 impliedVolatility'_ :: ((C2HSImp.Ptr (CCapFloor')) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CYieldTermStructure')) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))))))))))
166
167 foreign import ccall safe "QuantLib/Instrument/CapFloor.chs.h qlCapFloorOptionlet"
168 optionlet'_ :: ((C2HSImp.Ptr (CCapFloor')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CCapFloor'))))))