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