{-# LINE 1 "./QuantLib/Instrument/Credit.chs" #-}
module QuantLib.Instrument.Credit
(
CreditDefaultSwap
, SyntheticCDO
, NthToDefault
, ProtectionSide(..)
, Claim(..)
, creditDefaultSwap
, creditDefaultSwapWithUpfront
, cdsOption
, syntheticCdo
, nthToDefault
, atmRate
, impliedVolatility
, riskyAnnuity
, accrualRebateNpv
, conventionalSpread
, couponLegBps
, couponLegNpv
, coupons
, defaultLegNpv
, fairUpfront
, impliedHazardRate
, upfrontBps
, upfrontNpv
, fairPremium
, fairUpfrontPremium
, premiumValue
, protectionValue
, premiumLegNpv
, protectionLegNpv
, cdoRemainingNotional
, implicitCorrelation
, ntdFairPremium
) 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 Data.List.NonEmpty(NonEmpty)
import QuantLib.Internal
import QuantLib.Internal.Common
import QuantLib.Internal.Type
import QuantLib.Instrument(PricingModel)
data ProtectionSide = Buyer
| Seller
deriving (Int -> ProtectionSide
ProtectionSide -> Int
ProtectionSide -> [ProtectionSide]
ProtectionSide -> ProtectionSide
ProtectionSide -> ProtectionSide -> [ProtectionSide]
ProtectionSide
-> ProtectionSide -> ProtectionSide -> [ProtectionSide]
(ProtectionSide -> ProtectionSide)
-> (ProtectionSide -> ProtectionSide)
-> (Int -> ProtectionSide)
-> (ProtectionSide -> Int)
-> (ProtectionSide -> [ProtectionSide])
-> (ProtectionSide -> ProtectionSide -> [ProtectionSide])
-> (ProtectionSide -> ProtectionSide -> [ProtectionSide])
-> (ProtectionSide
-> ProtectionSide -> ProtectionSide -> [ProtectionSide])
-> Enum ProtectionSide
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: ProtectionSide -> ProtectionSide
succ :: ProtectionSide -> ProtectionSide
$cpred :: ProtectionSide -> ProtectionSide
pred :: ProtectionSide -> ProtectionSide
$ctoEnum :: Int -> ProtectionSide
toEnum :: Int -> ProtectionSide
$cfromEnum :: ProtectionSide -> Int
fromEnum :: ProtectionSide -> Int
$cenumFrom :: ProtectionSide -> [ProtectionSide]
enumFrom :: ProtectionSide -> [ProtectionSide]
$cenumFromThen :: ProtectionSide -> ProtectionSide -> [ProtectionSide]
enumFromThen :: ProtectionSide -> ProtectionSide -> [ProtectionSide]
$cenumFromTo :: ProtectionSide -> ProtectionSide -> [ProtectionSide]
enumFromTo :: ProtectionSide -> ProtectionSide -> [ProtectionSide]
$cenumFromThenTo :: ProtectionSide
-> ProtectionSide -> ProtectionSide -> [ProtectionSide]
enumFromThenTo :: ProtectionSide
-> ProtectionSide -> ProtectionSide -> [ProtectionSide]
Enum,Int -> ProtectionSide -> ShowS
[ProtectionSide] -> ShowS
ProtectionSide -> String
(Int -> ProtectionSide -> ShowS)
-> (ProtectionSide -> String)
-> ([ProtectionSide] -> ShowS)
-> Show ProtectionSide
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ProtectionSide -> ShowS
showsPrec :: Int -> ProtectionSide -> ShowS
$cshow :: ProtectionSide -> String
show :: ProtectionSide -> String
$cshowList :: [ProtectionSide] -> ShowS
showList :: [ProtectionSide] -> ShowS
Show,ProtectionSide -> ProtectionSide -> Bool
(ProtectionSide -> ProtectionSide -> Bool)
-> (ProtectionSide -> ProtectionSide -> Bool) -> Eq ProtectionSide
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ProtectionSide -> ProtectionSide -> Bool
== :: ProtectionSide -> ProtectionSide -> Bool
$c/= :: ProtectionSide -> ProtectionSide -> Bool
/= :: ProtectionSide -> ProtectionSide -> Bool
Eq,ReadPrec [ProtectionSide]
ReadPrec ProtectionSide
Int -> ReadS ProtectionSide
ReadS [ProtectionSide]
(Int -> ReadS ProtectionSide)
-> ReadS [ProtectionSide]
-> ReadPrec ProtectionSide
-> ReadPrec [ProtectionSide]
-> Read ProtectionSide
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS ProtectionSide
readsPrec :: Int -> ReadS ProtectionSide
$creadList :: ReadS [ProtectionSide]
readList :: ReadS [ProtectionSide]
$creadPrec :: ReadPrec ProtectionSide
readPrec :: ReadPrec ProtectionSide
$creadListPrec :: ReadPrec [ProtectionSide]
readListPrec :: ReadPrec [ProtectionSide]
Read)
{-# LINE 59 "./QuantLib/Instrument/Credit.chs" #-}
{-# LINE 61 "./QuantLib/Instrument/Credit.chs" #-}
{-# LINE 62 "./QuantLib/Instrument/Credit.chs" #-}
{-# LINE 63 "./QuantLib/Instrument/Credit.chs" #-}
{-# LINE 64 "./QuantLib/Instrument/Credit.chs" #-}
{-# LINE 65 "./QuantLib/Instrument/Credit.chs" #-}
{-# LINE 66 "./QuantLib/Instrument/Credit.chs" #-}
{-# LINE 67 "./QuantLib/Instrument/Credit.chs" #-}
{-# LINE 68 "./QuantLib/Instrument/Credit.chs" #-}
{-# LINE 69 "./QuantLib/Instrument/Credit.chs" #-}
{-# LINE 70 "./QuantLib/Instrument/Credit.chs" #-}
{-# LINE 71 "./QuantLib/Instrument/Credit.chs" #-}
{-# LINE 72 "./QuantLib/Instrument/Credit.chs" #-}
{-# LINE 73 "./QuantLib/Instrument/Credit.chs" #-}
creditDefaultSwap :: (ProtectionSide) -> (Double)
-> (Double)
-> (Schedule) -> (BusinessDayConvention) -> (DayCounter) -> (Bool)
-> (Bool)
-> (Maybe Day)
-> (Claim) -> (DayCounter)
-> (Bool)
-> (Maybe Day)
-> (Word)
-> IO ((CreditDefaultSwap))
creditDefaultSwap :: ProtectionSide
-> Double
-> Double
-> Schedule
-> BusinessDayConvention
-> DayCounter
-> Bool
-> Bool
-> Maybe Day
-> Claim
-> DayCounter
-> Bool
-> Maybe Day
-> Word
-> IO CreditDefaultSwap
creditDefaultSwap ProtectionSide
a1 Double
a2 Double
a3 Schedule
a4 BusinessDayConvention
a5 DayCounter
a6 Bool
a7 Bool
a8 Maybe Day
a9 Claim
a10 DayCounter
a11 Bool
a12 Maybe Day
a13 Word
a14 =
let {a1' :: CInt
a1' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (ProtectionSide -> Int) -> ProtectionSide -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProtectionSide -> Int
forall a. Enum a => a -> Int
fromEnum) ProtectionSide
a1} in
let {a2' :: CDouble
a2' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a2} in
let {a3' :: CDouble
a3' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a3} in
Schedule
-> (Ptr CSchedule -> IO CreditDefaultSwap) -> IO CreditDefaultSwap
forall b. Schedule -> (Ptr CSchedule -> IO b) -> IO b
withSchedule Schedule
a4 ((Ptr CSchedule -> IO CreditDefaultSwap) -> IO CreditDefaultSwap)
-> (Ptr CSchedule -> IO CreditDefaultSwap) -> IO CreditDefaultSwap
forall a b. (a -> b) -> a -> b
$ \Ptr CSchedule
a4' ->
let {a5' :: CInt
a5' = BusinessDayConvention -> CInt
forall a b. (Enum a, Integral b) => a -> b
fromEnumC BusinessDayConvention
a5} in
DayCounter
-> (Ptr CDayCounter -> IO CreditDefaultSwap)
-> IO CreditDefaultSwap
forall b. DayCounter -> (Ptr CDayCounter -> IO b) -> IO b
withDayCounter DayCounter
a6 ((Ptr CDayCounter -> IO CreditDefaultSwap) -> IO CreditDefaultSwap)
-> (Ptr CDayCounter -> IO CreditDefaultSwap)
-> IO CreditDefaultSwap
forall a b. (a -> b) -> a -> b
$ \Ptr CDayCounter
a6' ->
let {a7' :: CInt
a7' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a7} in
let {a8' :: CInt
a8' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a8} in
Maybe Day -> (CInt -> IO CreditDefaultSwap) -> IO CreditDefaultSwap
forall a. Maybe Day -> (CInt -> IO a) -> IO a
withMaybeDay Maybe Day
a9 ((CInt -> IO CreditDefaultSwap) -> IO CreditDefaultSwap)
-> (CInt -> IO CreditDefaultSwap) -> IO CreditDefaultSwap
forall a b. (a -> b) -> a -> b
$ \CInt
a9' ->
Claim
-> (Ptr CQlClaim -> IO CreditDefaultSwap) -> IO CreditDefaultSwap
forall a. Claim -> (Ptr CQlClaim -> IO a) -> IO a
withClaim Claim
a10 ((Ptr CQlClaim -> IO CreditDefaultSwap) -> IO CreditDefaultSwap)
-> (Ptr CQlClaim -> IO CreditDefaultSwap) -> IO CreditDefaultSwap
forall a b. (a -> b) -> a -> b
$ \Ptr CQlClaim
a10' ->
DayCounter
-> (Ptr CDayCounter -> IO CreditDefaultSwap)
-> IO CreditDefaultSwap
forall b. DayCounter -> (Ptr CDayCounter -> IO b) -> IO b
withDayCounter DayCounter
a11 ((Ptr CDayCounter -> IO CreditDefaultSwap) -> IO CreditDefaultSwap)
-> (Ptr CDayCounter -> IO CreditDefaultSwap)
-> IO CreditDefaultSwap
forall a b. (a -> b) -> a -> b
$ \Ptr CDayCounter
a11' ->
let {a12' :: CInt
a12' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a12} in
Maybe Day -> (CInt -> IO CreditDefaultSwap) -> IO CreditDefaultSwap
forall a. Maybe Day -> (CInt -> IO a) -> IO a
withMaybeDay Maybe Day
a13 ((CInt -> IO CreditDefaultSwap) -> IO CreditDefaultSwap)
-> (CInt -> IO CreditDefaultSwap) -> IO CreditDefaultSwap
forall a b. (a -> b) -> a -> b
$ \CInt
a13' ->
let {a14' :: CUInt
a14' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a14} in
(Ptr (Ptr CChar) -> IO CreditDefaultSwap) -> IO CreditDefaultSwap
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO CreditDefaultSwap) -> IO CreditDefaultSwap)
-> (Ptr (Ptr CChar) -> IO CreditDefaultSwap)
-> IO CreditDefaultSwap
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a15' ->
CInt
-> CDouble
-> CDouble
-> Ptr CSchedule
-> CInt
-> Ptr CDayCounter
-> CInt
-> CInt
-> CInt
-> Ptr CQlClaim
-> Ptr CDayCounter
-> CInt
-> CInt
-> CUInt
-> Ptr (Ptr CChar)
-> IO (Ptr CCreditDefaultSwap')
creditDefaultSwap'_ CInt
a1' CDouble
a2' CDouble
a3' Ptr CSchedule
a4' CInt
a5' Ptr CDayCounter
a6' CInt
a7' CInt
a8' CInt
a9' Ptr CQlClaim
a10' Ptr CDayCounter
a11' CInt
a12' CInt
a13' CUInt
a14' Ptr (Ptr CChar)
a15' IO (Ptr CCreditDefaultSwap')
-> (Ptr CCreditDefaultSwap' -> IO CreditDefaultSwap)
-> IO CreditDefaultSwap
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CCreditDefaultSwap'
res ->
Ptr CCreditDefaultSwap' -> IO CreditDefaultSwap
peekCreditDefaultSwap Ptr CCreditDefaultSwap'
res IO CreditDefaultSwap
-> (CreditDefaultSwap -> IO CreditDefaultSwap)
-> IO CreditDefaultSwap
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CreditDefaultSwap
res' ->
Ptr (Ptr CChar) -> IO ()
errorCheck Ptr (Ptr CChar)
a15'IO () -> IO CreditDefaultSwap -> IO CreditDefaultSwap
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
CreditDefaultSwap -> IO CreditDefaultSwap
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CreditDefaultSwap
res')
{-# LINE 87 "./QuantLib/Instrument/Credit.chs" #-}
creditDefaultSwapWithUpfront :: (ProtectionSide) -> (Double)
-> (Double)
-> (Double)
-> (Schedule) -> (BusinessDayConvention) -> (DayCounter) -> (Bool)
-> (Bool)
-> (Maybe Day)
-> (Maybe Day)
-> (Claim) -> (DayCounter)
-> (Bool)
-> (Maybe Day)
-> (Word)
-> IO ((CreditDefaultSwap))
creditDefaultSwapWithUpfront a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 =
let {a1' = (fromIntegral . fromEnum) a1} in
let {a2' = realToFrac a2} in
let {a3' = realToFrac a3} in
let {a4' = realToFrac a4} in
withSchedule a5 $ \a5' ->
let {a6' = fromEnumC a6} in
withDayCounter a7 $ \a7' ->
let {a8' = C2HSImp.fromBool a8} in
let {a9' = C2HSImp.fromBool a9} in
withMaybeDay a10 $ \a10' ->
withMaybeDay a11 $ \a11' ->
withClaim a12 $ \a12' ->
withDayCounter a13 $ \a13' ->
let {a14' = C2HSImp.fromBool a14} in
withMaybeDay a15 $ \a15' ->
let {a16' = fromIntegral a16} in
preErrorCheck $ \a17' ->
creditDefaultSwapWithUpfront'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' a13' a14' a15' a16' a17' >>= \res ->
peekCreditDefaultSwap res >>= \res' ->
errorCheck a17'>>
return (res')
{-# LINE 103 "./QuantLib/Instrument/Credit.chs" #-}
atmRate :: (CdsOption) -> IO ((Double))
atmRate a1 =
withCdsOption a1 $ \a1' ->
preErrorCheck $ \a2' ->
atmRate'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
errorCheck a2'>>
return (res')
{-# LINE 106 "./QuantLib/Instrument/Credit.chs" #-}
cdsOption :: (CreditDefaultSwap) -> (Exercise) -> (Bool)
-> IO ((CdsOption))
cdsOption a1 a2 a3 =
withGenInstrument a1 $ \a1' ->
withExercise a2 $ \a2' ->
let {a3' = C2HSImp.fromBool a3} in
preErrorCheck $ \a4' ->
cdsOption'_ a1' a2' a3' a4' >>= \res ->
peekCdsOption res >>= \res' ->
errorCheck a4'>>
return (res')
{-# LINE 110 "./QuantLib/Instrument/Credit.chs" #-}
impliedVolatility :: (CdsOption) -> (Double)
-> (GenYieldTermStructure y) -> (GenDefaultProbabilityTermStructure d) -> (Double)
-> (Double)
-> (Word)
-> (Double)
-> (Double)
-> IO ((Double))
impliedVolatility a1 a2 a3 a4 a5 a6 a7 a8 a9 =
withCdsOption a1 $ \a1' ->
let {a2' = realToFrac a2} in
withYieldTermStructure a3 $ \a3' ->
withDefaultProbabilityTermStructure a4 $ \a4' ->
let {a5' = realToFrac a5} in
let {a6' = realToFrac a6} in
let {a7' = fromIntegral a7} in
let {a8' = realToFrac a8} in
let {a9' = realToFrac a9} in
preErrorCheck $ \a10' ->
impliedVolatility'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' >>= \res ->
let {res' = realToFrac res} in
errorCheck a10'>>
return (res')
{-# LINE 120 "./QuantLib/Instrument/Credit.chs" #-}
riskyAnnuity :: (CdsOption) -> IO ((Double))
riskyAnnuity a1 =
withCdsOption a1 $ \a1' ->
preErrorCheck $ \a2' ->
riskyAnnuity'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
errorCheck a2'>>
return (res')
{-# LINE 123 "./QuantLib/Instrument/Credit.chs" #-}
conventionalSpread :: (CreditDefaultSwap) -> (Double) -> (GenYieldTermStructure y) -> (DayCounter) -> (PricingModel)
-> IO ((Double))
conventionalSpread a1 a2 a3 a4 a5 =
withGenInstrument a1 $ \a1' ->
let {a2' = realToFrac a2} in
withYieldTermStructure a3 $ \a3' ->
withDayCounter a4 $ \a4' ->
let {a5' = (fromIntegral . fromEnum) a5} in
preErrorCheck $ \a6' ->
conventionalSpread'_ a1' a2' a3' a4' a5' a6' >>= \res ->
let {res' = realToFrac res} in
errorCheck a6'>>
return (res')
{-# LINE 130 "./QuantLib/Instrument/Credit.chs" #-}
couponLegBps :: (CreditDefaultSwap) -> IO ((Double))
couponLegBps a1 =
withGenInstrument a1 $ \a1' ->
preErrorCheck $ \a2' ->
couponLegBps'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
errorCheck a2'>>
return (res')
{-# LINE 133 "./QuantLib/Instrument/Credit.chs" #-}
couponLegNpv :: (CreditDefaultSwap) -> IO ((Double))
couponLegNpv a1 =
withGenInstrument a1 $ \a1' ->
preErrorCheck $ \a2' ->
couponLegNpv'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
errorCheck a2'>>
return (res')
{-# LINE 136 "./QuantLib/Instrument/Credit.chs" #-}
coupons :: (CreditDefaultSwap) -> IO ((Leg))
coupons a1 =
withGenInstrument a1 $ \a1' ->
preErrorCheck $ \a2' ->
coupons'_ a1' a2' >>= \res ->
peekLeg res >>= \res' ->
errorCheck a2'>>
return (res')
{-# LINE 139 "./QuantLib/Instrument/Credit.chs" #-}
defaultLegNpv :: (CreditDefaultSwap) -> IO ((Double))
defaultLegNpv a1 =
withGenInstrument a1 $ \a1' ->
preErrorCheck $ \a2' ->
defaultLegNpv'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
errorCheck a2'>>
return (res')
{-# LINE 142 "./QuantLib/Instrument/Credit.chs" #-}
fairUpfront :: (CreditDefaultSwap) -> IO ((Double))
fairUpfront a1 =
withGenInstrument a1 $ \a1' ->
preErrorCheck $ \a2' ->
fairUpfront'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
errorCheck a2'>>
return (res')
{-# LINE 145 "./QuantLib/Instrument/Credit.chs" #-}
impliedHazardRate :: (CreditDefaultSwap) -> (Double)
-> (GenYieldTermStructure y) -> (DayCounter) -> (Double)
-> (Double)
-> (PricingModel)
-> IO ((Double))
impliedHazardRate :: forall y.
CreditDefaultSwap
-> Double
-> GenYieldTermStructure y
-> DayCounter
-> Double
-> Double
-> PricingModel
-> IO Double
impliedHazardRate CreditDefaultSwap
a1 Double
a2 GenYieldTermStructure y
a3 DayCounter
a4 Double
a5 Double
a6 PricingModel
a7 =
CreditDefaultSwap
-> (Ptr CCreditDefaultSwap' -> IO Double) -> IO Double
forall i b. GenInstrument (ForeignPtr i) -> (Ptr i -> IO b) -> IO b
withGenInstrument CreditDefaultSwap
a1 ((Ptr CCreditDefaultSwap' -> IO Double) -> IO Double)
-> (Ptr CCreditDefaultSwap' -> IO Double) -> IO Double
forall a b. (a -> b) -> a -> b
$ \Ptr CCreditDefaultSwap'
a1' ->
let {a2' :: CDouble
a2' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a2} in
GenYieldTermStructure y
-> (Ptr CYieldTermStructure' -> IO Double) -> IO Double
forall y b.
GenYieldTermStructure y
-> (Ptr CYieldTermStructure' -> IO b) -> IO b
withYieldTermStructure GenYieldTermStructure y
a3 ((Ptr CYieldTermStructure' -> IO Double) -> IO Double)
-> (Ptr CYieldTermStructure' -> IO Double) -> IO Double
forall a b. (a -> b) -> a -> b
$ \Ptr CYieldTermStructure'
a3' ->
DayCounter -> (Ptr CDayCounter -> IO Double) -> IO Double
forall b. DayCounter -> (Ptr CDayCounter -> IO b) -> IO b
withDayCounter DayCounter
a4 ((Ptr CDayCounter -> IO Double) -> IO Double)
-> (Ptr CDayCounter -> IO Double) -> IO Double
forall a b. (a -> b) -> a -> b
$ \Ptr CDayCounter
a4' ->
let {a5' :: CDouble
a5' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a5} in
let {a6' :: CDouble
a6' = realToFrac a6} in
let {a7' = (fromIntegral . fromEnum) a7} in
preErrorCheck $ \a8' ->
impliedHazardRate'_ a1' a2' a3' a4' a5' a6' a7' a8' >>= \res ->
let {res' = realToFrac res :: CDouble
res} in
Ptr (Ptr CChar) -> IO ()
errorCheck Ptr (Ptr CChar)
a8'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 (Double
res')
{-# LINE 153 "./QuantLib/Instrument/Credit.chs" #-}
upfrontBps :: (CreditDefaultSwap) -> IO ((Double))
upfrontBps a1 =
withGenInstrument a1 $ \a1' ->
preErrorCheck $ \a2' ->
upfrontBps'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
errorCheck a2'>>
return (res')
{-# LINE 156 "./QuantLib/Instrument/Credit.chs" #-}
upfrontNpv :: (CreditDefaultSwap) -> IO ((Double))
upfrontNpv a1 =
withGenInstrument a1 $ \a1' ->
preErrorCheck $ \a2' ->
upfrontNpv'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
errorCheck a2'>>
return (res')
{-# LINE 159 "./QuantLib/Instrument/Credit.chs" #-}
accrualRebateNpv :: (CreditDefaultSwap) -> IO ((Double))
accrualRebateNpv a1 =
withGenInstrument a1 $ \a1' ->
preErrorCheck $ \a2' ->
accrualRebateNpv'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
errorCheck a2'>>
return (res')
{-# LINE 163 "./QuantLib/Instrument/Credit.chs" #-}
syntheticCdo :: TrancheBasket -> ProtectionSide -> Schedule -> Double -> Double -> DayCounter -> BusinessDayConvention
-> Maybe Double -> IO SyntheticCDO
syntheticCdo basket side sched upfrontRate runningRate dc conv notional =
syntheticCDO_ basket side sched upfrontRate runningRate dc conv (maybe False (const True) notional) (maybe 0 id notional)
syntheticCDO_ :: (TrancheBasket) -> (ProtectionSide) -> (Schedule) -> (Double) -> (Double) -> (DayCounter) -> (BusinessDayConvention) -> (Bool) -> (Double) -> IO ((SyntheticCDO))
syntheticCDO_ a1 a2 a3 a4 a5 a6 a7 a8 a9 =
withTrancheBasket a1 $ \a1' ->
let {a2' = (fromIntegral . fromEnum) a2} in
withSchedule a3 $ \a3' ->
let {a4' = realToFrac a4} in
let {a5' = realToFrac a5} in
withDayCounter a6 $ \a6' ->
let {a7' = fromEnumC a7} in
let {a8' = C2HSImp.fromBool a8} in
let {a9' = realToFrac a9} in
preErrorCheck $ \a10' ->
syntheticCDO_'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' >>= \res ->
peekSyntheticCDO res >>= \res' ->
errorCheck a10'>>
return (res')
{-# LINE 172 "./QuantLib/Instrument/Credit.chs" #-}
fairPremium :: (SyntheticCDO) -> IO ((Double))
fairPremium a1 =
withGenInstrument a1 $ \a1' ->
preErrorCheck $ \a2' ->
fairPremium'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
errorCheck a2'>>
return (res')
{-# LINE 175 "./QuantLib/Instrument/Credit.chs" #-}
fairUpfrontPremium :: (SyntheticCDO) -> IO ((Double))
fairUpfrontPremium a1 =
withGenInstrument a1 $ \a1' ->
preErrorCheck $ \a2' ->
fairUpfrontPremium'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
errorCheck a2'>>
return (res')
{-# LINE 178 "./QuantLib/Instrument/Credit.chs" #-}
premiumValue :: (SyntheticCDO) -> IO ((Double))
premiumValue a1 =
withGenInstrument a1 $ \a1' ->
preErrorCheck $ \a2' ->
premiumValue'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
errorCheck a2'>>
return (res')
{-# LINE 181 "./QuantLib/Instrument/Credit.chs" #-}
protectionValue :: (SyntheticCDO) -> IO ((Double))
protectionValue a1 =
withGenInstrument a1 $ \a1' ->
preErrorCheck $ \a2' ->
protectionValue'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
errorCheck a2'>>
return (res')
{-# LINE 184 "./QuantLib/Instrument/Credit.chs" #-}
premiumLegNpv :: (SyntheticCDO) -> IO ((Double))
premiumLegNpv a1 =
withGenInstrument a1 $ \a1' ->
preErrorCheck $ \a2' ->
premiumLegNpv'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
errorCheck a2'>>
return (res')
{-# LINE 187 "./QuantLib/Instrument/Credit.chs" #-}
protectionLegNpv :: (SyntheticCDO) -> IO ((Double))
protectionLegNpv a1 =
withGenInstrument a1 $ \a1' ->
preErrorCheck $ \a2' ->
protectionLegNpv'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
errorCheck a2'>>
return (res')
{-# LINE 190 "./QuantLib/Instrument/Credit.chs" #-}
cdoRemainingNotional :: (SyntheticCDO) -> IO ((Double))
cdoRemainingNotional a1 =
withGenInstrument a1 $ \a1' ->
preErrorCheck $ \a2' ->
cdoRemainingNotional'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
errorCheck a2'>>
return (res')
{-# LINE 193 "./QuantLib/Instrument/Credit.chs" #-}
implicitCorrelation :: (SyntheticCDO) -> (NonEmpty Double)
-> (GenYieldTermStructure y)
-> (Double)
-> (Double)
-> IO ((Double))
implicitCorrelation :: forall y.
SyntheticCDO
-> NonEmpty Double
-> GenYieldTermStructure y
-> Double
-> Double
-> IO Double
implicitCorrelation SyntheticCDO
a1 NonEmpty Double
a2 GenYieldTermStructure y
a3 Double
a4 Double
a5 =
SyntheticCDO -> (Ptr CSyntheticCDO' -> IO Double) -> IO Double
forall i b. GenInstrument (ForeignPtr i) -> (Ptr i -> IO b) -> IO b
withGenInstrument SyntheticCDO
a1 ((Ptr CSyntheticCDO' -> IO Double) -> IO Double)
-> (Ptr CSyntheticCDO' -> IO Double) -> IO Double
forall a b. (a -> b) -> a -> b
$ \Ptr CSyntheticCDO'
a1' ->
NonEmpty Double -> ((CUInt, Ptr CDouble) -> IO Double) -> IO Double
forall b. NonEmpty Double -> ((CUInt, Ptr CDouble) -> IO b) -> IO b
withNonEmptyDoubleArray NonEmpty Double
a2 (((CUInt, Ptr CDouble) -> IO Double) -> IO Double)
-> ((CUInt, Ptr CDouble) -> IO Double) -> IO Double
forall a b. (a -> b) -> a -> b
$ \(CUInt
a2'1, Ptr CDouble
a2'2) ->
GenYieldTermStructure y
-> (Ptr CYieldTermStructure' -> IO Double) -> IO Double
forall y b.
GenYieldTermStructure y
-> (Ptr CYieldTermStructure' -> IO b) -> IO b
withYieldTermStructure GenYieldTermStructure y
a3 ((Ptr CYieldTermStructure' -> IO Double) -> IO Double)
-> (Ptr CYieldTermStructure' -> IO Double) -> IO Double
forall a b. (a -> b) -> a -> b
$ \Ptr CYieldTermStructure'
a3' ->
let {a4' :: CDouble
a4' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a4} in
let {a5' :: CDouble
a5' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a5} in
(Ptr (Ptr CChar) -> IO Double) -> IO Double
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO Double) -> IO Double)
-> (Ptr (Ptr CChar) -> IO Double) -> IO Double
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a6' ->
Ptr CSyntheticCDO'
-> CUInt
-> Ptr CDouble
-> Ptr CYieldTermStructure'
-> CDouble
-> CDouble
-> Ptr (Ptr CChar)
-> IO CDouble
implicitCorrelation'_ Ptr CSyntheticCDO'
a1' CUInt
a2'1 Ptr CDouble
a2'2 Ptr CYieldTermStructure'
a3' CDouble
a4' CDouble
a5' Ptr (Ptr CChar)
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 CChar) -> IO ()
errorCheck Ptr (Ptr CChar)
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 (Double
res')
{-# LINE 203 "./QuantLib/Instrument/Credit.chs" #-}
nthToDefault :: (DigitalBasket) -> (Word) -> (ProtectionSide) -> (Schedule) -> (Double) -> (Double) -> (DayCounter) -> (Double) -> (Bool) -> IO ((NthToDefault))
nthToDefault a1 a2 a3 a4 a5 a6 a7 a8 a9 =
withDigitalBasket a1 $ \a1' ->
let {a2' = fromIntegral a2} in
let {a3' = (fromIntegral . fromEnum) a3} in
withSchedule a4 $ \a4' ->
let {a5' = realToFrac a5} in
let {a6' = realToFrac a6} in
withDayCounter a7 $ \a7' ->
let {a8' = realToFrac a8} in
let {a9' = C2HSImp.fromBool a9} in
preErrorCheck $ \a10' ->
nthToDefault'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' >>= \res ->
peekNthToDefault res >>= \res' ->
errorCheck a10'>>
return (res')
{-# LINE 208 "./QuantLib/Instrument/Credit.chs" #-}
ntdFairPremium :: (NthToDefault) -> IO ((Double))
ntdFairPremium a1 =
withGenInstrument a1 $ \a1' ->
preErrorCheck $ \a2' ->
ntdFairPremium'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
errorCheck a2'>>
return (res')
{-# LINE 211 "./QuantLib/Instrument/Credit.chs" #-}
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlCreditDefaultSwap"
creditDefaultSwap'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CSchedule)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CQlClaim)) -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CCreditDefaultSwap'))))))))))))))))))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlCreditDefaultSwap1"
creditDefaultSwapWithUpfront'_ :: (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CSchedule)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CQlClaim)) -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CCreditDefaultSwap'))))))))))))))))))))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlCdsOptionAtmRate"
atmRate'_ :: ((C2HSImp.Ptr (CCdsOption')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlCdsOption"
cdsOption'_ :: ((C2HSImp.Ptr (CCreditDefaultSwap')) -> ((QlExercise) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CCdsOption')))))))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlCdsOptionImpliedVolatility"
impliedVolatility'_ :: ((C2HSImp.Ptr (CCdsOption')) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (CDefaultProbabilityTermStructure')) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))))))))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlCdsOptionRiskyAnnuity"
riskyAnnuity'_ :: ((C2HSImp.Ptr (CCdsOption')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlCreditDefaultSwapConventionalSpread"
conventionalSpread'_ :: ((C2HSImp.Ptr (CCreditDefaultSwap')) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlCreditDefaultSwapCouponLegBPS"
couponLegBps'_ :: ((C2HSImp.Ptr (CCreditDefaultSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlCreditDefaultSwapCouponLegNPV"
couponLegNpv'_ :: ((C2HSImp.Ptr (CCreditDefaultSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlCreditDefaultSwapCoupons"
coupons'_ :: ((C2HSImp.Ptr (CCreditDefaultSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CLeg')))))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlCreditDefaultSwapDefaultLegNPV"
defaultLegNpv'_ :: ((C2HSImp.Ptr (CCreditDefaultSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlCreditDefaultSwapFairUpfront"
fairUpfront'_ :: ((C2HSImp.Ptr (CCreditDefaultSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlCreditDefaultSwapImpliedHazardRate"
impliedHazardRate'_ :: ((C2HSImp.Ptr (CCreditDefaultSwap')) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CYieldTermStructure')) -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))))))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlCreditDefaultSwapUpfrontBPS"
upfrontBps'_ :: ((C2HSImp.Ptr (CCreditDefaultSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlCreditDefaultSwapUpfrontNPV"
upfrontNpv'_ :: ((C2HSImp.Ptr (CCreditDefaultSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlCreditDefaultSwapAccrualRebateNPV"
accrualRebateNpv'_ :: ((C2HSImp.Ptr (CCreditDefaultSwap')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlSyntheticCDO"
syntheticCDO_'_ :: ((C2HSImp.Ptr (CBasket)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CSchedule)) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CSyntheticCDO')))))))))))))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlSyntheticCDOFairPremium"
fairPremium'_ :: ((C2HSImp.Ptr (CSyntheticCDO')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlSyntheticCDOFairUpfrontPremium"
fairUpfrontPremium'_ :: ((C2HSImp.Ptr (CSyntheticCDO')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlSyntheticCDOPremiumValue"
premiumValue'_ :: ((C2HSImp.Ptr (CSyntheticCDO')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlSyntheticCDOProtectionValue"
protectionValue'_ :: ((C2HSImp.Ptr (CSyntheticCDO')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlSyntheticCDOPremiumLegNPV"
premiumLegNpv'_ :: ((C2HSImp.Ptr (CSyntheticCDO')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlSyntheticCDOProtectionLegNPV"
protectionLegNpv'_ :: ((C2HSImp.Ptr (CSyntheticCDO')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlSyntheticCDORemainingNotional"
cdoRemainingNotional'_ :: ((C2HSImp.Ptr (CSyntheticCDO')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlSyntheticCDOImplicitCorrelation"
implicitCorrelation'_ :: ((C2HSImp.Ptr (CSyntheticCDO')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CYieldTermStructure')) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))))))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlNthToDefault"
nthToDefault'_ :: ((C2HSImp.Ptr (CBasket)) -> (C2HSImp.CUInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CSchedule)) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CDayCounter)) -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CNthToDefault')))))))))))))
foreign import ccall safe "QuantLib/Instrument/Credit.chs.h qlNthToDefaultFairPremium"
ntdFairPremium'_ :: ((C2HSImp.Ptr (CNthToDefault')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))