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


{-# LINE 1 "./QuantLib/TermStructure/Credit.chs" #-}
-- | Credit term structures and helpers.
--
-- = Hazard shifts #hazard-shifts#
--
-- 'shiftedHazardRateCurve' retains QuantLib's parallel and relative wrappers. Their
-- survival calculation uses 48-point Gauss-Chebyshev quadrature, so even
-- a constant hazard integrates with a small numerical error. For a flat annual
-- hazard h, parallel survival is @exp(-k*h*t)@, with @k = pi\/(96*sin(pi\/96))@, rather
-- than exp(-h*t). This numerical behavior is retained for compatibility.
-- Parallel queries now refuse negative or non-finite resulting hazards, including
-- during native survival integration, rather than returning invalid credit rates.
-- Shaped shifts instead retain base survival and apply the exact interpolation
-- primitive of their spread; see 'shiftedHazardRateCurve' for bounds and query checks.
--
-- = Conditional survival #conditional-survival#
--
-- 'conditionalSurvivalCurve' is a hasquant curve view, not a QuantLib class binding.
-- It keeps the original native interpolation and hazard-wrapper quadrature. For
-- original-curve time s at its new fixed reference, a view-time t reads
-- @S(s+t)/S(s)@, @f(s+t)/S(s)@ and @h(s+t)@ from the original curve.
-- View times are years from the new reference on the original day counter. Date
-- queries preserve original-date ratios when that day counter adds year fractions;
-- callers must check that clock convention rather than silently re-interpolate.
-- The new reference must lie within the original support and have positive finite
-- survival: normalizing zero or an invalid value cannot define a conditional curve.
-- Sources exposing scheduled jumps are refused: the generic curve interface does not
-- expose their quote handles, so transferring their jump metadata would lose updates.
-- The view keeps its original curve alive, observes its updates and inherits its
-- calendar, day counter, maximum date and extrapolation permission. Its reference
-- remains fixed if the original curve moves; a reference that then becomes invalid
-- is refused when queried. Native query values must remain finite.
module QuantLib.TermStructure.Credit
  (
    -- * Types
    -- ** Curves and helpers
    GenDefaultProbabilityTermStructure
  , DefaultProbabilityTermStructure
  , AffineHazardRateCurve
  , PiecewiseDefaultCurve
  , DefaultProbabilityHelper

    -- ** Coordinates
  , Reference(..)
  , TermPoint(..)
  , TermInterval(..)

    -- ** Hazard shifts
  , HazardRateShift(..)

    -- ** Bootstrap configuration
  , ProbabilityTrait(..)
  , IterativeBootstrapOpts(..)

    -- * Constructors
    -- ** Flat, conditional and spreaded curves
  , shiftedHazardRateCurve
  , flatHazardRate
  , conditionalSurvivalCurve
    -- ** Helpers and bootstrapped curves
  , spreadCdsHelper
  , upfrontCdsHelper
  , interpolatedDefaultDensityCurve
  , interpolatedHazardRateCurve
  , interpolatedAffineHazardRateCurve
  , interpolatedSurvivalProbabilityCurve
  , defaultIterativeBootstrapOpts
  , piecewiseDefaultCurve
  , asDefaultProbabilityTermStructure

    -- * Inspectors
  , defaultProbability
  , hazardRate
  , survivalProbability
  , defaultDensity
  , defaultProbabilityBetween
  , conditionalSurvivalProbability
  , impliedQuote
  , impliedQuoteOn
  , HasNodes(..)
  ) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.ForeignPtr as C2HSImp
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp







import QuantLib.Internal
import QuantLib.Instrument(PricingModel)
import QuantLib.Internal.Type
import QuantLib.Time.Schedule(DateGenerationRule, Frequency)
import QuantLib.Internal.Common
import QuantLib.TermStructure (Reference(..), TermPoint(..), TermInterval(..), setExtrapolation, HasNodes(..))
import Data.List.NonEmpty(NonEmpty, toList)

data ProbabilityTrait = SurvivalProbability
                      | HazardRate
                      | DefaultDensity
  deriving (Int -> ProbabilityTrait -> ShowS
[ProbabilityTrait] -> ShowS
ProbabilityTrait -> String
(Int -> ProbabilityTrait -> ShowS)
-> (ProbabilityTrait -> String)
-> ([ProbabilityTrait] -> ShowS)
-> Show ProbabilityTrait
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ProbabilityTrait -> ShowS
showsPrec :: Int -> ProbabilityTrait -> ShowS
$cshow :: ProbabilityTrait -> String
show :: ProbabilityTrait -> String
$cshowList :: [ProbabilityTrait] -> ShowS
showList :: [ProbabilityTrait] -> ShowS
Show,ProbabilityTrait -> ProbabilityTrait -> Bool
(ProbabilityTrait -> ProbabilityTrait -> Bool)
-> (ProbabilityTrait -> ProbabilityTrait -> Bool)
-> Eq ProbabilityTrait
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ProbabilityTrait -> ProbabilityTrait -> Bool
== :: ProbabilityTrait -> ProbabilityTrait -> Bool
$c/= :: ProbabilityTrait -> ProbabilityTrait -> Bool
/= :: ProbabilityTrait -> ProbabilityTrait -> Bool
Eq,ReadPrec [ProbabilityTrait]
ReadPrec ProbabilityTrait
Int -> ReadS ProbabilityTrait
ReadS [ProbabilityTrait]
(Int -> ReadS ProbabilityTrait)
-> ReadS [ProbabilityTrait]
-> ReadPrec ProbabilityTrait
-> ReadPrec [ProbabilityTrait]
-> Read ProbabilityTrait
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS ProbabilityTrait
readsPrec :: Int -> ReadS ProbabilityTrait
$creadList :: ReadS [ProbabilityTrait]
readList :: ReadS [ProbabilityTrait]
$creadPrec :: ReadPrec ProbabilityTrait
readPrec :: ReadPrec ProbabilityTrait
$creadListPrec :: ReadPrec [ProbabilityTrait]
readListPrec :: ReadPrec [ProbabilityTrait]
Read)
instance Enum ProbabilityTrait where
  succ SurvivalProbability = HazardRate
  succ HazardRate = DefaultDensity
  succ DefaultDensity = error "ProbabilityTrait.succ: DefaultDensity has no successor"

  pred :: ProbabilityTrait -> ProbabilityTrait
pred ProbabilityTrait
HazardRate = ProbabilityTrait
SurvivalProbability
  pred ProbabilityTrait
DefaultDensity = ProbabilityTrait
HazardRate
  pred ProbabilityTrait
SurvivalProbability = String -> ProbabilityTrait
forall a. HasCallStack => String -> a
error String
"ProbabilityTrait.pred: SurvivalProbability has no predecessor"

  enumFromTo :: ProbabilityTrait -> ProbabilityTrait -> [ProbabilityTrait]
enumFromTo ProbabilityTrait
from ProbabilityTrait
to = ProbabilityTrait -> [ProbabilityTrait]
forall {t}. Enum t => t -> [t]
go ProbabilityTrait
from
    where
      end :: Int
end = ProbabilityTrait -> Int
forall a. Enum a => a -> Int
fromEnum ProbabilityTrait
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 :: ProbabilityTrait -> [ProbabilityTrait]
enumFrom ProbabilityTrait
from = ProbabilityTrait -> ProbabilityTrait -> [ProbabilityTrait]
forall a. Enum a => a -> a -> [a]
enumFromTo ProbabilityTrait
from ProbabilityTrait
DefaultDensity

  fromEnum :: ProbabilityTrait -> Int
fromEnum ProbabilityTrait
SurvivalProbability = Int
0
  fromEnum ProbabilityTrait
HazardRate = Int
1
  fromEnum ProbabilityTrait
DefaultDensity = Int
2

  toEnum :: Int -> ProbabilityTrait
toEnum Int
0 = ProbabilityTrait
SurvivalProbability
  toEnum Int
1 = ProbabilityTrait
HazardRate
  toEnum Int
2 = ProbabilityTrait
DefaultDensity
  toEnum Int
unmatched = String -> ProbabilityTrait
forall a. HasCallStack => String -> a
error (String
"ProbabilityTrait.toEnum: Cannot match " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
unmatched)

{-# LINE 94 "./QuantLib/TermStructure/Credit.chs" #-}



{-# LINE 96 "./QuantLib/TermStructure/Credit.chs" #-}


{-# LINE 97 "./QuantLib/TermStructure/Credit.chs" #-}


{-# LINE 98 "./QuantLib/TermStructure/Credit.chs" #-}


{-# LINE 99 "./QuantLib/TermStructure/Credit.chs" #-}


{-# LINE 100 "./QuantLib/TermStructure/Credit.chs" #-}


{-# LINE 101 "./QuantLib/TermStructure/Credit.chs" #-}


{-# LINE 102 "./QuantLib/TermStructure/Credit.chs" #-}


{-# LINE 103 "./QuantLib/TermStructure/Credit.chs" #-}


-- | A live shift of a credit curve. Spreads are annual continuous hazard fractions;
-- relative operands are dimensionless (0.01 means multiplying hazards by 1.01).
data HazardRateShift q
  = -- | QuantLib's additive parallel hazard wrapper.
    ParallelHazardShift (GenQuote q) -- ^Annual additive spread quote.
  | -- | QuantLib's relative hazard wrapper.
    RelativeHazardShift (GenQuote q) -- ^Fractional change quote, normally at least -1.
  | -- | Linear spread in curve time between dates, flat outside the grid.
    KeyRateHazardShifts (NonEmpty (Day, GenQuote q)) -- ^Strictly increasing dates after the underlying reference date, paired with annual spread quotes.
  | -- | Constant spread on [previous end, end), zero at and after the last end.
    BucketHazardShifts (NonEmpty (Day, GenQuote q)) -- ^Strictly increasing period ends after the underlying reference date, paired with annual spread quotes; the first period starts at that reference date.

-- | Apply a live hazard shift, retaining the underlying reference date, day counter,
-- calendar and maximum date. The underlying and all quotes remain observed.
--
-- Parallel and relative shifts retain QuantLib's original wrappers and numerical
-- integration; parallel queries additionally check finite nonnegative hazards.
-- The shaped adapter is defined by hasquant: it adds the spread to
-- the underlying hazard and multiplies underlying survival by
-- @exp(-integral spread dt)@. QuantLib's linear/forward-flat interpolation primitives
-- integrate the spread exactly, so bucket boundaries introduce no survival jumps
-- and the accumulated change remains after the last bucket. The base curve is
-- never sampled or re-interpolated. Curve times use its own day counter.
--
-- Shaped queries refuse non-finite spreads, negative or non-finite resulting hazards,
-- and non-finite survival probabilities or values outside [0,1]. Multiplication
-- roundoff at most four machine epsilons above one is clamped to one, so exactly
-- zero hazards are not refused because @exp(-x) * exp(x)@ rounded upward.
-- Survival queries
-- check their endpoint and both sides of earlier spread knots; this is not a proof
-- of positivity at every point of an arbitrary underlying curve. Underflow and
-- overflow of the exponential correction remain native floating-point limits.
shiftedHazardRateCurve
  :: GenDefaultProbabilityTermStructure d -- ^Underlying credit curve.
  -> HazardRateShift q -- ^Live shift quotes and, for shapes, their date grid.
  -> IO DefaultProbabilityTermStructure
shiftedHazardRateCurve :: forall d q.
GenDefaultProbabilityTermStructure d
-> HazardRateShift q -> IO DefaultProbabilityTermStructure
shiftedHazardRateCurve GenDefaultProbabilityTermStructure d
base HazardRateShift q
shift = case HazardRateShift q
shift of
  ParallelHazardShift GenQuote q
q -> GenDefaultProbabilityTermStructure d
-> GenQuote q -> IO DefaultProbabilityTermStructure
forall d q.
GenDefaultProbabilityTermStructure d
-> GenQuote q -> IO DefaultProbabilityTermStructure
parallelHazardRateCurveRaw GenDefaultProbabilityTermStructure d
base GenQuote q
q
  RelativeHazardShift GenQuote q
q -> GenDefaultProbabilityTermStructure d
-> GenQuote q -> IO DefaultProbabilityTermStructure
forall d q.
GenDefaultProbabilityTermStructure d
-> GenQuote q -> IO DefaultProbabilityTermStructure
relativeHazardRateCurveRaw GenDefaultProbabilityTermStructure d
base GenQuote q
q
  KeyRateHazardShifts NonEmpty (Day, GenQuote q)
nodes -> Bool
-> NonEmpty (Day, GenQuote q) -> IO DefaultProbabilityTermStructure
forall {q}.
Bool
-> NonEmpty (Day, GenQuote q) -> IO DefaultProbabilityTermStructure
shaped Bool
False NonEmpty (Day, GenQuote q)
nodes
  BucketHazardShifts NonEmpty (Day, GenQuote q)
nodes -> Bool
-> NonEmpty (Day, GenQuote q) -> IO DefaultProbabilityTermStructure
forall {q}.
Bool
-> NonEmpty (Day, GenQuote q) -> IO DefaultProbabilityTermStructure
shaped Bool
True NonEmpty (Day, GenQuote q)
nodes
  where
    shaped :: Bool
-> NonEmpty (Day, GenQuote q) -> IO DefaultProbabilityTermStructure
shaped Bool
buckets NonEmpty (Day, GenQuote q)
nodes = let ([Day]
dates, [GenQuote q]
quotes) = [(Day, GenQuote q)] -> ([Day], [GenQuote q])
forall a b. [(a, b)] -> ([a], [b])
unzip (NonEmpty (Day, GenQuote q) -> [(Day, GenQuote q)]
forall a. NonEmpty a -> [a]
toList NonEmpty (Day, GenQuote q)
nodes)
                          in GenDefaultProbabilityTermStructure d
-> [GenQuote q]
-> [Day]
-> Bool
-> IO DefaultProbabilityTermStructure
forall d q.
GenDefaultProbabilityTermStructure d
-> [GenQuote q]
-> [Day]
-> Bool
-> IO DefaultProbabilityTermStructure
shapedHazardRateCurveRaw GenDefaultProbabilityTermStructure d
base [GenQuote q]
quotes [Day]
dates Bool
buckets

shapedHazardRateCurveRaw :: (GenDefaultProbabilityTermStructure d) -> ([GenQuote q]) -> ([Day]) -> (Bool) -> IO ((DefaultProbabilityTermStructure))
shapedHazardRateCurveRaw :: forall d q.
GenDefaultProbabilityTermStructure d
-> [GenQuote q]
-> [Day]
-> Bool
-> IO DefaultProbabilityTermStructure
shapedHazardRateCurveRaw GenDefaultProbabilityTermStructure d
a1 [GenQuote q]
a2 [Day]
a3 Bool
a4 =
  GenDefaultProbabilityTermStructure d
-> (Ptr CDefaultProbabilityTermStructure'
    -> IO DefaultProbabilityTermStructure)
-> IO DefaultProbabilityTermStructure
forall d b.
GenDefaultProbabilityTermStructure d
-> (Ptr CDefaultProbabilityTermStructure' -> IO b) -> IO b
withDefaultProbabilityTermStructure GenDefaultProbabilityTermStructure d
a1 ((Ptr CDefaultProbabilityTermStructure'
  -> IO DefaultProbabilityTermStructure)
 -> IO DefaultProbabilityTermStructure)
-> (Ptr CDefaultProbabilityTermStructure'
    -> IO DefaultProbabilityTermStructure)
-> IO DefaultProbabilityTermStructure
forall a b. (a -> b) -> a -> b
$ \Ptr CDefaultProbabilityTermStructure'
a1' -> 
  [GenQuote q]
-> ((CUInt, Ptr (Ptr CQuote'))
    -> IO DefaultProbabilityTermStructure)
-> IO DefaultProbabilityTermStructure
forall q b.
[GenQuote q] -> ((CUInt, Ptr (Ptr CQuote')) -> IO b) -> IO b
withQuoteArray [GenQuote q]
a2 (((CUInt, Ptr (Ptr CQuote')) -> IO DefaultProbabilityTermStructure)
 -> IO DefaultProbabilityTermStructure)
-> ((CUInt, Ptr (Ptr CQuote'))
    -> IO DefaultProbabilityTermStructure)
-> IO DefaultProbabilityTermStructure
forall a b. (a -> b) -> a -> b
$ \(CUInt
a2'1, Ptr (Ptr CQuote')
a2'2) -> 
  [Day]
-> ((CUInt, Ptr CInt) -> IO DefaultProbabilityTermStructure)
-> IO DefaultProbabilityTermStructure
forall b. [Day] -> ((CUInt, Ptr CInt) -> IO b) -> IO b
withDayArray [Day]
a3 (((CUInt, Ptr CInt) -> IO DefaultProbabilityTermStructure)
 -> IO DefaultProbabilityTermStructure)
-> ((CUInt, Ptr CInt) -> IO DefaultProbabilityTermStructure)
-> IO DefaultProbabilityTermStructure
forall a b. (a -> b) -> a -> b
$ \(CUInt
a3'1, Ptr CInt
a3'2) -> 
  let {a4' :: CInt
a4' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a4} in 
  (Ptr (Ptr ()) -> IO DefaultProbabilityTermStructure)
-> IO DefaultProbabilityTermStructure
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO DefaultProbabilityTermStructure)
 -> IO DefaultProbabilityTermStructure)
-> (Ptr (Ptr ()) -> IO DefaultProbabilityTermStructure)
-> IO DefaultProbabilityTermStructure
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a5' -> 
  Ptr CDefaultProbabilityTermStructure'
-> CUInt
-> Ptr (Ptr CQuote')
-> CUInt
-> Ptr CInt
-> CInt
-> Ptr (Ptr ())
-> IO (Ptr CDefaultProbabilityTermStructure')
shapedHazardRateCurveRaw'_ Ptr CDefaultProbabilityTermStructure'
a1' CUInt
a2'1  Ptr (Ptr CQuote')
a2'2 CUInt
a3'1  Ptr CInt
a3'2 CInt
a4' Ptr (Ptr ())
a5' IO (Ptr CDefaultProbabilityTermStructure')
-> (Ptr CDefaultProbabilityTermStructure'
    -> IO DefaultProbabilityTermStructure)
-> IO DefaultProbabilityTermStructure
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CDefaultProbabilityTermStructure'
res ->
  Ptr CDefaultProbabilityTermStructure'
-> IO DefaultProbabilityTermStructure
peekDefaultProbabilityTermStructure Ptr CDefaultProbabilityTermStructure'
res IO DefaultProbabilityTermStructure
-> (DefaultProbabilityTermStructure
    -> IO DefaultProbabilityTermStructure)
-> IO DefaultProbabilityTermStructure
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \DefaultProbabilityTermStructure
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a5'IO ()
-> IO DefaultProbabilityTermStructure
-> IO DefaultProbabilityTermStructure
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  DefaultProbabilityTermStructure
-> IO DefaultProbabilityTermStructure
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (DefaultProbabilityTermStructure
res')

{-# LINE 155 "./QuantLib/TermStructure/Credit.chs" #-}


relativeHazardRateCurveRaw :: (GenDefaultProbabilityTermStructure d) -> (GenQuote q) -> IO ((DefaultProbabilityTermStructure))
relativeHazardRateCurveRaw a1 a2 =
  withDefaultProbabilityTermStructure a1 $ \a1' -> 
  withQuote a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  relativeHazardRateCurveRaw'_ a1' a2' a3' >>= \res ->
  peekDefaultProbabilityTermStructure res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 157 "./QuantLib/TermStructure/Credit.chs" #-}


-- | The original native credit curve conditioned on survival at a later fixed reference.
-- This is the delegated curve view described in [Conditional survival](#conditional-survival).
conditionalSurvivalCurve :: (GenDefaultProbabilityTermStructure d) -- ^Original credit curve, retained and observed by the view.
 -> (Day) -- ^New fixed reference date, on or after the original reference and no later than its maximum date.
 -> IO ((DefaultProbabilityTermStructure))
conditionalSurvivalCurve a1 a2 =
  withDefaultProbabilityTermStructure a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  conditionalSurvivalCurve'_ a1' a2' a3' >>= \res ->
  peekDefaultProbabilityTermStructure res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 164 "./QuantLib/TermStructure/Credit.chs" #-}


-- |Flat hazard-rate curve with either a fixed or evaluation-date-relative reference point.
flatHazardRate :: Reference -> GenQuote q -> DayCounter -> IO DefaultProbabilityTermStructure
flatHazardRate (ReferenceDate d) = flatHazardRateFixed d
flatHazardRate (SettlementDays n cal) = flatHazardRateMovingRaw n cal
flatHazardRateMovingRaw :: (Word) -> (Calendar) -> (GenQuote q) -> (DayCounter) -> IO ((DefaultProbabilityTermStructure))
flatHazardRateMovingRaw a1 a2 a3 a4 =
  let {a1' = fromIntegral a1} in 
  withCalendar a2 $ \a2' -> 
  withQuote a3 $ \a3' -> 
  withDayCounter a4 $ \a4' -> 
  preErrorCheck $ \a5' -> 
  flatHazardRateMovingRaw'_ a1' a2' a3' a4' a5' >>= \res ->
  peekDefaultProbabilityTermStructure res >>= \res' ->
  errorCheck  a5'>>
  return (res')

{-# LINE 170 "./QuantLib/TermStructure/Credit.chs" #-}

flatHazardRateFixed :: (Day) -> (GenQuote q) -> (DayCounter) -> IO ((DefaultProbabilityTermStructure))
flatHazardRateFixed a1 a2 a3 =
  withDay a1 $ \a1' -> 
  withQuote a2 $ \a2' -> 
  withDayCounter a3 $ \a3' -> 
  preErrorCheck $ \a4' -> 
  flatHazardRateFixed'_ a1' a2' a3' a4' >>= \res ->
  peekDefaultProbabilityTermStructure res >>= \res' ->
  errorCheck  a4'>>
  return (res')

{-# LINE 171 "./QuantLib/TermStructure/Credit.chs" #-}


parallelHazardRateCurveRaw :: (GenDefaultProbabilityTermStructure d) -> (GenQuote q) -> IO ((DefaultProbabilityTermStructure))
parallelHazardRateCurveRaw a1 a2 =
  withDefaultProbabilityTermStructure a1 $ \a1' -> 
  withQuote a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  parallelHazardRateCurveRaw'_ a1' a2' a3' >>= \res ->
  peekDefaultProbabilityTermStructure res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 173 "./QuantLib/TermStructure/Credit.chs" #-}


defaultProbabilityAtDateRaw :: (GenDefaultProbabilityTermStructure d) -> (Day) -> (Bool) -- ^extrapolate
 -> IO ((Double))
defaultProbabilityAtDateRaw a1 a2 a3 =
  withDefaultProbabilityTermStructure a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  let {a3' = C2HSImp.fromBool a3} in 
  preErrorCheck $ \a4' -> 
  defaultProbabilityAtDateRaw'_ a1' a2' a3' a4' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a4'>>
  return (res')

{-# LINE 176 "./QuantLib/TermStructure/Credit.chs" #-}


hazardRateAtTimeRaw :: (GenDefaultProbabilityTermStructure d) -> (Double) -> (Bool) -- ^extrapolate
 -> IO ((Double))
hazardRateAtTimeRaw a1 a2 a3 =
  withDefaultProbabilityTermStructure a1 $ \a1' -> 
  let {a2' = realToFrac a2} in 
  let {a3' = C2HSImp.fromBool a3} in 
  preErrorCheck $ \a4' -> 
  hazardRateAtTimeRaw'_ a1' a2' a3' a4' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a4'>>
  return (res')

{-# LINE 179 "./QuantLib/TermStructure/Credit.chs" #-}


hazardRateAtDateRaw :: (GenDefaultProbabilityTermStructure d) -> (Day) -> (Bool) -- ^extrapolate
 -> IO ((Double))
hazardRateAtDateRaw a1 a2 a3 =
  withDefaultProbabilityTermStructure a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  let {a3' = C2HSImp.fromBool a3} in 
  preErrorCheck $ \a4' -> 
  hazardRateAtDateRaw'_ a1' a2' a3' a4' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a4'>>
  return (res')

{-# LINE 182 "./QuantLib/TermStructure/Credit.chs" #-}


survivalProbabilityAtTimeRaw :: (GenDefaultProbabilityTermStructure d) -> (Double) -> (Bool) -- ^extrapolate
 -> IO ((Double))
survivalProbabilityAtTimeRaw a1 a2 a3 =
  withDefaultProbabilityTermStructure a1 $ \a1' -> 
  let {a2' = realToFrac a2} in 
  let {a3' = C2HSImp.fromBool a3} in 
  preErrorCheck $ \a4' -> 
  survivalProbabilityAtTimeRaw'_ a1' a2' a3' a4' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a4'>>
  return (res')

{-# LINE 185 "./QuantLib/TermStructure/Credit.chs" #-}


survivalProbabilityAtDateRaw :: (GenDefaultProbabilityTermStructure d) -> (Day) -> (Bool) -- ^extrapolate
 -> IO ((Double))
survivalProbabilityAtDateRaw a1 a2 a3 =
  withDefaultProbabilityTermStructure a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  let {a3' = C2HSImp.fromBool a3} in 
  preErrorCheck $ \a4' -> 
  survivalProbabilityAtDateRaw'_ a1' a2' a3' a4' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a4'>>
  return (res')

{-# LINE 188 "./QuantLib/TermStructure/Credit.chs" #-}


defaultDensityAtTimeRaw :: (GenDefaultProbabilityTermStructure d) -> (Double) -> (Bool) -- ^extrapolate
 -> IO ((Double))
defaultDensityAtTimeRaw a1 a2 a3 =
  withDefaultProbabilityTermStructure a1 $ \a1' -> 
  let {a2' = realToFrac a2} in 
  let {a3' = C2HSImp.fromBool a3} in 
  preErrorCheck $ \a4' -> 
  defaultDensityAtTimeRaw'_ a1' a2' a3' a4' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a4'>>
  return (res')

{-# LINE 191 "./QuantLib/TermStructure/Credit.chs" #-}


defaultDensityAtDateRaw :: (GenDefaultProbabilityTermStructure d) -> (Day) -> (Bool) -- ^extrapolate
 -> IO ((Double))
defaultDensityAtDateRaw a1 a2 a3 =
  withDefaultProbabilityTermStructure a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  let {a3' = C2HSImp.fromBool a3} in 
  preErrorCheck $ \a4' -> 
  defaultDensityAtDateRaw'_ a1' a2' a3' a4' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a4'>>
  return (res')

{-# LINE 194 "./QuantLib/TermStructure/Credit.chs" #-}


defaultProbabilityAtTimeRaw :: (GenDefaultProbabilityTermStructure d) -> (Double) -> (Bool) -- ^extrapolate
 -> IO ((Double))
defaultProbabilityAtTimeRaw a1 a2 a3 =
  withDefaultProbabilityTermStructure a1 $ \a1' -> 
  let {a2' = realToFrac a2} in 
  let {a3' = C2HSImp.fromBool a3} in 
  preErrorCheck $ \a4' -> 
  defaultProbabilityAtTimeRaw'_ a1' a2' a3' a4' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a4'>>
  return (res')

{-# LINE 197 "./QuantLib/TermStructure/Credit.chs" #-}


defaultProbabilityBetweenDatesRaw :: (GenDefaultProbabilityTermStructure d) -> (Day) -> (Day) -> (Bool) -- ^extrapolate
 -> IO ((Double))
defaultProbabilityBetweenDatesRaw a1 a2 a3 a4 =
  withDefaultProbabilityTermStructure a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  withDay a3 $ \a3' -> 
  let {a4' = C2HSImp.fromBool a4} in 
  preErrorCheck $ \a5' -> 
  defaultProbabilityBetweenDatesRaw'_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a5'>>
  return (res')

{-# LINE 200 "./QuantLib/TermStructure/Credit.chs" #-}


defaultProbabilityBetweenTimesRaw :: (GenDefaultProbabilityTermStructure d) -> (Double) -> (Double) -> (Bool) -- ^extrapolate
 -> IO ((Double))
defaultProbabilityBetweenTimesRaw a1 a2 a3 a4 =
  withDefaultProbabilityTermStructure a1 $ \a1' -> 
  let {a2' = realToFrac a2} in 
  let {a3' = realToFrac a3} in 
  let {a4' = C2HSImp.fromBool a4} in 
  preErrorCheck $ \a5' -> 
  defaultProbabilityBetweenTimesRaw'_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a5'>>
  return (res')

{-# LINE 203 "./QuantLib/TermStructure/Credit.chs" #-}


-- |Hazard rate at a date or year fraction, with annual frequency and continuous compounding.
hazardRate :: GenDefaultProbabilityTermStructure d -> TermPoint -> Bool -> IO Double
hazardRate curve point = case point of
  DatePoint d -> hazardRateAtDateRaw curve d
  TimePoint t -> hazardRateAtTimeRaw curve t

-- |Survival probability from the reference point to a date or year fraction.
survivalProbability :: GenDefaultProbabilityTermStructure d -> TermPoint -> Bool -> IO Double
survivalProbability curve point = case point of
  DatePoint d -> survivalProbabilityAtDateRaw curve d
  TimePoint t -> survivalProbabilityAtTimeRaw curve t

-- |Default density at a date or year fraction.
defaultDensity :: GenDefaultProbabilityTermStructure d -> TermPoint -> Bool -> IO Double
defaultDensity :: forall d.
GenDefaultProbabilityTermStructure d
-> TermPoint -> Bool -> IO Double
defaultDensity GenDefaultProbabilityTermStructure d
curve TermPoint
point = case TermPoint
point of
  DatePoint Day
d -> GenDefaultProbabilityTermStructure d -> Day -> Bool -> IO Double
forall d.
GenDefaultProbabilityTermStructure d -> Day -> Bool -> IO Double
defaultDensityAtDateRaw GenDefaultProbabilityTermStructure d
curve Day
d
  TimePoint Double
t -> GenDefaultProbabilityTermStructure d -> Double -> Bool -> IO Double
forall d.
GenDefaultProbabilityTermStructure d -> Double -> Bool -> IO Double
defaultDensityAtTimeRaw GenDefaultProbabilityTermStructure d
curve Double
t

-- |Default probability from the reference point to a date or year fraction.
defaultProbability :: GenDefaultProbabilityTermStructure d -> TermPoint -> Bool -> IO Double
defaultProbability :: forall d.
GenDefaultProbabilityTermStructure d
-> TermPoint -> Bool -> IO Double
defaultProbability GenDefaultProbabilityTermStructure d
curve TermPoint
point = case TermPoint
point of
  DatePoint Day
d -> GenDefaultProbabilityTermStructure d -> Day -> Bool -> IO Double
forall d.
GenDefaultProbabilityTermStructure d -> Day -> Bool -> IO Double
defaultProbabilityAtDateRaw GenDefaultProbabilityTermStructure d
curve Day
d
  TimePoint Double
t -> GenDefaultProbabilityTermStructure d -> Double -> Bool -> IO Double
forall d.
GenDefaultProbabilityTermStructure d -> Double -> Bool -> IO Double
defaultProbabilityAtTimeRaw GenDefaultProbabilityTermStructure d
curve Double
t

-- |Default probability over a same-representation date or year-fraction interval.
defaultProbabilityBetween :: GenDefaultProbabilityTermStructure d -> TermInterval -> Bool -> IO Double
defaultProbabilityBetween :: forall d.
GenDefaultProbabilityTermStructure d
-> TermInterval -> Bool -> IO Double
defaultProbabilityBetween GenDefaultProbabilityTermStructure d
curve TermInterval
interval = case TermInterval
interval of
  DateInterval Day
d1 Day
d2 -> GenDefaultProbabilityTermStructure d
-> Day -> Day -> Bool -> IO Double
forall d.
GenDefaultProbabilityTermStructure d
-> Day -> Day -> Bool -> IO Double
defaultProbabilityBetweenDatesRaw GenDefaultProbabilityTermStructure d
curve Day
d1 Day
d2
  TimeInterval Double
t1 Double
t2 -> GenDefaultProbabilityTermStructure d
-> Double -> Double -> Bool -> IO Double
forall d.
GenDefaultProbabilityTermStructure d
-> Double -> Double -> Bool -> IO Double
defaultProbabilityBetweenTimesRaw GenDefaultProbabilityTermStructure d
curve Double
t1 Double
t2

conditionalSurvivalProbabilityAtDatesRaw :: (AffineHazardRateCurve) -> (Day) -> (Day) -> (Double) -> (Bool) -- ^extrapolate
 -> IO ((Double))
conditionalSurvivalProbabilityAtDatesRaw :: AffineHazardRateCurve -> Day -> Day -> Double -> Bool -> IO Double
conditionalSurvivalProbabilityAtDatesRaw AffineHazardRateCurve
a1 Day
a2 Day
a3 Double
a4 Bool
a5 =
  AffineHazardRateCurve
-> (Ptr CAffineHazardRateCurve' -> IO Double) -> IO Double
forall b.
AffineHazardRateCurve
-> (Ptr CAffineHazardRateCurve' -> IO b) -> IO b
withAffineHazardRateCurve AffineHazardRateCurve
a1 ((Ptr CAffineHazardRateCurve' -> IO Double) -> IO Double)
-> (Ptr CAffineHazardRateCurve' -> IO Double) -> IO Double
forall a b. (a -> b) -> a -> b
$ \Ptr CAffineHazardRateCurve'
a1' -> 
  Day -> (CInt -> IO Double) -> IO Double
forall a. Day -> (CInt -> IO a) -> IO a
withDay Day
a2 ((CInt -> IO Double) -> IO Double)
-> (CInt -> IO Double) -> IO Double
forall a b. (a -> b) -> a -> b
$ \CInt
a2' -> 
  Day -> (CInt -> IO Double) -> IO Double
forall a. Day -> (CInt -> IO a) -> IO a
withDay Day
a3 ((CInt -> IO Double) -> IO Double)
-> (CInt -> IO Double) -> IO Double
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} AffineHazardRateCurve
in 
  let {a5' :: CInt
a5' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a5} in 
  (Ptr (Ptr ()) -> IO Double) -> IO Double
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO Double) -> IO Double)
-> (Ptr (Ptr ()) -> IO Double) -> IO Double
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a6' -> 
  Ptr CAffineHazardRateCurve'
-> CInt -> CInt -> CDouble -> CInt -> Ptr (Ptr ()) -> IO CDouble
conditionalSurvivalProbabilityAtDatesRaw'_ Ptr CAffineHazardRateCurve'
a1' CInt
a2' CInt
a3' CDouble
a4' CInt
a5' Ptr (Ptr ())
a6' IO CDouble -> (CDouble -> IO Double) -> IO Double
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CDouble
res ->
  let {res' :: Double
res' = CDouble -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac CDouble
res} in
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a6'IO () -> IO Double -> IO Double
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Double -> IO Double
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (res')

{-# LINE 236 "./QuantLib/TermStructure/Credit.chs" #-}


conditionalSurvivalProbabilityAtTimesRaw :: (AffineHazardRateCurve) -> (Double) -> (Double) -> (Double) -> (Bool) -- ^extrapolate
 -> IO ((Double))
conditionalSurvivalProbabilityAtTimesRaw a1 a2 a3 a4 a5 =
  withAffineHazardRateCurve a1 $ \a1' -> 
  let {a2' = realToFrac a2} in 
  let {a3' = realToFrac a3} in 
  let {a4' = realToFrac a4} in 
  let {a5' = C2HSImp.fromBool a5} in 
  preErrorCheck $ \a6' -> 
  conditionalSurvivalProbabilityAtTimesRaw'_ a1' a2' a3' a4' a5' a6' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a6'>>
  return (res')

{-# LINE 239 "./QuantLib/TermStructure/Credit.chs" #-}


-- |Probability of survival to the interval's later point, conditional on survival to its earlier
-- point and on the stochastic hazard-rate component realizing @yVal@ there -- see
-- 'ql/experimental/credit/onefactoraffinesurvival.hpp'.
conditionalSurvivalProbability :: AffineHazardRateCurve -> TermInterval -> Double -- ^yVal
  -> Bool -> IO Double
conditionalSurvivalProbability curve interval yVal = case interval of
  DateInterval d1 d2 -> conditionalSurvivalProbabilityAtDatesRaw curve d1 d2 yVal
  TimeInterval t1 t2 -> conditionalSurvivalProbabilityAtTimesRaw curve t1 t2 yVal

-- |bootstrap helper for a CDS quoted by running spread
spreadCdsHelper :: (GenQuote q) -- ^runningSpread
 -> ((Word,TimeUnit)) -- ^tenor
 -> (Int) -- ^settlementDays
 -> (Calendar) -> (Frequency) -> (BusinessDayConvention) -> (DateGenerationRule) -> (DayCounter) -> (Double) -- recoveryRate
 -> (GenYieldTermStructure y) -- ^discountCurve
 -> (Bool) -- ^settlesAccrual
 -> (Bool) -- ^paysAtDefaultTime
 -> (Maybe Day) -- ^startDate
 -> (DayCounter) -- ^lastPeriodDayCounter
 -> (Bool) -- ^rebatesAccrual
 -> (PricingModel) -- ^model
 -> (Maybe Day) -- ^tradeDate (1.44; QuantLib 1.43 requires 'Nothing')
 -> IO ((DefaultProbabilityHelper))
spreadCdsHelper :: forall q y.
GenQuote q
-> (Word, TimeUnit)
-> Int
-> Calendar
-> Frequency
-> BusinessDayConvention
-> DateGenerationRule
-> DayCounter
-> Double
-> GenYieldTermStructure y
-> Bool
-> Bool
-> Maybe Day
-> DayCounter
-> Bool
-> PricingModel
-> Maybe Day
-> IO DefaultProbabilityHelper
spreadCdsHelper GenQuote q
a1 (Word, TimeUnit)
a2 Int
a3 Calendar
a4 Frequency
a5 BusinessDayConvention
a6 DateGenerationRule
a7 DayCounter
a8 Double
a9 GenYieldTermStructure y
a10 Bool
a11 Bool
a12 Maybe Day
a13 DayCounter
a14 Bool
a15 PricingModel
a16 Maybe Day
a17 =
  GenQuote q
-> (Ptr CQuote' -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall q b. GenQuote q -> (Ptr CQuote' -> IO b) -> IO b
withQuote GenQuote q
a1 ((Ptr CQuote' -> IO DefaultProbabilityHelper)
 -> IO DefaultProbabilityHelper)
-> (Ptr CQuote' -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall a b. (a -> b) -> a -> b
$ \Ptr CQuote'
a1' -> 
  let {(CInt
a2'1, CInt
a2'2) = (Word, TimeUnit) -> (CInt, CInt)
forall a b c.
(Enum a, Integral b, Integral c) =>
(b, a) -> (CInt, c)
fromEnumQuantity (Word, TimeUnit)
a2} in 
  let {a3' :: CInt
a3' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a3} in 
  Calendar
-> (Ptr CCalendar -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall b. Calendar -> (Ptr CCalendar -> IO b) -> IO b
withCalendar Calendar
a4 ((Ptr CCalendar -> IO DefaultProbabilityHelper)
 -> IO DefaultProbabilityHelper)
-> (Ptr CCalendar -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall a b. (a -> b) -> a -> b
$ \Ptr CCalendar
a4' -> 
  let {a5' :: CInt
a5' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (Frequency -> Int) -> Frequency -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Frequency -> Int
forall a. Enum a => a -> Int
fromEnum) Frequency
a5} in 
  let {a6' :: CInt
a6' = BusinessDayConvention -> CInt
forall a b. (Enum a, Integral b) => a -> b
fromEnumC BusinessDayConvention
a6} in 
  let {a7' :: CInt
a7' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt)
-> (DateGenerationRule -> Int) -> DateGenerationRule -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DateGenerationRule -> Int
forall a. Enum a => a -> Int
fromEnum) DateGenerationRule
a7} in 
  DayCounter
-> (Ptr CDayCounter -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall b. DayCounter -> (Ptr CDayCounter -> IO b) -> IO b
withDayCounter DayCounter
a8 ((Ptr CDayCounter -> IO DefaultProbabilityHelper)
 -> IO DefaultProbabilityHelper)
-> (Ptr CDayCounter -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall a b. (a -> b) -> a -> b
$ \Ptr CDayCounter
a8' -> 
  let {a9' :: CDouble
a9' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a9} in 
  GenYieldTermStructure y
-> (Ptr CYieldTermStructure' -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall y b.
GenYieldTermStructure y
-> (Ptr CYieldTermStructure' -> IO b) -> IO b
withYieldTermStructure GenYieldTermStructure y
a10 ((Ptr CYieldTermStructure' -> IO DefaultProbabilityHelper)
 -> IO DefaultProbabilityHelper)
-> (Ptr CYieldTermStructure' -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall a b. (a -> b) -> a -> b
$ \Ptr CYieldTermStructure'
a10' -> 
  let {a11' :: CInt
a11' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a11} in 
  let {a12' :: CInt
a12' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a12} in 
  Maybe Day
-> (CInt -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall a. Maybe Day -> (CInt -> IO a) -> IO a
withMaybeDay Maybe Day
a13 ((CInt -> IO DefaultProbabilityHelper)
 -> IO DefaultProbabilityHelper)
-> (CInt -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall a b. (a -> b) -> a -> b
$ \CInt
a13' -> 
  DayCounter
-> (Ptr CDayCounter -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall b. DayCounter -> (Ptr CDayCounter -> IO b) -> IO b
withDayCounter DayCounter
a14 ((Ptr CDayCounter -> IO DefaultProbabilityHelper)
 -> IO DefaultProbabilityHelper)
-> (Ptr CDayCounter -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall a b. (a -> b) -> a -> b
$ \Ptr CDayCounter
a14' -> 
  let {a15' :: CInt
a15' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a15} in 
  let {a16' :: CInt
a16' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (PricingModel -> Int) -> PricingModel -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PricingModel -> Int
forall a. Enum a => a -> Int
fromEnum) PricingModel
a16} in 
  Maybe Day
-> (CInt -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall a. Maybe Day -> (CInt -> IO a) -> IO a
withMaybeDay Maybe Day
a17 ((CInt -> IO DefaultProbabilityHelper)
 -> IO DefaultProbabilityHelper)
-> (CInt -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall a b. (a -> b) -> a -> b
$ \CInt
a17' -> 
  (Ptr (Ptr ()) -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO DefaultProbabilityHelper)
 -> IO DefaultProbabilityHelper)
-> (Ptr (Ptr ()) -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a18' -> 
  Ptr CQuote'
-> CInt
-> CInt
-> CInt
-> Ptr CCalendar
-> CInt
-> CInt
-> CInt
-> Ptr CDayCounter
-> CDouble
-> Ptr CYieldTermStructure'
-> CInt
-> CInt
-> CInt
-> Ptr CDayCounter
-> CInt
-> CInt
-> CInt
-> Ptr (Ptr ())
-> IO (Ptr CDefaultProbabilityHelper)
spreadCdsHelper'_ Ptr CQuote'
a1' CInt
a2'1  CInt
a2'2 CInt
a3' Ptr CCalendar
a4' CInt
a5' CInt
a6' CInt
a7' Ptr CDayCounter
a8' CDouble
a9' Ptr CYieldTermStructure'
a10' CInt
a11' CInt
a12' CInt
a13' Ptr CDayCounter
a14' CInt
a15' CInt
a16' CInt
a17' Ptr (Ptr ())
a18' IO (Ptr CDefaultProbabilityHelper)
-> (Ptr CDefaultProbabilityHelper -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CDefaultProbabilityHelper
res ->
  Ptr CDefaultProbabilityHelper -> IO DefaultProbabilityHelper
peekDefaultProbabilityHelper Ptr CDefaultProbabilityHelper
res IO DefaultProbabilityHelper
-> (DefaultProbabilityHelper -> IO DefaultProbabilityHelper)
-> IO DefaultProbabilityHelper
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \DefaultProbabilityHelper
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a18'IO () -> IO DefaultProbabilityHelper -> IO DefaultProbabilityHelper
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  DefaultProbabilityHelper -> IO DefaultProbabilityHelper
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (DefaultProbabilityHelper
res')

{-# LINE 264 "./QuantLib/TermStructure/Credit.chs" #-}


-- |the upfront must be quoted in fractional units.
upfrontCdsHelper :: (GenQuote q) -- ^upfront
 -> (Double) -- ^runningSpread
 -> ((Word,TimeUnit)) -- ^tenor
 -> (Int) -- ^settlementDays
 -> (Calendar) -> (Frequency) -> (BusinessDayConvention) -> (DateGenerationRule) -> (DayCounter) -> (Double) -- ^recoveryDate
 -> (GenYieldTermStructure y) -- ^discountCurve
 -> (Word) -- ^upfrontSettlementDays
 -> (Bool) -- &settlesAccrual
 -> (Bool) -- ^paysAtDefaultTime
 -> (Maybe Day) -- ^startDate
 -> (DayCounter) -- ^lastPeriodDayCounter
 -> (Bool) -- ^rebatesAccrual
 -> (PricingModel) -- ^model
 -> (Maybe Day) -- ^tradeDate (1.44; QuantLib 1.43 requires 'Nothing')
 -> IO ((DefaultProbabilityHelper))
upfrontCdsHelper a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 =
  withQuote a1 $ \a1' -> 
  let {a2' = realToFrac a2} in 
  let {(a3'1, a3'2) = fromEnumQuantity a3} in 
  let {a4' = fromIntegral a4} in 
  withCalendar a5 $ \a5' -> 
  let {a6' = (fromIntegral . fromEnum) a6} in 
  let {a7' = fromEnumC a7} in 
  let {a8' = (fromIntegral . fromEnum) a8} in 
  withDayCounter a9 $ \a9' -> 
  let {a10' = realToFrac a10} in 
  withYieldTermStructure a11 $ \a11' -> 
  let {a12' = fromIntegral a12} in 
  let {a13' = C2HSImp.fromBool a13} in 
  let {a14' = C2HSImp.fromBool a14} in 
  withMaybeDay a15 $ \a15' -> 
  withDayCounter a16 $ \a16' -> 
  let {a17' = C2HSImp.fromBool a17} in 
  let {a18' = (fromIntegral . fromEnum) a18} in 
  withMaybeDay a19 $ \a19' -> 
  preErrorCheck $ \a20' -> 
  upfrontCdsHelper'_ a1' a2' a3'1  a3'2 a4' a5' a6' a7' a8' a9' a10' a11' a12' a13' a14' a15' a16' a17' a18' a19' a20' >>= \res ->
  peekDefaultProbabilityHelper res >>= \res' ->
  errorCheck  a20'>>
  return (res')

{-# LINE 282 "./QuantLib/TermStructure/Credit.chs" #-}


-- |The fair running-spread/upfront quote implied by the helper's current market data and pricing
-- engine -- the value that would make the quoted instrument re-price at par. Requires the helper
-- to have already been used to bootstrap a curve (throws otherwise, per upstream).
impliedQuote :: (DefaultProbabilityHelper) -> IO ((Double))
impliedQuote a1 =
  withDefaultProbabilityHelper a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  impliedQuote'_ a1' a2' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 288 "./QuantLib/TermStructure/Credit.chs" #-}


-- |The quote that would make the helper reprice exactly on the given default-probability curve:
-- a par spread or upfront read with the helper's own conventions on any credit curve.
impliedQuoteOn :: (DefaultProbabilityHelper) -> (GenDefaultProbabilityTermStructure d) -> IO ((Double))
impliedQuoteOn a1 a2 =
  withDefaultProbabilityHelper a1 $ \a1' -> 
  withDefaultProbabilityTermStructure a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  impliedQuoteOn'_ a1' a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 294 "./QuantLib/TermStructure/Credit.chs" #-}


interpolatedDefaultDensityCurve :: NonEmpty (Day, Double) -> DayCounter -> Calendar -> [(Day, GenQuote q)] -- ^jumps
  -> Interpolation -> Bool -> IO DefaultProbabilityTermStructure
interpolatedDefaultDensityCurve d dc c q i ex = do
  curve <- uncurryNested (qlInterpolatedDefaultDensityCurve dd dq dc c qq qd) (qlInterpolation i)
  setExtrapolation curve ex
  pure curve
  where (qd, qq) = unzip q
        (dd, dq) = unzip (toList d)

-- |default-probability term structure built by interpolating default densities at given dates
qlInterpolatedDefaultDensityCurve :: ([Day]) -> ([Double]) -> (DayCounter) -> (Calendar) -> ([GenQuote q]) -> ([Day]) -> (Int) -> (Int) -> (Int) -> IO ((DefaultProbabilityTermStructure))
qlInterpolatedDefaultDensityCurve a1 a2 a3 a4 a5 a6 a7 a8 a9 =
  withDayArray a1 $ \(a1'1, a1'2) -> 
  withDoubleArray a2 $ \(a2'1, a2'2) -> 
  withDayCounter a3 $ \a3' -> 
  withCalendar a4 $ \a4' -> 
  withQuoteArray a5 $ \(a5'1, a5'2) -> 
  withDayArray a6 $ \(a6'1, a6'2) -> 
  let {a7' = fromIntegral a7} in 
  let {a8' = fromIntegral a8} in 
  let {a9' = fromIntegral a9} in 
  preErrorCheck $ \a10' -> 
  qlInterpolatedDefaultDensityCurve'_ a1'1  a1'2 a2'1  a2'2 a3' a4' a5'1  a5'2 a6'1  a6'2 a7' a8' a9' a10' >>= \res ->
  peekDefaultProbabilityTermStructure res >>= \res' ->
  errorCheck  a10'>>
  return (res')

{-# LINE 306 "./QuantLib/TermStructure/Credit.chs" #-}


interpolatedHazardRateCurve :: NonEmpty (Day, Double) -> DayCounter -> Calendar -> [(Day, GenQuote q)] -- ^jumps
  -> Interpolation
  -> Bool -- ^extrapolate past the curve's max date
  -> IO DefaultProbabilityTermStructure
interpolatedHazardRateCurve d dc c q i ex = uncurryNested (qlInterpolatedHazardRateCurve dd dq dc c qq qd) (qlInterpolation i) ex where {(qd, qq) = unzip q; (dd, dq) = unzip (toList d)}

-- |default-probability term structure built by interpolating hazard rates at given dates
qlInterpolatedHazardRateCurve :: ([Day]) -> ([Double]) -> (DayCounter) -> (Calendar) -> ([GenQuote q]) -> ([Day]) -> (Int) -> (Int) -> (Int) -> (Bool) -> IO ((DefaultProbabilityTermStructure))
qlInterpolatedHazardRateCurve a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 =
  withDayArray a1 $ \(a1'1, a1'2) -> 
  withDoubleArray a2 $ \(a2'1, a2'2) -> 
  withDayCounter a3 $ \a3' -> 
  withCalendar a4 $ \a4' -> 
  withQuoteArray a5 $ \(a5'1, a5'2) -> 
  withDayArray a6 $ \(a6'1, a6'2) -> 
  let {a7' = fromIntegral a7} in 
  let {a8' = fromIntegral a8} in 
  let {a9' = fromIntegral a9} in 
  let {a10' = C2HSImp.fromBool a10} in 
  preErrorCheck $ \a11' -> 
  qlInterpolatedHazardRateCurve'_ a1'1  a1'2 a2'1  a2'2 a3' a4' a5'1  a5'2 a6'1  a6'2 a7' a8' a9' a10' a11' >>= \res ->
  peekDefaultProbabilityTermStructure res >>= \res' ->
  errorCheck  a11'>>
  return (res')

{-# LINE 315 "./QuantLib/TermStructure/Credit.chs" #-}


-- |Hazard-rate curve interpolated deterministically between nodes, combined with a one-factor
-- affine short-rate model's stochastic discount mechanics -- see
-- 'ql/experimental/credit/interpolatedaffinehazardratecurve.hpp'.
interpolatedAffineHazardRateCurve :: NonEmpty (Day, Double) -> DayCounter -> GenOneFactorAffineModel om -> Calendar -> [(Day, GenQuote q)] -- ^jumps
  -> Interpolation
  -> Bool -- ^extrapolate past the curve's max date
  -> IO AffineHazardRateCurve
interpolatedAffineHazardRateCurve d dc m c q i ex =
  uncurryNested (qlInterpolatedAffineHazardRateCurve dd dq dc m c qq qd) (qlInterpolation i) ex
  where {(qd, qq) = unzip q; (dd, dq) = unzip (toList d)}

qlInterpolatedAffineHazardRateCurve :: ([Day]) -> ([Double]) -> (DayCounter) -> (GenOneFactorAffineModel om) -> (Calendar) -> ([GenQuote q]) -> ([Day]) -> (Int) -> (Int) -> (Int) -> (Bool) -> IO ((AffineHazardRateCurve))
qlInterpolatedAffineHazardRateCurve a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 =
  withDayArray a1 $ \(a1'1, a1'2) -> 
  withDoubleArray a2 $ \(a2'1, a2'2) -> 
  withDayCounter a3 $ \a3' -> 
  withOneFactorAffineModel a4 $ \a4' -> 
  withCalendar a5 $ \a5' -> 
  withQuoteArray a6 $ \(a6'1, a6'2) -> 
  withDayArray a7 $ \(a7'1, a7'2) -> 
  let {a8' = fromIntegral a8} in 
  let {a9' = fromIntegral a9} in 
  let {a10' = fromIntegral a10} in 
  let {a11' = C2HSImp.fromBool a11} in 
  preErrorCheck $ \a12' -> 
  qlInterpolatedAffineHazardRateCurve'_ a1'1  a1'2 a2'1  a2'2 a3' a4' a5' a6'1  a6'2 a7'1  a7'2 a8' a9' a10' a11' a12' >>= \res ->
  peekAffineHazardRateCurve res >>= \res' ->
  errorCheck  a12'>>
  return (res')

{-# LINE 328 "./QuantLib/TermStructure/Credit.chs" #-}


interpolatedSurvivalProbabilityCurve :: NonEmpty (Day, Double) -> DayCounter -> Calendar -> [(Day, GenQuote q)] -- ^jumps
  -> Interpolation -> Bool -> IO DefaultProbabilityTermStructure
interpolatedSurvivalProbabilityCurve d dc c q i ex = do
  curve <- uncurryNested (qlInterpolatedSurvivalProbabilityCurve dd dq dc c qq qd) (qlInterpolation i)
  setExtrapolation curve ex
  pure curve
  where (qd, qq) = unzip q
        (dd, dq) = unzip (toList d)

-- |default-probability term structure built by interpolating survival probabilities at given dates
qlInterpolatedSurvivalProbabilityCurve :: ([Day]) -> ([Double]) -> (DayCounter) -> (Calendar) -> ([GenQuote q]) -> ([Day]) -> (Int) -> (Int) -> (Int) -> IO ((DefaultProbabilityTermStructure))
qlInterpolatedSurvivalProbabilityCurve a1 a2 a3 a4 a5 a6 a7 a8 a9 =
  withDayArray a1 $ \(a1'1, a1'2) -> 
  withDoubleArray a2 $ \(a2'1, a2'2) -> 
  withDayCounter a3 $ \a3' -> 
  withCalendar a4 $ \a4' -> 
  withQuoteArray a5 $ \(a5'1, a5'2) -> 
  withDayArray a6 $ \(a6'1, a6'2) -> 
  let {a7' = fromIntegral a7} in 
  let {a8' = fromIntegral a8} in 
  let {a9' = fromIntegral a9} in 
  preErrorCheck $ \a10' -> 
  qlInterpolatedSurvivalProbabilityCurve'_ a1'1  a1'2 a2'1  a2'2 a3' a4' a5'1  a5'2 a6'1  a6'2 a7' a8' a9' a10' >>= \res ->
  peekDefaultProbabilityTermStructure res >>= \res' ->
  errorCheck  a10'>>
  return (res')

{-# LINE 340 "./QuantLib/TermStructure/Credit.chs" #-}


-- QuantLib uses Null<Real>() rather than a number for these defaults.
nullableDouble :: Maybe Double -> Double
nullableDouble = realToFrac . fromMaybeDouble

-- |Default-probability term structure bootstrapped from CDS/default helpers with either a fixed
-- or evaluation-date-relative reference point and complete iterative-bootstrap settings.
piecewiseDefaultCurve :: Reference
  -> NonEmpty DefaultProbabilityHelper -- ^instruments
  -> DayCounter -- ^dayCounter
  -> [(Day, GenQuote q)] -- ^jumps paired with their dates
  -> ProbabilityTrait -- ^bootstrap trait
  -> Interpolation -- ^interpolator
  -> IterativeBootstrapOpts -- ^bootstrap settings
  -> Bool -- ^extrapolate past the curve's max date
  -> IO PiecewiseDefaultCurve
piecewiseDefaultCurve reference h dc q t i b ex = do
  curve <- case reference of
    ReferenceDate d -> uncurryNested (piecewiseDefaultCurve_ d hs dc qq qd t) (qlInterpolation i)
      (nullableDouble (ibAccuracy b)) (nullableDouble (ibMinValue b)) (nullableDouble (ibMaxValue b))
      (ibMaxAttempts b) (ibMaxFactor b) (ibMinFactor b) (ibDontThrow b) (ibDontThrowSteps b) (ibMaxEvaluations b)
    SettlementDays d c -> uncurryNested (piecewiseDefaultCurve1_ d c hs dc qq qd t) (qlInterpolation i)
      (nullableDouble (ibAccuracy b)) (nullableDouble (ibMinValue b)) (nullableDouble (ibMaxValue b))
      (ibMaxAttempts b) (ibMaxFactor b) (ibMinFactor b) (ibDontThrow b) (ibDontThrowSteps b) (ibMaxEvaluations b)
  setExtrapolation curve ex
  pure curve
  where (qd, qq) = unzip q
        hs = toList h
piecewiseDefaultCurve_ :: (Day) -> ([DefaultProbabilityHelper]) -> (DayCounter) -> ([GenQuote q]) -> ([Day]) -> (ProbabilityTrait) -> (Int) -> (Int) -> (Int) -> (Double) -> (Double) -> (Double) -> (Word) -> (Double) -> (Double) -> (Bool) -> (Word) -> (Word) -> IO ((PiecewiseDefaultCurve))
piecewiseDefaultCurve_ :: forall q.
Day
-> [DefaultProbabilityHelper]
-> DayCounter
-> [GenQuote q]
-> [Day]
-> ProbabilityTrait
-> Int
-> Int
-> Int
-> Double
-> Double
-> Double
-> Word
-> Double
-> Double
-> Bool
-> Word
-> Word
-> IO PiecewiseDefaultCurve
piecewiseDefaultCurve_ Day
a1 [DefaultProbabilityHelper]
a2 DayCounter
a3 a4 [Day]
a5 ProbabilityTrait
a6 Int
a7 Int
a8 Int
a9 Double
a10 Double
a11 Double
a12 Word
a13 Double
a14 Double
a15 Bool
a16 a17 Word
a18 =
  Day
-> (CInt -> IO PiecewiseDefaultCurve) -> IO PiecewiseDefaultCurve
forall a. Day -> (CInt -> IO a) -> IO a
withDay Day
a1 ((CInt -> IO PiecewiseDefaultCurve) -> IO PiecewiseDefaultCurve)
-> (CInt -> IO PiecewiseDefaultCurve) -> IO PiecewiseDefaultCurve
forall a b. (a -> b) -> a -> b
$ \CInt
a1' -> 
  [DefaultProbabilityHelper]
-> ((CUInt, Ptr (Ptr CDefaultProbabilityHelper))
    -> IO PiecewiseDefaultCurve)
-> IO PiecewiseDefaultCurve
forall b.
[DefaultProbabilityHelper]
-> ((CUInt, Ptr (Ptr CDefaultProbabilityHelper)) -> IO b) -> IO b
withDefaultProbabilityHelperArray [DefaultProbabilityHelper]
a2 (((CUInt, Ptr (Ptr CDefaultProbabilityHelper))
  -> IO PiecewiseDefaultCurve)
 -> IO PiecewiseDefaultCurve)
-> ((CUInt, Ptr (Ptr CDefaultProbabilityHelper))
    -> IO PiecewiseDefaultCurve)
-> IO PiecewiseDefaultCurve
forall a b. (a -> b) -> a -> b
$ \(CUInt
a2'1, Ptr (Ptr CDefaultProbabilityHelper)
a2'2) -> 
  DayCounter
-> (Ptr CDayCounter -> IO PiecewiseDefaultCurve)
-> IO PiecewiseDefaultCurve
forall b. DayCounter -> (Ptr CDayCounter -> IO b) -> IO b
withDayCounter DayCounter
a3 ((Ptr CDayCounter -> IO PiecewiseDefaultCurve)
 -> IO PiecewiseDefaultCurve)
-> (Ptr CDayCounter -> IO PiecewiseDefaultCurve)
-> IO PiecewiseDefaultCurve
forall a b. (a -> b) -> a -> b
$ \Ptr CDayCounter
a3' -> 
  [GenQuote q]
-> ((CUInt, Ptr (Ptr CQuote')) -> IO PiecewiseDefaultCurve)
-> IO PiecewiseDefaultCurve
forall q b.
[GenQuote q] -> ((CUInt, Ptr (Ptr CQuote')) -> IO b) -> IO b
withQuoteArray [GenQuote q]
a4 (((CUInt, Ptr (Ptr CQuote')) -> IO PiecewiseDefaultCurve)
 -> IO PiecewiseDefaultCurve)
-> ((CUInt, Ptr (Ptr CQuote')) -> IO PiecewiseDefaultCurve)
-> IO PiecewiseDefaultCurve
forall a b. (a -> b) -> a -> b
$ \(CUInt
a4'1, Ptr (Ptr CQuote')
a4'2) -> 
  [Day]
-> ((CUInt, Ptr CInt) -> IO PiecewiseDefaultCurve)
-> IO PiecewiseDefaultCurve
forall b. [Day] -> ((CUInt, Ptr CInt) -> IO b) -> IO b
withDayArray [Day]
a5 (((CUInt, Ptr CInt) -> IO PiecewiseDefaultCurve)
 -> IO PiecewiseDefaultCurve)
-> ((CUInt, Ptr CInt) -> IO PiecewiseDefaultCurve)
-> IO PiecewiseDefaultCurve
forall a b. (a -> b) -> a -> b
$ \(CUInt
a5'1, Ptr CInt
a5'2) -> 
  let {a6' :: CInt
a6' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt)
-> (ProbabilityTrait -> Int) -> ProbabilityTrait -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProbabilityTrait -> Int
forall a. Enum a => a -> Int
fromEnum) ProbabilityTrait
a6} in 
  let {a7' :: CInt
a7' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a7} in 
  let {a8' :: CInt
a8' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a8} in 
  let {a9' :: CInt
a9' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a9} in 
  let {a10' :: CDouble
a10' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a10} in 
  let {a11' :: CDouble
a11' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a11} in 
  let {a12' :: CDouble
a12' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a12} in 
  let {a13' :: CUInt
a13' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a13} in 
  let {a14' :: CDouble
a14' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a14} in 
  let {a15' :: CDouble
a15' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a15} in 
  let {a16' :: CInt
a16' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a16} in 
  let {a17' :: CUInt
a17' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a17} in 
  let {a18' :: CUInt
a18' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a18} in 
  (Ptr (Ptr ()) -> IO PiecewiseDefaultCurve)
-> IO PiecewiseDefaultCurve
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO PiecewiseDefaultCurve)
 -> IO PiecewiseDefaultCurve)
-> (Ptr (Ptr ()) -> IO PiecewiseDefaultCurve)
-> IO PiecewiseDefaultCurve
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a19' -> 
  CInt
-> CUInt
-> Ptr (Ptr CDefaultProbabilityHelper)
-> Ptr CDayCounter
-> CUInt
-> Ptr (Ptr CQuote')
-> CUInt
-> Ptr CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> CDouble
-> CDouble
-> CDouble
-> CUInt
-> CDouble
-> CDouble
-> CInt
-> CUInt
-> CUInt
-> Ptr (Ptr ())
-> IO (Ptr CPiecewiseDefaultCurve')
piecewiseDefaultCurve_'_ CInt
a1' CUInt
a2'1  Ptr (Ptr CDefaultProbabilityHelper)
a2'2 Ptr CDayCounter
a3' CUInt
a4'1  Ptr (Ptr CQuote')
a4'2 CUInt
a5'1  Ptr CInt
a5'2 CInt
a6' CInt
a7' CInt
a8' CInt
a9' CDouble
a10' CDouble
a11' CDouble
a12' CUInt
a13' CDouble
a14' CDouble
a15' CInt
a16' CUInt
a17' CUInt
a18' Ptr (Ptr ())
a19' IO (Ptr CPiecewiseDefaultCurve')
-> (Ptr CPiecewiseDefaultCurve' -> IO PiecewiseDefaultCurve)
-> IO PiecewiseDefaultCurve
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CPiecewiseDefaultCurve'
res ->
  Ptr CPiecewiseDefaultCurve' -> IO PiecewiseDefaultCurve
peekPiecewiseDefaultCurve Ptr CPiecewiseDefaultCurve'
res IO PiecewiseDefaultCurve
-> (PiecewiseDefaultCurve -> IO PiecewiseDefaultCurve)
-> IO PiecewiseDefaultCurve
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \PiecewiseDefaultCurve
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a19'IO () -> IO PiecewiseDefaultCurve -> IO PiecewiseDefaultCurve
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  PiecewiseDefaultCurve -> IO PiecewiseDefaultCurve
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (PiecewiseDefaultCurve
res')

{-# LINE 369 "./QuantLib/TermStructure/Credit.chs" #-}

piecewiseDefaultCurve1_ :: (Word) -> (Calendar) -> ([DefaultProbabilityHelper]) -> (DayCounter) -> ([GenQuote q]) -> ([Day]) -> (ProbabilityTrait) -> (Int) -> (Int) -> (Int) -> (Double) -> (Double) -> (Double) -> (Word) -> (Double) -> (Double) -> (Bool) -> (Word) -> (Word) -> IO ((PiecewiseDefaultCurve))
piecewiseDefaultCurve1_ a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 =
  let {a1' = fromIntegral a1} in 
  withCalendar a2 $ \a2' -> 
  withDefaultProbabilityHelperArray a3 $ \(a3'1, a3'2) -> 
  withDayCounter a4 $ \a4' -> 
  withQuoteArray a5 $ \(a5'1, a5'2) -> 
  withDayArray a6 $ \(a6'1, a6'2) -> 
  let {a7' = (fromIntegral . fromEnum) a7} in 
  let {a8' = fromIntegral a8} in 
  let {a9' = fromIntegral a9} in 
  let {a10' = fromIntegral a10} in 
  let {a11' = realToFrac a11} in 
  let {a12' = realToFrac a12} in 
  let {a13' = realToFrac a13} in 
  let {a14' = fromIntegral a14} in 
  let {a15' = realToFrac a15} in 
  let {a16' = realToFrac a16} in 
  let {a17' = C2HSImp.fromBool a17} in 
  let {a18' = fromIntegral a18} in 
  let {a19' = fromIntegral a19} in 
  preErrorCheck $ \a20' -> 
  piecewiseDefaultCurve1_'_ a1' a2' a3'1  a3'2 a4' a5'1  a5'2 a6'1  a6'2 a7' a8' a9' a10' a11' a12' a13' a14' a15' a16' a17' a18' a19' a20' >>= \res ->
  peekPiecewiseDefaultCurve res >>= \res' ->
  errorCheck  a20'>>
  return (res')

{-# LINE 370 "./QuantLib/TermStructure/Credit.chs" #-}


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

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlShapedHazardRateCurve"
  shapedHazardRateCurveRaw'_ :: ((C2HSImp.Ptr (CDefaultProbabilityTermStructure')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CQuote'))) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CDefaultProbabilityTermStructure'))))))))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlFactorSpreadedHazardRateCurve"
  relativeHazardRateCurveRaw'_ :: ((C2HSImp.Ptr (CDefaultProbabilityTermStructure')) -> ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CDefaultProbabilityTermStructure'))))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlConditionalSurvivalCurve"
  conditionalSurvivalCurve'_ :: ((C2HSImp.Ptr (CDefaultProbabilityTermStructure')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CDefaultProbabilityTermStructure'))))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlFlatHazardRate1"
  flatHazardRateMovingRaw'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCalendar)) -> ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CDefaultProbabilityTermStructure'))))))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlFlatHazardRate"
  flatHazardRateFixed'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CDefaultProbabilityTermStructure')))))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlSpreadedHazardRateCurve"
  parallelHazardRateCurveRaw'_ :: ((C2HSImp.Ptr (CDefaultProbabilityTermStructure')) -> ((C2HSImp.Ptr (CQuote')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CDefaultProbabilityTermStructure'))))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlDefaultProbabilityTermStructureDefaultProbability"
  defaultProbabilityAtDateRaw'_ :: ((C2HSImp.Ptr (CDefaultProbabilityTermStructure')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlDefaultProbabilityTermStructureHazardRate1"
  hazardRateAtTimeRaw'_ :: ((C2HSImp.Ptr (CDefaultProbabilityTermStructure')) -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlDefaultProbabilityTermStructureHazardRate"
  hazardRateAtDateRaw'_ :: ((C2HSImp.Ptr (CDefaultProbabilityTermStructure')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlDefaultProbabilityTermStructureSurvivalProbability1"
  survivalProbabilityAtTimeRaw'_ :: ((C2HSImp.Ptr (CDefaultProbabilityTermStructure')) -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlDefaultProbabilityTermStructureSurvivalProbability"
  survivalProbabilityAtDateRaw'_ :: ((C2HSImp.Ptr (CDefaultProbabilityTermStructure')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlDefaultProbabilityTermStructureDefaultDensity1"
  defaultDensityAtTimeRaw'_ :: ((C2HSImp.Ptr (CDefaultProbabilityTermStructure')) -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlDefaultProbabilityTermStructureDefaultDensity"
  defaultDensityAtDateRaw'_ :: ((C2HSImp.Ptr (CDefaultProbabilityTermStructure')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlDefaultProbabilityTermStructureDefaultProbability1"
  defaultProbabilityAtTimeRaw'_ :: ((C2HSImp.Ptr (CDefaultProbabilityTermStructure')) -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlDefaultProbabilityTermStructureDefaultProbability2"
  defaultProbabilityBetweenDatesRaw'_ :: ((C2HSImp.Ptr (CDefaultProbabilityTermStructure')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlDefaultProbabilityTermStructureDefaultProbability3"
  defaultProbabilityBetweenTimesRaw'_ :: ((C2HSImp.Ptr (CDefaultProbabilityTermStructure')) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlAffineHazardRateCurveConditionalSurvivalProbability"
  conditionalSurvivalProbabilityAtDatesRaw'_ :: ((C2HSImp.Ptr (CAffineHazardRateCurve')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlAffineHazardRateCurveConditionalSurvivalProbability1"
  conditionalSurvivalProbabilityAtTimesRaw'_ :: ((C2HSImp.Ptr (CAffineHazardRateCurve')) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlSpreadCdsHelper"
  spreadCdsHelper'_ :: ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CYieldTermStructure')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CDefaultProbabilityHelper))))))))))))))))))))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlUpfrontCdsHelper"
  upfrontCdsHelper'_ :: ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CYieldTermStructure')) -> (C2HSImp.CUInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CDefaultProbabilityHelper))))))))))))))))))))))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlDefaultProbabilityHelperImpliedQuote"
  impliedQuote'_ :: ((C2HSImp.Ptr (CDefaultProbabilityHelper)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlDefaultProbabilityHelperImpliedQuoteOn"
  impliedQuoteOn'_ :: ((C2HSImp.Ptr (CDefaultProbabilityHelper)) -> ((C2HSImp.Ptr (CDefaultProbabilityTermStructure')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlInterpolatedDefaultDensityCurve"
  qlInterpolatedDefaultDensityCurve'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CQuote'))) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CDefaultProbabilityTermStructure')))))))))))))))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlInterpolatedHazardRateCurve"
  qlInterpolatedHazardRateCurve'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CQuote'))) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CDefaultProbabilityTermStructure'))))))))))))))))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlInterpolatedAffineHazardRateCurve"
  qlInterpolatedAffineHazardRateCurve'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (COneFactorAffineModel')) -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CQuote'))) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CAffineHazardRateCurve')))))))))))))))))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlInterpolatedSurvivalProbabilityCurve"
  qlInterpolatedSurvivalProbabilityCurve'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CDayCounter)) -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CQuote'))) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CDefaultProbabilityTermStructure')))))))))))))))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlPiecewiseDefaultCurve"
  piecewiseDefaultCurve_'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CDefaultProbabilityHelper))) -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CQuote'))) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CPiecewiseDefaultCurve')))))))))))))))))))))))))

foreign import ccall safe "QuantLib/TermStructure/Credit.chs.h qlPiecewiseDefaultCurve1"
  piecewiseDefaultCurve1_'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CDefaultProbabilityHelper))) -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CQuote'))) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CPiecewiseDefaultCurve'))))))))))))))))))))))))))