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


{-# LINE 1 "./QuantLib/Internal/Common.chs" #-}
{-# LANGUAGE TemplateHaskell, StandaloneDeriving, ExistentialQuantification #-}
-- internal utilities to convert special enums: either complex ones or represented as QuantLib objects that I didn't want to expose so I represented them as ADTs
{-# OPTIONS_GHC -Wno-unused-top-binds #-}
module QuantLib.Internal.Common
  (
    qlInterpolation
  , qlInterpolation'
  , Approximation(..)
  , Interpolation(..)
  , Interpolation2D(..)
  , IterativeBootstrapOpts(..)
  , defaultIterativeBootstrapOpts

  , ExerciseType(..)
  , Exercise(..)
  , QlExercise
  , EuropeanExercise(..)
  , BermudanExercise(..)
  , QlEuropeanExercise
  , QlBermudanExercise
  , SwingExercise(..)
  , QlSwingExercise

  , OptionType(..)
  , PositionType(..)
  , BondPriceType(..)

  , StrikedPayoff(..)
  , PlainVanillaPayoff(..)
  , PercentageStrikePayoff(..)
  , QlPlainVanillaPayoff
  , QlPercentageStrikePayoff
  , QlStrikedTypePayoff
  , Payoff(..)
  , QlPayoff
  , BasketPayoff(..)
  , QlBasketPayoff
  , TypePayoff(..)
  , QlTypePayoff

  , CallabilityType(..)
  , Callability(..)
  , QlCallability

  , Claim(..)
  , QlClaim
  , withClaim

  , FittingMethod(..)
  , QlFittedBondDiscountCurveFittingMethod
  , withFittedBondDiscountCurveFittingMethod

  , FdmSchemeType(..)
  , FdmScheme(..)
  , QlFdmSchemeDesc
  , withFdmSchemeDesc

  , CPIInterpolationType(..)

  , StubIndexSelection(..)
  , withStubIndexSelection
  , OvernightObservation(..)
  , defaultOvernightObservation

  , Constraint(..)
  , QlConstraint
  , withConstraint
  , withMaybeConstraint
  , OptimizationMethod(..)
  , QlOptimizationMethod
  , withOptimizationMethod
  , withMaybeOptimizationMethod
  , EndCriteria(..)
  , QlEndCriteria
  , withEndCriteria
  , withMaybeEndCriteria

  , QlRounding
  , RoundingType(..)
  , Rounding(..)
  , withRounding
  , withMaybeRounding

  , withCallability
  , withCallabilityArray

  , QlLmVolatilityModel
  , LmVolatilityModel(..)
  , QlLmCorrelationModel
  , LmCorrelationModel(..)
  , withLmCorrelationModel
  , withLmVolatilityModel

  , TimeUnit(..)
  , BusinessDayConvention(..)

  , withEuropeanExercise
  , withSwingExercise
  , withBermudanExercise
  , withExercise
  , withPercentageStrikePayoff
  , withPlainVanillaPayoff
  , withStrikedPayoff
  , withTypePayoff
  , withBasketPayoff
  , withPayoff
  , withCustomPayoff
  , withCustomStrikedPayoff
  , withCustomBasketPayoff

  , strikedPayoff
  , percentageStrikePayoff
  , plainVanillaPayoff
  , swingExercise

  , CalibrationBasketType(..)

  , UnitOfMeasureType(..)
  , PaymentTermEventType(..)
  , PricingErrorLevel(..)
  , peekPricingErrorLevelArray
  , DeliverySchedule(..)
  , QuantityPeriodicity(..)

  , AdditionalResultType(..)
  , AdditionalResultVal(..)
  , RawResultPtr
  , RawResult(..)
  , convertResult
  , preAdditionalResults
  , peekAdditionalResults
  ) 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 qualified Foreign.Storable as C2HSImp


import Foreign.Ptr(Ptr, nullPtr, castPtr)
import Foreign.C.Types(CUInt, CInt, CDouble)
import Foreign.C.String(CString, peekCString)
import Foreign.Storable(Storable(..))
import Foreign.Marshal.Utils(withMany)
import Foreign.Marshal.Array(withArray, peekArray)
import Data.List.NonEmpty(NonEmpty, toList)

import QuantLib.Internal
import QuantLib.Internal.Type hiding(ptr)
import QuantLib.Internal.Syntax







-- |Every constructor parameter of QuantLib's curve-generic @IterativeBootstrap@.
-- The first three fields are 'Maybe' because 'Nothing' preserves QuantLib's
-- @Null\<Real\>()@ sentinel, which selects a suitable value for each curve pillar.
$(deriveOptionsRecord "IterativeBootstrapOpts" []
  [ ("ibAccuracy", [t|Maybe Double|], [|Nothing|])
  , ("ibMinValue", [t|Maybe Double|], [|Nothing|])
  , ("ibMaxValue", [t|Maybe Double|], [|Nothing|])
  , ("ibMaxAttempts", [t|Word|], [|1|])
  , ("ibMaxFactor", [t|Double|], [|2.0|])
  , ("ibMinFactor", [t|Double|], [|2.0|])
  , ("ibDontThrow", [t|Bool|], [|False|])
  , ("ibDontThrowSteps", [t|Word|], [|10|])
  , ("ibMaxEvaluations", [t|Word|], [|100|])
  ])

-- this enum is not special, just used in many places and was put here to avoid cyclic dependencies
data TimeUnit = Days
              | Weeks
              | Months
              | Years
              | Hours
              | Minutes
              | Seconds
              | Milliseconds
              | Microseconds
  deriving (Enum,Show,Eq,Read,Bounded)

{-# LINE 167 "./QuantLib/Internal/Common.chs" #-}

-- moved from QuantLib.Time.Calendar, its "natural" home, for the same reason as TimeUnit above --
-- needed directly here for RebatedExercise's rebatePaymentConvention param. Like TimeUnit, every
-- cross-module use marshals through a manual fromEnumC/toEnumC/fromMaybeEnum function rather than
-- a bare c2hs backtick spec: a bare `` `BusinessDayConvention' `` needs the type's own module's
-- .chi already built, which this other-modules-listed module isn't guaranteed to have by the time
-- an early exposed-modules file (e.g. QuantLib.Time.Calendar itself) is processed.
data BusinessDayConvention = Following
                           | ModifiedFollowing
                           | Preceding
                           | ModifiedPreceding
                           | Unadjusted
                           | HalfMonthModifiedFollowing
                           | Nearest
  deriving (Enum,Show,Eq,Read)

{-# LINE 174 "./QuantLib/Internal/Common.chs" #-}

data ApproximationType = Approximation__NaturalSpline
                       | Approximation__Parabolic
                       | Approximation__Kruger
                       | Approximation__FritschButland
  deriving (Enum,Show,Eq,Read)

{-# LINE 175 "./QuantLib/Internal/Common.chs" #-}

data InterpolationType = InterpolationBackwardFlat
                       | InterpolationForwardFlat
                       | InterpolationLinear
                       | InterpolationLogLinear
                       | InterpolationCubic
                       | InterpolationLogCubic
                       | InterpolationAbcd
  deriving (Enum,Show,Eq,Read)

{-# LINE 176 "./QuantLib/Internal/Common.chs" #-}

-- 2-D interpolators for a BlackVarianceSurface. Unlike InterpolationType/ApproximationType
-- above (merged into the public Interpolation ADT by deriveCrossEnum), this enum is itself the
-- public type: setInterpolation on a surface is a member template over a default-constructed
-- interpolator, so there is no approximator to pair it with. Declared here rather than in
-- QuantLib.TermStructure.Volatility for the usual cross-module {#import#} ordering reason.
data Interpolation2D = Bilinear
                     | Bicubic
  deriving (Enum,Show,Eq,Read,Bounded)

{-# LINE 182 "./QuantLib/Internal/Common.chs" #-}

data ExerciseType = ExerciseTypeAmerican
                  | ExerciseTypeBermudan
                  | ExerciseTypeEuropean
  deriving (Enum,Show,Eq,Read)

{-# LINE 183 "./QuantLib/Internal/Common.chs" #-}

data OptionType = Put
                | Call
  deriving (Show,Eq,Read)
instance Enum OptionType where
  succ Put = Call
  succ Call = error "OptionType.succ: Call has no successor"

  pred Call = Put
  pred Put = error "OptionType.pred: Put 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 Call

  fromEnum Put = (-1)
  fromEnum Call = 1

  toEnum (-1) = Put
  toEnum 1 = Call
  toEnum unmatched = error ("OptionType.toEnum: Cannot match " ++ show unmatched)

{-# LINE 184 "./QuantLib/Internal/Common.chs" #-}

data PositionType = Long
                  | Short
  deriving (Enum,Show,Eq,Read)

{-# LINE 185 "./QuantLib/Internal/Common.chs" #-}

data BondPriceType = Dirty
                   | Clean
  deriving (Enum,Show,Eq,Read)

{-# LINE 186 "./QuantLib/Internal/Common.chs" #-}

data CallabilityType = CallabilityCall
                     | CallabilityPut
  deriving (Enum,Show,Eq,Read)

{-# LINE 187 "./QuantLib/Internal/Common.chs" #-}

data FdmSchemeType = HundsdorferType
                   | DouglasType
                   | CraigSneydType
                   | ModifiedCraigSneydType
                   | ImplicitEulerType
                   | ExplicitEulerType
                   | MethodOfLinesType
                   | TrBDF2Type
                   | CrankNicolsonType
  deriving (Enum,Show,Eq,Read)

{-# LINE 188 "./QuantLib/Internal/Common.chs" #-}

data RoundingType = None
                  | Up
                  | Down
                  | Closest
                  | Floor
                  | Ceiling
  deriving (Enum,Show,Eq,Read)

{-# LINE 189 "./QuantLib/Internal/Common.chs" #-}

-- experimental/commodities: cross-cutting the same way TimeUnit is (UnitOfMeasureType is used by
-- both UnitOfMeasure itself and, in a later stage, CommodityPricingHelper/EnergyCommodity).
-- Quantity's C tag is renamed QuantityUnit in cbits/qlEnumC2HS.h to avoid colliding with the
-- Quantity class bound in QuantLib.Commodity.
data UnitOfMeasureType = Mass
                       | Volume
                       | Energy
                       | QuantityUnit
  deriving (Enum,Show,Eq,Read,Bounded)

{-# LINE 194 "./QuantLib/Internal/Common.chs" #-}

data PaymentTermEventType = TradeDate
                          | PricingDate
  deriving (Enum,Show,Eq,Read,Bounded)

{-# LINE 195 "./QuantLib/Internal/Common.chs" #-}

-- experimental/commodities/commodity.hpp (PricingError::Level) and
-- experimental/commodities/energycommodity.hpp (EnergyCommodity::DeliverySchedule,
-- EnergyCommodity::QuantityPeriodicity), homed here for the same cross-cutting reason as
-- UnitOfMeasureType above (used by both EnergyCommodity's leaf constructors and
-- CommodityPricingHelper::createPricingPeriods, both in QuantLib.Instrument.Energy -- a later
-- stage than this module).
data PricingErrorLevel = Info
                       | Warning
                       | Error
                       | Fatal
  deriving (Enum,Show,Eq,Read,Bounded)

{-# LINE 202 "./QuantLib/Internal/Common.chs" #-}

peekPricingErrorLevelArray :: Ptr CUInt -> Ptr (Ptr CInt) -> IO [PricingErrorLevel]
peekPricingErrorLevelArray = peekIntArray' toEnumC
-- Prefix these tags to avoid clashes with QuantLib.Time.Schedule's Frequency constructors.
data DeliverySchedule = DeliveryConstant
                      | DeliveryWindow
                      | DeliveryHourly
                      | DeliveryDaily
                      | DeliveryWeekly
                      | DeliveryMonthly
                      | DeliveryQuarterly
                      | DeliveryYearly
  deriving (Enum,Show,Eq,Read,Bounded)

{-# LINE 206 "./QuantLib/Internal/Common.chs" #-}

data QuantityPeriodicity = Absolute
                         | PerHour
                         | PerDay
                         | PerWeek
                         | PerMonth
                         | PerQuarter
                         | PerYear
  deriving (Enum,Show,Eq,Read,Bounded)

{-# LINE 207 "./QuantLib/Internal/Common.chs" #-}

-- CPI interpolation skips upstream's deprecated AsIndex value, so the enum starts at 1.
-- Shared users import it from here to avoid a module cycle.
data CPIInterpolationType = CPIFlat
                          | CPILinear
  deriving (Show,Eq,Read,Bounded)
instance Enum CPIInterpolationType where
  succ CPIFlat = CPILinear
  succ CPILinear = error "CPIInterpolationType.succ: CPILinear has no successor"

  pred CPILinear = CPIFlat
  pred CPIFlat = error "CPIInterpolationType.pred: CPIFlat 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 CPILinear

  fromEnum :: CPIInterpolationType -> Int
fromEnum CPIInterpolationType
CPIFlat = Int
1
  fromEnum CPIInterpolationType
CPILinear = Int
2

  toEnum :: Int -> CPIInterpolationType
toEnum Int
1 = CPIInterpolationType
CPIFlat
  toEnum Int
2 = CPIInterpolationType
CPILinear
  toEnum Int
unmatched = String -> CPIInterpolationType
forall a. HasCallStack => String -> a
error (String
"CPIInterpolationType.toEnum: Cannot match " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
unmatched)

{-# LINE 210 "./QuantLib/Internal/Common.chs" #-}

data CalibrationBasketType = CalibrationBasketNaive
                           | MaturityStrikeByDeltaGamma
  deriving (Enum,Show,Eq,Read,Bounded)

{-# LINE 211 "./QuantLib/Internal/Common.chs" #-}


-- |How an overnight leg observes its index fixings. Shared by every overnight-leg producer:
-- the swap constructors, the OIS rate helpers, and the cross-currency swaps. 'lookbackDays'
-- is 'Nothing' for upstream's @Null@ default, meaning the index's own fixing days.
--
-- Declared here rather than in a topical module because its producers span
-- "QuantLib.Instrument.Swap" and "QuantLib.TermStructure.Yield", whose build order cannot
-- accommodate one importing the other.
data OvernightObservation = OvernightObservation
  { lookbackDays :: !(Maybe Word)
  , lockoutDays :: !Word
  , applyObservationShift :: !Bool
  } deriving (Eq, Show)

-- |Upstream's own defaults: index fixing days, no lockout, no observation shift.
defaultOvernightObservation :: OvernightObservation
defaultOvernightObservation = OvernightObservation Nothing 0 False

-- Payoff/Exercise pointer hierarchy: the Finalizable/Upcastable instances and raw phantom
-- tags (CPayoff' etc.) live in QuantLib.Internal.Type alongside every other class hierarchy;
-- these are just c2hs-local aliases so {#fun#} specs below can keep writing the bare `QlX'
-- names, resolving to a raw, unwrapped Ptr (no auto-generated foreign-pointer code) since
-- construction/upcasting is handled by hand in the with* functions further down.
type QlPayoff = Ptr CPayoff'
type QlBasketPayoff = Ptr CBasketPayoff'
type QlTypePayoff = Ptr CTypePayoff'
type QlStrikedTypePayoff = Ptr CStrikedTypePayoff'
type QlPercentageStrikePayoff = Ptr CPercentageStrikePayoff'
type QlPlainVanillaPayoff = Ptr CPlainVanillaPayoff'
type QlExercise = Ptr CExercise'
type QlEuropeanExercise = Ptr CEuropeanExercise'
type QlAmericanExercise = Ptr CAmericanExercise'
type QlSwingExercise = Ptr CSwingExercise'
type QlBermudanExercise = Ptr CBermudanExercise'
type QlRebatedExercise = Ptr CRebatedExercise'
-- identity peek function: c2hs {#fun#} return specs always need a named out-marshaller,
-- even when (as here) construction should just hand back the raw, un-wrapped pointer.
peekPtr :: Ptr a -> IO (Ptr a)
peekPtr :: forall a. Ptr a -> IO (Ptr a)
peekPtr = Ptr a -> IO (Ptr a)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure

{-# LINE 251 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 252 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 253 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 254 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 255 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 256 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 257 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 258 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 259 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 260 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 261 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 262 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 263 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 264 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 265 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 266 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 267 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 268 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 269 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 270 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 271 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 272 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 273 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 274 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 275 "./QuantLib/Internal/Common.chs" #-}


-- |Discriminants for `QlAdditionalResult.type`, bound from `enum AdditionalResultType` in
-- `cbits/qlInstrument.h` (read from the header, not hardcoded).
data AdditionalResultType = AdditionalResultDouble
                          | AdditionalResultString
                          | AdditionalResultDoubleVector
                          | AdditionalResultUnknown
  deriving (Int -> AdditionalResultType -> ShowS
[AdditionalResultType] -> ShowS
AdditionalResultType -> String
(Int -> AdditionalResultType -> ShowS)
-> (AdditionalResultType -> String)
-> ([AdditionalResultType] -> ShowS)
-> Show AdditionalResultType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AdditionalResultType -> ShowS
showsPrec :: Int -> AdditionalResultType -> ShowS
$cshow :: AdditionalResultType -> String
show :: AdditionalResultType -> String
$cshowList :: [AdditionalResultType] -> ShowS
showList :: [AdditionalResultType] -> ShowS
Show,AdditionalResultType -> AdditionalResultType -> Bool
(AdditionalResultType -> AdditionalResultType -> Bool)
-> (AdditionalResultType -> AdditionalResultType -> Bool)
-> Eq AdditionalResultType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AdditionalResultType -> AdditionalResultType -> Bool
== :: AdditionalResultType -> AdditionalResultType -> Bool
$c/= :: AdditionalResultType -> AdditionalResultType -> Bool
/= :: AdditionalResultType -> AdditionalResultType -> Bool
Eq,ReadPrec [AdditionalResultType]
ReadPrec AdditionalResultType
Int -> ReadS AdditionalResultType
ReadS [AdditionalResultType]
(Int -> ReadS AdditionalResultType)
-> ReadS [AdditionalResultType]
-> ReadPrec AdditionalResultType
-> ReadPrec [AdditionalResultType]
-> Read AdditionalResultType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS AdditionalResultType
readsPrec :: Int -> ReadS AdditionalResultType
$creadList :: ReadS [AdditionalResultType]
readList :: ReadS [AdditionalResultType]
$creadPrec :: ReadPrec AdditionalResultType
readPrec :: ReadPrec AdditionalResultType
$creadListPrec :: ReadPrec [AdditionalResultType]
readListPrec :: ReadPrec [AdditionalResultType]
Read)
instance Enum AdditionalResultType where
  succ :: AdditionalResultType -> AdditionalResultType
succ AdditionalResultType
AdditionalResultDouble = AdditionalResultType
AdditionalResultString
  succ AdditionalResultType
AdditionalResultString = AdditionalResultType
AdditionalResultDoubleVector
  succ AdditionalResultType
AdditionalResultDoubleVector = AdditionalResultType
AdditionalResultUnknown
  succ AdditionalResultType
AdditionalResultUnknown = String -> AdditionalResultType
forall a. HasCallStack => String -> a
error String
"AdditionalResultType.succ: AdditionalResultUnknown has no successor"

  pred AdditionalResultString = AdditionalResultDouble
  pred AdditionalResultDoubleVector = AdditionalResultString
  pred AdditionalResultUnknown = AdditionalResultDoubleVector
  pred AdditionalResultDouble = error "AdditionalResultType.pred: AdditionalResultDouble has no predecessor"

  enumFromTo :: AdditionalResultType
-> AdditionalResultType -> [AdditionalResultType]
enumFromTo AdditionalResultType
from AdditionalResultType
to = AdditionalResultType -> [AdditionalResultType]
forall {t}. Enum t => t -> [t]
go AdditionalResultType
from
    where
      end :: Int
end = AdditionalResultType -> Int
forall a. Enum a => a -> Int
fromEnum AdditionalResultType
to
      go :: t -> [t]
go t
v = case Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (t -> Int
forall a. Enum a => a -> Int
fromEnum t
v) Int
end of
                 Ordering
LT -> t
v t -> [t] -> [t]
forall a. a -> [a] -> [a]
: t -> [t]
go (t -> t
forall a. Enum a => a -> a
succ t
v)
                 Ordering
EQ -> [t
v]
                 Ordering
GT -> []

  enumFrom :: AdditionalResultType -> [AdditionalResultType]
enumFrom AdditionalResultType
from = AdditionalResultType
-> AdditionalResultType -> [AdditionalResultType]
forall a. Enum a => a -> a -> [a]
enumFromTo AdditionalResultType
from AdditionalResultType
AdditionalResultUnknown

  fromEnum AdditionalResultDouble = 0
  fromEnum AdditionalResultString = 1
  fromEnum AdditionalResultDoubleVector = 2
  fromEnum AdditionalResultUnknown = 3

  toEnum :: Int -> AdditionalResultType
toEnum Int
0 = AdditionalResultType
AdditionalResultDouble
  toEnum Int
1 = AdditionalResultType
AdditionalResultString
  toEnum 2 = AdditionalResultDoubleVector
  toEnum Int
3 = AdditionalResultType
AdditionalResultUnknown
  toEnum Int
unmatched = String -> AdditionalResultType
forall a. HasCallStack => String -> a
error (String
"AdditionalResultType.toEnum: Cannot match " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
unmatched)

{-# LINE 279 "./QuantLib/Internal/Common.chs" #-}


-- monotonic flag for CubicInterpolation::Spline/::Parabolic -- tells deriveCrossEnum to give
-- these two values a runtime Bool field instead of cross-producting named sub-values (same
-- pattern as Actual360Convention etc. in CalendarEnum.chs). Order matters here in a way it
-- doesn't for the ApproximationType enum itself: these two type synonyms (and ApproximationExtra
-- below) must be declared textually *above* the deriveCrossEnum splice, since a TH splice can
-- only see top-level declarations that already exist earlier in the same module -- classifySub's
-- lookupTypeName would silently miss them (falling back to NoSub, dropping the Bool field) if
-- they were moved below the splice.
type NaturalSplineMonotonic = Bool
type ParabolicMonotonic = Bool

-- every Approximation case is driven by ApproximationType itself, so unlike
-- CalendarExtra/DayCounterExtra/IborExtra there are no non-enum-driven cases to add here
data ApproximationExtra

$(deriveCrossEnum CrossEnumSpec
    { crossTypeName = "Approximation"
    , crossMapperFn = "qlApproximation"
    , crossMainEnum = ''ApproximationType
    , crossSubSuffix = "Monotonic"
    , crossExtraType = ''ApproximationExtra
    })

deriving instance Show Approximation
deriving instance Eq Approximation
deriving instance Read Approximation

-- Approximation and interpolation dispatch through `qlTermStructureAux.cpp` rather than a factory
-- table. New enum values need no Haskell change, but `dispatchInterpolation` (and `makeCubic` for
-- an approximation) still needs a matching C++ case; otherwise QuantLib fails at runtime.

qlInterpolation :: Interpolation -> (Int, (Int, Int))
qlInterpolation BackwardFlat = (fromEnum InterpolationBackwardFlat, (0, 0))
qlInterpolation ForwardFlat = (fromEnum InterpolationForwardFlat, (0, 0))
qlInterpolation Linear = (fromEnum InterpolationLinear, (0, 0))
qlInterpolation LogLinear = (fromEnum InterpolationLogLinear, (0, 0))
qlInterpolation (Cubic x) = (fromEnum InterpolationCubic, qlApproximation x)
qlInterpolation (LogCubic x) = (fromEnum InterpolationLogCubic, qlApproximation x)
qlInterpolation Abcd = (fromEnum InterpolationAbcd, (0, 0))

qlInterpolation' :: Maybe Interpolation -> (Int, (Int, Int))
qlInterpolation' :: Maybe Interpolation -> (Int, (Int, Int))
qlInterpolation' Maybe Interpolation
Nothing = (CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
qlNullInteger, (Int
0, Int
0))
qlInterpolation' (Just Interpolation
i) = Interpolation -> (Int, (Int, Int))
qlInterpolation Interpolation
i

data Interpolation =
  BackwardFlat
  | ForwardFlat
  | Linear
  | LogLinear
  | Cubic !Approximation
  | LogCubic !Approximation
  | Abcd
  deriving (Int -> Interpolation -> ShowS
[Interpolation] -> ShowS
Interpolation -> String
(Int -> Interpolation -> ShowS)
-> (Interpolation -> String)
-> ([Interpolation] -> ShowS)
-> Show Interpolation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Interpolation -> ShowS
showsPrec :: Int -> Interpolation -> ShowS
$cshow :: Interpolation -> String
show :: Interpolation -> String
$cshowList :: [Interpolation] -> ShowS
showList :: [Interpolation] -> ShowS
Show, Interpolation -> Interpolation -> Bool
(Interpolation -> Interpolation -> Bool)
-> (Interpolation -> Interpolation -> Bool) -> Eq Interpolation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Interpolation -> Interpolation -> Bool
== :: Interpolation -> Interpolation -> Bool
$c/= :: Interpolation -> Interpolation -> Bool
/= :: Interpolation -> Interpolation -> Bool
Eq)

data EuropeanExercise = EuropeanExercise Day

-- | Use 'swingExerice' to construct 'Exercise'
data SwingExercise =
    SwingListExercise !(NonEmpty (Day, Word)) -- ^(dates, seconds)
    | SwingIntervalExercise !Day !Day !Word -- ^stepSizeSecs
data BermudanExercise =
    BermudanExercise !(NonEmpty Day) !Bool
    | Swing SwingExercise

-- | > Exercise
-- >  American
-- >  Early
-- >  Vanilla
-- >  EuropeanExercise
-- >  BermudanExercise
-- >    SwingExercise
-- >  Rebated (wraps another Exercise)
data Exercise =
    American
      !(Maybe Day) -- ^earliestDate
      !Day -- ^latestDate
      !Bool -- ^paoffAtExpiry
    | Early !ExerciseType !Bool
    | Vanilla !ExerciseType
    | European !EuropeanExercise
    | Bermudan !BermudanExercise
    | Rebated
        !Exercise -- ^wrapped exercise
        !Double -- ^rebate
        !Word -- ^rebateSettlementDays
        !Calendar -- ^rebatePaymentCalendar
        !BusinessDayConvention -- ^rebatePaymentConvention

-- |Candidate indices for broken IBOR periods, selected by nearest maturity or interpolated
-- between bracketing maturities in calendar days. Candidates keep their own curves and histories.
-- Their currency, fixing days/calendar and day counter must match; enable indexed coupons
-- when supplying a selection. Requires QuantLib 1.44.
data StubIndexSelection ibor
  = ClosestStubIndex !(NonEmpty (GenIborIndex ibor))
  | InterpolatedStubIndexes !(NonEmpty (GenIborIndex ibor))

type StubSelectionPtr = Ptr CStubIndexSelection'

{-# LINE 378 "./QuantLib/Internal/Common.chs" #-}


{-# LINE 379 "./QuantLib/Internal/Common.chs" #-}


withStubIndexSelection :: Maybe (StubIndexSelection ibor) -> (Ptr CStubIndexSelection' -> IO r) -> IO r
withStubIndexSelection :: forall ibor r.
Maybe (StubIndexSelection ibor)
-> (Ptr CStubIndexSelection' -> IO r) -> IO r
withStubIndexSelection Maybe (StubIndexSelection ibor)
Nothing Ptr CStubIndexSelection' -> IO r
f = Ptr CStubIndexSelection' -> IO r
f Ptr CStubIndexSelection'
forall a. Ptr a
nullPtr
withStubIndexSelection (Just StubIndexSelection ibor
selection) Ptr CStubIndexSelection' -> IO r
f = case StubIndexSelection ibor
selection of
  ClosestStubIndex NonEmpty (GenIborIndex ibor)
indices -> IO (Ptr CStubIndexSelection')
-> (Ptr CStubIndexSelection' -> IO r) -> IO r
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (Int -> [GenIborIndex ibor] -> IO (Ptr CStubIndexSelection')
forall ibor.
Int -> [GenIborIndex ibor] -> IO (Ptr CStubIndexSelection')
stubIndexSelectionRaw Int
0 (NonEmpty (GenIborIndex ibor) -> [GenIborIndex ibor]
forall a. NonEmpty a -> [a]
toList NonEmpty (GenIborIndex ibor)
indices)) Ptr CStubIndexSelection' -> IO r
f
  InterpolatedStubIndexes NonEmpty (GenIborIndex ibor)
indices -> IO (Ptr CStubIndexSelection')
-> (Ptr CStubIndexSelection' -> IO r) -> IO r
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (Int -> [GenIborIndex ibor] -> IO (Ptr CStubIndexSelection')
forall ibor.
Int -> [GenIborIndex ibor] -> IO (Ptr CStubIndexSelection')
stubIndexSelectionRaw Int
1 (NonEmpty (GenIborIndex ibor) -> [GenIborIndex ibor]
forall a. NonEmpty a -> [a]
toList NonEmpty (GenIborIndex ibor)
indices)) Ptr CStubIndexSelection' -> IO r
f

qlExercise :: (ExerciseType) -> IO ((QlExercise))
qlExercise :: ExerciseType -> IO QlExercise
qlExercise ExerciseType
a1 =
  let {a1' :: CInt
a1' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (ExerciseType -> Int) -> ExerciseType -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExerciseType -> Int
forall a. Enum a => a -> Int
fromEnum) ExerciseType
a1} in 
  (Ptr (Ptr ()) -> IO QlExercise) -> IO QlExercise
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO QlExercise) -> IO QlExercise)
-> (Ptr (Ptr ()) -> IO QlExercise) -> IO QlExercise
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a2' -> 
  CInt -> Ptr (Ptr ()) -> IO QlExercise
qlExercise'_ CInt
a1' Ptr (Ptr ())
a2' IO QlExercise -> (QlExercise -> IO QlExercise) -> IO QlExercise
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \QlExercise
res ->
  QlExercise -> IO QlExercise
forall a. Ptr a -> IO (Ptr a)
peekPtr QlExercise
res IO QlExercise -> (QlExercise -> IO QlExercise) -> IO QlExercise
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \QlExercise
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a2'IO () -> IO QlExercise -> IO QlExercise
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  QlExercise -> IO QlExercise
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (QlExercise
res')

{-# LINE 387 "./QuantLib/Internal/Common.chs" #-}

qlAmericanExercise :: (Day) -> (Day) -> (Bool) -> IO ((QlAmericanExercise))
qlAmericanExercise a1 a2 a3 =
  withDay a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  let {a3' = C2HSImp.fromBool a3} in 
  preErrorCheck $ \a4' -> 
  qlAmericanExercise'_ a1' a2' a3' a4' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a4'>>
  return (res')

{-# LINE 388 "./QuantLib/Internal/Common.chs" #-}

qlAmericanExercise1 :: (Day) -> (Bool) -> IO ((QlAmericanExercise))
qlAmericanExercise1 a1 a2 =
  withDay a1 $ \a1' -> 
  let {a2' = C2HSImp.fromBool a2} in 
  preErrorCheck $ \a3' -> 
  qlAmericanExercise1'_ a1' a2' a3' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 389 "./QuantLib/Internal/Common.chs" #-}

qlBermudanExercise :: ([Day]) -> (Bool) -> IO ((QlBermudanExercise))
qlBermudanExercise a1 a2 =
  withDayArray a1 $ \(a1'1, a1'2) -> 
  let {a2' = C2HSImp.fromBool a2} in 
  preErrorCheck $ \a3' -> 
  qlBermudanExercise'_ a1'1  a1'2 a2' a3' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 390 "./QuantLib/Internal/Common.chs" #-}

qlEarlyExercise :: (ExerciseType) -> (Bool) -> IO ((QlExercise))
qlEarlyExercise a1 a2 =
  let {a1' = (fromIntegral . fromEnum) a1} in 
  let {a2' = C2HSImp.fromBool a2} in 
  preErrorCheck $ \a3' -> 
  qlEarlyExercise'_ a1' a2' a3' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 391 "./QuantLib/Internal/Common.chs" #-}

qlEuropeanExercise :: (Day) -> IO ((QlEuropeanExercise))
qlEuropeanExercise a1 =
  withDay a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  qlEuropeanExercise'_ a1' a2' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 392 "./QuantLib/Internal/Common.chs" #-}

qlSwingExercise :: ([Day]) -> ([Word]) -> IO ((QlSwingExercise))
qlSwingExercise a1 a2 =
  withDayArray a1 $ \(a1'1, a1'2) -> 
  withIntArray a2 $ \(a2'1, a2'2) -> 
  preErrorCheck $ \a3' -> 
  qlSwingExercise'_ a1'1  a1'2 a2'1  a2'2 a3' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 393 "./QuantLib/Internal/Common.chs" #-}

qlSwingExercise1 :: (Day) -> (Day) -> (Word) -> IO ((QlSwingExercise))
qlSwingExercise1 a1 a2 a3 =
  withDay a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  let {a3' = fromIntegral a3} in 
  preErrorCheck $ \a4' -> 
  qlSwingExercise1'_ a1' a2' a3' a4' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a4'>>
  return (res')

{-# LINE 394 "./QuantLib/Internal/Common.chs" #-}

qlRebatedExercise :: (QlExercise) -> (Double) -> (Word) -> (Calendar) -> (BusinessDayConvention) -> IO ((QlRebatedExercise))
qlRebatedExercise a1 a2 a3 a4 a5 =
  let {a1' = id a1} in 
  let {a2' = realToFrac a2} in 
  let {a3' = fromIntegral a3} in 
  withCalendar a4 $ \a4' -> 
  let {a5' = fromEnumC a5} in 
  preErrorCheck $ \a6' -> 
  qlRebatedExercise'_ a1' a2' a3' a4' a5' a6' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a6'>>
  return (res')

{-# LINE 395 "./QuantLib/Internal/Common.chs" #-}


withEuropeanExercise :: EuropeanExercise -> (QlEuropeanExercise -> IO a) -> IO a
withEuropeanExercise (EuropeanExercise d) f = withConstructed (qlEuropeanExercise d) f

withSwingExercise :: SwingExercise -> (QlSwingExercise -> IO a) -> IO a
withSwingExercise (SwingListExercise ds) f = withConstructed (uncurry qlSwingExercise (unzip (toList ds))) f
withSwingExercise (SwingIntervalExercise d1 d2 s) f = withConstructed (qlSwingExercise1 d1 d2 s) f

withBermudanExercise :: BermudanExercise -> (QlBermudanExercise -> IO a) -> IO a
withBermudanExercise (BermudanExercise d p) f = withConstructed (qlBermudanExercise (toList d) p) f
withBermudanExercise (Swing e) f = withSwingExercise e (\sp -> withUpcast sp f)

withExercise :: Exercise -> (QlExercise -> IO a) -> IO a
withExercise :: forall a. Exercise -> (QlExercise -> IO a) -> IO a
withExercise (American Maybe Day
Nothing Day
d Bool
p) QlExercise -> IO a
f = IO (Ptr CAmericanExercise')
-> (Ptr (Base CAmericanExercise') -> IO a) -> IO a
forall a b.
(Finalizable a, Upcastable a, Finalizable (Base a)) =>
IO (Ptr a) -> (Ptr (Base a) -> IO b) -> IO b
withConstructedUpcast (Day -> Bool -> IO (Ptr CAmericanExercise')
qlAmericanExercise1 Day
d Bool
p) QlExercise -> IO a
Ptr (Base CAmericanExercise') -> IO a
f
withExercise (American (Just Day
d0) Day
d Bool
p) QlExercise -> IO a
f = IO (Ptr CAmericanExercise')
-> (Ptr (Base CAmericanExercise') -> IO a) -> IO a
forall a b.
(Finalizable a, Upcastable a, Finalizable (Base a)) =>
IO (Ptr a) -> (Ptr (Base a) -> IO b) -> IO b
withConstructedUpcast (Day -> Day -> Bool -> IO (Ptr CAmericanExercise')
qlAmericanExercise Day
d0 Day
d Bool
p) QlExercise -> IO a
Ptr (Base CAmericanExercise') -> IO a
f
withExercise (Early ExerciseType
t Bool
p) QlExercise -> IO a
f = IO QlExercise -> (QlExercise -> IO a) -> IO a
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (ExerciseType -> Bool -> IO QlExercise
qlEarlyExercise ExerciseType
t Bool
p) QlExercise -> IO a
f
withExercise (Vanilla ExerciseType
t) QlExercise -> IO a
f = IO QlExercise -> (QlExercise -> IO a) -> IO a
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (ExerciseType -> IO QlExercise
qlExercise ExerciseType
t) QlExercise -> IO a
f
withExercise (European EuropeanExercise
e) QlExercise -> IO a
f = EuropeanExercise -> (QlEuropeanExercise -> IO a) -> IO a
forall a. EuropeanExercise -> (QlEuropeanExercise -> IO a) -> IO a
withEuropeanExercise EuropeanExercise
e (\QlEuropeanExercise
ep -> QlEuropeanExercise
-> (Ptr (Base CEuropeanExercise') -> IO a) -> IO a
forall a b.
(Upcastable a, Finalizable (Base a)) =>
Ptr a -> (Ptr (Base a) -> IO b) -> IO b
withUpcast QlEuropeanExercise
ep QlExercise -> IO a
Ptr (Base CEuropeanExercise') -> IO a
f)
withExercise (Bermudan BermudanExercise
e) QlExercise -> IO a
f = BermudanExercise -> (QlBermudanExercise -> IO a) -> IO a
forall a. BermudanExercise -> (QlBermudanExercise -> IO a) -> IO a
withBermudanExercise BermudanExercise
e (\QlBermudanExercise
bp -> QlBermudanExercise
-> (Ptr (Base CBermudanExercise') -> IO a) -> IO a
forall a b.
(Upcastable a, Finalizable (Base a)) =>
Ptr a -> (Ptr (Base a) -> IO b) -> IO b
withUpcast QlBermudanExercise
bp QlExercise -> IO a
Ptr (Base CBermudanExercise') -> IO a
f)
withExercise (Rebated Exercise
e Double
rebate Word
days Calendar
cal BusinessDayConvention
bdc) QlExercise -> IO a
f = Exercise -> (QlExercise -> IO a) -> IO a
forall a. Exercise -> (QlExercise -> IO a) -> IO a
withExercise Exercise
e (\QlExercise
ep -> IO (Ptr CRebatedExercise')
-> (Ptr (Base CRebatedExercise') -> IO a) -> IO a
forall a b.
(Finalizable a, Upcastable a, Finalizable (Base a)) =>
IO (Ptr a) -> (Ptr (Base a) -> IO b) -> IO b
withConstructedUpcast (QlExercise
-> Double
-> Word
-> Calendar
-> BusinessDayConvention
-> IO (Ptr CRebatedExercise')
qlRebatedExercise QlExercise
ep Double
rebate Word
days Calendar
cal BusinessDayConvention
bdc) QlExercise -> IO a
Ptr (Base CRebatedExercise') -> IO a
f)

-- | use 'percentageStrikePayoff' to construct 'Payoff'
data PercentageStrikePayoff = PercentageStrikePayoff
      !OptionType -- ^type
      !Double -- ^moneyness

-- | use 'plainVanillaPayoff' to construct 'Payoff'
data PlainVanillaPayoff = PlainVanillaPayoff
      !OptionType -- ^type
      !Double -- ^strike

-- | use 'strikedPayoff' to construct 'Payoff'
data StrikedPayoff =
  AssetOrNothing
    !OptionType -- ^type
    !Double -- ^strike
  | CashOrNothing
      !OptionType -- ^type
      !Double -- ^strike
      !Double -- ^cashPayoff
  | Gap
      !OptionType -- ^type
      !Double -- ^strike
      !Double -- ^secondStrike
  | PercentageStrike !PercentageStrikePayoff
  | PlainVanilla !PlainVanillaPayoff
  | SuperFund
      !Double -- ^strike
      !Double -- ^secondStrike
  | SuperSharePayoff
      !Double -- ^strike
      !Double -- ^secondStrike
      !Double -- ^cashPayoff
  -- |A Haskell-defined payoff carrying an advisory @(type, strike)@ pair. Build it with
  -- 'withCustomStrikedPayoff'.
  | CustomStriked
      !OptionType -- ^type
      !Double -- ^strike
      !String -- ^name
      !Callback

withPercentageStrikePayoff :: PercentageStrikePayoff -> (QlPercentageStrikePayoff -> IO a) -> IO a
withPercentageStrikePayoff :: forall a.
PercentageStrikePayoff
-> (QlPercentageStrikePayoff -> IO a) -> IO a
withPercentageStrikePayoff (PercentageStrikePayoff OptionType
t Double
m) QlPercentageStrikePayoff -> IO a
f = IO QlPercentageStrikePayoff
-> (QlPercentageStrikePayoff -> IO a) -> IO a
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (OptionType -> Double -> IO QlPercentageStrikePayoff
qlPercentageStrikePayoff OptionType
t Double
m) QlPercentageStrikePayoff -> IO a
f

withPlainVanillaPayoff :: PlainVanillaPayoff -> (QlPlainVanillaPayoff -> IO a) -> IO a
withPlainVanillaPayoff :: forall a.
PlainVanillaPayoff -> (QlPlainVanillaPayoff -> IO a) -> IO a
withPlainVanillaPayoff (PlainVanillaPayoff OptionType
t Double
s) QlPlainVanillaPayoff -> IO a
f = IO QlPlainVanillaPayoff -> (QlPlainVanillaPayoff -> IO a) -> IO a
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (OptionType -> Double -> IO QlPlainVanillaPayoff
qlPlainVanillaPayoff OptionType
t Double
s) QlPlainVanillaPayoff -> IO a
f

withStrikedPayoff :: StrikedPayoff -> (QlStrikedTypePayoff -> IO a) -> IO a
withStrikedPayoff :: forall a. StrikedPayoff -> (QlStrikedTypePayoff -> IO a) -> IO a
withStrikedPayoff (AssetOrNothing OptionType
t Double
s) QlStrikedTypePayoff -> IO a
f = IO QlStrikedTypePayoff -> (QlStrikedTypePayoff -> IO a) -> IO a
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (OptionType -> Double -> IO QlStrikedTypePayoff
qlAssetOrNothingPayoff OptionType
t Double
s) QlStrikedTypePayoff -> IO a
f
withStrikedPayoff (CashOrNothing OptionType
t Double
s Double
c) QlStrikedTypePayoff -> IO a
f = IO QlStrikedTypePayoff -> (QlStrikedTypePayoff -> IO a) -> IO a
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (OptionType -> Double -> Double -> IO QlStrikedTypePayoff
qlCashOrNothingPayoff OptionType
t Double
s Double
c) QlStrikedTypePayoff -> IO a
f
withStrikedPayoff (Gap OptionType
t Double
s Double
ss) QlStrikedTypePayoff -> IO a
f = IO QlStrikedTypePayoff -> (QlStrikedTypePayoff -> IO a) -> IO a
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (OptionType -> Double -> Double -> IO QlStrikedTypePayoff
qlGapPayoff OptionType
t Double
s Double
ss) QlStrikedTypePayoff -> IO a
f
withStrikedPayoff (PercentageStrike PercentageStrikePayoff
p) QlStrikedTypePayoff -> IO a
f = PercentageStrikePayoff
-> (QlPercentageStrikePayoff -> IO a) -> IO a
forall a.
PercentageStrikePayoff
-> (QlPercentageStrikePayoff -> IO a) -> IO a
withPercentageStrikePayoff PercentageStrikePayoff
p (\QlPercentageStrikePayoff
pp -> QlPercentageStrikePayoff
-> (Ptr (Base CPercentageStrikePayoff') -> IO a) -> IO a
forall a b.
(Upcastable a, Finalizable (Base a)) =>
Ptr a -> (Ptr (Base a) -> IO b) -> IO b
withUpcast QlPercentageStrikePayoff
pp QlStrikedTypePayoff -> IO a
Ptr (Base CPercentageStrikePayoff') -> IO a
f)
withStrikedPayoff (PlainVanilla PlainVanillaPayoff
p) QlStrikedTypePayoff -> IO a
f = PlainVanillaPayoff -> (QlPlainVanillaPayoff -> IO a) -> IO a
forall a.
PlainVanillaPayoff -> (QlPlainVanillaPayoff -> IO a) -> IO a
withPlainVanillaPayoff PlainVanillaPayoff
p (\QlPlainVanillaPayoff
pp -> QlPlainVanillaPayoff
-> (Ptr (Base CPlainVanillaPayoff') -> IO a) -> IO a
forall a b.
(Upcastable a, Finalizable (Base a)) =>
Ptr a -> (Ptr (Base a) -> IO b) -> IO b
withUpcast QlPlainVanillaPayoff
pp QlStrikedTypePayoff -> IO a
Ptr (Base CPlainVanillaPayoff') -> IO a
f)
withStrikedPayoff (SuperFund Double
s Double
ss) QlStrikedTypePayoff -> IO a
f = IO QlStrikedTypePayoff -> (QlStrikedTypePayoff -> IO a) -> IO a
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (Double -> Double -> IO QlStrikedTypePayoff
qlSuperFundPayoff Double
s Double
ss) QlStrikedTypePayoff -> IO a
f
withStrikedPayoff (SuperSharePayoff Double
s Double
ss Double
c) QlStrikedTypePayoff -> IO a
f = IO QlStrikedTypePayoff -> (QlStrikedTypePayoff -> IO a) -> IO a
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (Double -> Double -> Double -> IO QlStrikedTypePayoff
qlSuperSharePayoff Double
s Double
ss Double
c) QlStrikedTypePayoff -> IO a
f
withStrikedPayoff (CustomStriked OptionType
t Double
k String
n Callback
fp) QlStrikedTypePayoff -> IO a
f = IO QlStrikedTypePayoff -> (QlStrikedTypePayoff -> IO a) -> IO a
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (OptionType
-> Double -> String -> Callback -> IO QlStrikedTypePayoff
qlStrikedPayoffFromFunction OptionType
t Double
k String
n Callback
fp) QlStrikedTypePayoff -> IO a
f

data TypePayoff = Striked !StrikedPayoff
  | Floating !OptionType -- ^type
data BasketPayoff =
    Average
      !Payoff -- ^p
      !Word -- ^n
  | AverageMultiple
      !Payoff -- ^p
      ![Double] -- ^a
  | Max
      !Payoff -- ^p
  | Min
      !Payoff -- ^p
  | Spread
      !Payoff -- ^p
  -- |A Haskell-defined @accumulate@ over the underlying-state vector, wrapped around a base
  -- 'Payoff' exactly as 'Max'\/'Min'\/'Spread' are. Build it with 'withCustomBasketPayoff'.
  | CustomAccumulate
      !Payoff -- ^base payoff, applied to the accumulated value
      !Callback

withTypePayoff :: TypePayoff -> (QlTypePayoff -> IO a) -> IO a
withTypePayoff :: forall a. TypePayoff -> (QlTypePayoff -> IO a) -> IO a
withTypePayoff (Floating OptionType
t) QlTypePayoff -> IO a
f = IO QlTypePayoff -> (QlTypePayoff -> IO a) -> IO a
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (OptionType -> IO QlTypePayoff
qlFloatingTypePayoff OptionType
t) QlTypePayoff -> IO a
f
withTypePayoff (Striked StrikedPayoff
s) QlTypePayoff -> IO a
f = StrikedPayoff -> (QlStrikedTypePayoff -> IO a) -> IO a
forall a. StrikedPayoff -> (QlStrikedTypePayoff -> IO a) -> IO a
withStrikedPayoff StrikedPayoff
s (\QlStrikedTypePayoff
sp -> QlStrikedTypePayoff
-> (Ptr (Base CStrikedTypePayoff') -> IO a) -> IO a
forall a b.
(Upcastable a, Finalizable (Base a)) =>
Ptr a -> (Ptr (Base a) -> IO b) -> IO b
withUpcast QlStrikedTypePayoff
sp QlTypePayoff -> IO a
Ptr (Base CStrikedTypePayoff') -> IO a
f)

withBasketPayoff :: BasketPayoff -> (QlBasketPayoff -> IO a) -> IO a
withBasketPayoff :: forall a. BasketPayoff -> (QlBasketPayoff -> IO a) -> IO a
withBasketPayoff (Average Payoff
p Word
n) QlBasketPayoff -> IO a
f = Payoff -> (QlPayoff -> IO a) -> IO a
forall a. Payoff -> (QlPayoff -> IO a) -> IO a
withPayoff Payoff
p (\QlPayoff
pp -> IO QlBasketPayoff -> (QlBasketPayoff -> IO a) -> IO a
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (QlPayoff -> Word -> IO QlBasketPayoff
qlAverageBasketPayoff QlPayoff
pp Word
n) QlBasketPayoff -> IO a
f)
withBasketPayoff (AverageMultiple Payoff
p [Double]
a) QlBasketPayoff -> IO a
f = Payoff -> (QlPayoff -> IO a) -> IO a
forall a. Payoff -> (QlPayoff -> IO a) -> IO a
withPayoff Payoff
p (\QlPayoff
pp -> IO QlBasketPayoff -> (QlBasketPayoff -> IO a) -> IO a
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (QlPayoff -> [Double] -> IO QlBasketPayoff
qlAverageBasketPayoff1 QlPayoff
pp [Double]
a) QlBasketPayoff -> IO a
f)
withBasketPayoff (Max Payoff
p) QlBasketPayoff -> IO a
f = Payoff -> (QlPayoff -> IO a) -> IO a
forall a. Payoff -> (QlPayoff -> IO a) -> IO a
withPayoff Payoff
p (\QlPayoff
pp -> IO QlBasketPayoff -> (QlBasketPayoff -> IO a) -> IO a
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (QlPayoff -> IO QlBasketPayoff
qlMaxBasketPayoff QlPayoff
pp) QlBasketPayoff -> IO a
f)
withBasketPayoff (Min Payoff
p) QlBasketPayoff -> IO a
f = Payoff -> (QlPayoff -> IO a) -> IO a
forall a. Payoff -> (QlPayoff -> IO a) -> IO a
withPayoff Payoff
p (\QlPayoff
pp -> IO QlBasketPayoff -> (QlBasketPayoff -> IO a) -> IO a
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (QlPayoff -> IO QlBasketPayoff
qlMinBasketPayoff QlPayoff
pp) QlBasketPayoff -> IO a
f)
withBasketPayoff (Spread Payoff
p) QlBasketPayoff -> IO a
f = Payoff -> (QlPayoff -> IO a) -> IO a
forall a. Payoff -> (QlPayoff -> IO a) -> IO a
withPayoff Payoff
p (\QlPayoff
pp -> IO QlBasketPayoff -> (QlBasketPayoff -> IO a) -> IO a
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (QlPayoff -> IO QlBasketPayoff
qlSpreadBasketPayoff QlPayoff
pp) QlBasketPayoff -> IO a
f)
withBasketPayoff (CustomAccumulate Payoff
p Callback
fp) QlBasketPayoff -> IO a
f = Payoff -> (QlPayoff -> IO a) -> IO a
forall a. Payoff -> (QlPayoff -> IO a) -> IO a
withPayoff Payoff
p (\QlPayoff
pp -> IO QlBasketPayoff -> (QlBasketPayoff -> IO a) -> IO a
forall a b. Finalizable a => IO (Ptr a) -> (Ptr a -> IO b) -> IO b
withConstructed (QlPayoff -> Callback -> IO QlBasketPayoff
qlBasketPayoffFromFunction QlPayoff
pp Callback
fp) QlBasketPayoff -> IO a
f)

-- | > Payoff
-- >  DoubleStickyRatchet
-- >  ForwardType
-- >  RatchettMax
-- >  RatchetMin
-- >  StickyMax
-- >  StickyMin
-- >  Sticky
-- >  Custom
-- >  TypePayoff
-- >    Floating
-- >    Striked
-- >      AssetOrNothing
-- >      CashOrNothing
-- >      Gap
-- >      PercentageStrike
-- >      PlainVanilla
-- >      SuperFund
-- >      SuperSharePayoff
-- >      CustomStriked
-- >  BasketPayoff
-- >    Average
-- >    AverageMultiple
-- >    Max
-- >    Min
-- >    Spread
-- >    CustomAccumulate
data Payoff =
    DoubleStickyRatchet
      !Double -- ^type1
      !Double -- ^type2
      !Double -- ^gearing1
      !Double -- ^gearing2
      !Double -- ^gearing3
      !Double -- ^spread1
      !Double -- ^spread2
      !Double -- ^spread3
      !Double -- ^initialValue1
      !Double -- ^initialValue2
      !Double -- ^accrualFactor
  | ForwardType
      !PositionType -- ^type
      !Double -- ^strike
  | RatchetMax
      !Double -- ^gearing1
      !Double -- ^gearing2
      !Double -- ^gearing3
      !Double -- ^spread1
      !Double -- ^spread2
      !Double -- ^spread3
      !Double -- ^initialValue1
      !Double -- ^initialValue2
      !Double -- ^accrualFactor
  | RatchetMin
      !Double -- ^gearing1
      !Double -- ^gearing2
      !Double -- ^gearing3
      !Double -- ^spread1
      !Double -- ^spread2
      !Double -- ^spread3
      !Double -- ^initialValue1
      !Double -- ^initialValue2
      !Double -- ^accrualFactor
  | Ratchet
      !Double -- ^gearing1
      !Double -- ^gearing2
      !Double -- ^spread1
      !Double -- ^spread2
      !Double -- ^initialValue
      !Double -- ^accrualFactor
  | StickyMax
      !Double -- ^gearing1
      !Double -- ^gearing2
      !Double -- ^gearing3
      !Double -- ^spread1
      !Double -- ^spread2
      !Double -- ^spread3
      !Double -- ^initialValue1
      !Double -- ^initialValue2
      !Double -- ^accrualFactor
  | StickyMin
      !Double -- ^gearing1
      !Double -- ^gearing2
      !Double -- ^gearing3
      !Double -- ^spread1
      !Double -- ^spread2
      !Double -- ^spread3
      !Double -- ^initialValue1
      !Double -- ^initialValue2
      !Double -- ^accrualFactor
  | Sticky
      !Double -- ^gearing1
      !Double -- ^gearing2
      !Double -- ^spread1
      !Double -- ^spread2
      !Double -- ^initialValue
      !Double -- ^accrualFactor
  | Type !TypePayoff
  | Basket !BasketPayoff
  -- |A Haskell-defined payoff with a managed callback; build with 'withCustomPayoff'.
  | Custom
      !String -- ^name
      !String -- ^description
      !Callback


qlAssetOrNothingPayoff :: (OptionType) -> (Double) -> IO ((QlStrikedTypePayoff))
qlAssetOrNothingPayoff :: OptionType -> Double -> IO QlStrikedTypePayoff
qlAssetOrNothingPayoff OptionType
a1 Double
a2 =
  let {a1' :: CInt
a1' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (OptionType -> Int) -> OptionType -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OptionType -> Int
forall a. Enum a => a -> Int
fromEnum) OptionType
a1} in 
  let {a2' :: CDouble
a2' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a2} in 
  (Ptr (Ptr ()) -> IO QlStrikedTypePayoff) -> IO QlStrikedTypePayoff
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO QlStrikedTypePayoff)
 -> IO QlStrikedTypePayoff)
-> (Ptr (Ptr ()) -> IO QlStrikedTypePayoff)
-> IO QlStrikedTypePayoff
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a3' -> 
  CInt -> CDouble -> Ptr (Ptr ()) -> IO QlStrikedTypePayoff
qlAssetOrNothingPayoff'_ CInt
a1' CDouble
a2' Ptr (Ptr ())
a3' IO QlStrikedTypePayoff
-> (QlStrikedTypePayoff -> IO QlStrikedTypePayoff)
-> IO QlStrikedTypePayoff
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \QlStrikedTypePayoff
res ->
  QlStrikedTypePayoff -> IO QlStrikedTypePayoff
forall a. Ptr a -> IO (Ptr a)
peekPtr QlStrikedTypePayoff
res IO QlStrikedTypePayoff
-> (QlStrikedTypePayoff -> IO QlStrikedTypePayoff)
-> IO QlStrikedTypePayoff
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \QlStrikedTypePayoff
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a3'IO () -> IO QlStrikedTypePayoff -> IO QlStrikedTypePayoff
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  QlStrikedTypePayoff -> IO QlStrikedTypePayoff
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (QlStrikedTypePayoff
res')

{-# LINE 612 "./QuantLib/Internal/Common.chs" #-}

qlAverageBasketPayoff :: (QlPayoff) -> (Word) -> IO ((QlBasketPayoff))
qlAverageBasketPayoff a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  preErrorCheck $ \a3' -> 
  qlAverageBasketPayoff'_ a1' a2' a3' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 613 "./QuantLib/Internal/Common.chs" #-}

qlCashOrNothingPayoff :: (OptionType) -> (Double) -> (Double) -> IO ((QlStrikedTypePayoff))
qlCashOrNothingPayoff a1 a2 a3 =
  let {a1' = (fromIntegral . fromEnum) a1} in 
  let {a2' = realToFrac a2} in 
  let {a3' = realToFrac a3} in 
  preErrorCheck $ \a4' -> 
  qlCashOrNothingPayoff'_ a1' a2' a3' a4' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a4'>>
  return (res')

{-# LINE 614 "./QuantLib/Internal/Common.chs" #-}

qlDoubleStickyRatchetPayoff :: (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> IO ((QlPayoff))
qlDoubleStickyRatchetPayoff a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 =
  let {a1' = realToFrac a1} in 
  let {a2' = realToFrac a2} in 
  let {a3' = realToFrac a3} in 
  let {a4' = realToFrac a4} in 
  let {a5' = realToFrac a5} in 
  let {a6' = realToFrac a6} in 
  let {a7' = realToFrac a7} in 
  let {a8' = realToFrac a8} in 
  let {a9' = realToFrac a9} in 
  let {a10' = realToFrac a10} in 
  let {a11' = realToFrac a11} in 
  preErrorCheck $ \a12' -> 
  qlDoubleStickyRatchetPayoff'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a12'>>
  return (res')

{-# LINE 615 "./QuantLib/Internal/Common.chs" #-}

qlFloatingTypePayoff :: (OptionType) -> IO ((QlTypePayoff))
qlFloatingTypePayoff a1 =
  let {a1' = (fromIntegral . fromEnum) a1} in 
  preErrorCheck $ \a2' -> 
  qlFloatingTypePayoff'_ a1' a2' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 616 "./QuantLib/Internal/Common.chs" #-}

qlForwardTypePayoff :: (PositionType) -> (Double) -> IO ((QlPayoff))
qlForwardTypePayoff a1 a2 =
  let {a1' = (fromIntegral . fromEnum) a1} in 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  qlForwardTypePayoff'_ a1' a2' a3' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 617 "./QuantLib/Internal/Common.chs" #-}

qlGapPayoff :: (OptionType) -> (Double) -> (Double) -> IO ((QlStrikedTypePayoff))
qlGapPayoff a1 a2 a3 =
  let {a1' = (fromIntegral . fromEnum) a1} in 
  let {a2' = realToFrac a2} in 
  let {a3' = realToFrac a3} in 
  preErrorCheck $ \a4' -> 
  qlGapPayoff'_ a1' a2' a3' a4' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a4'>>
  return (res')

{-# LINE 618 "./QuantLib/Internal/Common.chs" #-}

qlMaxBasketPayoff :: (QlPayoff) -> IO ((QlBasketPayoff))
qlMaxBasketPayoff a1 =
  let {a1' = id a1} in 
  preErrorCheck $ \a2' -> 
  qlMaxBasketPayoff'_ a1' a2' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 619 "./QuantLib/Internal/Common.chs" #-}

qlMinBasketPayoff :: (QlPayoff) -> IO ((QlBasketPayoff))
qlMinBasketPayoff a1 =
  let {a1' = id a1} in 
  preErrorCheck $ \a2' -> 
  qlMinBasketPayoff'_ a1' a2' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 620 "./QuantLib/Internal/Common.chs" #-}

qlPercentageStrikePayoff :: (OptionType) -> (Double) -> IO ((QlPercentageStrikePayoff))
qlPercentageStrikePayoff a1 a2 =
  let {a1' = (fromIntegral . fromEnum) a1} in 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  qlPercentageStrikePayoff'_ a1' a2' a3' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 621 "./QuantLib/Internal/Common.chs" #-}

qlPlainVanillaPayoff :: (OptionType) -> (Double) -> IO ((QlPlainVanillaPayoff))
qlPlainVanillaPayoff a1 a2 =
  let {a1' = (fromIntegral . fromEnum) a1} in 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  qlPlainVanillaPayoff'_ a1' a2' a3' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 622 "./QuantLib/Internal/Common.chs" #-}

qlRatchetMaxPayoff :: (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> IO ((QlPayoff))
qlRatchetMaxPayoff a1 a2 a3 a4 a5 a6 a7 a8 a9 =
  let {a1' = realToFrac a1} in 
  let {a2' = realToFrac a2} in 
  let {a3' = realToFrac a3} in 
  let {a4' = realToFrac a4} in 
  let {a5' = realToFrac a5} in 
  let {a6' = realToFrac a6} in 
  let {a7' = realToFrac a7} in 
  let {a8' = realToFrac a8} in 
  let {a9' = realToFrac a9} in 
  preErrorCheck $ \a10' -> 
  qlRatchetMaxPayoff'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a10'>>
  return (res')

{-# LINE 623 "./QuantLib/Internal/Common.chs" #-}

qlRatchetMinPayoff :: (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> IO ((QlPayoff))
qlRatchetMinPayoff a1 a2 a3 a4 a5 a6 a7 a8 a9 =
  let {a1' = realToFrac a1} in 
  let {a2' = realToFrac a2} in 
  let {a3' = realToFrac a3} in 
  let {a4' = realToFrac a4} in 
  let {a5' = realToFrac a5} in 
  let {a6' = realToFrac a6} in 
  let {a7' = realToFrac a7} in 
  let {a8' = realToFrac a8} in 
  let {a9' = realToFrac a9} in 
  preErrorCheck $ \a10' -> 
  qlRatchetMinPayoff'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a10'>>
  return (res')

{-# LINE 624 "./QuantLib/Internal/Common.chs" #-}

qlRatchetPayoff :: (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> IO ((QlPayoff))
qlRatchetPayoff a1 a2 a3 a4 a5 a6 =
  let {a1' = realToFrac a1} in 
  let {a2' = realToFrac a2} in 
  let {a3' = realToFrac a3} in 
  let {a4' = realToFrac a4} in 
  let {a5' = realToFrac a5} in 
  let {a6' = realToFrac a6} in 
  preErrorCheck $ \a7' -> 
  qlRatchetPayoff'_ a1' a2' a3' a4' a5' a6' a7' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a7'>>
  return (res')

{-# LINE 625 "./QuantLib/Internal/Common.chs" #-}

qlSpreadBasketPayoff :: (QlPayoff) -> IO ((QlBasketPayoff))
qlSpreadBasketPayoff a1 =
  let {a1' = id a1} in 
  preErrorCheck $ \a2' -> 
  qlSpreadBasketPayoff'_ a1' a2' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 626 "./QuantLib/Internal/Common.chs" #-}

qlStickyMaxPayoff :: (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> IO ((QlPayoff))
qlStickyMaxPayoff a1 a2 a3 a4 a5 a6 a7 a8 a9 =
  let {a1' = realToFrac a1} in 
  let {a2' = realToFrac a2} in 
  let {a3' = realToFrac a3} in 
  let {a4' = realToFrac a4} in 
  let {a5' = realToFrac a5} in 
  let {a6' = realToFrac a6} in 
  let {a7' = realToFrac a7} in 
  let {a8' = realToFrac a8} in 
  let {a9' = realToFrac a9} in 
  preErrorCheck $ \a10' -> 
  qlStickyMaxPayoff'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a10'>>
  return (res')

{-# LINE 627 "./QuantLib/Internal/Common.chs" #-}

qlStickyMinPayoff :: (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> IO ((QlPayoff))
qlStickyMinPayoff a1 a2 a3 a4 a5 a6 a7 a8 a9 =
  let {a1' = realToFrac a1} in 
  let {a2' = realToFrac a2} in 
  let {a3' = realToFrac a3} in 
  let {a4' = realToFrac a4} in 
  let {a5' = realToFrac a5} in 
  let {a6' = realToFrac a6} in 
  let {a7' = realToFrac a7} in 
  let {a8' = realToFrac a8} in 
  let {a9' = realToFrac a9} in 
  preErrorCheck $ \a10' -> 
  qlStickyMinPayoff'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a10'>>
  return (res')

{-# LINE 628 "./QuantLib/Internal/Common.chs" #-}

qlStickyPayoff :: (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> (Double) -> IO ((QlPayoff))
qlStickyPayoff a1 a2 a3 a4 a5 a6 =
  let {a1' = realToFrac a1} in 
  let {a2' = realToFrac a2} in 
  let {a3' = realToFrac a3} in 
  let {a4' = realToFrac a4} in 
  let {a5' = realToFrac a5} in 
  let {a6' = realToFrac a6} in 
  preErrorCheck $ \a7' -> 
  qlStickyPayoff'_ a1' a2' a3' a4' a5' a6' a7' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a7'>>
  return (res')

{-# LINE 629 "./QuantLib/Internal/Common.chs" #-}

qlSuperFundPayoff :: (Double) -> (Double) -> IO ((QlStrikedTypePayoff))
qlSuperFundPayoff a1 a2 =
  let {a1' = realToFrac a1} in 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  qlSuperFundPayoff'_ a1' a2' a3' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 630 "./QuantLib/Internal/Common.chs" #-}

qlSuperSharePayoff :: (Double) -> (Double) -> (Double) -> IO ((QlStrikedTypePayoff))
qlSuperSharePayoff a1 a2 a3 =
  let {a1' = realToFrac a1} in 
  let {a2' = realToFrac a2} in 
  let {a3' = realToFrac a3} in 
  preErrorCheck $ \a4' -> 
  qlSuperSharePayoff'_ a1' a2' a3' a4' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a4'>>
  return (res')

{-# LINE 631 "./QuantLib/Internal/Common.chs" #-}

qlAverageBasketPayoff1 :: (QlPayoff) -> ([Double]) -> IO ((QlBasketPayoff))
qlAverageBasketPayoff1 a1 a2 =
  let {a1' = id a1} in 
  withDoubleArray a2 $ \(a2'1, a2'2) -> 
  preErrorCheck $ \a3' -> 
  qlAverageBasketPayoff1'_ a1' a2'1  a2'2 a3' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 632 "./QuantLib/Internal/Common.chs" #-}

qlPayoffFromFunction :: (String) -> (String) -> (Callback) -> IO ((QlPayoff))
qlPayoffFromFunction a1 a2 a3 =
  C2HSImp.withCString a1 $ \a1' -> 
  C2HSImp.withCString a2 $ \a2' -> 
  withCallbackPtr a3 $ \a3' -> 
  preErrorCheck $ \a4' -> 
  qlPayoffFromFunction'_ a1' a2' a3' a4' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a4'>>
  return (res')

{-# LINE 633 "./QuantLib/Internal/Common.chs" #-}

qlBasketPayoffFromFunction :: (QlPayoff) -> (Callback) -> IO ((QlBasketPayoff))
qlBasketPayoffFromFunction a1 a2 =
  let {a1' = id a1} in 
  withCallbackPtr a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  qlBasketPayoffFromFunction'_ a1' a2' a3' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 634 "./QuantLib/Internal/Common.chs" #-}

qlStrikedPayoffFromFunction :: (OptionType) -> (Double) -> (String) -> (Callback) -> IO ((QlStrikedTypePayoff))
qlStrikedPayoffFromFunction a1 a2 a3 a4 =
  let {a1' = (fromIntegral . fromEnum) a1} in 
  let {a2' = realToFrac a2} in 
  C2HSImp.withCString a3 $ \a3' -> 
  withCallbackPtr a4 $ \a4' -> 
  preErrorCheck $ \a5' -> 
  qlStrikedPayoffFromFunction'_ a1' a2' a3' a4' a5' >>= \res ->
  peekPtr res >>= \res' ->
  errorCheck  a5'>>
  return (res')

{-# LINE 635 "./QuantLib/Internal/Common.chs" #-}


withPayoff :: Payoff -> (QlPayoff -> IO a) -> IO a
withPayoff (DoubleStickyRatchet t1 t2 g1 g2 g3 s1 s2 s3 i1 i2 a) f = withConstructed (qlDoubleStickyRatchetPayoff t1 t2 g1 g2 g3 s1 s2 s3 i1 i2 a) f
withPayoff (ForwardType t s) f = withConstructed (qlForwardTypePayoff t s) f
withPayoff (RatchetMax g1 g2 g3 s1 s2 s3 i1 i2 a) f = withConstructed (qlRatchetMaxPayoff g1 g2 g3 s1 s2 s3 i1 i2 a) f
withPayoff (RatchetMin g1 g2 g3 s1 s2 s3 i1 i2 a) f = withConstructed (qlRatchetMinPayoff g1 g2 g3 s1 s2 s3 i1 i2 a) f
withPayoff (Ratchet g1 g2 s1 s2 i a) f = withConstructed (qlRatchetPayoff g1 g2 s1 s2 i a) f
withPayoff (StickyMax g1 g2 g3 s1 s2 s3 i1 i2 a) f = withConstructed (qlStickyMaxPayoff g1 g2 g3 s1 s2 s3 i1 i2 a) f
withPayoff (StickyMin g1 g2 g3 s1 s2 s3 i1 i2 a) f = withConstructed (qlStickyMinPayoff g1 g2 g3 s1 s2 s3 i1 i2 a) f
withPayoff (Sticky g1 g2 s1 s2 i a) f = withConstructed (qlStickyPayoff g1 g2 s1 s2 i a) f
withPayoff (Type t) f = withTypePayoff t (\tp -> withUpcast tp f)
withPayoff (Basket b) f = withBasketPayoff b (\bp -> withUpcast bp f)
withPayoff (Custom n d fp) f = withConstructed (qlPayoffFromFunction n d fp) f

-- |Wrap a Haskell @price -> value@ function as a real QuantLib @Payoff@, usable anywhere a
-- 'Payoff' is (@QuantLib.Instrument.Option.oneAssetOption@, @multiAssetOption@,
-- @QuantLib.Instrument.Swap.varianceOption@, @QuantLib.Method.fdmLogInnerValue@,
-- @fdmCellAveragingInnerValue@, ...) -- the fully custom counterpart to the concrete
-- pre-implemented payoffs listed by the 'Payoff' constructors above.
--
-- The payoff ADT and every native consumer retain the callback after the continuation returns.
-- Callback exceptions are rethrown by the enclosing Haskell call.
--
-- @name@ and @description@ are what QuantLib's own error messages and @Payoff::name@ report; they
-- are not interpreted.
--
-- __Not every engine accepts a non-standard payoff.__ QuantLib's analytic, binomial, finite-
-- difference and @MCEuropeanEngine@ families all recover the strike by downcasting to
-- @StrikedTypePayoff@\/@PlainVanillaPayoff@ first, and a further ~30 engines route through
-- @BlackCalculator@, whose @AcyclicVisitor@ knows only the four built-in striked payoffs. Most of
-- these fail with a clean QuantLib exception. The two bound finite-difference vanilla engines
-- validate the required striked payoff, including on QuantLib 1.43. Confirmed-generic consumers:
-- @QuantLib.Method.fdmLogInnerValue@\/@fdmCellAveragingInnerValue@ (and hence @fdmSolve@), and
-- @QuantLib.PricingEngine.mcAmericanEngine@ with @controlVariate = False@.
withCustomPayoff :: String -- ^name
  -> String -- ^description
  -> (Double -> Double) -- ^payoff(price)
  -> (Payoff -> IO b) -> IO b
withCustomPayoff :: forall b.
String -> String -> (Double -> Double) -> (Payoff -> IO b) -> IO b
withCustomPayoff String
n String
d Double -> Double
f Payoff -> IO b
k = (Double -> Double) -> (Callback -> IO b) -> IO b
forall b. (Double -> Double) -> (Callback -> IO b) -> IO b
withPayoffFun Double -> Double
f (Payoff -> IO b
k (Payoff -> IO b) -> (Callback -> Payoff) -> Callback -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String -> Callback -> Payoff
Custom String
n String
d)

-- |As 'withCustomPayoff', but produces a real QuantLib @StrikedTypePayoff@ carrying an
-- @(optionType, strike)@ pair alongside the Haskell function.
--
-- __The pair is advisory: it does not define the payoff__ -- @payoff(price)@ alone does, exactly
-- as for 'withCustomPayoff'. It exists because QuantLib's finite-difference vanilla engines reach
-- past the @Payoff@ interface for a strike when sizing their grid:
-- @FdBlackScholesVanillaEngine@ @dynamic_pointer_cast@s to @StrikedTypePayoff@ and calls
-- @strike()@ twice -- once for the mesher's extent, once for its node-concentration point -- then
-- hands the payoff itself to @FdmLogInnerValue@, which takes a plain @Payoff@. So a payoff built
-- here prices correctly through 'QuantLib.PricingEngine.fdBlackScholesVanillaEngine' and
-- 'QuantLib.PricingEngine.fdHestonVanillaEngine', where one built by 'withCustomPayoff' is
-- rejected with an exception. Pass the strike you want the grid centred on.
--
-- The payoff and native consumers retain the callback after the continuation returns.
-- @description@ is derived from the type and strike by @StrikedTypePayoff@.
--
-- Engines routing through @BlackCalculator@ (the @analytic*@ family) still reject this, as they
-- must: its @AcyclicVisitor@ knows only the four built-in striked payoffs, and there is no
-- closed-form price for an arbitrary function. That rejection is a clean QuantLib exception.
withCustomStrikedPayoff :: OptionType -- ^advisory option type
  -> Double -- ^advisory strike (grid centring only)
  -> String -- ^name
  -> (Double -> Double) -- ^payoff(price)
  -> (StrikedPayoff -> IO b) -> IO b
withCustomStrikedPayoff :: forall b.
OptionType
-> Double
-> String
-> (Double -> Double)
-> (StrikedPayoff -> IO b)
-> IO b
withCustomStrikedPayoff OptionType
t Double
k String
n Double -> Double
f StrikedPayoff -> IO b
g = (Double -> Double) -> (Callback -> IO b) -> IO b
forall b. (Double -> Double) -> (Callback -> IO b) -> IO b
withPayoffFun Double -> Double
f (StrikedPayoff -> IO b
g (StrikedPayoff -> IO b)
-> (Callback -> StrikedPayoff) -> Callback -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OptionType -> Double -> String -> Callback -> StrikedPayoff
CustomStriked OptionType
t Double
k String
n)

-- |Wrap a Haskell @underlyings -> accumulated@ function as a real QuantLib @BasketPayoff@ around
-- @base@ (which is applied to the accumulated value, exactly as for 'Max'\/'Min'\/'Spread') --
-- usable with @QuantLib.Instrument.Option.basketOption@ and
-- @QuantLib.Method.fdmLogBasketInnerValue@. Same ownership rule as 'withCustomPayoff';
-- unlike it, this callback crosses once per evaluation with the whole underlying-state vector,
-- because that is the shape @BasketPayoff::accumulate@ already has upstream.
withCustomBasketPayoff :: Payoff -- ^base payoff
  -> ([Double] -> Double) -- ^accumulate(underlyings)
  -> (BasketPayoff -> IO b) -> IO b
withCustomBasketPayoff :: forall b.
Payoff -> ([Double] -> Double) -> (BasketPayoff -> IO b) -> IO b
withCustomBasketPayoff Payoff
base [Double] -> Double
f BasketPayoff -> IO b
k = ([Double] -> Double) -> (Callback -> IO b) -> IO b
forall b. ([Double] -> Double) -> (Callback -> IO b) -> IO b
withBasketAccumulateFun [Double] -> Double
f (BasketPayoff -> IO b
k (BasketPayoff -> IO b)
-> (Callback -> BasketPayoff) -> Callback -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Payoff -> Callback -> BasketPayoff
CustomAccumulate Payoff
base)

data Callability =
  Soft
    !(Double, BondPriceType)
    !Day
    !Double -- ^trigger
  | Callability
      !(Double, BondPriceType)
      !CallabilityType
      !Day

callability :: Callability -> IO (Standalone CQlCallability)
callability :: Callability -> IO (Standalone CQlCallability)
callability (Soft (Double
p, BondPriceType
t) Day
d Double
tg) = Double
-> BondPriceType -> Day -> Double -> IO (Standalone CQlCallability)
qlSoftCallability Double
p BondPriceType
t Day
d Double
tg
callability (Callability (Double
p, BondPriceType
t) CallabilityType
ct Day
d) = Double
-> BondPriceType
-> CallabilityType
-> Day
-> IO (Standalone CQlCallability)
qlCallability Double
p BondPriceType
t CallabilityType
ct Day
d

newtype EnumMeta a b = EnumMeta (a -> IO (Standalone b))

withEnumType :: EnumMeta a b -> a -> (Ptr b -> IO c) -> IO c
withEnumType :: forall a b c. EnumMeta a b -> a -> (Ptr b -> IO c) -> IO c
withEnumType (EnumMeta a -> IO (Standalone b)
t) a
x Ptr b -> IO c
f = a -> IO (Standalone b)
t a
x IO (Standalone b) -> (Standalone b -> IO c) -> IO c
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Standalone b -> (Ptr b -> IO c) -> IO c
forall a b. Standalone a -> (Ptr a -> IO b) -> IO b
`withStandalone` Ptr b -> IO c
f)

withMaybeEnumType :: EnumMeta a b -> Maybe a -> (Ptr b -> IO c) -> IO c
withMaybeEnumType :: forall a b c. EnumMeta a b -> Maybe a -> (Ptr b -> IO c) -> IO c
withMaybeEnumType (EnumMeta a -> IO (Standalone b)
t) Maybe a
x Ptr b -> IO c
f = IO c -> (a -> IO c) -> Maybe a -> IO c
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Ptr b -> IO c
f Ptr b
forall a. Ptr a
nullPtr) (\a
xx -> a -> IO (Standalone b)
t a
xx IO (Standalone b) -> (Standalone b -> IO c) -> IO c
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Standalone b -> (Ptr b -> IO c) -> IO c
forall a b. Standalone a -> (Ptr a -> IO b) -> IO b
`withStandalone` Ptr b -> IO c
f)) Maybe a
x

withEnumTypeArray :: EnumMeta a b -> [a] -> ((CUInt, Ptr (Ptr b)) -> IO c) -> IO c
withEnumTypeArray :: forall a b c.
EnumMeta a b -> [a] -> ((CUInt, Ptr (Ptr b)) -> IO c) -> IO c
withEnumTypeArray EnumMeta a b
m [a]
x (CUInt, Ptr (Ptr b)) -> IO c
f = (a -> (Ptr b -> IO c) -> IO c) -> [a] -> ([Ptr b] -> IO c) -> IO c
forall a b res.
(a -> (b -> res) -> res) -> [a] -> ([b] -> res) -> res
withMany (EnumMeta a b -> a -> (Ptr b -> IO c) -> IO c
forall a b c. EnumMeta a b -> a -> (Ptr b -> IO c) -> IO c
withEnumType EnumMeta a b
m) [a]
x ([Ptr b] -> (Ptr (Ptr b) -> IO c) -> IO c
forall a b. Storable a => [a] -> (Ptr a -> IO b) -> IO b
`withArray` (\Ptr (Ptr b)
px -> (CUInt, Ptr (Ptr b)) -> IO c
f (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CUInt) -> Int -> CUInt
forall a b. (a -> b) -> a -> b
$ [a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
x, Ptr (Ptr b)
px)))

callabilityMeta :: EnumMeta Callability CQlCallability
callabilityMeta :: EnumMeta Callability CQlCallability
callabilityMeta = (Callability -> IO (Standalone CQlCallability))
-> EnumMeta Callability CQlCallability
forall a b. (a -> IO (Standalone b)) -> EnumMeta a b
EnumMeta Callability -> IO (Standalone CQlCallability)
callability

withCallability :: Callability -> (Ptr CQlCallability -> IO a) -> IO a
withCallability :: forall a. Callability -> (Ptr CQlCallability -> IO a) -> IO a
withCallability = EnumMeta Callability CQlCallability
-> Callability -> (Ptr CQlCallability -> IO a) -> IO a
forall a b c. EnumMeta a b -> a -> (Ptr b -> IO c) -> IO c
withEnumType EnumMeta Callability CQlCallability
callabilityMeta

withCallabilityArray :: [Callability] -> ((CUInt, Ptr (Ptr CQlCallability)) -> IO c) -> IO c
withCallabilityArray :: forall c.
[Callability]
-> ((CUInt, Ptr (Ptr CQlCallability)) -> IO c) -> IO c
withCallabilityArray = EnumMeta Callability CQlCallability
-> [Callability]
-> ((CUInt, Ptr (Ptr CQlCallability)) -> IO c)
-> IO c
forall a b c.
EnumMeta a b -> [a] -> ((CUInt, Ptr (Ptr b)) -> IO c) -> IO c
withEnumTypeArray EnumMeta Callability CQlCallability
callabilityMeta

constraintMeta :: EnumMeta Constraint CConstraint
constraintMeta :: EnumMeta Constraint CConstraint
constraintMeta = (Constraint -> IO (Standalone CConstraint))
-> EnumMeta Constraint CConstraint
forall a b. (a -> IO (Standalone b)) -> EnumMeta a b
EnumMeta Constraint -> IO (Standalone CConstraint)
constraint

roundingMeta :: EnumMeta Rounding CRounding
roundingMeta :: EnumMeta Rounding CRounding
roundingMeta = (Rounding -> IO (Standalone CRounding))
-> EnumMeta Rounding CRounding
forall a b. (a -> IO (Standalone b)) -> EnumMeta a b
EnumMeta Rounding -> IO (Standalone CRounding)
rounding

withMaybeConstraint :: Maybe Constraint -> (Ptr CConstraint -> IO a) -> IO a
withMaybeConstraint :: forall a. Maybe Constraint -> (Ptr CConstraint -> IO a) -> IO a
withMaybeConstraint = EnumMeta Constraint CConstraint
-> Maybe Constraint -> (Ptr CConstraint -> IO a) -> IO a
forall a b c. EnumMeta a b -> Maybe a -> (Ptr b -> IO c) -> IO c
withMaybeEnumType EnumMeta Constraint CConstraint
constraintMeta

withMaybeRounding :: Maybe Rounding -> (Ptr CRounding -> IO a) -> IO a
withMaybeRounding :: forall a. Maybe Rounding -> (Ptr CRounding -> IO a) -> IO a
withMaybeRounding = EnumMeta Rounding CRounding
-> Maybe Rounding -> (Ptr CRounding -> IO a) -> IO a
forall a b c. EnumMeta a b -> Maybe a -> (Ptr b -> IO c) -> IO c
withMaybeEnumType EnumMeta Rounding CRounding
roundingMeta

withConstraint :: Constraint -> (Ptr CConstraint -> IO a) -> IO a
withConstraint :: forall a. Constraint -> (Ptr CConstraint -> IO a) -> IO a
withConstraint = EnumMeta Constraint CConstraint
-> Constraint -> (Ptr CConstraint -> IO a) -> IO a
forall a b c. EnumMeta a b -> a -> (Ptr b -> IO c) -> IO c
withEnumType EnumMeta Constraint CConstraint
constraintMeta

withRounding :: Rounding -> (Ptr CRounding -> IO a) -> IO a
withRounding :: forall a. Rounding -> (Ptr CRounding -> IO a) -> IO a
withRounding = EnumMeta Rounding CRounding
-> Rounding -> (Ptr CRounding -> IO a) -> IO a
forall a b c. EnumMeta a b -> a -> (Ptr b -> IO c) -> IO c
withEnumType EnumMeta Rounding CRounding
roundingMeta

fittedBondDiscountFittingMethodMeta :: EnumMeta FittingMethod CFittedBondDiscountCurveFittingMethod
fittedBondDiscountFittingMethodMeta :: EnumMeta FittingMethod CFittedBondDiscountCurveFittingMethod
fittedBondDiscountFittingMethodMeta = (FittingMethod
 -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> EnumMeta FittingMethod CFittedBondDiscountCurveFittingMethod
forall a b. (a -> IO (Standalone b)) -> EnumMeta a b
EnumMeta FittingMethod
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
fittingMethod

withFittedBondDiscountCurveFittingMethod :: FittingMethod -> (Ptr CFittedBondDiscountCurveFittingMethod -> IO a) -> IO a
withFittedBondDiscountCurveFittingMethod :: forall a.
FittingMethod
-> (Ptr CFittedBondDiscountCurveFittingMethod -> IO a) -> IO a
withFittedBondDiscountCurveFittingMethod = EnumMeta FittingMethod CFittedBondDiscountCurveFittingMethod
-> FittingMethod
-> (Ptr CFittedBondDiscountCurveFittingMethod -> IO a)
-> IO a
forall a b c. EnumMeta a b -> a -> (Ptr b -> IO c) -> IO c
withEnumType EnumMeta FittingMethod CFittedBondDiscountCurveFittingMethod
fittedBondDiscountFittingMethodMeta

endCriteriaMeta :: EnumMeta EndCriteria CEndCriteria
endCriteriaMeta :: EnumMeta EndCriteria CEndCriteria
endCriteriaMeta = (EndCriteria -> IO (Standalone CEndCriteria))
-> EnumMeta EndCriteria CEndCriteria
forall a b. (a -> IO (Standalone b)) -> EnumMeta a b
EnumMeta EndCriteria -> IO (Standalone CEndCriteria)
endCriteria

withEndCriteria :: EndCriteria -> (Ptr CEndCriteria -> IO a) -> IO a
withEndCriteria :: forall a. EndCriteria -> (Ptr CEndCriteria -> IO a) -> IO a
withEndCriteria = EnumMeta EndCriteria CEndCriteria
-> EndCriteria -> (Ptr CEndCriteria -> IO a) -> IO a
forall a b c. EnumMeta a b -> a -> (Ptr b -> IO c) -> IO c
withEnumType EnumMeta EndCriteria CEndCriteria
endCriteriaMeta

withMaybeEndCriteria :: Maybe EndCriteria -> (Ptr CEndCriteria -> IO a) -> IO a
withMaybeEndCriteria :: forall a. Maybe EndCriteria -> (Ptr CEndCriteria -> IO a) -> IO a
withMaybeEndCriteria = EnumMeta EndCriteria CEndCriteria
-> Maybe EndCriteria -> (Ptr CEndCriteria -> IO a) -> IO a
forall a b c. EnumMeta a b -> Maybe a -> (Ptr b -> IO c) -> IO c
withMaybeEnumType EnumMeta EndCriteria CEndCriteria
endCriteriaMeta

fdmSchemeDescMeta :: EnumMeta FdmScheme CFdmSchemeDesc
fdmSchemeDescMeta :: EnumMeta FdmScheme CFdmSchemeDesc
fdmSchemeDescMeta = (FdmScheme -> IO (Standalone CFdmSchemeDesc))
-> EnumMeta FdmScheme CFdmSchemeDesc
forall a b. (a -> IO (Standalone b)) -> EnumMeta a b
EnumMeta FdmScheme -> IO (Standalone CFdmSchemeDesc)
fdmScheme

withFdmSchemeDesc :: FdmScheme -> (Ptr CFdmSchemeDesc -> IO a) -> IO a
withFdmSchemeDesc :: forall a. FdmScheme -> (Ptr CFdmSchemeDesc -> IO a) -> IO a
withFdmSchemeDesc = EnumMeta FdmScheme CFdmSchemeDesc
-> FdmScheme -> (Ptr CFdmSchemeDesc -> IO a) -> IO a
forall a b c. EnumMeta a b -> a -> (Ptr b -> IO c) -> IO c
withEnumType EnumMeta FdmScheme CFdmSchemeDesc
fdmSchemeDescMeta

optimizationMethodMeta :: EnumMeta OptimizationMethod COptimizationMethod
optimizationMethodMeta :: EnumMeta OptimizationMethod COptimizationMethod
optimizationMethodMeta = (OptimizationMethod -> IO (Standalone COptimizationMethod))
-> EnumMeta OptimizationMethod COptimizationMethod
forall a b. (a -> IO (Standalone b)) -> EnumMeta a b
EnumMeta OptimizationMethod -> IO (Standalone COptimizationMethod)
optimizationMethod

withOptimizationMethod :: OptimizationMethod -> (Ptr COptimizationMethod -> IO a) -> IO a
withOptimizationMethod :: forall a.
OptimizationMethod -> (Ptr COptimizationMethod -> IO a) -> IO a
withOptimizationMethod = EnumMeta OptimizationMethod COptimizationMethod
-> OptimizationMethod -> (Ptr COptimizationMethod -> IO a) -> IO a
forall a b c. EnumMeta a b -> a -> (Ptr b -> IO c) -> IO c
withEnumType EnumMeta OptimizationMethod COptimizationMethod
optimizationMethodMeta

withMaybeOptimizationMethod :: Maybe OptimizationMethod -> (Ptr COptimizationMethod -> IO a) -> IO a
withMaybeOptimizationMethod :: forall a.
Maybe OptimizationMethod
-> (Ptr COptimizationMethod -> IO a) -> IO a
withMaybeOptimizationMethod = EnumMeta OptimizationMethod COptimizationMethod
-> Maybe OptimizationMethod
-> (Ptr COptimizationMethod -> IO a)
-> IO a
forall a b c. EnumMeta a b -> Maybe a -> (Ptr b -> IO c) -> IO c
withMaybeEnumType EnumMeta OptimizationMethod COptimizationMethod
optimizationMethodMeta

-- Payoff/Exercise with* functions are now defined directly, near their ADTs, using
-- Upcastable/GenForeignPtr (see QuantLib.Internal.Type) instead of EnumMeta'/IsQlPayoff/IsQlExercise.

-- |callability leaving to the holder the possibility to convert
qlSoftCallability :: (Double) -> (BondPriceType) -> (Day) -> (Double) -> IO ((QlCallability))
qlSoftCallability :: Double
-> BondPriceType -> Day -> Double -> IO (Standalone CQlCallability)
qlSoftCallability Double
a1 BondPriceType
a2 a3 Double
a4 =
  let {a1' :: CDouble
a1' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a1} in 
  let {a2' :: CInt
a2' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (BondPriceType -> Int) -> BondPriceType -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BondPriceType -> Int
forall a. Enum a => a -> Int
fromEnum) BondPriceType
a2} in 
  Day
-> (CInt -> IO (Standalone CQlCallability))
-> IO (Standalone CQlCallability)
forall a. Day -> (CInt -> IO a) -> IO a
withDay Day
a3 ((CInt -> IO (Standalone CQlCallability))
 -> IO (Standalone CQlCallability))
-> (CInt -> IO (Standalone CQlCallability))
-> IO (Standalone CQlCallability)
forall a b. (a -> b) -> a -> b
$ \CInt
a3' -> 
  let {a4' :: CDouble
a4' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a4} in 
  (Ptr (Ptr ()) -> IO (Standalone CQlCallability))
-> IO (Standalone CQlCallability)
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO (Standalone CQlCallability))
 -> IO (Standalone CQlCallability))
-> (Ptr (Ptr ()) -> IO (Standalone CQlCallability))
-> IO (Standalone CQlCallability)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a5' -> 
  CDouble
-> CInt
-> CInt
-> CDouble
-> Ptr (Ptr ())
-> IO (Ptr CQlCallability)
qlSoftCallability'_ CDouble
a1' CInt
a2' CInt
a3' CDouble
a4' Ptr (Ptr ())
a5' IO (Ptr CQlCallability)
-> (Ptr CQlCallability -> IO (Standalone CQlCallability))
-> IO (Standalone CQlCallability)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CQlCallability
res ->
  Ptr CQlCallability -> IO (Standalone CQlCallability)
CDouble
-> CInt -> CInt -> CInt -> Ptr (Ptr ()) -> IO (Ptr CQlCallability)
peekCallability :: Ptr CQlCallability -> IO (Standalone CQlCallability)
qlCallability'_ :: CDouble
-> CInt -> CInt -> CInt -> Ptr (Ptr ()) -> IO (Ptr CQlCallability)
peekCallability Ptr CQlCallability
CDouble
res :: Ptr CQlCallability
a1' :: CDouble
res CInt
IO (Standalone CQlCallability)
-> (Standalone CQlCallability -> IO (Standalone CQlCallability))
-> IO (Standalone CQlCallability)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= :: forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
a2' :: CInt
>>= \res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a5'IO ()
-> IO (Standalone CQlCallability) -> IO (Standalone CQlCallability)
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Standalone CQlCallability -> IO (Standalone CQlCallability)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Standalone CQlCallability
res')

{-# LINE 799 "./QuantLib/Internal/Common.chs" #-}

qlCallability :: (Double) -> (BondPriceType) -> (CallabilityType) -> (Day) -> IO ((QlCallability))
qlCallability a1 a2 a3 a4 =
  let {a1' = realToFrac a1} in 
  let {a2' = (fromIntegral . fromEnum) a2} in 
  let {a3' = (fromIntegral . fromEnum) a3} in 
  withDay a4 $ \a4' -> 
  preErrorCheck $ \a5' -> 
  qlCallability'_ a1' a2' a3' a4' a5' >>= \res ->
  peekCallability res >>= \res' ->
  errorCheck  a5'>>
  return (res')

{-# LINE 800 "./QuantLib/Internal/Common.chs" #-}


-- Every constructor below binds the QuantLib overload's leading optimizationMethod param via a
-- trailing Maybe OptimizationMethod field (Nothing -> upstream's own empty-shared_ptr default,
-- letting the fit fall back to LevenbergMarquardt). OptimizationMethod's hasquant-side handle
-- (QlOptimizationMethod) is a shared_ptr box, not a raw Haskell-finalized pointer -- see the
-- qlaux.h comment above the QlEndCriteria/QlOptimizationMethod typedefs -- so a caller-supplied
-- one can safely be copied into FittingMethod's own shared_ptr member (and survive
-- FittedBondDiscountCurve cloning the fitting method) regardless of when Haskell's own box is
-- collected.
data FittingMethod =
  CubicBSplines
    ![Double] -- ^knotVector (year fraction)
    !Bool -- ^constrainAtZero
    ![Double] -- ^weights
    ![Double] -- ^l2
    !Double -- ^minCutoffTime
    !Double -- ^maxCutoffTime
    !(Maybe Constraint)
    !(Maybe OptimizationMethod)
  | ExponentialSplines
    !Bool -- ^constrainAtZero
    ![Double] -- ^weights
    ![Double] -- ^l2
    !Double -- ^minCutoffTime
    !Double -- ^maxCutoffTime
    !Word -- ^numCoeffs
    !(Maybe Double) -- ^fixedKappa
    !(Maybe Constraint)
    !(Maybe OptimizationMethod)
  | NelsonSiegel
    ![Double] -- ^weights
    ![Double] -- ^l2
    !Double -- ^minCutoffTime
    !Double -- ^maxCutoffTime
    !(Maybe Constraint)
    !(Maybe OptimizationMethod)
  | SimplePolynomial
    !Word -- ^degree
    !Bool -- ^constrainAtZero
    ![Double] -- ^weights
    ![Double] -- ^l2
    !Double -- ^minCutoffTime
    !Double -- ^maxCutoffTime
    !(Maybe Constraint)
    !(Maybe OptimizationMethod)
  | Svensson
    ![Double] -- ^weights
    ![Double] -- ^l2
    !Double -- ^minCutoffTime
    !Double -- ^maxCutoffTime
    !(Maybe Constraint)
    !(Maybe OptimizationMethod)

fittingMethod :: FittingMethod -> IO QlFittedBondDiscountCurveFittingMethod
fittingMethod :: FittingMethod
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
fittingMethod (CubicBSplines [Double]
k Bool
c [Double]
w [Double]
l2 Double
mn Double
mx Maybe Constraint
cn Maybe OptimizationMethod
om) = [Double]
-> Bool
-> [Double]
-> [Double]
-> Double
-> Double
-> Maybe OptimizationMethod
-> Maybe Constraint
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
qlCubicBSplinesFitting [Double]
k Bool
c [Double]
w [Double]
l2 Double
mn Double
mx Maybe OptimizationMethod
om Maybe Constraint
cn
fittingMethod (ExponentialSplines Bool
c [Double]
w [Double]
l2 Double
mn Double
mx Word
n Maybe Double
fk Maybe Constraint
cn Maybe OptimizationMethod
om) = Bool
-> [Double]
-> [Double]
-> Double
-> Double
-> Word
-> Maybe Double
-> Maybe OptimizationMethod
-> Maybe Constraint
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
qlExponentialSplinesFitting Bool
c [Double]
w [Double]
l2 Double
mn Double
mx Word
n Maybe Double
fk Maybe OptimizationMethod
om Maybe Constraint
cn
fittingMethod (NelsonSiegel [Double]
w [Double]
l2 Double
mn Double
mx Maybe Constraint
cn Maybe OptimizationMethod
om) = [Double]
-> [Double]
-> Double
-> Double
-> Maybe OptimizationMethod
-> Maybe Constraint
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
qlNelsonSiegelFitting [Double]
w [Double]
l2 Double
mn Double
mx Maybe OptimizationMethod
om Maybe Constraint
cn
fittingMethod (SimplePolynomial Word
d Bool
c [Double]
w [Double]
l2 Double
mn Double
mx Maybe Constraint
cn Maybe OptimizationMethod
om) = Word
-> Bool
-> [Double]
-> [Double]
-> Double
-> Double
-> Maybe OptimizationMethod
-> Maybe Constraint
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
qlSimplePolynomialFitting Word
d Bool
c [Double]
w [Double]
l2 Double
mn Double
mx Maybe OptimizationMethod
om Maybe Constraint
cn
fittingMethod (Svensson [Double]
w [Double]
l2 Double
mn Double
mx Maybe Constraint
cn Maybe OptimizationMethod
om) = [Double]
-> [Double]
-> Double
-> Double
-> Maybe OptimizationMethod
-> Maybe Constraint
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
qlSvenssonFitting [Double]
w [Double]
l2 Double
mn Double
mx Maybe OptimizationMethod
om Maybe Constraint
cn

qlCubicBSplinesFitting :: ([Double]) -> (Bool) -> ([Double]) -- ^weights
 -> ([Double]) -- ^l2
 -> (Double) -- ^minCutoffTime
 -> (Double) -- ^maxCutoffTime
 -> (Maybe OptimizationMethod) -> (Maybe Constraint) -> IO ((QlFittedBondDiscountCurveFittingMethod))
qlCubicBSplinesFitting :: [Double]
-> Bool
-> [Double]
-> [Double]
-> Double
-> Double
-> Maybe OptimizationMethod
-> Maybe Constraint
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
qlCubicBSplinesFitting [Double]
a1 Bool
a2 [Double]
a3 [Double]
a4 Double
a5 Double
a6 Maybe OptimizationMethod
a7 Maybe Constraint
a8 =
  [Double]
-> ((CUInt, Ptr CDouble)
    -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
forall b. [Double] -> ((CUInt, Ptr CDouble) -> IO b) -> IO b
withDoubleArray [Double]
a1 (((CUInt, Ptr CDouble)
  -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
 -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> ((CUInt, Ptr CDouble)
    -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
forall a b. (a -> b) -> a -> b
$ \(CUInt
a1'1, Ptr CDouble
a1'2) -> 
  let {a2' :: CInt
a2' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a2} in 
  [Double]
-> ((CUInt, Ptr CDouble)
    -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
forall b. [Double] -> ((CUInt, Ptr CDouble) -> IO b) -> IO b
withDoubleArray [Double]
a3 (((CUInt, Ptr CDouble)
  -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
 -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> ((CUInt, Ptr CDouble)
    -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
forall a b. (a -> b) -> a -> b
$ \(CUInt
a3'1, Ptr CDouble
a3'2) -> 
  [Double]
-> ((CUInt, Ptr CDouble)
    -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
forall b. [Double] -> ((CUInt, Ptr CDouble) -> IO b) -> IO b
withDoubleArray [Double]
a4 (((CUInt, Ptr CDouble)
  -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
 -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> ((CUInt, Ptr CDouble)
    -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
forall a b. (a -> b) -> a -> b
$ \(CUInt
a4'1, Ptr CDouble
a4'2) -> 
  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 
  Maybe OptimizationMethod
-> (Ptr COptimizationMethod
    -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
forall a.
Maybe OptimizationMethod
-> (Ptr COptimizationMethod -> IO a) -> IO a
withMaybeOptimizationMethod Maybe OptimizationMethod
a7 ((Ptr COptimizationMethod
  -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
 -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> (Ptr COptimizationMethod
    -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
forall a b. (a -> b) -> a -> b
$ \Ptr COptimizationMethod
a7' -> 
  Maybe Constraint
-> (Ptr CConstraint
    -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
forall a. Maybe Constraint -> (Ptr CConstraint -> IO a) -> IO a
withMaybeConstraint Maybe Constraint
a8 ((Ptr CConstraint
  -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
 -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> (Ptr CConstraint
    -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
forall a b. (a -> b) -> a -> b
$ \Ptr CConstraint
a8' -> 
  (Ptr (Ptr ())
 -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ())
  -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
 -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> (Ptr (Ptr ())
    -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a9' -> 
  CUInt
-> Ptr CDouble
-> CInt
-> CUInt
-> Ptr CDouble
-> CUInt
-> Ptr CDouble
-> CDouble
-> CDouble
-> Ptr COptimizationMethod
-> Ptr CConstraint
-> Ptr (Ptr ())
-> IO (Ptr CFittedBondDiscountCurveFittingMethod)
qlCubicBSplinesFitting'_ CUInt
a1'1  Ptr CDouble
a1'2 CInt
a2' CUInt
a3'1  a3'2 a4'1  a4'2 a5' a6' a7' a8' a9' IO (Ptr CFittedBondDiscountCurveFittingMethod)
-> (Ptr CFittedBondDiscountCurveFittingMethod
    -> IO (Standalone CFittedBondDiscountCurveFittingMethod))
-> IO (Standalone CFittedBondDiscountCurveFittingMethod)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res ->
  peekFittedBondDiscountCurveFittingMethod res >>= \res' ->
  errorCheck  a9'>>
  return (res')

{-# LINE 868 "./QuantLib/Internal/Common.chs" #-}

qlExponentialSplinesFitting :: (Bool) -> ([Double]) -- ^weights
 -> ([Double]) -- ^l2
 -> (Double) -- ^minCutoffTime
 -> (Double) -- ^maxCutoffTime
 -> (Word) -- ^numCoeffs
 -> (Maybe Double) -- ^fixedKappa
 -> (Maybe OptimizationMethod) -> (Maybe Constraint) -> IO ((QlFittedBondDiscountCurveFittingMethod))
qlExponentialSplinesFitting a1 a2 a3 a4 a5 a6 a7 a8 a9 =
  let {a1' = C2HSImp.fromBool a1} in 
  withDoubleArray a2 $ \(a2'1, a2'2) -> 
  withDoubleArray a3 $ \(a3'1, a3'2) -> 
  let {a4' = realToFrac a4} in 
  let {a5' = realToFrac a5} in 
  let {a6' = fromIntegral a6} in 
  let {a7' = fromMaybeDouble a7} in 
  withMaybeOptimizationMethod a8 $ \a8' -> 
  withMaybeConstraint a9 $ \a9' -> 
  preErrorCheck $ \a10' -> 
  qlExponentialSplinesFitting'_ a1' a2'1  a2'2 a3'1  a3'2 a4' a5' a6' a7' a8' a9' a10' >>= \res ->
  peekFittedBondDiscountCurveFittingMethod res >>= \res' ->
  errorCheck  a10'>>
  return (res')

{-# LINE 878 "./QuantLib/Internal/Common.chs" #-}

qlNelsonSiegelFitting :: ([Double]) -- ^weights
 -> ([Double]) -- ^l2
 -> (Double) -- ^minCutoffTime
 -> (Double) -- ^maxCutoffTime
 -> (Maybe OptimizationMethod) -> (Maybe Constraint) -> IO ((QlFittedBondDiscountCurveFittingMethod))
qlNelsonSiegelFitting a1 a2 a3 a4 a5 a6 =
  withDoubleArray a1 $ \(a1'1, a1'2) -> 
  withDoubleArray a2 $ \(a2'1, a2'2) -> 
  let {a3' = realToFrac a3} in 
  let {a4' = realToFrac a4} in 
  withMaybeOptimizationMethod a5 $ \a5' -> 
  withMaybeConstraint a6 $ \a6' -> 
  preErrorCheck $ \a7' -> 
  qlNelsonSiegelFitting'_ a1'1  a1'2 a2'1  a2'2 a3' a4' a5' a6' a7' >>= \res ->
  peekFittedBondDiscountCurveFittingMethod res >>= \res' ->
  errorCheck  a7'>>
  return (res')

{-# LINE 885 "./QuantLib/Internal/Common.chs" #-}

qlSimplePolynomialFitting :: (Word) -> (Bool) -> ([Double]) -- ^weights
 -> ([Double]) -- ^l2
 -> (Double) -- ^minCutoffTime
 -> (Double) -- ^maxCutoffTime
 -> (Maybe OptimizationMethod) -> (Maybe Constraint) -> IO ((QlFittedBondDiscountCurveFittingMethod))
qlSimplePolynomialFitting a1 a2 a3 a4 a5 a6 a7 a8 =
  let {a1' = fromIntegral a1} in 
  let {a2' = C2HSImp.fromBool a2} in 
  withDoubleArray a3 $ \(a3'1, a3'2) -> 
  withDoubleArray a4 $ \(a4'1, a4'2) -> 
  let {a5' = realToFrac a5} in 
  let {a6' = realToFrac a6} in 
  withMaybeOptimizationMethod a7 $ \a7' -> 
  withMaybeConstraint a8 $ \a8' -> 
  preErrorCheck $ \a9' -> 
  qlSimplePolynomialFitting'_ a1' a2' a3'1  a3'2 a4'1  a4'2 a5' a6' a7' a8' a9' >>= \res ->
  peekFittedBondDiscountCurveFittingMethod res >>= \res' ->
  errorCheck  a9'>>
  return (res')

{-# LINE 893 "./QuantLib/Internal/Common.chs" #-}

qlSvenssonFitting :: ([Double]) -- ^weights
 -> ([Double]) -- ^l2
 -> (Double) -- ^minCutoffTime
 -> (Double) -- ^maxCutoffTime
 -> (Maybe OptimizationMethod) -> (Maybe Constraint) -> IO ((QlFittedBondDiscountCurveFittingMethod))
qlSvenssonFitting a1 a2 a3 a4 a5 a6 =
  withDoubleArray a1 $ \(a1'1, a1'2) -> 
  withDoubleArray a2 $ \(a2'1, a2'2) -> 
  let {a3' = realToFrac a3} in 
  let {a4' = realToFrac a4} in 
  withMaybeOptimizationMethod a5 $ \a5' -> 
  withMaybeConstraint a6 $ \a6' -> 
  preErrorCheck $ \a7' -> 
  qlSvenssonFitting'_ a1'1  a1'2 a2'1  a2'2 a3' a4' a5' a6' a7' >>= \res ->
  peekFittedBondDiscountCurveFittingMethod res >>= \res' ->
  errorCheck  a7'>>
  return (res')

{-# LINE 900 "./QuantLib/Internal/Common.chs" #-}


data FdmScheme =
  FdmScheme
    !FdmSchemeType -- ^type
    !Double -- ^theta
    !Double -- ^mu
  | CraigSneyd
  | Douglas
  | ExplicitEuler
  | Hundsdorfer
  | ImplicitEuler
  | ModifiedCraigSneyd
  | ModifiedHundsdorfer
  | MethodOfLines
    !Double -- ^eps
    !Double -- ^relInitStepSize

qlFdmSchemeDesc :: (FdmSchemeType) -> (Double) -> (Double) -> IO ((QlFdmSchemeDesc))
qlFdmSchemeDesc :: FdmSchemeType -> Double -> Double -> IO (Standalone CFdmSchemeDesc)
qlFdmSchemeDesc FdmSchemeType
a1 Double
a2 Double
a3 =
  let {a1' :: CInt
a1' = (fromIntegral . fromEnum) a1} in 
  let {a2' = realToFrac a2} in 
  let {a3' = realToFrac a3} in 
  preErrorCheck $ \a4' -> 
  qlFdmSchemeDesc'_ a1' a2' a3' a4' >>= \res ->
  peekFdmSchemeDesc res >>= \res' ->
  errorCheck  a4'>>
  return (res')

{-# LINE 918 "./QuantLib/Internal/Common.chs" #-}

qlFdmSchemeDescCraigSneyd :: IO ((QlFdmSchemeDesc))
qlFdmSchemeDescCraigSneyd =
  preErrorCheck $ \a1' -> 
  qlFdmSchemeDescCraigSneyd'_ a1' >>= \res ->
  peekFdmSchemeDesc res >>= \res' ->
  errorCheck  a1'>>
  return (res')

{-# LINE 919 "./QuantLib/Internal/Common.chs" #-}

qlFdmSchemeDescDouglas :: IO ((QlFdmSchemeDesc))
qlFdmSchemeDescDouglas =
  preErrorCheck $ \a1' -> 
  qlFdmSchemeDescDouglas'_ a1' >>= \res ->
  peekFdmSchemeDesc res >>= \res' ->
  errorCheck  a1'>>
  return (res')

{-# LINE 920 "./QuantLib/Internal/Common.chs" #-}

qlFdmSchemeDescExplicitEuler :: IO ((QlFdmSchemeDesc))
qlFdmSchemeDescExplicitEuler =
  preErrorCheck $ \a1' -> 
  qlFdmSchemeDescExplicitEuler'_ a1' >>= \res ->
  peekFdmSchemeDesc res >>= \res' ->
  errorCheck  a1'>>
  return (res')

{-# LINE 921 "./QuantLib/Internal/Common.chs" #-}

qlFdmSchemeDescHundsdorfer :: IO ((QlFdmSchemeDesc))
qlFdmSchemeDescHundsdorfer =
  preErrorCheck $ \a1' -> 
  qlFdmSchemeDescHundsdorfer'_ a1' >>= \res ->
  peekFdmSchemeDesc res >>= \res' ->
  errorCheck  a1'>>
  return (res')

{-# LINE 922 "./QuantLib/Internal/Common.chs" #-}

qlFdmSchemeDescImplicitEuler :: IO ((QlFdmSchemeDesc))
qlFdmSchemeDescImplicitEuler =
  preErrorCheck $ \a1' -> 
  qlFdmSchemeDescImplicitEuler'_ a1' >>= \res ->
  peekFdmSchemeDesc res >>= \res' ->
  errorCheck  a1'>>
  return (res')

{-# LINE 923 "./QuantLib/Internal/Common.chs" #-}

qlFdmSchemeDescModifiedCraigSneyd :: IO ((QlFdmSchemeDesc))
qlFdmSchemeDescModifiedCraigSneyd =
  preErrorCheck $ \a1' -> 
  qlFdmSchemeDescModifiedCraigSneyd'_ a1' >>= \res ->
  peekFdmSchemeDesc res >>= \res' ->
  errorCheck  a1'>>
  return (res')

{-# LINE 924 "./QuantLib/Internal/Common.chs" #-}

qlFdmSchemeDescModifiedHundsdorfer :: IO ((QlFdmSchemeDesc))
qlFdmSchemeDescModifiedHundsdorfer =
  preErrorCheck $ \a1' -> 
  qlFdmSchemeDescModifiedHundsdorfer'_ a1' >>= \res ->
  peekFdmSchemeDesc res >>= \res' ->
  errorCheck  a1'>>
  return (res')

{-# LINE 925 "./QuantLib/Internal/Common.chs" #-}

qlFdmSchemeDescMethodOfLines :: (Double) -- ^eps
 -> (Double) -- ^relInitStepSize
 -> IO ((QlFdmSchemeDesc))
qlFdmSchemeDescMethodOfLines a1 a2 =
  let {a1' = realToFrac a1} in 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  qlFdmSchemeDescMethodOfLines'_ a1' a2' a3' >>= \res ->
  peekFdmSchemeDesc res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 928 "./QuantLib/Internal/Common.chs" #-}


fdmScheme :: FdmScheme -> IO QlFdmSchemeDesc
fdmScheme (FdmScheme t th mu) = qlFdmSchemeDesc t th mu
fdmScheme CraigSneyd = qlFdmSchemeDescCraigSneyd
fdmScheme Douglas = qlFdmSchemeDescDouglas
fdmScheme ExplicitEuler = qlFdmSchemeDescExplicitEuler
fdmScheme Hundsdorfer = qlFdmSchemeDescHundsdorfer
fdmScheme ImplicitEuler = qlFdmSchemeDescImplicitEuler
fdmScheme ModifiedCraigSneyd = qlFdmSchemeDescModifiedCraigSneyd
fdmScheme ModifiedHundsdorfer = qlFdmSchemeDescModifiedHundsdorfer
fdmScheme (MethodOfLines eps relInitStepSize) = qlFdmSchemeDescMethodOfLines eps relInitStepSize

data Constraint =
  Boundary
    !Double -- ^low
    !Double -- ^high
  | Composite
    !Constraint -- ^c1
    !Constraint -- ^c2
  | NoConstraint
  | PositiveConstraint

constraint :: Constraint -> IO QlConstraint
constraint :: Constraint -> IO (Standalone CConstraint)
constraint (Boundary Double
l Double
h) = Double -> Double -> IO (Standalone CConstraint)
qlBoundaryConstraint Double
l Double
h
constraint (Composite Constraint
c1 Constraint
c2) = Constraint -> Constraint -> IO (Standalone CConstraint)
qlCompositeConstraint Constraint
c1 Constraint
c2
constraint Constraint
NoConstraint = IO (Standalone CConstraint)
qlNoConstraint
constraint Constraint
PositiveConstraint = IO (Standalone CConstraint)
qlPositiveConstraint

qlBoundaryConstraint :: (Double) -> (Double) -> IO ((QlConstraint))
qlBoundaryConstraint :: Double -> Double -> IO (Standalone CConstraint)
qlBoundaryConstraint Double
a1 Double
a2 =
  let {a1' :: CDouble
a1' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a1} in 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  qlBoundaryConstraint'_ a1' a2' a3' >>= \res ->
  peekConstraint res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 957 "./QuantLib/Internal/Common.chs" #-}

qlCompositeConstraint :: (Constraint) -> (Constraint) -> IO ((QlConstraint))
qlCompositeConstraint a1 a2 =
  withConstraint a1 $ \a1' -> 
  withConstraint a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  qlCompositeConstraint'_ a1' a2' a3' >>= \res ->
  peekConstraint res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 958 "./QuantLib/Internal/Common.chs" #-}

qlNoConstraint :: IO ((QlConstraint))
qlNoConstraint =
  preErrorCheck $ \a1' -> 
  qlNoConstraint'_ a1' >>= \res ->
  peekConstraint res >>= \res' ->
  errorCheck  a1'>>
  return (res')

{-# LINE 959 "./QuantLib/Internal/Common.chs" #-}

qlPositiveConstraint :: IO ((QlConstraint))
qlPositiveConstraint =
  preErrorCheck $ \a1' -> 
  qlPositiveConstraint'_ a1' >>= \res ->
  peekConstraint res >>= \res' ->
  errorCheck  a1'>>
  return (res')

{-# LINE 960 "./QuantLib/Internal/Common.chs" #-}


data OptimizationMethod =
  LevenbergMarquardt
    !Double -- ^epsfcn
    !Double -- ^xtol
    !Double -- ^gtol
    !Bool -- ^useCostFunctionsJacobian
  | Simplex !Double -- ^lambda, characteristic length

optimizationMethod :: OptimizationMethod -> IO QlOptimizationMethod
optimizationMethod :: OptimizationMethod -> IO (Standalone COptimizationMethod)
optimizationMethod (LevenbergMarquardt Double
e Double
x Double
g Bool
j) = Double
-> Double -> Double -> Bool -> IO (Standalone COptimizationMethod)
qlLevenbergMarquardt Double
e Double
x Double
g Bool
j
optimizationMethod (Simplex Double
l) = Double -> IO (Standalone COptimizationMethod)
qlSimplex Double
l
qlLevenbergMarquardt :: (Double) -> (Double) -> (Double) -> (Bool) -> IO ((QlOptimizationMethod))
qlLevenbergMarquardt :: Double
-> Double -> Double -> Bool -> IO (Standalone COptimizationMethod)
qlLevenbergMarquardt Double
a1 Double
a2 Double
a3 Bool
a4 =
  let {a1' :: CDouble
a1' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a1} in 
  let {a2' :: CDouble
a2' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a2} in 
  let {a3' :: CDouble
a3' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a3} in 
  let {a4' :: CInt
a4' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a4} in 
  (Ptr (Ptr ()) -> IO (Standalone COptimizationMethod))
-> IO (Standalone COptimizationMethod)
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO (Standalone COptimizationMethod))
 -> IO (Standalone COptimizationMethod))
-> (Ptr (Ptr ()) -> IO (Standalone COptimizationMethod))
-> IO (Standalone COptimizationMethod)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a5' -> 
  CDouble
-> CDouble
-> CDouble
-> CInt
-> Ptr (Ptr ())
-> IO (Ptr COptimizationMethod)
qlLevenbergMarquardt'_ CDouble
a1' CDouble
a2' CDouble
a3' CInt
a4' Ptr (Ptr ())
a5' IO (Ptr COptimizationMethod)
-> (Ptr COptimizationMethod -> IO (Standalone COptimizationMethod))
-> IO (Standalone COptimizationMethod)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr COptimizationMethod
res ->
  Ptr COptimizationMethod -> IO (Standalone COptimizationMethod)
peekOptimizationMethod Ptr COptimizationMethod
res IO (Standalone COptimizationMethod)
-> (Standalone COptimizationMethod
    -> IO (Standalone COptimizationMethod))
-> IO (Standalone COptimizationMethod)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Standalone COptimizationMethod
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a5'IO ()
-> IO (Standalone COptimizationMethod)
-> IO (Standalone COptimizationMethod)
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Standalone COptimizationMethod
-> IO (Standalone COptimizationMethod)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Standalone COptimizationMethod
res')

{-# LINE 973 "./QuantLib/Internal/Common.chs" #-}

qlSimplex :: (Double) -> IO ((QlOptimizationMethod))
qlSimplex a1 =
  let {a1' = realToFrac a1} in 
  preErrorCheck $ \a2' -> 
  qlSimplex'_ a1' a2' >>= \res ->
  peekOptimizationMethod res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 974 "./QuantLib/Internal/Common.chs" #-}


data EndCriteria =
  EndCriteria
    !Word -- ^maxIterations
    !Word -- ^maxStationaryStateIterations
    !Double -- ^rootEpsilon
    !Double -- ^functionEpsilon
    !Double -- ^gradientNormEpsilon

endCriteria :: EndCriteria -> IO QlEndCriteria
endCriteria (EndCriteria m1 m2 e f g) = qlEndCriteria m1 m2 e f g
qlEndCriteria :: (Word) -> (Word) -> (Double) -> (Double) -> (Double) -> IO ((QlEndCriteria))
qlEndCriteria :: Word
-> Word
-> Double
-> Double
-> Double
-> IO (Standalone CEndCriteria)
qlEndCriteria Word
a1 Word
a2 Double
a3 Double
a4 Double
a5 =
  let {a1' :: CUInt
a1' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a1} in 
  let {a2' :: CUInt
a2' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a2} in 
  let {a3' :: CDouble
a3' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a3} in 
  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 
  (Ptr (Ptr ()) -> IO (Standalone CEndCriteria))
-> IO (Standalone CEndCriteria)
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO (Standalone CEndCriteria))
 -> IO (Standalone CEndCriteria))
-> (Ptr (Ptr ()) -> IO (Standalone CEndCriteria))
-> IO (Standalone CEndCriteria)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a6' -> 
  CUInt
-> CUInt
-> CDouble
-> CDouble
-> CDouble
-> Ptr (Ptr ())
-> IO (Ptr CEndCriteria)
qlEndCriteria'_ CUInt
a1' CUInt
a2' CDouble
a3' CDouble
a4' CDouble
a5' Ptr (Ptr ())
a6' IO (Ptr CEndCriteria)
-> (Ptr CEndCriteria -> IO (Standalone CEndCriteria))
-> IO (Standalone CEndCriteria)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CEndCriteria
res ->
  Ptr CEndCriteria -> IO (Standalone CEndCriteria)
peekEndCriteria Ptr CEndCriteria
res IO (Standalone CEndCriteria)
-> (Standalone CEndCriteria -> IO (Standalone CEndCriteria))
-> IO (Standalone CEndCriteria)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Standalone CEndCriteria
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a6'IO ()
-> IO (Standalone CEndCriteria) -> IO (Standalone CEndCriteria)
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Standalone CEndCriteria -> IO (Standalone CEndCriteria)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Standalone CEndCriteria
res')

{-# LINE 986 "./QuantLib/Internal/Common.chs" #-}


data Rounding = NoRounding
  | Rounding
    !Int -- ^precision
    !RoundingType
    !Int -- ^digit
  deriving (Show, Eq)

rounding :: Rounding -> IO QlRounding
rounding NoRounding = qlRounding
rounding (Rounding p t d) = qlRounding1 p t d

qlRounding :: IO ((QlRounding))
qlRounding :: IO (Standalone CRounding)
qlRounding =
  (Ptr (Ptr ()) -> IO (Standalone CRounding))
-> IO (Standalone CRounding)
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO (Standalone CRounding))
 -> IO (Standalone CRounding))
-> (Ptr (Ptr ()) -> IO (Standalone CRounding))
-> IO (Standalone CRounding)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a1' -> 
  Ptr (Ptr ()) -> IO (Ptr CRounding)
qlRounding'_ Ptr (Ptr ())
a1' IO (Ptr CRounding)
-> (Ptr CRounding -> IO (Standalone CRounding))
-> IO (Standalone CRounding)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CRounding
res ->
  Ptr CRounding -> IO (Standalone CRounding)
peekRounding Ptr CRounding
res IO (Standalone CRounding)
-> (Standalone CRounding -> IO (Standalone CRounding))
-> IO (Standalone CRounding)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Standalone CRounding
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a1'IO () -> IO (Standalone CRounding) -> IO (Standalone CRounding)
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Standalone CRounding -> IO (Standalone CRounding)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Standalone CRounding
res')

{-# LINE 999 "./QuantLib/Internal/Common.chs" #-}

qlRounding1 :: (Int) -> (RoundingType) -> (Int) -> IO ((QlRounding))
qlRounding1 a1 a2 a3 =
  let {a1' = fromIntegral a1} in 
  let {a2' = (fromIntegral . fromEnum) a2} in 
  let {a3' = fromIntegral a3} in 
  preErrorCheck $ \a4' -> 
  qlRounding1'_ a1' a2' a3' a4' >>= \res ->
  peekRounding res >>= \res' ->
  errorCheck  a4'>>
  return (res')

{-# LINE 1000 "./QuantLib/Internal/Common.chs" #-}


data LmCorrelationModel = ConstWrapperCorrelation LmCorrelationModel
  | ExponentialCorrelation Word -- ^size
    !Double -- ^rho
  | LinearExponentialCorrelation Word -- ^size
    !Double -- ^rho
    !Double -- ^beta
    !Word -- ^factors
  deriving (Show, Eq)

qlLmConstWrapperCorrelationModel :: (QlLmCorrelationModel) -> IO ((QlLmCorrelationModel))
qlLmConstWrapperCorrelationModel :: QlLmCorrelationModel -> IO QlLmCorrelationModel
qlLmConstWrapperCorrelationModel QlLmCorrelationModel
a1 =
  QlLmCorrelationModel
-> (Ptr CLmCorrelationModel -> IO QlLmCorrelationModel)
-> IO QlLmCorrelationModel
forall a b. Standalone a -> (Ptr a -> IO b) -> IO b
withStandalone QlLmCorrelationModel
a1 ((Ptr CLmCorrelationModel -> IO QlLmCorrelationModel)
 -> IO QlLmCorrelationModel)
-> (Ptr CLmCorrelationModel -> IO QlLmCorrelationModel)
-> IO QlLmCorrelationModel
forall a b. (a -> b) -> a -> b
$ \Ptr CLmCorrelationModel
a1' -> 
  (Ptr (Ptr ()) -> IO QlLmCorrelationModel)
-> IO QlLmCorrelationModel
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO QlLmCorrelationModel)
 -> IO QlLmCorrelationModel)
-> (Ptr (Ptr ()) -> IO QlLmCorrelationModel)
-> IO QlLmCorrelationModel
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a2' -> 
  Ptr CLmCorrelationModel
-> Ptr (Ptr ()) -> IO (Ptr CLmCorrelationModel)
qlLmConstWrapperCorrelationModel'_ Ptr CLmCorrelationModel
a1' Ptr (Ptr ())
a2' IO (Ptr CLmCorrelationModel)
-> (Ptr CLmCorrelationModel -> IO QlLmCorrelationModel)
-> IO QlLmCorrelationModel
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CLmCorrelationModel
res ->
  Ptr CLmCorrelationModel -> IO QlLmCorrelationModel
peekLmCorrelationModel res IO QlLmCorrelationModel
-> (QlLmCorrelationModel -> IO QlLmCorrelationModel)
-> IO QlLmCorrelationModel
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 1011 "./QuantLib/Internal/Common.chs" #-}

qlLmExponentialCorrelationModel :: (Word) -> (Double) -> IO ((QlLmCorrelationModel))
qlLmExponentialCorrelationModel a1 a2 =
  let {a1' = fromIntegral a1} in 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  qlLmExponentialCorrelationModel'_ a1' a2' a3' >>= \res ->
  peekLmCorrelationModel res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 1012 "./QuantLib/Internal/Common.chs" #-}

qlLmLinearExponentialCorrelationModel :: (Word) -> (Double) -> (Double) -> (Word) -> IO ((QlLmCorrelationModel))
qlLmLinearExponentialCorrelationModel a1 a2 a3 a4 =
  let {a1' = fromIntegral a1} in 
  let {a2' = realToFrac a2} in 
  let {a3' = realToFrac a3} in 
  let {a4' = fromIntegral a4} in 
  preErrorCheck $ \a5' -> 
  qlLmLinearExponentialCorrelationModel'_ a1' a2' a3' a4' a5' >>= \res ->
  peekLmCorrelationModel res >>= \res' ->
  errorCheck  a5'>>
  return (res')

{-# LINE 1013 "./QuantLib/Internal/Common.chs" #-}


correlationModel :: LmCorrelationModel -> IO QlLmCorrelationModel
correlationModel (ConstWrapperCorrelation m) = correlationModel m >>= qlLmConstWrapperCorrelationModel
correlationModel (ExponentialCorrelation s r) = qlLmExponentialCorrelationModel s r
correlationModel (LinearExponentialCorrelation s r b f) = qlLmLinearExponentialCorrelationModel s r b f

correlationModelMeta :: EnumMeta LmCorrelationModel CLmCorrelationModel
correlationModelMeta = EnumMeta correlationModel

withLmCorrelationModel :: LmCorrelationModel -> (Ptr CLmCorrelationModel -> IO a) -> IO a
withLmCorrelationModel = withEnumType correlationModelMeta

data LmVolatilityModel = ConstWrapperVolatility LmVolatilityModel
  | FixedVolatility !(NonEmpty (Double, Double)) -- ^(start time, volatility)
  | LinearExponentialVolatility ![Double] -- ^fixing times
    !Double -- ^a
    !Double -- ^b
    !Double -- ^c
    !Double -- ^d
  deriving (Int -> LmVolatilityModel -> ShowS
[LmVolatilityModel] -> ShowS
LmVolatilityModel -> String
(Int -> LmVolatilityModel -> ShowS)
-> (LmVolatilityModel -> String)
-> ([LmVolatilityModel] -> ShowS)
-> Show LmVolatilityModel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LmVolatilityModel -> ShowS
showsPrec :: Int -> LmVolatilityModel -> ShowS
$cshow :: LmVolatilityModel -> String
show :: LmVolatilityModel -> String
$cshowList :: [LmVolatilityModel] -> ShowS
showList :: [LmVolatilityModel] -> ShowS
Show, LmVolatilityModel -> LmVolatilityModel -> Bool
(LmVolatilityModel -> LmVolatilityModel -> Bool)
-> (LmVolatilityModel -> LmVolatilityModel -> Bool)
-> Eq LmVolatilityModel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LmVolatilityModel -> LmVolatilityModel -> Bool
== :: LmVolatilityModel -> LmVolatilityModel -> Bool
$c/= :: LmVolatilityModel -> LmVolatilityModel -> Bool
/= :: LmVolatilityModel -> LmVolatilityModel -> Bool
Eq)

qlLmConstWrapperVolatilityModel :: (QlLmVolatilityModel) -> IO ((QlLmVolatilityModel))
qlLmConstWrapperVolatilityModel :: QlLmVolatilityModel -> IO QlLmVolatilityModel
qlLmConstWrapperVolatilityModel QlLmVolatilityModel
a1 =
  QlLmVolatilityModel
-> (Ptr CLmVolatilityModel -> IO QlLmVolatilityModel)
-> IO QlLmVolatilityModel
forall a b. Standalone a -> (Ptr a -> IO b) -> IO b
withStandalone QlLmVolatilityModel
a1 ((Ptr CLmVolatilityModel -> IO QlLmVolatilityModel)
 -> IO QlLmVolatilityModel)
-> (Ptr CLmVolatilityModel -> IO QlLmVolatilityModel)
-> IO QlLmVolatilityModel
forall a b. (a -> b) -> a -> b
$ \Ptr CLmVolatilityModel
a1' -> 
  (Ptr (Ptr ()) -> IO QlLmVolatilityModel) -> IO QlLmVolatilityModel
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO QlLmVolatilityModel)
 -> IO QlLmVolatilityModel)
-> (Ptr (Ptr ()) -> IO QlLmVolatilityModel)
-> IO QlLmVolatilityModel
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a2' -> 
  Ptr CLmVolatilityModel
-> Ptr (Ptr ()) -> IO (Ptr CLmVolatilityModel)
qlLmConstWrapperVolatilityModel'_ Ptr CLmVolatilityModel
a1' Ptr (Ptr ())
a2' IO (Ptr CLmVolatilityModel)
-> (Ptr CLmVolatilityModel -> IO QlLmVolatilityModel)
-> IO QlLmVolatilityModel
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CLmVolatilityModel
res ->
  Ptr CLmVolatilityModel -> IO QlLmVolatilityModel
peekLmVolatilityModel Ptr CLmVolatilityModel
res IO QlLmVolatilityModel
-> (QlLmVolatilityModel -> IO QlLmVolatilityModel)
-> IO QlLmVolatilityModel
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \QlLmVolatilityModel
res' ->
  Ptr (Ptr ()) -> IO ()
errorCheck  a2'IO () -> IO QlLmVolatilityModel -> IO QlLmVolatilityModel
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  return (res')

{-# LINE 1035 "./QuantLib/Internal/Common.chs" #-}

qlLmFixedVolatilityModel :: ([Double]) -> ([Double]) -> IO ((QlLmVolatilityModel))
qlLmFixedVolatilityModel a1 a2 =
  withDoubleArray a1 $ \(a1'1, a1'2) -> 
  withDoubleArray a2 $ \(a2'1, a2'2) -> 
  preErrorCheck $ \a3' -> 
  qlLmFixedVolatilityModel'_ a1'1  a1'2 a2'1  a2'2 a3' >>= \res ->
  peekLmVolatilityModel res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 1036 "./QuantLib/Internal/Common.chs" #-}

qlLmLinearExponentialVolatilityModel :: ([Double]) -> (Double) -> (Double) -> (Double) -> (Double) -> IO ((QlLmVolatilityModel))
qlLmLinearExponentialVolatilityModel a1 a2 a3 a4 a5 =
  withDoubleArray a1 $ \(a1'1, a1'2) -> 
  let {a2' = realToFrac a2} in 
  let {a3' = realToFrac a3} in 
  let {a4' = realToFrac a4} in 
  let {a5' = realToFrac a5} in 
  preErrorCheck $ \a6' -> 
  qlLmLinearExponentialVolatilityModel'_ a1'1  a1'2 a2' a3' a4' a5' a6' >>= \res ->
  peekLmVolatilityModel res >>= \res' ->
  errorCheck  a6'>>
  return (res')

{-# LINE 1037 "./QuantLib/Internal/Common.chs" #-}


volatilityModel :: LmVolatilityModel -> IO QlLmVolatilityModel
volatilityModel (ConstWrapperVolatility m) = volatilityModel m >>= qlLmConstWrapperVolatilityModel
volatilityModel (FixedVolatility tv) = qlLmFixedVolatilityModel vols times
  where (times, vols) = unzip (toList tv)
volatilityModel (LinearExponentialVolatility s a b c d) = qlLmLinearExponentialVolatilityModel s a b c d

volatilityModelMeta :: EnumMeta LmVolatilityModel CLmVolatilityModel
volatilityModelMeta = EnumMeta volatilityModel

withLmVolatilityModel :: LmVolatilityModel -> (Ptr CLmVolatilityModel -> IO a) -> IO a
withLmVolatilityModel = withEnumType volatilityModelMeta

data Claim = FaceValue | forall b. FaceValueAccrual (GenBond b)
claimMeta :: EnumMeta Claim CQlClaim
claimMeta :: EnumMeta Claim CQlClaim
claimMeta = (Claim -> IO (Standalone CQlClaim)) -> EnumMeta Claim CQlClaim
forall a b. (a -> IO (Standalone b)) -> EnumMeta a b
EnumMeta Claim -> IO (Standalone CQlClaim)
claim

withClaim :: Claim -> (Ptr CQlClaim -> IO a) -> IO a
withClaim :: forall a. Claim -> (Ptr CQlClaim -> IO a) -> IO a
withClaim = EnumMeta Claim CQlClaim -> Claim -> (Ptr CQlClaim -> IO a) -> IO a
forall a b c. EnumMeta a b -> a -> (Ptr b -> IO c) -> IO c
withEnumType EnumMeta Claim CQlClaim
claimMeta

claim :: Claim -> IO QlClaim
claim :: Claim -> IO (Standalone CQlClaim)
claim Claim
FaceValue = IO (Standalone CQlClaim)
qlFaceValueClaim
claim (FaceValueAccrual GenBond b
b) = GenBond b -> IO (Standalone CQlClaim)
forall b. GenBond b -> IO (Standalone CQlClaim)
qlFaceValueAccrualClaim GenBond b
b

-- |Claim on a notional
qlFaceValueClaim :: IO ((QlClaim))
qlFaceValueClaim :: IO (Standalone CQlClaim)
qlFaceValueClaim =
  (Ptr (Ptr ()) -> IO (Standalone CQlClaim))
-> IO (Standalone CQlClaim)
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO (Standalone CQlClaim))
 -> IO (Standalone CQlClaim))
-> (Ptr (Ptr ()) -> IO (Standalone CQlClaim))
-> IO (Standalone CQlClaim)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a1' -> 
  Ptr (Ptr ()) -> IO (Ptr CQlClaim)
qlFaceValueClaim'_ Ptr (Ptr ())
a1' IO (Ptr CQlClaim)
-> (Ptr CQlClaim -> IO (Standalone CQlClaim))
-> IO (Standalone CQlClaim)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CQlClaim
res ->
  Ptr CQlClaim -> IO (Standalone CQlClaim)
peekClaim Ptr CQlClaim
res IO (Standalone CQlClaim)
-> (Standalone CQlClaim -> IO (Standalone CQlClaim))
-> IO (Standalone CQlClaim)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Standalone CQlClaim
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a1'IO () -> IO (Standalone CQlClaim) -> IO (Standalone CQlClaim)
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Standalone CQlClaim -> IO (Standalone CQlClaim)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Standalone CQlClaim
res')

{-# LINE 1063 "./QuantLib/Internal/Common.chs" #-}


-- |Claim on the notional of a reference security, including accrual
qlFaceValueAccrualClaim :: (GenBond b) -> IO ((QlClaim))
qlFaceValueAccrualClaim a1 =
  withBond a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  qlFaceValueAccrualClaim'_ a1' a2' >>= \res ->
  peekClaim res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 1066 "./QuantLib/Internal/Common.chs" #-}


strikedPayoff :: StrikedPayoff -> Payoff
strikedPayoff = Type . Striked

percentageStrikePayoff :: PercentageStrikePayoff -> Payoff
percentageStrikePayoff = Type . Striked . PercentageStrike

plainVanillaPayoff :: PlainVanillaPayoff -> Payoff
plainVanillaPayoff = Type . Striked . PlainVanilla

swingExercise :: SwingExercise -> Exercise
swingExercise :: SwingExercise -> Exercise
swingExercise = BermudanExercise -> Exercise
Bermudan (BermudanExercise -> Exercise)
-> (SwingExercise -> BermudanExercise) -> SwingExercise -> Exercise
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwingExercise -> BermudanExercise
Swing

-- |One value from QuantLib's `Instrument::additionalResults()` map. QuantLib stores the map as
-- `ext::any`, so this Haskell view picks three concrete shapes -- `Real` (`Double`), `std::string`
-- (`String`), `std::vector<Real>` (`[Double]`) -- plus an `UnsupportedVal` fallback recording the
-- value's C++ RTTI type name, so no key is ever silently dropped or mislabelled.
data AdditionalResultVal = RealVal Double | StringVal String | RealVectorVal [Double] | UnsupportedVal String
  deriving (Int -> AdditionalResultVal -> ShowS
[AdditionalResultVal] -> ShowS
AdditionalResultVal -> String
(Int -> AdditionalResultVal -> ShowS)
-> (AdditionalResultVal -> String)
-> ([AdditionalResultVal] -> ShowS)
-> Show AdditionalResultVal
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AdditionalResultVal -> ShowS
showsPrec :: Int -> AdditionalResultVal -> ShowS
$cshow :: AdditionalResultVal -> String
show :: AdditionalResultVal -> String
$cshowList :: [AdditionalResultVal] -> ShowS
showList :: [AdditionalResultVal] -> ShowS
Show, AdditionalResultVal -> AdditionalResultVal -> Bool
(AdditionalResultVal -> AdditionalResultVal -> Bool)
-> (AdditionalResultVal -> AdditionalResultVal -> Bool)
-> Eq AdditionalResultVal
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AdditionalResultVal -> AdditionalResultVal -> Bool
== :: AdditionalResultVal -> AdditionalResultVal -> Bool
$c/= :: AdditionalResultVal -> AdditionalResultVal -> Bool
/= :: AdditionalResultVal -> AdditionalResultVal -> Bool
Eq)

type RawResultPtr = Ptr RawResult

-- |One raw `QlAdditionalResult` entry, peeked field-by-field via c2hs `{#get#}` hooks. Its
-- `Storable` instance (`sizeOf`/`alignment` from `{#sizeof#}`/`{#alignof#}`, both read straight
-- from the C struct layout, not hand-computed) is what lets `peekStructArray`
-- (`QuantLib.Internal`) walk the C array via a plain `peekArray`, rather than hand-rolled pointer
-- arithmetic.
data RawResult = RawResult
  { RawResult -> CString
rKey :: CString, RawResult -> CInt
rType :: CInt, RawResult -> CDouble
rDval :: CDouble
  , RawResult -> CString
rSval :: CString, RawResult -> Ptr CDouble
rVarr :: Ptr CDouble, RawResult -> CUInt
rVlen :: CUInt }

instance Storable RawResult where
  sizeOf :: RawResult -> Int
sizeOf RawResult
_ = Int
48
{-# LINE 1099 "./QuantLib/Internal/Common.chs" #-}

  alignment _ = 8
{-# LINE 1100 "./QuantLib/Internal/Common.chs" #-}

  peek p = RawResult <$> (\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO (C2HSImp.Ptr C2HSImp.CChar)}) p
                      <*> (\ptr -> do {C2HSImp.peekByteOff ptr 8 :: IO C2HSImp.CInt}) p
                      <*> (\ptr -> do {C2HSImp.peekByteOff ptr 16 :: IO C2HSImp.CDouble}) p
                      <*> (\ptr -> do {C2HSImp.peekByteOff ptr 24 :: IO (C2HSImp.Ptr C2HSImp.CChar)}) p
                      <*> (\ptr -> do {C2HSImp.peekByteOff ptr 32 :: IO (C2HSImp.Ptr C2HSImp.CDouble)}) p
                      <*> (\ptr -> do {C2HSImp.peekByteOff ptr 40 :: IO C2HSImp.CUInt}) p
  poke :: Ptr RawResult -> RawResult -> IO ()
poke = String -> Ptr RawResult -> RawResult -> IO ()
forall a. HasCallStack => String -> a
error String
"RawResult is peek-only (read from C, never constructed in Haskell)"

-- |Convert one raw entry into its keyed Haskell value. `sval`/`varr` are only read for the
-- discriminant that owns them; their buffers are released in bulk afterwards, by
-- `qlFreeAdditionalResults`, not per-field here.
convertResult :: RawResult -> IO (String, AdditionalResultVal)
convertResult :: RawResult -> IO (String, AdditionalResultVal)
convertResult RawResult
r = do
  key <- CString -> IO String
peekCString (RawResult -> CString
rKey RawResult
r)
  val <- case toEnum (fromIntegral (rType r)) of
    AdditionalResultType
AdditionalResultDouble -> AdditionalResultVal -> IO AdditionalResultVal
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Double -> AdditionalResultVal
RealVal (CDouble -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac (RawResult -> CDouble
rDval RawResult
r)))
    AdditionalResultType
AdditionalResultString -> String -> AdditionalResultVal
StringVal (String -> AdditionalResultVal)
-> IO String -> IO AdditionalResultVal
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CString -> IO String
peekCString (RawResult -> CString
rSval RawResult
r)
    AdditionalResultType
AdditionalResultDoubleVector -> [Double] -> AdditionalResultVal
RealVectorVal ([Double] -> AdditionalResultVal)
-> ([CDouble] -> [Double]) -> [CDouble] -> AdditionalResultVal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CDouble -> Double) -> [CDouble] -> [Double]
forall a b. (a -> b) -> [a] -> [b]
map CDouble -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac
                                       ([CDouble] -> AdditionalResultVal)
-> IO [CDouble] -> IO AdditionalResultVal
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Ptr CDouble -> IO [CDouble]
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray (CUInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (RawResult -> CUInt
rVlen RawResult
r)) (RawResult -> Ptr CDouble
rVarr RawResult
r)
    AdditionalResultType
AdditionalResultUnknown -> String -> AdditionalResultVal
UnsupportedVal (String -> AdditionalResultVal)
-> IO String -> IO AdditionalResultVal
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CString -> IO String
peekCString (RawResult -> CString
rSval RawResult
r)
  return (key, val)

-- |Peek the C array of `QlAdditionalResult` into a keyed list, then release the whole array (keys,
-- `sval`/`varr` buffers, and the array itself) in one `qlFreeAdditionalResults` call.
peekAdditionalResults :: Ptr CUInt -> Ptr RawResultPtr -> IO [(String, AdditionalResultVal)]
peekAdditionalResults :: Ptr CUInt
-> Ptr (Ptr RawResult) -> IO [(String, AdditionalResultVal)]
peekAdditionalResults = (RawResult -> IO (String, AdditionalResultVal))
-> (CUInt -> Ptr RawResult -> IO ())
-> Ptr CUInt
-> Ptr (Ptr RawResult)
-> IO [(String, AdditionalResultVal)]
forall a b.
Storable a =>
(a -> IO b)
-> (CUInt -> Ptr a -> IO ()) -> Ptr CUInt -> Ptr (Ptr a) -> IO [b]
peekStructArray RawResult -> IO (String, AdditionalResultVal)
convertResult (\CUInt
l Ptr RawResult
p -> CUInt -> Ptr () -> IO ()
qlFreeAdditionalResults CUInt
l (Ptr RawResult -> Ptr ()
forall a b. Ptr a -> Ptr b
castPtr Ptr RawResult
p))

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

preAdditionalResults :: ((Ptr CUInt, Ptr RawResultPtr) -> IO b) -> IO b
preAdditionalResults :: forall b. ((Ptr CUInt, Ptr (Ptr RawResult)) -> IO b) -> IO b
preAdditionalResults = (CUInt -> Ptr RawResult -> IO ())
-> ((Ptr CUInt, Ptr (Ptr RawResult)) -> IO b) -> IO b
forall a b.
(CUInt -> Ptr a -> IO ())
-> ((Ptr CUInt, Ptr (Ptr a)) -> IO b) -> IO b
preArrayWith (\CUInt
l Ptr RawResult
p -> CUInt -> Ptr () -> IO ()
qlFreeAdditionalResults CUInt
l (Ptr RawResult -> Ptr ()
forall a b. Ptr a -> Ptr b
castPtr Ptr RawResult
p))

stubIndexSelectionRaw :: (Int) -> ([GenIborIndex ibor]) -> IO ((StubSelectionPtr))
stubIndexSelectionRaw :: forall ibor.
Int -> [GenIborIndex ibor] -> IO (Ptr CStubIndexSelection')
stubIndexSelectionRaw Int
a1 [GenIborIndex ibor]
a2 =
  let {a1' :: CInt
a1' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a1} in 
  [GenIborIndex ibor]
-> ((CUInt, Ptr (Ptr CIborIndex'))
    -> IO (Ptr CStubIndexSelection'))
-> IO (Ptr CStubIndexSelection')
forall ibor r.
[GenIborIndex ibor]
-> ((CUInt, Ptr (Ptr CIborIndex')) -> IO r) -> IO r
withIborIndexArray [GenIborIndex ibor]
a2 (((CUInt, Ptr (Ptr CIborIndex')) -> IO (Ptr CStubIndexSelection'))
 -> IO (Ptr CStubIndexSelection'))
-> ((CUInt, Ptr (Ptr CIborIndex'))
    -> IO (Ptr CStubIndexSelection'))
-> IO (Ptr CStubIndexSelection')
forall a b. (a -> b) -> a -> b
$ \(CUInt
a2'1, Ptr (Ptr CIborIndex')
a2'2) -> 
  (Ptr (Ptr ()) -> IO (Ptr CStubIndexSelection'))
-> IO (Ptr CStubIndexSelection')
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO (Ptr CStubIndexSelection'))
 -> IO (Ptr CStubIndexSelection'))
-> (Ptr (Ptr ()) -> IO (Ptr CStubIndexSelection'))
-> IO (Ptr CStubIndexSelection')
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a3' -> 
  CInt
-> CUInt
-> Ptr (Ptr CIborIndex')
-> Ptr (Ptr ())
-> IO (Ptr CStubIndexSelection')
stubIndexSelectionRaw'_ CInt
a1' CUInt
a2'1  Ptr (Ptr CIborIndex')
a2'2 Ptr (Ptr ())
a3' IO (Ptr CStubIndexSelection')
-> (Ptr CStubIndexSelection' -> IO (Ptr CStubIndexSelection'))
-> IO (Ptr CStubIndexSelection')
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CStubIndexSelection'
res ->
  Ptr CStubIndexSelection' -> IO (Ptr CStubIndexSelection')
forall a. Ptr a -> IO (Ptr a)
peekPtr Ptr CStubIndexSelection'
res IO (Ptr CStubIndexSelection')
-> (Ptr CStubIndexSelection' -> IO (Ptr CStubIndexSelection'))
-> IO (Ptr CStubIndexSelection')
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CStubIndexSelection'
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a3'IO ()
-> IO (Ptr CStubIndexSelection') -> IO (Ptr CStubIndexSelection')
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Ptr CStubIndexSelection' -> IO (Ptr CStubIndexSelection')
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr CStubIndexSelection'
res')

{-# LINE 1135 "./QuantLib/Internal/Common.chs" #-}


foreign import ccall safe "QuantLib/Internal/Common.chs.h qlExercise"
  qlExercise'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlExercise))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlAmericanExercise"
  qlAmericanExercise'_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlAmericanExercise))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlAmericanExercise1"
  qlAmericanExercise1'_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlAmericanExercise)))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlBermudanExercise"
  qlBermudanExercise'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlBermudanExercise))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlEarlyExercise"
  qlEarlyExercise'_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlExercise)))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlEuropeanExercise"
  qlEuropeanExercise'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlEuropeanExercise))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlSwingExercise"
  qlSwingExercise'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlSwingExercise)))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlSwingExercise1"
  qlSwingExercise1'_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlSwingExercise))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlRebatedExercise"
  qlRebatedExercise'_ :: ((QlExercise) -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlRebatedExercise))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlAssetOrNothingPayoff"
  qlAssetOrNothingPayoff'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlStrikedTypePayoff)))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlAverageBasketPayoff"
  qlAverageBasketPayoff'_ :: ((QlPayoff) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlBasketPayoff)))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlCashOrNothingPayoff"
  qlCashOrNothingPayoff'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlStrikedTypePayoff))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlDoubleStickyRatchetPayoff"
  qlDoubleStickyRatchetPayoff'_ :: (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlPayoff))))))))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlFloatingTypePayoff"
  qlFloatingTypePayoff'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlTypePayoff))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlForwardTypePayoff"
  qlForwardTypePayoff'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlPayoff)))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlGapPayoff"
  qlGapPayoff'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlStrikedTypePayoff))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlMaxBasketPayoff"
  qlMaxBasketPayoff'_ :: ((QlPayoff) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlBasketPayoff))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlMinBasketPayoff"
  qlMinBasketPayoff'_ :: ((QlPayoff) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlBasketPayoff))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlPercentageStrikePayoff"
  qlPercentageStrikePayoff'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlPercentageStrikePayoff)))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlPlainVanillaPayoff"
  qlPlainVanillaPayoff'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlPlainVanillaPayoff)))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlRatchetMaxPayoff"
  qlRatchetMaxPayoff'_ :: (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlPayoff))))))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlRatchetMinPayoff"
  qlRatchetMinPayoff'_ :: (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlPayoff))))))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlRatchetPayoff"
  qlRatchetPayoff'_ :: (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlPayoff)))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlSpreadBasketPayoff"
  qlSpreadBasketPayoff'_ :: ((QlPayoff) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlBasketPayoff))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlStickyMaxPayoff"
  qlStickyMaxPayoff'_ :: (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlPayoff))))))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlStickyMinPayoff"
  qlStickyMinPayoff'_ :: (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlPayoff))))))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlStickyPayoff"
  qlStickyPayoff'_ :: (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlPayoff)))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlSuperFundPayoff"
  qlSuperFundPayoff'_ :: (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlStrikedTypePayoff)))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlSuperSharePayoff"
  qlSuperSharePayoff'_ :: (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlStrikedTypePayoff))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlAverageBasketPayoff1"
  qlAverageBasketPayoff1'_ :: ((QlPayoff) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlBasketPayoff))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlPayoffFromFunction"
  qlPayoffFromFunction'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlPayoff))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlBasketPayoffFromFunction"
  qlBasketPayoffFromFunction'_ :: ((QlPayoff) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlBasketPayoff)))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlStrikedPayoffFromFunction"
  qlStrikedPayoffFromFunction'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlStrikedTypePayoff)))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlSoftCallability"
  qlSoftCallability'_ :: (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CQlCallability))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlCallability"
  qlCallability'_ :: (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CQlCallability))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlCubicBSplinesFitting"
  qlCubicBSplinesFitting'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (COptimizationMethod)) -> ((C2HSImp.Ptr (CConstraint)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFittedBondDiscountCurveFittingMethod)))))))))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlExponentialSplinesFitting"
  qlExponentialSplinesFitting'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (COptimizationMethod)) -> ((C2HSImp.Ptr (CConstraint)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFittedBondDiscountCurveFittingMethod)))))))))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlNelsonSiegelFitting"
  qlNelsonSiegelFitting'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (COptimizationMethod)) -> ((C2HSImp.Ptr (CConstraint)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFittedBondDiscountCurveFittingMethod))))))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlSimplePolynomialFitting"
  qlSimplePolynomialFitting'_ :: (C2HSImp.CUInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (COptimizationMethod)) -> ((C2HSImp.Ptr (CConstraint)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFittedBondDiscountCurveFittingMethod))))))))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlSvenssonFitting"
  qlSvenssonFitting'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (COptimizationMethod)) -> ((C2HSImp.Ptr (CConstraint)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFittedBondDiscountCurveFittingMethod))))))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlFdmSchemeDesc"
  qlFdmSchemeDesc'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmSchemeDesc)))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlFdmSchemeDescCraigSneyd"
  qlFdmSchemeDescCraigSneyd'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmSchemeDesc))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlFdmSchemeDescDouglas"
  qlFdmSchemeDescDouglas'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmSchemeDesc))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlFdmSchemeDescExplicitEuler"
  qlFdmSchemeDescExplicitEuler'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmSchemeDesc))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlFdmSchemeDescHundsdorfer"
  qlFdmSchemeDescHundsdorfer'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmSchemeDesc))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlFdmSchemeDescImplicitEuler"
  qlFdmSchemeDescImplicitEuler'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmSchemeDesc))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlFdmSchemeDescModifiedCraigSneyd"
  qlFdmSchemeDescModifiedCraigSneyd'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmSchemeDesc))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlFdmSchemeDescModifiedHundsdorfer"
  qlFdmSchemeDescModifiedHundsdorfer'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmSchemeDesc))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlFdmSchemeDescMethodOfLines"
  qlFdmSchemeDescMethodOfLines'_ :: (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmSchemeDesc))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlBoundaryConstraint"
  qlBoundaryConstraint'_ :: (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CConstraint))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlCompositeConstraint"
  qlCompositeConstraint'_ :: ((C2HSImp.Ptr (CConstraint)) -> ((C2HSImp.Ptr (CConstraint)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CConstraint))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlNoConstraint"
  qlNoConstraint'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CConstraint))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlPositiveConstraint"
  qlPositiveConstraint'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CConstraint))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlLevenbergMarquardt"
  qlLevenbergMarquardt'_ :: (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (COptimizationMethod))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlSimplex"
  qlSimplex'_ :: (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (COptimizationMethod)))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlEndCriteria"
  qlEndCriteria'_ :: (C2HSImp.CUInt -> (C2HSImp.CUInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CEndCriteria)))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlRounding"
  qlRounding'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CRounding))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlRounding1"
  qlRounding1'_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CRounding)))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlLmConstWrapperCorrelationModel"
  qlLmConstWrapperCorrelationModel'_ :: ((C2HSImp.Ptr (CLmCorrelationModel)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CLmCorrelationModel)))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlLmExponentialCorrelationModel"
  qlLmExponentialCorrelationModel'_ :: (C2HSImp.CUInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CLmCorrelationModel))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlLmLinearExponentialCorrelationModel"
  qlLmLinearExponentialCorrelationModel'_ :: (C2HSImp.CUInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CLmCorrelationModel))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlLmConstWrapperVolatilityModel"
  qlLmConstWrapperVolatilityModel'_ :: ((C2HSImp.Ptr (CLmVolatilityModel)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CLmVolatilityModel)))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlLmFixedVolatilityModel"
  qlLmFixedVolatilityModel'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CLmVolatilityModel))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlLmLinearExponentialVolatilityModel"
  qlLmLinearExponentialVolatilityModel'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CLmVolatilityModel))))))))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlFaceValueClaim"
  qlFaceValueClaim'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CQlClaim))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlFaceValueAccrualClaim"
  qlFaceValueAccrualClaim'_ :: ((C2HSImp.Ptr (CBond')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CQlClaim)))))

foreign import ccall safe "QuantLib/Internal/Common.chs.h qlStubIndexSelection"
  stubIndexSelectionRaw'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CIborIndex'))) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (QlStubIndexSelection))))))