-- 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
  , fxCashSpotQuote
  , 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 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 = QuoteDivide
  succ QuoteOp
QuoteDivide = 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)

{-# 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" #-}


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


{-# LINE 85 "./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 88 "./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 95 "./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 102 "./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 105 "./QuantLib/Quote.chs" #-}


-- |Set the quote's value. The change propagates to all users of the quote.
setValue :: (SimpleQuote) -> (Double) -> IO ()
setValue a1 a2 =
  withGenQuote a1 $ \a1' -> 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  setValue'_ a1' a2' a3' >>
  errorCheck  a3'>>
  return ()

{-# LINE 108 "./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' -> 
  GenQuote q2 -> (Ptr CQuote' -> IO Quote) -> IO Quote
forall q b. GenQuote q -> (Ptr CQuote' -> IO b) -> IO b
withQuote GenQuote q2
a2 ((Ptr CQuote' -> IO Quote) -> IO Quote)
-> (Ptr CQuote' -> IO Quote) -> IO Quote
forall a b. (a -> b) -> a -> b
$ \Ptr CQuote'
a2' -> 
  GenQuote q3 -> (Ptr CQuote' -> IO Quote) -> IO Quote
forall q b. GenQuote q -> (Ptr CQuote' -> IO b) -> IO b
withQuote GenQuote q3
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' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a4} in 
  let {a5' :: CDouble
a5' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a5} in 
  let {a6' :: CDouble
a6' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a6} in 
  let {a7' :: CUInt
a7' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a7} in 
  (Ptr (Ptr ()) -> IO Quote) -> IO Quote
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO Quote) -> IO Quote)
-> (Ptr (Ptr ()) -> IO Quote) -> IO Quote
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a8' -> 
  Ptr CQuote'
-> Ptr CQuote'
-> Ptr CQuote'
-> CDouble
-> CDouble
-> CDouble
-> CUInt
-> Ptr (Ptr ())
-> IO (Ptr CQuote')
eurodollarFuturesImpliedStdDevQuote'_ Ptr CQuote'
a1' Ptr CQuote'
a2' Ptr CQuote'
a3' CDouble
a4' CDouble
a5' CDouble
a6' CUInt
a7' Ptr (Ptr ())
a8' 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 ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a8'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 118 "./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 123 "./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 126 "./QuantLib/Quote.chs" #-}


-- |The cash value, at the evaluation date @d@, of an FX spot quoted for settlement on
-- @V = advance calendar d settlementDays Days@ (business days; with zero days, @d@ adjusted
-- Following). Its value is
--
-- > S_d = S_V * (P_dom(V) / P_dom(d)) / (P_for(V) / P_for(d))
--
-- with @P@ each curve's discount factor, so a forward built from it,
-- @S_d * (P_for(T) \/ P_for(d)) \/ (P_dom(T) \/ P_dom(d))@, equals @S_V@ at @T = V@. Use it as a
-- Garman-Kohlhagen process's spot when the market quotes spot for settlement rather than cash.
--
-- This class is defined by hasquant, not QuantLib (which has no quote observing yield curves);
-- QuantExt's @FxRateQuote@ is the prior art. It is live: it notifies its observers when the
-- settlement spot, either curve (including a relink) or the evaluation date changes, and recomputes
-- @V@ and every discount factor on each read. A read throws when a curve cannot discount to @d@, for
-- instance when its reference date is after the evaluation date.
fxCashSpotQuote :: (GenQuote q) -- ^settlementSpot: @S_V@, domestic currency per unit of foreign, for settlement on @V@
 -> (GenYieldTermStructure y1) -- ^domesticTS: discounting in the domestic (quote) currency
 -> (GenYieldTermStructure y2) -- ^foreignTS: discounting in the foreign (base) currency
 -> (Calendar) -- ^settlementCalendar: business days that set @V@
 -> (Word) -- ^settlementDays: spot lag in business days from the evaluation date
 -> IO ((Quote))
fxCashSpotQuote :: forall q y1 y2.
GenQuote q
-> GenYieldTermStructure y1
-> GenYieldTermStructure y2
-> Calendar
-> Word
-> IO Quote
fxCashSpotQuote GenQuote q
a1 GenYieldTermStructure y1
a2 GenYieldTermStructure y2
a3 Calendar
a4 Word
a5 =
  GenQuote q -> (Ptr CQuote' -> IO Quote) -> IO Quote
forall q b. GenQuote q -> (Ptr CQuote' -> IO b) -> IO b
withQuote GenQuote q
a1 ((Ptr CQuote' -> IO Quote) -> IO Quote)
-> (Ptr CQuote' -> IO Quote) -> IO Quote
forall a b. (a -> b) -> a -> b
$ \Ptr CQuote'
a1' -> 
  GenYieldTermStructure y1
-> (Ptr CYieldTermStructure' -> IO Quote) -> IO Quote
forall y b.
GenYieldTermStructure y
-> (Ptr CYieldTermStructure' -> IO b) -> IO b
withYieldTermStructure GenYieldTermStructure y1
a2 ((Ptr CYieldTermStructure' -> IO Quote) -> IO Quote)
-> (Ptr CYieldTermStructure' -> IO Quote) -> IO Quote
forall a b. (a -> b) -> a -> b
$ \Ptr CYieldTermStructure'
a2' -> 
  GenYieldTermStructure y2
-> (Ptr CYieldTermStructure' -> IO Quote) -> IO Quote
forall y b.
GenYieldTermStructure y
-> (Ptr CYieldTermStructure' -> IO b) -> IO b
withYieldTermStructure GenYieldTermStructure y2
a3 ((Ptr CYieldTermStructure' -> IO Quote) -> IO Quote)
-> (Ptr CYieldTermStructure' -> IO Quote) -> IO Quote
forall a b. (a -> b) -> a -> b
$ \Ptr CYieldTermStructure'
a3' -> 
  Calendar -> (Ptr CCalendar -> IO Quote) -> IO Quote
forall b. Calendar -> (Ptr CCalendar -> IO b) -> IO b
withCalendar Calendar
a4 ((Ptr CCalendar -> IO Quote) -> IO Quote)
-> (Ptr CCalendar -> IO Quote) -> IO Quote
forall a b. (a -> b) -> a -> b
$ \Ptr CCalendar
a4' -> 
  let {a5' :: CUInt
a5' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a5} in 
  (Ptr (Ptr ()) -> IO Quote) -> IO Quote
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO Quote) -> IO Quote)
-> (Ptr (Ptr ()) -> IO Quote) -> IO Quote
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a6' -> 
  Ptr CQuote'
-> Ptr CYieldTermStructure'
-> Ptr CYieldTermStructure'
-> Ptr CCalendar
-> CUInt
-> Ptr (Ptr ())
-> IO (Ptr CQuote')
fxCashSpotQuote'_ Ptr CQuote'
a1' Ptr CYieldTermStructure'
a2' Ptr CYieldTermStructure'
a3' Ptr CCalendar
a4' CUInt
a5' Ptr (Ptr ())
a6' 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 ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a6'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 148 "./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 155 "./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 162 "./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 165 "./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' -> 
  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' -> 
  impliedStdDevQuote'_ a1' a2' a3' a4' a5' a6' a7' a8' >>= \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 ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a8'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 174 "./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 177 "./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 180 "./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 185 "./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 190 "./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 ()) -> IO Quote) -> IO Quote
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO Quote) -> IO Quote)
-> (Ptr (Ptr ()) -> IO Quote) -> IO Quote
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a4' -> 
  CInt -> Ptr CQuote' -> CDouble -> Ptr (Ptr ()) -> IO (Ptr CQuote')
derivedQuote'_ CInt
a1' Ptr CQuote'
a2' CDouble
a3' Ptr (Ptr ())
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 ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
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 202 "./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 207 "./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 214 "./QuantLib/Quote.chs" #-}


qlDerivedQuoteFromFunction :: (GenQuote q) -> (Callback) -> IO ((Quote))
qlDerivedQuoteFromFunction a1 a2 =
  withQuote a1 $ \a1' -> 
  withCallbackPtr a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  qlDerivedQuoteFromFunction'_ a1' a2' a3' >>= \res ->
  peekQuote res >>= \res' ->
  errorCheck  a3'>>
  return (res')

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

qlCompositeQuoteFromFunction :: (GenQuote q1) -> (GenQuote q2) -> (Callback) -> IO ((Quote))
qlCompositeQuoteFromFunction a1 a2 a3 =
  withQuote a1 $ \a1' -> 
  withQuote a2 $ \a2' -> 
  withCallbackPtr a3 $ \a3' -> 
  preErrorCheck $ \a4' -> 
  qlCompositeQuoteFromFunction'_ a1' a2' a3' a4' >>= \res ->
  peekQuote res >>= \res' ->
  errorCheck  a4'>>
  return (res')

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

qlMultiCompositeQuoteFromFunction :: ([GenQuote q]) -> (Callback) -> IO ((Quote))
qlMultiCompositeQuoteFromFunction a1 a2 =
  withQuoteArray a1 $ \(a1'1, a1'2) -> 
  withCallbackPtr a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  qlMultiCompositeQuoteFromFunction'_ a1'1  a1'2 a2' a3' >>= \res ->
  peekQuote res >>= \res' ->
  errorCheck  a3'>>
  return (res')

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


-- |As 'derivedQuote', with an arbitrary Haskell function.
--
-- The quote and its native dependents retain the callback after the continuation returns.
-- Callback exceptions are rethrown by the enclosing Haskell call.
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
-- ownership and exception 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) -> (Callback -> IO b) -> IO b
forall b.
(Double -> Double -> Double) -> (Callback -> IO b) -> IO b
withQuoteBinaryFun Double -> Double -> Double
f (\Callback
fp -> GenQuote q1 -> GenQuote q2 -> Callback -> IO Quote
forall q1 q2. GenQuote q1 -> GenQuote q2 -> Callback -> IO Quote
qlCompositeQuoteFromFunction GenQuote q1
q1 GenQuote q2
q2 Callback
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 ownership and exception 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) -> (Callback -> IO b) -> IO b
forall b. ([Double] -> Double) -> (Callback -> IO b) -> IO b
withBasketAccumulateFun [Double] -> Double
f (\Callback
fp -> [GenQuote q] -> Callback -> IO Quote
forall q. [GenQuote q] -> Callback -> IO Quote
qlMultiCompositeQuoteFromFunction [GenQuote q]
qs Callback
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 ())) -> (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 ())) -> (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 ())) -> (IO (C2HSImp.Ptr (CDeltaVolQuote'))))))))

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

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

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 ())) -> (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 ())) -> (IO (C2HSImp.Ptr (CQuote'))))))))

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

foreign import ccall safe "QuantLib/Quote.chs.h qlFxCashSpotQuote"
  fxCashSpotQuote'_ :: ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (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 ())) -> (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 ())) -> (IO (C2HSImp.Ptr (CFuturesConvAdjustmentQuote')))))))))

foreign import ccall safe "QuantLib/Quote.chs.h qlFuturesConvAdjustmentQuoteFuturesValue"
  futuresValue'_ :: ((C2HSImp.Ptr (CFuturesConvAdjustmentQuote')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (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 ())) -> (IO (C2HSImp.Ptr (CQuote')))))))))))

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

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

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

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

foreign import ccall safe "QuantLib/Quote.chs.h qlDerivedQuote"
  derivedQuote'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (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 ())) -> (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 ())) -> (IO (C2HSImp.Ptr (CQuote')))))))

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

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

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