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