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


{-# LINE 1 "./QuantLib/Credit.chs" #-}
-- |Portfolio-credit types, baskets, and loss models.
module QuantLib.Credit
  (
    -- * Types
    -- ** Issuers, pools and baskets
    DefaultProbKey
  , Issuer
  , Pool
  , Basket
  , TrancheBasket
  , DigitalBasket
    -- ** Loss models
  , DefaultLossModel
  , DigitalLossModel
    -- ** Configuration
  , Seniority(..)
  , RestructuringType(..)
  , LatentModelIntegrationType(..)

    -- * Constructors
  , northAmericaCorpDefaultKey
  , issuer
  , pool
  , basket
  , trancheBasketAsBasket
  , digitalBasket
  , digitalBasketAsBasket
  , gaussianLhpLossModel
  , constantLossModel

    -- * Inspectors
  , expectedTrancheLoss
  , probOverLoss
  , percentile
  , expectedShortfall
  , defaultCorrelation
  , probAtLeastNEvents
  , notional
  , remainingNotional
  , recoveryRate
  ) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.ForeignPtr as C2HSImp
import qualified Foreign.Ptr as C2HSImp


import Data.List.NonEmpty(NonEmpty, toList)

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







-- |Seniority of a bond; also used as the ISDA tier\/seniority for CDS conventional spreads.
data Seniority = SecDom
               | SeniorSec
               | SnrFor
               | SeniorUnSec
               | SubLT2
               | SubLoweTier2
               | JrSubT2
               | SubUpperTier2
               | PrefT1
               | SubTier1
               | NoSeniority
  deriving (Show,Eq,Read,Bounded)
instance Enum Seniority where
  succ SecDom = SnrFor
  succ SeniorSec = SnrFor
  succ SnrFor = SubLT2
  succ SeniorUnSec = SubLT2
  succ SubLT2 = JrSubT2
  succ SubLoweTier2 = JrSubT2
  pred :: RestructuringType -> RestructuringType
succ JrSubT2 = PrefT1
  succ SubUpperTier2 = PrefT1
  succ PrefT1 = NoSeniority
  succ SubTier1 = NoSeniority
  succ NoSeniority = error "Seniority.succ: NoSeniority has no successor"

  pred SnrFor = SecDom
  pred SeniorUnSec = SecDom
  pred SubLT2 = SnrFor
  pred SubLoweTier2 = SnrFor
  pred JrSubT2 = SubLT2
  pred SubUpperTier2 = SubLT2
  pred PrefT1 = JrSubT2
  pred SubTier1 = JrSubT2
  pred NoSeniority = PrefT1
  pred SecDom = error "Seniority.pred: SecDom has no predecessor"
  pred SeniorSec = error "Seniority.pred: SeniorSec 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 NoSeniority

  fromEnum SecDom = 0
  fromEnum SeniorSec = 0
  fromEnum SnrFor = 1
  fromEnum SeniorUnSec = 1
  fromEnum SubLT2 = 2
  fromEnum SubLoweTier2 = 2
  fromEnum JrSubT2 = 3
  fromEnum SubUpperTier2 = 3
  fromEnum PrefT1 = 4
  fromEnum SubTier1 = 4
  fromEnum NoSeniority = 5

  toEnum 0 = SecDom
  toEnum 1 = SnrFor
  toEnum 2 = SubLT2
  toEnum 3 = JrSubT2
  toEnum 4 = PrefT1
  toEnum 5 = NoSeniority
  toEnum unmatched = error ("Seniority.toEnum: Cannot match " ++ show unmatched)

{-# LINE 55 "./QuantLib/Credit.chs" #-}


-- |Restructuring clause of a default-probability key (ISDA @XR@\/@MR@\/@MM@\/@CR@).
data RestructuringType = NoRestructuring
                       | XR
                       | ModifiedRestructuring
                       | MR
                       | ModifiedModifiedRestructuring
                       | MM
                       | FullRestructuring
                       | CR
                       | AnyRestructuring
  deriving (Show,Eq,Read,Bounded)
instance Enum RestructuringType where
  succ NoRestructuring = ModifiedRestructuring
  succ XR = ModifiedRestructuring
  succ ModifiedRestructuring = ModifiedModifiedRestructuring
  succ MR = ModifiedModifiedRestructuring
  succ ModifiedModifiedRestructuring = FullRestructuring
  succ MM = FullRestructuring
  succ FullRestructuring = AnyRestructuring
  succ CR = AnyRestructuring
  succ AnyRestructuring = error "RestructuringType.succ: AnyRestructuring has no successor"

  pred ModifiedRestructuring = NoRestructuring
  pred MR = NoRestructuring
  pred ModifiedModifiedRestructuring = ModifiedRestructuring
  pred MM = ModifiedRestructuring
  pred FullRestructuring = ModifiedModifiedRestructuring
  pred CR = ModifiedModifiedRestructuring
  pred AnyRestructuring = FullRestructuring
  pred NoRestructuring = error "RestructuringType.pred: NoRestructuring has no predecessor"
  pred XR = error "RestructuringType.pred: XR 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 AnyRestructuring

  fromEnum NoRestructuring = 0
  fromEnum XR = 0
  fromEnum ModifiedRestructuring = 1
  fromEnum MR = 1
  fromEnum ModifiedModifiedRestructuring = 2
  fromEnum MM = 2
  fromEnum FullRestructuring = 3
  fromEnum CR = 3
  fromEnum AnyRestructuring = 4

  toEnum 0 = NoRestructuring
  toEnum 1 = ModifiedRestructuring
  toEnum 2 = ModifiedModifiedRestructuring
  toEnum 3 = FullRestructuring
  toEnum 4 = AnyRestructuring
  toEnum unmatched = error ("RestructuringType.toEnum: Cannot match " ++ show unmatched)

{-# LINE 58 "./QuantLib/Credit.chs" #-}


-- |Numerical-integration scheme used by a 'QuantLib.Credit.LatentModel'-based copula loss
-- model (e.g. the gaussian\/student constant-loss dispatcher bound alongside 'NthToDefault').
data LatentModelIntegrationType = GaussianQuadrature
                                | Trapezoid
  deriving (Enum,Show,Eq,Read,Bounded)

{-# LINE 62 "./QuantLib/Credit.chs" #-}



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


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


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


{-# LINE 67 "./QuantLib/Credit.chs" #-}


{-# LINE 68 "./QuantLib/Credit.chs" #-}


{-# LINE 69 "./QuantLib/Credit.chs" #-}


{-# LINE 70 "./QuantLib/Credit.chs" #-}


{-# LINE 71 "./QuantLib/Credit.chs" #-}


{-# LINE 72 "./QuantLib/Credit.chs" #-}


{-# LINE 73 "./QuantLib/Credit.chs" #-}


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


{-# LINE 75 "./QuantLib/Credit.chs" #-}


-- |ISDA standard default contractual key for corporate US debt. @restructuringType@ may be
-- 'NoRestructuring' to disable restructuring as a trigger.
northAmericaCorpDefaultKey :: (Currency) -- ^currency
 -> (Seniority) -- ^seniority
 -> ((Int,TimeUnit)) -- ^graceFailureToPay
 -> (Double) -- ^amountFailure
 -> (RestructuringType) -- ^restructuringType
 -> IO ((DefaultProbKey))
northAmericaCorpDefaultKey a1 a2 a3 a4 a5 =
  withCurrency a1 $ \a1' -> 
  let {a2' = (fromIntegral . fromEnum) a2} in 
  let {(a3'1, a3'2) = fromEnumQuantity a3} in 
  let {a4' = realToFrac a4} in 
  let {a5' = (fromIntegral . fromEnum) a5} in 
  preErrorCheck $ \a6' -> 
  northAmericaCorpDefaultKey'_ a1' a2' a3'1  a3'2 a4' a5' a6' >>= \res ->
  peekDefaultProbKey res >>= \res' ->
  errorCheck  a6'>>
  return (res')

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


-- |An issuer's default-probability term structures, keyed by contract terms.
issuer :: NonEmpty (DefaultProbKey, GenDefaultProbabilityTermStructure d) -> IO Issuer
issuer probs = qlIssuer keys curves
  where (keys, curves) = unzip (toList probs)
qlIssuer :: ([DefaultProbKey]) -> ([GenDefaultProbabilityTermStructure d]) -> IO ((Issuer))
qlIssuer a1 a2 =
  withDefaultProbKeyArray a1 $ \(a1'1, a1'2) -> 
  withDefaultProbabilityTermStructureArrayRaw a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  qlIssuer'_ a1'1  a1'2 a2' a3' >>= \res ->
  peekIssuer res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 92 "./QuantLib/Credit.chs" #-}


-- |A named collection of issuers and their default-probability keys.
pool :: NonEmpty (String, Issuer, DefaultProbKey) -> IO Pool
pool entries = qlPool names issuers keys
  where (names, issuers, keys) = unzip3 (toList entries)
qlPool :: ([String]) -> ([Issuer]) -> ([DefaultProbKey]) -> IO ((Pool))
qlPool a1 a2 a3 =
  withStringArray a1 $ \(a1'1, a1'2) -> 
  withIssuerArrayRaw a2 $ \a2' -> 
  withDefaultProbKeyArrayRaw a3 $ \a3' -> 
  preErrorCheck $ \a4' -> 
  qlPool'_ a1'1  a1'2 a2' a3' a4' >>= \res ->
  peekPool res >>= \res' ->
  errorCheck  a4'>>
  return (res')

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


-- |A tranched basket with a tranche-loss model; usable for CDO pricing.
basket :: Day -> NonEmpty (String, Double) -> Pool -> Double -> Double -> Claim -> DefaultLossModel -> IO TrancheBasket
basket refDate positions p attachmentRatio detachmentRatio cl lm =
  qlBasket refDate names notionals p attachmentRatio detachmentRatio cl lm
  where (names, notionals) = unzip (toList positions)
qlBasket :: (Day) -- ^refDate
 -> ([String]) -> ([Double]) -> (Pool) -> (Double) -- ^attachmentRatio
 -> (Double) -- ^detachmentRatio
 -> (Claim) -> (DefaultLossModel) -> IO ((TrancheBasket))
qlBasket a1 a2 a3 a4 a5 a6 a7 a8 =
  withDay a1 $ \a1' -> 
  withStringArray a2 $ \(a2'1, a2'2) -> 
  withDoubleArrayRaw a3 $ \a3' -> 
  withPool a4 $ \a4' -> 
  let {a5' = realToFrac a5} in 
  let {a6' = realToFrac a6} in 
  withClaim a7 $ \a7' -> 
  withDefaultLossModel a8 $ \a8' -> 
  preErrorCheck $ \a9' -> 
  qlBasket'_ a1' a2'1  a2'2 a3' a4' a5' a6' a7' a8' a9' >>= \res ->
  peekTrancheBasket res >>= \res' ->
  errorCheck  a9'>>
  return (res')

{-# LINE 116 "./QuantLib/Credit.chs" #-}


-- |Basket total notional at inception, before losses.
notional :: (Basket) -> IO ((Double))
notional a1 =
  withBasket a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  notional'_ a1' a2' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 119 "./QuantLib/Credit.chs" #-}


-- |Live (undefaulted) notional remaining at date @d@. Loss-model-agnostic.
remainingNotional :: (Basket) -> (Day) -- ^d
 -> IO ((Double))
remainingNotional a1 a2 =
  withBasket a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  remainingNotional'_ a1' a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 123 "./QuantLib/Credit.chs" #-}


-- |Expected recovery rate of the @iName@-th pool name (0-based, in basket-construction order),
-- conditional on default by date @d@. Loss-model-agnostic.
recoveryRate :: (Basket) -> (Day) -- ^d
 -> (Word) -- ^iName
 -> IO ((Double))
recoveryRate a1 a2 a3 =
  withBasket a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  let {a3' = fromIntegral a3} in 
  preErrorCheck $ \a4' -> 
  recoveryRate'_ a1' a2' a3' a4' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a4'>>
  return (res')

{-# LINE 129 "./QuantLib/Credit.chs" #-}


-- |Expected tranche loss on date @d@; requires a tranche-loss model.
expectedTrancheLoss :: (TrancheBasket) -> (Day) -- ^d
 -> IO ((Double))
expectedTrancheLoss a1 a2 =
  withTrancheBasket a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  expectedTrancheLoss'_ a1' a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 133 "./QuantLib/Credit.chs" #-}


-- |Probability the tranche loses at least @lossFraction@ of the tranche notional by date @d@.
probOverLoss :: (TrancheBasket) -> (Day) -- ^d
 -> (Double) -- ^lossFraction
 -> IO ((Double))
probOverLoss a1 a2 a3 =
  withTrancheBasket a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  let {a3' = realToFrac a3} in 
  preErrorCheck $ \a4' -> 
  probOverLoss'_ a1' a2' a3' a4' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a4'>>
  return (res')

{-# LINE 138 "./QuantLib/Credit.chs" #-}


-- |Tranche loss fraction at the given percentile of the loss distribution on date @d@ (VaR).
percentile :: (TrancheBasket) -> (Day) -- ^d
 -> (Double) -- ^prob
 -> IO ((Double))
percentile a1 a2 a3 =
  withTrancheBasket a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  let {a3' = realToFrac a3} in 
  preErrorCheck $ \a4' -> 
  percentile'_ a1' a2' a3' a4' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a4'>>
  return (res')

{-# LINE 143 "./QuantLib/Credit.chs" #-}


-- |Expected tranche loss given loss exceeds the given percentile on date @d@.
expectedShortfall :: (TrancheBasket) -> (Day) -- ^d
 -> (Double) -- ^prob
 -> IO ((Double))
expectedShortfall a1 a2 a3 =
  withTrancheBasket a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  let {a3' = realToFrac a3} in 
  preErrorCheck $ \a4' -> 
  expectedShortfall'_ a1' a2' a3' a4' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a4'>>
  return (res')

{-# LINE 148 "./QuantLib/Credit.chs" #-}


-- |Pearson default-probability correlation between pool names @iName@ and @jName@ (0-based) by
-- date @d@.
defaultCorrelation :: (DigitalBasket) -> (Day) -- ^d
 -> (Word) -- ^iName
 -> (Word) -- ^jName
 -> IO ((Double))
defaultCorrelation a1 a2 a3 a4 =
  withDigitalBasket a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  let {a3' = fromIntegral a3} in 
  let {a4' = fromIntegral a4} in 
  preErrorCheck $ \a5' -> 
  defaultCorrelation'_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a5'>>
  return (res')

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


-- |Probability of at least @n@ defaults in the basket by date @d@.
probAtLeastNEvents :: (DigitalBasket) -> (Word) -- ^n
 -> (Day) -- ^d
 -> IO ((Double))
probAtLeastNEvents a1 a2 a3 =
  withDigitalBasket a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  withDay a3 $ \a3' -> 
  preErrorCheck $ \a4' -> 
  probAtLeastNEvents'_ a1' a2' a3' a4' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a4'>>
  return (res')

{-# LINE 161 "./QuantLib/Credit.chs" #-}


-- |A digital-loss basket for nth-to-default pricing.
digitalBasket :: Day -> NonEmpty (String, Double) -> Pool -> Double -> Double -> Claim -> DigitalLossModel -> IO DigitalBasket
digitalBasket refDate positions p attachmentRatio detachmentRatio cl lm =
  qlDigitalBasket refDate names notionals p attachmentRatio detachmentRatio cl lm
  where (names, notionals) = unzip (toList positions)
qlDigitalBasket :: (Day) -- ^refDate
 -> ([String]) -> ([Double]) -> (Pool) -> (Double) -- ^attachmentRatio
 -> (Double) -- ^detachmentRatio
 -> (Claim) -> (DigitalLossModel) -> IO ((DigitalBasket))
qlDigitalBasket :: Day
-> [String]
-> [Double]
-> Pool
-> Double
-> Double
-> Claim
-> DigitalLossModel
-> IO DigitalBasket
qlDigitalBasket Day
a1 [String]
a2 [Double]
a3 Pool
a4 Double
a5 Double
a6 Claim
a7 DigitalLossModel
a8 =
  Day -> (CInt -> IO DigitalBasket) -> IO DigitalBasket
forall a. Day -> (CInt -> IO a) -> IO a
withDay Day
a1 ((CInt -> IO DigitalBasket) -> IO DigitalBasket)
-> (CInt -> IO DigitalBasket) -> IO DigitalBasket
forall a b. (a -> b) -> a -> b
$ \CInt
a1' -> 
  [String]
-> ((CUInt, Ptr CString) -> IO DigitalBasket) -> IO DigitalBasket
forall b. [String] -> ((CUInt, Ptr CString) -> IO b) -> IO b
withStringArray [String]
a2 (((CUInt, Ptr CString) -> IO DigitalBasket) -> IO DigitalBasket)
-> ((CUInt, Ptr CString) -> IO DigitalBasket) -> IO DigitalBasket
forall a b. (a -> b) -> a -> b
$ \(CUInt
a2'1, Ptr CString
a2'2) -> 
  [Double] -> (Ptr CDouble -> IO DigitalBasket) -> IO DigitalBasket
forall b. [Double] -> (Ptr CDouble -> IO b) -> IO b
withDoubleArrayRaw [Double]
a3 ((Ptr CDouble -> IO DigitalBasket) -> IO DigitalBasket)
-> (Ptr CDouble -> IO DigitalBasket) -> IO DigitalBasket
forall a b. (a -> b) -> a -> b
$ \Ptr CDouble
a3' -> 
  Pool -> (Ptr CPool -> IO DigitalBasket) -> IO DigitalBasket
forall b. Pool -> (Ptr CPool -> IO b) -> IO b
withPool Pool
a4 ((Ptr CPool -> IO DigitalBasket) -> IO DigitalBasket)
-> (Ptr CPool -> IO DigitalBasket) -> IO DigitalBasket
forall a b. (a -> b) -> a -> b
$ \Ptr CPool
a4' -> 
  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 
  Claim -> (Ptr CQlClaim -> IO DigitalBasket) -> IO DigitalBasket
forall a. Claim -> (Ptr CQlClaim -> IO a) -> IO a
withClaim Claim
a7 ((Ptr CQlClaim -> IO DigitalBasket) -> IO DigitalBasket)
-> (Ptr CQlClaim -> IO DigitalBasket) -> IO DigitalBasket
forall a b. (a -> b) -> a -> b
$ \Ptr CQlClaim
a7' -> 
  DigitalLossModel
-> (Ptr CDefaultLossModel -> IO DigitalBasket) -> IO DigitalBasket
forall b.
DigitalLossModel -> (Ptr CDefaultLossModel -> IO b) -> IO b
withDigitalLossModel DigitalLossModel
a8 ((Ptr CDefaultLossModel -> IO DigitalBasket) -> IO DigitalBasket)
-> (Ptr CDefaultLossModel -> IO DigitalBasket) -> IO DigitalBasket
forall a b. (a -> b) -> a -> b
$ \Ptr CDefaultLossModel
a8' -> 
  (Ptr (Ptr ()) -> IO DigitalBasket) -> IO DigitalBasket
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO DigitalBasket) -> IO DigitalBasket)
-> (Ptr (Ptr ()) -> IO DigitalBasket) -> IO DigitalBasket
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a9' -> 
  CInt
-> CUInt
-> Ptr CString
-> Ptr CDouble
-> Ptr CPool
-> CDouble
-> CDouble
-> Ptr CQlClaim
-> Ptr CDefaultLossModel
-> Ptr (Ptr ())
-> IO (Ptr CBasket)
qlDigitalBasket'_ CInt
a1' CUInt
a2'1  Ptr CString
a2'2 Ptr CDouble
a3' Ptr CPool
a4' CDouble
a5' CDouble
a6' Ptr CQlClaim
a7' Ptr CDefaultLossModel
a8' Ptr (Ptr ())
a9' IO (Ptr CBasket)
-> (Ptr CBasket -> IO DigitalBasket) -> IO DigitalBasket
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CBasket
res ->
  Ptr CBasket -> IO DigitalBasket
peekDigitalBasket Ptr CBasket
res IO DigitalBasket
-> (DigitalBasket -> IO DigitalBasket) -> IO DigitalBasket
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \DigitalBasket
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a9'IO () -> IO DigitalBasket -> IO DigitalBasket
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  DigitalBasket -> IO DigitalBasket
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (DigitalBasket
res')

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


-- |One-factor Gaussian-copula LHP loss model. @recoveries@ follow basket-name order.
gaussianLhpLossModel :: GenQuote q -> NonEmpty Double -> IO DefaultLossModel
gaussianLhpLossModel correlQuote recoveries = qlGaussianLHPLossModel correlQuote (toList recoveries)
qlGaussianLHPLossModel :: (GenQuote q) -- ^correlQuote
 -> ([Double]) -> IO ((DefaultLossModel))
qlGaussianLHPLossModel a1 a2 =
  withQuote a1 $ \a1' -> 
  withDoubleArray a2 $ \(a2'1, a2'2) -> 
  preErrorCheck $ \a3' -> 
  qlGaussianLHPLossModel'_ a1' a2'1  a2'2 a3' >>= \res ->
  peekDefaultLossModel res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 183 "./QuantLib/Credit.chs" #-}


-- |One-factor Gaussian- or Student-T-copula model for digital-loss baskets.
-- @[]@ selects Gaussian; @tOrders@ selects Student-T degrees of freedom.
constantLossModel :: GenQuote q -> NonEmpty Double -> LatentModelIntegrationType -> [Int] -> IO DigitalLossModel
constantLossModel correlQuote recoveries integralType tOrders =
  qlConstantLossModel correlQuote (toList recoveries) integralType tOrders
qlConstantLossModel :: (GenQuote q) -> ([Double]) -> (LatentModelIntegrationType) -> ([Int]) -> IO ((DigitalLossModel))
qlConstantLossModel a1 a2 a3 a4 =
  withQuote a1 $ \a1' -> 
  withDoubleArray a2 $ \(a2'1, a2'2) -> 
  let {a3' = (fromIntegral . fromEnum) a3} in 
  withIntArray a4 $ \(a4'1, a4'2) -> 
  preErrorCheck $ \a5' -> 
  qlConstantLossModel'_ a1' a2'1  a2'2 a3' a4'1  a4'2 a5' >>= \res ->
  peekDigitalLossModel res >>= \res' ->
  errorCheck  a5'>>
  return (res')

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


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

foreign import ccall safe "QuantLib/Credit.chs.h qlNorthAmericaCorpDefaultKey"
  northAmericaCorpDefaultKey'_ :: ((C2HSImp.Ptr (CCurrency)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CDefaultProbKey))))))))))

foreign import ccall safe "QuantLib/Credit.chs.h qlIssuer"
  qlIssuer'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CDefaultProbKey))) -> ((C2HSImp.Ptr (C2HSImp.Ptr (CDefaultProbabilityTermStructure'))) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CIssuer)))))))

foreign import ccall safe "QuantLib/Credit.chs.h qlPool"
  qlPool'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> ((C2HSImp.Ptr (C2HSImp.Ptr (CIssuer))) -> ((C2HSImp.Ptr (C2HSImp.Ptr (CDefaultProbKey))) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CPool))))))))

foreign import ccall safe "QuantLib/Credit.chs.h qlBasket"
  qlBasket'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CPool)) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CQlClaim)) -> ((C2HSImp.Ptr (CDefaultLossModel)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CBasket)))))))))))))

foreign import ccall safe "QuantLib/Credit.chs.h qlBasketNotional"
  notional'_ :: ((C2HSImp.Ptr (CBasket)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))

foreign import ccall safe "QuantLib/Credit.chs.h qlBasketRemainingNotional"
  remainingNotional'_ :: ((C2HSImp.Ptr (CBasket)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Credit.chs.h qlBasketRecoveryRate"
  recoveryRate'_ :: ((C2HSImp.Ptr (CBasket)) -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/Credit.chs.h qlBasketExpectedTrancheLoss"
  expectedTrancheLoss'_ :: ((C2HSImp.Ptr (CBasket)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Credit.chs.h qlBasketProbOverLoss"
  probOverLoss'_ :: ((C2HSImp.Ptr (CBasket)) -> (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/Credit.chs.h qlBasketPercentile"
  percentile'_ :: ((C2HSImp.Ptr (CBasket)) -> (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/Credit.chs.h qlBasketExpectedShortfall"
  expectedShortfall'_ :: ((C2HSImp.Ptr (CBasket)) -> (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/Credit.chs.h qlBasketDefaultCorrelation"
  defaultCorrelation'_ :: ((C2HSImp.Ptr (CBasket)) -> (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))))

foreign import ccall safe "QuantLib/Credit.chs.h qlBasketProbAtLeastNEvents"
  probAtLeastNEvents'_ :: ((C2HSImp.Ptr (CBasket)) -> (C2HSImp.CUInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/Credit.chs.h qlDigitalBasket"
  qlDigitalBasket'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CPool)) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CQlClaim)) -> ((C2HSImp.Ptr (CDefaultLossModel)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CBasket)))))))))))))

foreign import ccall safe "QuantLib/Credit.chs.h qlGaussianLHPLossModel"
  qlGaussianLHPLossModel'_ :: ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CDefaultLossModel)))))))

foreign import ccall safe "QuantLib/Credit.chs.h qlConstantLossModel"
  qlConstantLossModel'_ :: ((C2HSImp.Ptr (CQuote')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CDefaultLossModel))))))))))