-- GENERATED by C->Haskell Compiler, version 0.28.8 Switcheroo, 25 November 2017 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "./QuantLib/Quote.chs" #-}
module QuantLib.Quote
  (
    -- * Types
    -- ** Quote hierarchy
    GenQuote
  , Quote
  , SimpleQuote
  , DeltaVolQuote
  , FuturesConvAdjustmentQuote
  , RelinkableQuote

    -- ** Configuration
  , PriceType(..)
  , IntervalPriceType(..)
  , AtmType(..)
  , DeltaType(..)
  , QuoteOp(..)
  , MultiQuoteOp(..)

    -- * Constructors
    -- ** Basic quotes and conversions
  , asQuote
  , simpleQuote
  , deltaVolQuote
  , atmVolQuote
  , eurodollarFuturesImpliedStdDevQuote
  , forwardSwapQuote
  , forwardValueQuote
  , futuresConvAdjustmentQuoteFromImmCode
  , futuresConvAdjustmentQuote
  , impliedStdDevQuote
  , lastFixingQuote
  , relinkableQuote
    -- ** Composite quotes
  , derivedQuote
  , compositeQuote
  , multiCompositeQuote
  , withDerivedQuote
  , withCompositeQuote
  , withMultiCompositeQuote

    -- * Mutators
  , setValue
  , linkTo

    -- * Inspectors
  , value
  , isValid
  , futuresValue
  ) where
import qualified Foreign.C.String as C2HSImp
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.ForeignPtr as C2HSImp
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp


import Foreign.Ptr(FunPtr)

import QuantLib.Internal
import QuantLib.Internal.Common
import QuantLib.Internal.Type







data IntervalPriceType = IntervalPriceOpen
                       | IntervalPriceClose
                       | IntervalPriceHigh
                       | IntervalPriceLow
  deriving (Enum,Show,Eq,Read)

{-# LINE 63 "./QuantLib/Quote.chs" #-}

data AtmType = AtmNull
             | AtmSpot
             | AtmFwd
             | AtmDeltaNeutral
             | AtmVegaMax
             | AtmGammaMax
             | AtmPutCall50
  deriving (Enum,Show,Eq,Read)

{-# LINE 64 "./QuantLib/Quote.chs" #-}

data PriceType = Bid
               | Ask
               | Last
               | Close
               | Mid
               | MidEquivalent
               | MidSafe
  deriving (Enum,Show,Eq,Read)

{-# LINE 65 "./QuantLib/Quote.chs" #-}

data DeltaType = Spot
               | Fwd
               | PaSpot
               | PaFwd
  deriving (Enum,Show,Eq,Read)

{-# LINE 66 "./QuantLib/Quote.chs" #-}


-- |Operation used by 'derivedQuote' or 'compositeQuote'. The former applies
-- @quote \`op\` operand@; the latter applies @quote1 \`op\` quote2@. Use
-- 'withDerivedQuote' for reversed unary operations such as FX inversion.
data QuoteOp = QuoteAdd
             | QuoteSubtract
             | QuoteMultiply
             | QuoteDivide
  deriving (Show,Eq,Read,Bounded)
instance Enum QuoteOp where
  succ :: QuoteOp -> QuoteOp
succ QuoteOp
QuoteAdd = QuoteOp
QuoteSubtract
  succ QuoteOp
QuoteSubtract = QuoteOp
QuoteMultiply
  succ QuoteOp
QuoteMultiply = QuoteOp
QuoteDivide
  succ QuoteOp
QuoteDivide = String -> QuoteOp
forall a. HasCallStack => String -> a
error String
"QuoteOp.succ: QuoteDivide has no successor"

  pred :: QuoteOp -> QuoteOp
pred QuoteOp
QuoteSubtract = QuoteOp
QuoteAdd
  pred QuoteOp
QuoteMultiply = QuoteOp
QuoteSubtract
  pred QuoteOp
QuoteDivide = QuoteOp
QuoteMultiply
  pred QuoteOp
QuoteAdd = String -> QuoteOp
forall a. HasCallStack => String -> a
error String
"QuoteOp.pred: QuoteAdd has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from QuoteDivide

  fromEnum QuoteAdd = 0
  fromEnum QuoteSubtract = 1
  fromEnum QuoteMultiply = 2
  fromEnum QuoteDivide = 3

  toEnum 0 = QuoteAdd
  toEnum 1 = QuoteSubtract
  toEnum 2 = QuoteMultiply
  toEnum 3 = QuoteDivide
  toEnum unmatched = error ("QuoteOp.toEnum: Cannot match " ++ show unmatched)

setValue :: SimpleQuote -> Double -> IO Double
{-# LINE 71 "./QuantLib/Quote.chs" #-}


-- |Which fold a catalogue 'multiCompositeQuote' applies over its elements.
data MultiQuoteOp = QuoteSum
                  | QuoteProduct
                  | QuoteNorm2
  deriving (Show,Eq,Read,Bounded)
instance Enum MultiQuoteOp where
  succ QuoteSum = QuoteProduct
  succ QuoteProduct = QuoteNorm2
  succ QuoteNorm2 = error "MultiQuoteOp.succ: QuoteNorm2 has no successor"

  pred QuoteProduct = QuoteSum
  pred QuoteNorm2 = QuoteProduct
  pred QuoteSum = error "MultiQuoteOp.pred: QuoteSum has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from QuoteNorm2

  fromEnum QuoteSum = 0
  fromEnum QuoteProduct = 1
  fromEnum QuoteNorm2 = 2

  toEnum 0 = QuoteSum
  toEnum 1 = QuoteProduct
  toEnum 2 = QuoteNorm2
  toEnum unmatched = error ("MultiQuoteOp.toEnum: Cannot match " ++ show unmatched)

{-# LINE 74 "./QuantLib/Quote.chs" #-}



{-# LINE 76 "./QuantLib/Quote.chs" #-}


{-# LINE 77 "./QuantLib/Quote.chs" #-}


{-# LINE 78 "./QuantLib/Quote.chs" #-}


{-# LINE 79 "./QuantLib/Quote.chs" #-}


{-# LINE 80 "./QuantLib/Quote.chs" #-}


{-# LINE 81 "./QuantLib/Quote.chs" #-}


{-# LINE 82 "./QuantLib/Quote.chs" #-}


{-# LINE 83 "./QuantLib/Quote.chs" #-}


-- |market element returning a stored value
simpleQuote :: (Double) -> IO ((SimpleQuote))
simpleQuote a1 =
  let {a1' = realToFrac a1} in 
  preErrorCheck $ \a2' -> 
  simpleQuote'_ a1' a2' >>= \res ->
  peekSimpleQuote res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 86 "./QuantLib/Quote.chs" #-}


-- |quotation of an FX delta vs vol, e.g. a 25-delta risk-reversal/butterfly point
deltaVolQuote :: (Double) -- ^delta
 -> (GenQuote q) -- ^vol
 -> (Double) -- ^maturity
 -> (DeltaType) -> IO ((DeltaVolQuote))
deltaVolQuote a1 a2 a3 a4 =
  let {a1' = realToFrac a1} in 
  withQuote a2 $ \a2' -> 
  let {a3' = realToFrac a3} in 
  let {a4' = fromEnumC a4} in 
  preErrorCheck $ \a5' -> 
  deltaVolQuote'_ a1' a2' a3' a4' a5' >>= \res ->
  peekDeltaVolQuote res >>= \res' ->
  errorCheck  a5'>>
  return (res')

{-# LINE 93 "./QuantLib/Quote.chs" #-}


-- |quotation of an FX at-the-money vol point (e.g. ATM straddle)
atmVolQuote :: (GenQuote q) -- ^vol
 -> (DeltaType) -> (Double) -- ^maturity
 -> (AtmType) -> IO ((DeltaVolQuote))
atmVolQuote a1 a2 a3 a4 =
  withQuote a1 $ \a1' -> 
  let {a2' = fromEnumC a2} in 
  let {a3' = realToFrac a3} in 
  let {a4' = fromEnumC a4} in 
  preErrorCheck $ \a5' -> 
  atmVolQuote'_ a1' a2' a3' a4' a5' >>= \res ->
  peekDeltaVolQuote res >>= \res' ->
  errorCheck  a5'>>
  return (res')

{-# LINE 100 "./QuantLib/Quote.chs" #-}


-- |Returns the current value of the given Quote object
value :: (GenQuote q) -> IO ((Double))
value a1 =
  withQuote a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  value'_ a1' a2' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 103 "./QuantLib/Quote.chs" #-}


-- |returns the difference between the new value and the old value
-- /NB/ The change will propagate to all users of the quote
setValue :: (SimpleQuote) -> (Double) -> IO ((Double))
setValue a1 a2 =
  withGenQuote a1 $ \a1' -> 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  setValue'_ a1' a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 107 "./QuantLib/Quote.chs" #-}


-- |implied standard deviation of a Eurodollar future's underlying, solved from its call/put prices
eurodollarFuturesImpliedStdDevQuote :: (GenQuote q1) -- ^forward
 -> (GenQuote q2) -- ^callPrice
 -> (GenQuote q3) -- ^putPrice
 -> (Double) -- ^strike
 -> (Double) -- ^guess
 -> (Double) -- ^accuracy
 -> (Word) -- ^maxIter
 -> IO ((Quote))
eurodollarFuturesImpliedStdDevQuote :: forall q1 q2 q3.
GenQuote q1
-> GenQuote q2
-> GenQuote q3
-> Double
-> Double
-> Double
-> Word
-> IO Quote
eurodollarFuturesImpliedStdDevQuote GenQuote q1
a1 GenQuote q2
a2 GenQuote q3
a3 Double
a4 Double
a5 Double
a6 Word
a7 =
  GenQuote q1 -> (Ptr CQuote' -> IO Quote) -> IO Quote
forall q b. GenQuote q -> (Ptr CQuote' -> IO b) -> IO b
withQuote GenQuote q1
a1 ((Ptr CQuote' -> IO Quote) -> IO Quote)
-> (Ptr CQuote' -> IO Quote) -> IO Quote
forall a b. (a -> b) -> a -> b
$ \Ptr CQuote'
a1' -> 
  withQuote a2 $ \a2' -> 
  withQuote a3 $ \a3' -> 
  let {a4' = realToFrac a4} in 
  let {a5' = realToFrac a5} in 
  let {a6' = realToFrac a6} in 
  let {a7' = fromIntegral a7} in 
  preErrorCheck $ \a8' -> 
  eurodollarFuturesImpliedStdDevQuote'_ a1' a2' a3' a4' a5' a6' a7' a8' >>= \res ->
  peekQuote res >>= \res' ->
  errorCheck  a8'>>
  return (res')

{-# LINE 117 "./QuantLib/Quote.chs" #-}


-- |implied rate of a forward-starting swap on the given swap index, offset by a spread quote
forwardSwapQuote :: (GenSwapIndex sidx) -> (GenQuote q) -- ^spread
 -> ((Int,TimeUnit)) -- ^fwdStart
 -> IO ((Quote))
forwardSwapQuote a1 a2 a3 =
  withSwapIndex a1 $ \a1' -> 
  withQuote a2 $ \a2' -> 
  let {(a3'1, a3'2) = fromEnumQuantity a3} in 
  preErrorCheck $ \a4' -> 
  forwardSwapQuote'_ a1' a2' a3'1  a3'2 a4' >>= \res ->
  peekQuote res >>= \res' ->
  errorCheck  a4'>>
  return (res')

{-# LINE 122 "./QuantLib/Quote.chs" #-}


-- |forward value of an index as of a given fixing date
forwardValueQuote :: (GenIndex idx) -> (Day) -> IO ((Quote))
forwardValueQuote a1 a2 =
  withIndex a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  forwardValueQuote'_ a1' a2' a3' >>= \res ->
  peekQuote res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 125 "./QuantLib/Quote.chs" #-}


-- |futures-convexity adjustment for an Ibor future identified by its IMM code
futuresConvAdjustmentQuoteFromImmCode :: (GenIborIndex ibor) -> (String) -- ^immCode
 -> (GenQuote q1) -- ^futuresQuote
 -> (GenQuote q2) -- ^volatility
 -> (GenQuote q3) -- ^meanReversion
 -> IO ((FuturesConvAdjustmentQuote))
futuresConvAdjustmentQuoteFromImmCode a1 a2 a3 a4 a5 =
  withIborIndex a1 $ \a1' -> 
  C2HSImp.withCString a2 $ \a2' -> 
  withQuote a3 $ \a3' -> 
  withQuote a4 $ \a4' -> 
  withQuote a5 $ \a5' -> 
  preErrorCheck $ \a6' -> 
  futuresConvAdjustmentQuoteFromImmCode'_ a1' a2' a3' a4' a5' a6' >>= \res ->
  peekFuturesConvAdjustmentQuote res >>= \res' ->
  errorCheck  a6'>>
  return (res')

{-# LINE 132 "./QuantLib/Quote.chs" #-}


-- |futures-convexity adjustment for an Ibor future identified by its futures (IMM) date
futuresConvAdjustmentQuote :: (GenIborIndex ibor) -> (Day) -- ^futuresDate
 -> (GenQuote q1) -- ^futuresQuote
 -> (GenQuote q2) -- ^volatility
 -> (GenQuote q3) -- ^meanReversion
 -> IO ((FuturesConvAdjustmentQuote))
futuresConvAdjustmentQuote a1 a2 a3 a4 a5 =
  withIborIndex a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  withQuote a3 $ \a3' -> 
  withQuote a4 $ \a4' -> 
  withQuote a5 $ \a5' -> 
  preErrorCheck $ \a6' -> 
  futuresConvAdjustmentQuote'_ a1' a2' a3' a4' a5' a6' >>= \res ->
  peekFuturesConvAdjustmentQuote res >>= \res' ->
  errorCheck  a6'>>
  return (res')

{-# LINE 139 "./QuantLib/Quote.chs" #-}


-- |The futures-vs-forward-rate value implied by the futures quote alone (@futuresQuote_->value()@).
futuresValue :: (FuturesConvAdjustmentQuote) -> IO ((Double))
futuresValue a1 =
  withGenQuote a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  futuresValue'_ a1' a2' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 142 "./QuantLib/Quote.chs" #-}


-- |implied standard deviation of an underlying, solved from its option price at a given strike
impliedStdDevQuote :: (OptionType) -> (GenQuote q1) -- ^forward
 -> (GenQuote q2) -- ^price
 -> (Double) -- ^strike
 -> (Double) -- ^guess
 -> (Double) -- ^accuracy
 -> (Word) -- ^maxIter
 -> IO ((Quote))
impliedStdDevQuote :: forall q1 q2.
OptionType
-> GenQuote q1
-> GenQuote q2
-> Double
-> Double
-> Double
-> Word
-> IO Quote
impliedStdDevQuote OptionType
a1 GenQuote q1
a2 GenQuote q2
a3 Double
a4 Double
a5 Double
a6 Word
a7 =
  let {a1' :: CInt
a1' = OptionType -> CInt
forall a b. (Enum a, Integral b) => a -> b
fromEnumC OptionType
a1} in 
  GenQuote q1 -> (Ptr CQuote' -> IO Quote) -> IO Quote
forall q b. GenQuote q -> (Ptr CQuote' -> IO b) -> IO b
withQuote GenQuote q1
a2 ((Ptr CQuote' -> IO Quote) -> IO Quote)
-> (Ptr CQuote' -> IO Quote) -> IO Quote
forall a b. (a -> b) -> a -> b
$ \Ptr CQuote'
a2' -> 
  GenQuote q2 -> (Ptr CQuote' -> IO Quote) -> IO Quote
forall q b. GenQuote q -> (Ptr CQuote' -> IO b) -> IO b
withQuote GenQuote q2
a3 ((Ptr CQuote' -> IO Quote) -> IO Quote)
-> (Ptr CQuote' -> IO Quote) -> IO Quote
forall a b. (a -> b) -> a -> b
$ \Ptr CQuote'
a3' -> 
  let {a4' :: CDouble
a4' = realToFrac a4} in 
  let {a5' = realToFrac a5} in 
  let {a6' = realToFrac a6} in 
  let {a7' = fromIntegral a7} in 
  preErrorCheck $ \a8' -> 
  impliedStdDevQuote'_ a1' a2' a3' a4' a5' a6' a7' a8' >>= \res ->
  peekQuote res >>= \res' ->
  errorCheck  a8'>>
  return (res')

{-# LINE 151 "./QuantLib/Quote.chs" #-}


-- |last available fixing of the given index, updating whenever a new fixing is added
lastFixingQuote :: (GenIndex idx) -> IO ((Quote))
lastFixingQuote a1 =
  withIndex a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  lastFixingQuote'_ a1' a2' >>= \res ->
  peekQuote res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 154 "./QuantLib/Quote.chs" #-}


-- |returns true if the Quote holds a valid value
isValid :: (GenQuote q) -> IO ((Bool))
isValid a1 =
  withQuote a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  isValid'_ a1' a2' >>= \res ->
  let {res' = C2HSImp.toBool res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 157 "./QuantLib/Quote.chs" #-}


-- |A relinkable quote handle. Objects built from it follow later 'linkTo' calls.
-- 'Nothing' creates an empty handle; reading it throws until linked.
relinkableQuote :: (Maybe (GenQuote q)) -> IO ((RelinkableQuote))
relinkableQuote a1 =
  withMaybeQuote a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  relinkableQuote'_ a1' a2' >>= \res ->
  peekRelinkableQuote res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 162 "./QuantLib/Quote.chs" #-}


-- |Point a relinkable handle at another quote. Existing dependents reprice without reconstruction.
-- Use 'setValue' for a value bump; this swaps the quote object.
linkTo :: (RelinkableQuote) -> (GenQuote q) -> IO ()
linkTo a1 a2 =
  withRelinkableQuote a1 $ \a1' -> 
  withQuote a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  linkTo'_ a1' a2' a3' >>
  errorCheck  a3'>>
  return ()

{-# LINE 167 "./QuantLib/Quote.chs" #-}


-- These composite quotes are live observer-graph nodes. Haskell-side recomputation would be a snapshot and would not notify dependent curves or instruments.

-- |A quote derived from another by applying @quote \`op\` operand@, live: it recomputes whenever
-- the underlying quote moves, and notifies everything built on it.
--
-- @'derivedQuote' 'QuoteAdd' base 0.0005@ is the "base plus 5bp" spread quote for a rate helper.
-- For anything outside the 'QuoteOp' catalogue -- @1\/x@, a cap, a nonlinear transform -- use
-- 'withDerivedQuote'.
derivedQuote :: (QuoteOp) -> (GenQuote q) -> (Double) -- ^operand
 -> IO ((Quote))
derivedQuote :: forall q. QuoteOp -> GenQuote q -> Double -> IO Quote
derivedQuote QuoteOp
a1 GenQuote q
a2 Double
a3 =
  let {a1' :: CInt
a1' = QuoteOp -> CInt
forall a b. (Enum a, Integral b) => a -> b
fromEnumC QuoteOp
a1} in 
  GenQuote q -> (Ptr CQuote' -> IO Quote) -> IO Quote
forall q b. GenQuote q -> (Ptr CQuote' -> IO b) -> IO b
withQuote GenQuote q
a2 ((Ptr CQuote' -> IO Quote) -> IO Quote)
-> (Ptr CQuote' -> IO Quote) -> IO Quote
forall a b. (a -> b) -> a -> b
$ \Ptr CQuote'
a2' -> 
  let {a3' :: CDouble
a3' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a3} in 
  (Ptr (Ptr CChar) -> IO Quote) -> IO Quote
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO Quote) -> IO Quote)
-> (Ptr (Ptr CChar) -> IO Quote) -> IO Quote
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a4' -> 
  CInt
-> Ptr CQuote' -> CDouble -> Ptr (Ptr CChar) -> IO (Ptr CQuote')
derivedQuote'_ CInt
a1' Ptr CQuote'
a2' CDouble
a3' Ptr (Ptr CChar)
a4' IO (Ptr CQuote') -> (Ptr CQuote' -> IO Quote) -> IO Quote
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CQuote'
res ->
  Ptr CQuote' -> IO Quote
peekQuote Ptr CQuote'
res IO Quote -> (Quote -> IO Quote) -> IO Quote
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Quote
res' ->
  Ptr (Ptr CChar) -> IO ()
errorCheck  Ptr (Ptr CChar)
a4'IO () -> IO Quote -> IO Quote
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Quote -> IO Quote
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Quote
res')

{-# LINE 179 "./QuantLib/Quote.chs" #-}


-- |A quote combining two others as @quote1 \`op\` quote2@, live in both: it recomputes whenever
-- either moves. Use 'withCompositeQuote' for an operation outside the 'QuoteOp' catalogue.
compositeQuote :: (QuoteOp) -> (GenQuote q1) -> (GenQuote q2) -> IO ((Quote))
compositeQuote a1 a2 a3 =
  let {a1' = fromEnumC a1} in 
  withQuote a2 $ \a2' -> 
  withQuote a3 $ \a3' -> 
  preErrorCheck $ \a4' -> 
  compositeQuote'_ a1' a2' a3' a4' >>= \res ->
  peekQuote res >>= \res' ->
  errorCheck  a4'>>
  return (res')

{-# LINE 184 "./QuantLib/Quote.chs" #-}


-- |A quote folding any number of others, live in all of them. An empty list is accepted and
-- gives the fold's identity (@0@ for 'QuoteSum' and 'QuoteNorm2', @1@ for 'QuoteProduct') --
-- upstream imposes no non-empty requirement. Use 'withMultiCompositeQuote' for a fold outside
-- the 'MultiQuoteOp' catalogue.
multiCompositeQuote :: (MultiQuoteOp) -> ([GenQuote q]) -> IO ((Quote))
multiCompositeQuote a1 a2 =
  let {a1' = fromEnumC a1} in 
  withQuoteArray a2 $ \(a2'1, a2'2) -> 
  preErrorCheck $ \a3' -> 
  multiCompositeQuote'_ a1' a2'1  a2'2 a3' >>= \res ->
  peekQuote res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 191 "./QuantLib/Quote.chs" #-}


qlDerivedQuoteFromFunction :: (GenQuote q) -> (FunPtr QuoteUnaryFun) -> IO ((Quote))
qlDerivedQuoteFromFunction a1 a2 =
  withQuote a1 $ \a1' -> 
  let {a2' = id a2} in 
  preErrorCheck $ \a3' -> 
  qlDerivedQuoteFromFunction'_ a1' a2' a3' >>= \res ->
  peekQuote res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 194 "./QuantLib/Quote.chs" #-}

qlCompositeQuoteFromFunction :: (GenQuote q1) -> (GenQuote q2) -> (FunPtr QuoteBinaryFun) -> IO ((Quote))
qlCompositeQuoteFromFunction a1 a2 a3 =
  withQuote a1 $ \a1' -> 
  withQuote a2 $ \a2' -> 
  let {a3' = id a3} in 
  preErrorCheck $ \a4' -> 
  qlCompositeQuoteFromFunction'_ a1' a2' a3' a4' >>= \res ->
  peekQuote res >>= \res' ->
  errorCheck  a4'>>
  return (res')

{-# LINE 196 "./QuantLib/Quote.chs" #-}

qlMultiCompositeQuoteFromFunction :: ([GenQuote q]) -> (FunPtr QuoteArrayFun) -> IO ((Quote))
qlMultiCompositeQuoteFromFunction a1 a2 =
  withQuoteArray a1 $ \(a1'1, a1'2) -> 
  let {a2' = id a2} in 
  preErrorCheck $ \a3' -> 
  qlMultiCompositeQuoteFromFunction'_ a1'1  a1'2 a2' a3' >>= \res ->
  peekQuote res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 198 "./QuantLib/Quote.chs" #-}


-- |As 'derivedQuote', with an arbitrary Haskell function.
--
-- __The continuation must span the whole use, not only construction.__ QuantLib calls @f@ later from @Quote::value()@. Returning frees its function pointer, so a later read crashes.
--
-- @f@ must be total: exceptions cross C++, including during bootstrap. Prefer 'derivedQuote' when its 'QuoteOp' fits.
withDerivedQuote :: (Double -> Double) -- ^f(value)
  -> GenQuote q -> (Quote -> IO b) -> IO b
withDerivedQuote f q k = withPayoffFun f (\fp -> qlDerivedQuoteFromFunction q fp >>= k)

-- |As 'compositeQuote', but combining the two quotes with an arbitrary Haskell function. Same
-- continuation-lifetime and totality rules as 'withDerivedQuote'.
withCompositeQuote :: (Double -> Double -> Double) -- ^f(value1, value2)
  -> GenQuote q1 -> GenQuote q2 -> (Quote -> IO b) -> IO b
withCompositeQuote :: forall q1 q2 b.
(Double -> Double -> Double)
-> GenQuote q1 -> GenQuote q2 -> (Quote -> IO b) -> IO b
withCompositeQuote Double -> Double -> Double
f GenQuote q1
q1 GenQuote q2
q2 Quote -> IO b
k = (Double -> Double -> Double)
-> (FunPtr QuoteBinaryFun -> IO b) -> IO b
forall b.
(Double -> Double -> Double)
-> (FunPtr QuoteBinaryFun -> IO b) -> IO b
withQuoteBinaryFun Double -> Double -> Double
f (\FunPtr QuoteBinaryFun
fp -> GenQuote q1 -> GenQuote q2 -> FunPtr QuoteBinaryFun -> IO Quote
forall q1 q2.
GenQuote q1 -> GenQuote q2 -> FunPtr QuoteBinaryFun -> IO Quote
qlCompositeQuoteFromFunction GenQuote q1
q1 GenQuote q2
q2 FunPtr QuoteBinaryFun
fp IO Quote -> (Quote -> IO b) -> IO b
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Quote -> IO b
k)

-- |As 'multiCompositeQuote', but folding with an arbitrary Haskell function. The whole element
-- vector is passed per evaluation, so this crosses into Haskell once per value, not once per
-- element. Same continuation-lifetime and totality rules as 'withDerivedQuote'.
withMultiCompositeQuote :: ([Double] -> Double) -- ^f(values)
  -> [GenQuote q] -> (Quote -> IO b) -> IO b
withMultiCompositeQuote :: forall q b.
([Double] -> Double) -> [GenQuote q] -> (Quote -> IO b) -> IO b
withMultiCompositeQuote [Double] -> Double
f [GenQuote q]
qs Quote -> IO b
k = ([Double] -> Double)
-> (FunPtr BasketAccumulateFun -> IO b) -> IO b
forall b.
([Double] -> Double)
-> (FunPtr BasketAccumulateFun -> IO b) -> IO b
withBasketAccumulateFun [Double] -> Double
f (\FunPtr BasketAccumulateFun
fp -> [GenQuote q] -> FunPtr BasketAccumulateFun -> IO Quote
forall q. [GenQuote q] -> FunPtr BasketAccumulateFun -> IO Quote
qlMultiCompositeQuoteFromFunction [GenQuote q]
qs FunPtr BasketAccumulateFun
fp IO Quote -> (Quote -> IO b) -> IO b
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Quote -> IO b
k)

-- vim: set ff=unix ts=8 sts=2 sw=2 et:

foreign import ccall safe "QuantLib/Quote.chs.h qlSimpleQuote"
  simpleQuote'_ :: (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CSimpleQuote')))))

foreign import ccall safe "QuantLib/Quote.chs.h qlDeltaVolQuote1"
  deltaVolQuote'_ :: (C2HSImp.CDouble -> ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CDeltaVolQuote'))))))))

foreign import ccall safe "QuantLib/Quote.chs.h qlDeltaVolQuote2"
  atmVolQuote'_ :: ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CDeltaVolQuote'))))))))

foreign import ccall safe "QuantLib/Quote.chs.h qlQuoteValue"
  value'_ :: ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))

foreign import ccall safe "QuantLib/Quote.chs.h qlSimpleQuoteSetValue"
  setValue'_ :: ((C2HSImp.Ptr (CSimpleQuote')) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Quote.chs.h qlEurodollarFuturesImpliedStdDevQuote"
  eurodollarFuturesImpliedStdDevQuote'_ :: ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CQuote')))))))))))

foreign import ccall safe "QuantLib/Quote.chs.h qlForwardSwapQuote"
  forwardSwapQuote'_ :: ((C2HSImp.Ptr (CSwapIndex')) -> ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CQuote'))))))))

foreign import ccall safe "QuantLib/Quote.chs.h qlForwardValueQuote"
  forwardValueQuote'_ :: ((C2HSImp.Ptr (CIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CQuote'))))))

foreign import ccall safe "QuantLib/Quote.chs.h qlFuturesConvAdjustmentQuote1"
  futuresConvAdjustmentQuoteFromImmCode'_ :: ((C2HSImp.Ptr (CIborIndex')) -> ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CFuturesConvAdjustmentQuote')))))))))

foreign import ccall safe "QuantLib/Quote.chs.h qlFuturesConvAdjustmentQuote"
  futuresConvAdjustmentQuote'_ :: ((C2HSImp.Ptr (CIborIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CFuturesConvAdjustmentQuote')))))))))

foreign import ccall safe "QuantLib/Quote.chs.h qlFuturesConvAdjustmentQuoteFuturesValue"
  futuresValue'_ :: ((C2HSImp.Ptr (CFuturesConvAdjustmentQuote')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))

foreign import ccall safe "QuantLib/Quote.chs.h qlImpliedStdDevQuote"
  impliedStdDevQuote'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CQuote')))))))))))

foreign import ccall safe "QuantLib/Quote.chs.h qlLastFixingQuote"
  lastFixingQuote'_ :: ((C2HSImp.Ptr (CIndex')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CQuote')))))

foreign import ccall safe "QuantLib/Quote.chs.h qlQuoteIsValid"
  isValid'_ :: ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CInt)))

foreign import ccall safe "QuantLib/Quote.chs.h qlRelinkableQuote"
  relinkableQuote'_ :: ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CRelinkableQuote')))))

foreign import ccall safe "QuantLib/Quote.chs.h qlRelinkableQuoteLinkTo"
  linkTo'_ :: ((C2HSImp.Ptr (CRelinkableQuote')) -> ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO ()))))

foreign import ccall safe "QuantLib/Quote.chs.h qlDerivedQuote"
  derivedQuote'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CQuote')))))))

foreign import ccall safe "QuantLib/Quote.chs.h qlCompositeQuote"
  compositeQuote'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CQuote')))))))

foreign import ccall safe "QuantLib/Quote.chs.h qlMultiCompositeQuote"
  multiCompositeQuote'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CQuote'))) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CQuote')))))))

foreign import ccall safe "QuantLib/Quote.chs.h qlDerivedQuoteFromFunction"
  qlDerivedQuoteFromFunction'_ :: ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.FunPtr (C2HSImp.CDouble -> (IO C2HSImp.CDouble))) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CQuote'))))))

foreign import ccall safe "QuantLib/Quote.chs.h qlCompositeQuoteFromFunction"
  qlCompositeQuoteFromFunction'_ :: ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.FunPtr (C2HSImp.CDouble -> (C2HSImp.CDouble -> (IO C2HSImp.CDouble)))) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CQuote')))))))

foreign import ccall safe "QuantLib/Quote.chs.h qlMultiCompositeQuoteFromFunction"
  qlMultiCompositeQuoteFromFunction'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CQuote'))) -> ((C2HSImp.FunPtr ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> (IO C2HSImp.CDouble)))) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CQuote')))))))