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


{-# LINE 1 "./QuantLib/Math.chs" #-}
-- |Numeric helpers and matrix/vector value types.
-- 'RealMatrix' stores dense numeric grids; boxed 'Matrix' supports small or object-valued data.
module QuantLib.Math
  (
    -- * Types
    -- ** Matrices, vectors and grids
    Matrix
  , RealMatrix
  , RealVector
  , NonEmptyVector
  , TimeGrid

    -- ** Rounding and optimization
  , RoundingType(..)
  , Rounding(..)
  , EndCriteriaType(..)
  , EndCriteria(..)
  , OptimizationMethod(..)
  , Constraint(..)

    -- ** Interpolation and numerical traits
  , Interpolation(..)
  , Interpolation2D(..)
  , Approximation(..)
  , PolynomialType(..)
  , ComplexLogFormula(..)
  , SalvagingAlgorithm(..)
  , BinomialTree(..)
  , HistogramAlgorithm(..)
  , CmsMarketCalibrationType(..)

    -- ** Random sequences and statistics
  , RngTrait(..)
  , StatisticsTrait(..)
  , SobolDirectionIntegers(..)

    -- ** Finite-difference schemes
  , BoundaryConditionSide(..)
  , FdmSchemeType(..)
  , FdmScheme(..)

    -- * Constructors
    -- ** Matrices and vectors
  , boxedRealMatrix
  , realMatrixFromVector
  , objectMatrix
  , singletonNonEmptyVector
  , consNonEmptyVector
  , nonEmptyVector
    -- ** Time grids
  , timeGrid
  , timeGridFromVector
  , timeGridFromVectorWithSteps

    -- * Inspectors
    -- ** Rounding and optimization
  , applyRounding
  , optimize
    -- ** Matrix decompositions
  , symmetricSchurDecomposition
  , pseudoSqrt
  , rankReducedSqrt
  , choleskyDecomposition
  , choleskySolveFor
    -- ** Risk statistics
  , riskStatisticsMean
  , riskStatisticsStandardDeviation
  , riskStatisticsVariance
  , riskStatisticsSkewness
  , riskStatisticsKurtosis
  , riskStatisticsMin
  , riskStatisticsMax
  , riskStatisticsSemiVariance
  , riskStatisticsSemiDeviation
  , riskStatisticsDownsideVariance
  , riskStatisticsDownsideDeviation
  , riskStatisticsPercentile
  , riskStatisticsGaussianPercentile
  , riskStatisticsValueAtRisk
  , riskStatisticsGaussianValueAtRisk
  , riskStatisticsExpectedShortfall
  , riskStatisticsGaussianExpectedShortfall
  , riskStatisticsPotentialUpside
  , riskStatisticsGaussianPotentialUpside
  , riskStatisticsRegret
  , riskStatisticsShortfall
  , riskStatisticsAverageShortfall
    -- ** Matrices and vectors
  , matrixRows
  , matrixColumns
  , matrixData
  , realMatrixRows
  , realMatrixColumns
  , realMatrixData
  , nonEmptyVectorToVector
    -- ** Time grids
  , timeAt
  , size
  , points
  ) 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 qualified System.IO.Unsafe as C2HSImp


import QuantLib.Internal
import QuantLib.Internal.Common
import QuantLib.Internal.Type
import Foreign.Marshal.Alloc(alloca)







data EndCriteriaType = EndNone
                     | MaxIterations
                     | StationaryPoint
                     | StationaryFunctionValue
                     | StationaryFunctionAccuracy
                     | ZeroGradientNorm
                     | Unknown
  deriving (Enum,Show,Eq,Read)

{-# LINE 112 "./QuantLib/Math.chs" #-}

data HistogramAlgorithm = HistogramNone
                        | Sturges
                        | FD
                        | Scott
  deriving (Enum,Show,Eq,Read)

{-# LINE 113 "./QuantLib/Math.chs" #-}

data RngTrait = PseudoRandom
              | PoissonPseudoRandom
              | LowDiscrepancy
              | Ziggurat
  deriving (Show,Eq,Read)
instance Enum RngTrait where
  succ PseudoRandom = PoissonPseudoRandom
  succ PoissonPseudoRandom = LowDiscrepancy
  succ LowDiscrepancy = Ziggurat
  succ Ziggurat = error "RngTrait.succ: Ziggurat has no successor"

  pred PoissonPseudoRandom = PseudoRandom
  pred LowDiscrepancy = PoissonPseudoRandom
  pred Ziggurat = LowDiscrepancy
  pred PseudoRandom = error "RngTrait.pred: PseudoRandom has no predecessor"

  enumFromTo :: RngTrait -> RngTrait -> [RngTrait]
enumFromTo RngTrait
from RngTrait
to = RngTrait -> [RngTrait]
forall {t}. Enum t => t -> [t]
go RngTrait
from
    where
      end :: Int
end = RngTrait -> Int
forall a. Enum a => a -> Int
fromEnum RngTrait
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)
                 EQ -> [v]
                 Ordering
GT -> []

  enumFrom from = enumFromTo from Ziggurat

  fromEnum PseudoRandom = 0
  fromEnum PoissonPseudoRandom = 1
  fromEnum LowDiscrepancy = 2
  fromEnum Ziggurat = 3

  toEnum 0 = PseudoRandom
  toEnum 1 = PoissonPseudoRandom
  toEnum 2 = LowDiscrepancy
  toEnum 3 = Ziggurat
  toEnum unmatched = error ("RngTrait.toEnum: Cannot match " ++ show unmatched)

{-# LINE 114 "./QuantLib/Math.chs" #-}

data StatisticsTrait = Statistics
                     | GaussianStatistics
                     | GeneralStatistics
                     | IncrementalStatistics
  deriving (Show,Eq,Read)
instance Enum StatisticsTrait where
  succ Statistics = GaussianStatistics
  succ GaussianStatistics = GeneralStatistics
  succ GeneralStatistics = IncrementalStatistics
  succ IncrementalStatistics = error "StatisticsTrait.succ: IncrementalStatistics has no successor"

  pred GaussianStatistics = Statistics
  pred GeneralStatistics = GaussianStatistics
  pred IncrementalStatistics = GeneralStatistics
  pred Statistics = error "StatisticsTrait.pred: Statistics 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 IncrementalStatistics

  fromEnum Statistics = 0
  fromEnum GaussianStatistics = 1
  fromEnum GeneralStatistics = 2
  fromEnum IncrementalStatistics = 3

  toEnum 0 = Statistics
  toEnum 1 = GaussianStatistics
  toEnum 2 = GeneralStatistics
  toEnum 3 = IncrementalStatistics
  toEnum unmatched = error ("StatisticsTrait.toEnum: Cannot match " ++ show unmatched)

{-# LINE 115 "./QuantLib/Math.chs" #-}

data BinomialTree = JarrowRudd
                  | CoxRossRubinstein
                  | AdditiveEQPBinomialTree
                  | Trigeorgis
                  | Tian
                  | LeisenReimer
                  | Joshi4
                  | ExtendedJarrowRudd
                  | ExtendedCoxRossRubinstein
                  | ExtendedAdditiveEQPBinomialTree
                  | ExtendedTrigeorgis
                  | ExtendedTian
                  | ExtendedLeisenReimer
                  | ExtendedJoshi4
  deriving (Show,Eq,Read)
instance Enum BinomialTree where
  succ JarrowRudd = CoxRossRubinstein
  succ CoxRossRubinstein = AdditiveEQPBinomialTree
  succ AdditiveEQPBinomialTree = Trigeorgis
  succ Trigeorgis = Tian
  succ Tian = LeisenReimer
  succ LeisenReimer = Joshi4
  succ Joshi4 = ExtendedJarrowRudd
  succ ExtendedJarrowRudd = ExtendedCoxRossRubinstein
  succ ExtendedCoxRossRubinstein = ExtendedAdditiveEQPBinomialTree
  succ ExtendedAdditiveEQPBinomialTree = ExtendedTrigeorgis
  succ ExtendedTrigeorgis = ExtendedTian
  succ ExtendedTian = ExtendedLeisenReimer
  succ ExtendedLeisenReimer = ExtendedJoshi4
  succ ExtendedJoshi4 = error "BinomialTree.succ: ExtendedJoshi4 has no successor"

  pred CoxRossRubinstein = JarrowRudd
  pred AdditiveEQPBinomialTree = CoxRossRubinstein
  pred Trigeorgis = AdditiveEQPBinomialTree
  pred Tian = Trigeorgis
  pred LeisenReimer = Tian
  pred Joshi4 = LeisenReimer
  pred ExtendedJarrowRudd = Joshi4
  pred ExtendedCoxRossRubinstein = ExtendedJarrowRudd
  pred ExtendedAdditiveEQPBinomialTree = ExtendedCoxRossRubinstein
  pred ExtendedTrigeorgis = ExtendedAdditiveEQPBinomialTree
  pred ExtendedTian = ExtendedTrigeorgis
  pred ExtendedLeisenReimer = ExtendedTian
  pred ExtendedJoshi4 = ExtendedLeisenReimer
  pred JarrowRudd = error "BinomialTree.pred: JarrowRudd 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 ExtendedJoshi4

  fromEnum JarrowRudd = 0
  fromEnum CoxRossRubinstein = 1
  fromEnum AdditiveEQPBinomialTree = 2
  fromEnum Trigeorgis = 3
  fromEnum Tian = 4
  fromEnum LeisenReimer = 5
  fromEnum Joshi4 = 6
  fromEnum ExtendedJarrowRudd = 7
  fromEnum ExtendedCoxRossRubinstein = 8
  fromEnum ExtendedAdditiveEQPBinomialTree = 9
  fromEnum ExtendedTrigeorgis = 10
  fromEnum ExtendedTian = 11
  fromEnum ExtendedLeisenReimer = 12
  fromEnum ExtendedJoshi4 = 13

  toEnum 0 = JarrowRudd
  toEnum 1 = CoxRossRubinstein
  toEnum 2 = AdditiveEQPBinomialTree
  toEnum 3 = Trigeorgis
  toEnum 4 = Tian
  toEnum 5 = LeisenReimer
  toEnum 6 = Joshi4
  toEnum 7 = ExtendedJarrowRudd
  toEnum 8 = ExtendedCoxRossRubinstein
  toEnum 9 = ExtendedAdditiveEQPBinomialTree
  toEnum 10 = ExtendedTrigeorgis
  toEnum 11 = ExtendedTian
  toEnum 12 = ExtendedLeisenReimer
  toEnum 13 = ExtendedJoshi4
  toEnum unmatched = error ("BinomialTree.toEnum: Cannot match " ++ show unmatched)

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

data BoundaryConditionSide = BoundaryNone
                           | Upper
                           | Lower
  deriving (Enum,Show,Eq,Read)

{-# LINE 117 "./QuantLib/Math.chs" #-}

data PolynomialType = Monomial
                    | Laguerre
                    | Hermite
                    | Hyperbolic
                    | Legendre
                    | Chebyshev
                    | Chebyshev2nd
  deriving (Enum,Show,Eq,Read)

{-# LINE 118 "./QuantLib/Math.chs" #-}


-- |Characteristic-function contour/control-variate choice used by Heston integrations.
data ComplexLogFormula = Gatheral
                       | BranchCorrection
                       | AndersenPiterbarg
                       | AndersenPiterbargOptCV
                       | AsymptoticChF
                       | AngledContour
                       | AngledContourNoCV
                       | OptimalCV
  deriving (Enum,Show,Eq,Read)

{-# LINE 121 "./QuantLib/Math.chs" #-}

data CmsMarketCalibrationType = OnSpread
                              | OnPrice
                              | OnForwardCmsPrice
  deriving (Enum,Show,Eq,Read)

{-# LINE 122 "./QuantLib/Math.chs" #-}

data SobolDirectionIntegers = Unit
                            | Jaeckel
                            | SobolLevitan
                            | SobolLevitanLemieux
                            | JoeKuoD5
                            | JoeKuoD6
                            | JoeKuoD7
                            | Kuo
                            | Kuo2
                            | Kuo3
  deriving (Enum,Show,Eq,Read)

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


-- |Algorithm used to salvage a matrix that is not positive semi-definite before taking its
-- pseudo square root. @Higham@ only works for correlation matrices.
data SalvagingAlgorithm = SalvagingNone
                        | Spectral
                        | Hypersphere
                        | LowerDiagonal
                        | Higham
                        | Principal
  deriving (Enum,Show,Eq,Read)

{-# LINE 127 "./QuantLib/Math.chs" #-}



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


{-# LINE 130 "./QuantLib/Math.chs" #-}


{-# LINE 131 "./QuantLib/Math.chs" #-}


{-# LINE 132 "./QuantLib/Math.chs" #-}


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


-- |rounds a value to the precision and rule carried by the given 'Rounding'
applyRounding :: (Rounding) -- ^rounding
 -> (Double) -- ^value
 -> (Double)
applyRounding a1 a2 =
  C2HSImp.unsafePerformIO $
  withRounding a1 $ \a1' -> 
  let {a2' = realToFrac a2} in 
  applyRounding'_ a1' a2' >>= \res ->
  let {res' = realToFrac res} in
  return (res')

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


-- |Minimizes an arbitrary Haskell-defined cost function via QuantLib's general-purpose
-- 'Problem'\/'OptimizationMethod' machinery -- unlike 'QuantLib.Model.calibrate', which drives a
-- 'QuantLib.Model.CalibratedModel''s own built-in calibration error against bound
-- 'QuantLib.Model.CalibrationHelper's, this takes any 'RealVector -> Double' objective. The cost
-- function crosses back into Haskell once per outer optimizer iteration over the whole parameter
-- vector; see 'QuantLib.Internal.Type.withCostFunction'.
optimize :: (RealVector -> Double) -- ^cost function
 -> (RealVector) -- ^initial guess
 -> (Maybe Constraint) -> (OptimizationMethod) -> (EndCriteria) -> IO ((RealVector), (Double), (EndCriteriaType))
optimize a1 a2 a3 a4 a5 =
  withCostFunction a1 $ \a1' -> 
  withRealVector a2 $ \(a2'1, a2'2) -> 
  withMaybeConstraint a3 $ \a3' -> 
  withOptimizationMethod a4 $ \a4' -> 
  withEndCriteria a5 $ \a5' -> 
  preArray $ \(a6'1, a6'2) -> 
  alloca $ \a7' -> 
  alloca $ \a8' -> 
  preErrorCheck $ \a9' -> 
  optimize'_ a1' a2'1  a2'2 a3' a4' a5' a6'1  a6'2 a7' a8' a9' >>
  peekRealVector  a6'1  a6'2>>= \a6'' -> 
  peekDouble  a7'>>= \a7'' -> 
  peekEnum  a8'>>= \a8'' -> 
  errorCheck  a9'>>
  return (a6'', a7'', a8'')

{-# LINE 154 "./QuantLib/Math.chs" #-}


-- |Regularly spaced time-grid.
timeGrid :: (Double) -- ^end
 -> (Word) -- ^steps
 -> IO ((TimeGrid))
timeGrid a1 a2 =
  let {a1' = realToFrac a1} in 
  let {a2' = fromIntegral a2} in 
  preErrorCheck $ \a3' -> 
  timeGrid'_ a1' a2' a3' >>= \res ->
  peekTimeGrid res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 159 "./QuantLib/Math.chs" #-}


-- |Time grid with mandatory time points.
-- Mandatory points are guaranteed to belong to the grid. No additional points are added.
timeGridFromVector :: (NonEmptyVector Double) -- ^mandatoryTimes
 -> IO ((TimeGrid))
timeGridFromVector a1 =
  withNonEmptyRealVector a1 $ \(a1'1, a1'2) -> 
  preErrorCheck $ \a2' -> 
  timeGridFromVector'_ a1'1  a1'2 a2' >>= \res ->
  peekTimeGrid res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 164 "./QuantLib/Math.chs" #-}


-- |Time grid with mandatory time points.
-- Mandatory points are guaranteed to belong to the grid. Additional points are then added with regular spacing between pairs of mandatory times in order to reach the desired number of steps.
timeGridFromVectorWithSteps :: (NonEmptyVector Double) -- ^mandatoryTimes
 -> (Word) -- ^steps
 -> IO ((TimeGrid))
timeGridFromVectorWithSteps a1 a2 =
  withNonEmptyRealVector a1 $ \(a1'1, a1'2) -> 
  let {a2' = fromIntegral a2} in 
  preErrorCheck $ \a3' -> 
  timeGridFromVectorWithSteps'_ a1'1  a1'2 a2' a3' >>= \res ->
  peekTimeGrid res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 170 "./QuantLib/Math.chs" #-}


-- |returns the number of times on the grid
size :: (TimeGrid) -> (Word)
size a1 =
  C2HSImp.unsafePerformIO $
  withTimeGrid a1 $ \a1' -> 
  size'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 173 "./QuantLib/Math.chs" #-}


-- |returns the time at the given index of the grid
timeAt :: (TimeGrid) -- ^grid
 -> (Word) -- ^index
 -> IO ((Double))
timeAt a1 a2 =
  withTimeGrid a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  preErrorCheck $ \a3' -> 
  timeAt'_ a1' a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 178 "./QuantLib/Math.chs" #-}


-- |Returns all times on the grid in contiguous storage.
points :: (TimeGrid) -> IO ((RealVector))
points a1 =
  withTimeGrid a1 $ \a1' -> 
  preArray $ \(a2'1, a2'2) -> 
  preErrorCheck $ \a3' -> 
  points'_ a1' a2'1  a2'2 a3' >>
  peekRealVector  a2'1  a2'2>>= \a2'' -> 
  errorCheck  a3'>>
  return (a2'')

{-# LINE 181 "./QuantLib/Math.chs" #-}


-- |Mean of a caller-supplied sample. Each @riskStatistics*@ call evaluates a fresh sample.
riskStatisticsMean :: (RealVector) -- ^sample
 -> IO ((Double))
riskStatisticsMean a1 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  preErrorCheck $ \a2' -> 
  riskStatisticsMean'_ a1'1  a1'2 a2' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 185 "./QuantLib/Math.chs" #-}


-- |Standard deviation of the sample (square root of 'riskStatisticsVariance').
riskStatisticsStandardDeviation :: (RealVector) -- ^sample
 -> IO ((Double))
riskStatisticsStandardDeviation a1 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  preErrorCheck $ \a2' -> 
  riskStatisticsStandardDeviation'_ a1'1  a1'2 a2' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 189 "./QuantLib/Math.chs" #-}


-- |Variance of the sample, @N\/(N-1)@-corrected.
riskStatisticsVariance :: (RealVector) -- ^sample
 -> IO ((Double))
riskStatisticsVariance a1 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  preErrorCheck $ \a2' -> 
  riskStatisticsVariance'_ a1'1  a1'2 a2' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 193 "./QuantLib/Math.chs" #-}


-- |Skewness of the sample; 0 for a gaussian distribution.
riskStatisticsSkewness :: (RealVector) -- ^sample
 -> IO ((Double))
riskStatisticsSkewness a1 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  preErrorCheck $ \a2' -> 
  riskStatisticsSkewness'_ a1'1  a1'2 a2' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 197 "./QuantLib/Math.chs" #-}


-- |Excess kurtosis of the sample; 0 for a gaussian distribution.
riskStatisticsKurtosis :: (RealVector) -- ^sample
 -> IO ((Double))
riskStatisticsKurtosis a1 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  preErrorCheck $ \a2' -> 
  riskStatisticsKurtosis'_ a1'1  a1'2 a2' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 201 "./QuantLib/Math.chs" #-}


-- |Minimum sample value. Throws if the sample is empty.
riskStatisticsMin :: (RealVector) -- ^sample
 -> IO ((Double))
riskStatisticsMin a1 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  preErrorCheck $ \a2' -> 
  riskStatisticsMin'_ a1'1  a1'2 a2' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 205 "./QuantLib/Math.chs" #-}


-- |Maximum sample value. Throws if the sample is empty.
riskStatisticsMax :: (RealVector) -- ^sample
 -> IO ((Double))
riskStatisticsMax a1 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  preErrorCheck $ \a2' -> 
  riskStatisticsMax'_ a1'1  a1'2 a2' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 209 "./QuantLib/Math.chs" #-}


-- |Variance of the sample values falling below the sample mean (Markowitz semi-variance).
-- Throws if fewer than two sample values fall below the mean.
riskStatisticsSemiVariance :: (RealVector) -- ^sample
 -> IO ((Double))
riskStatisticsSemiVariance a1 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  preErrorCheck $ \a2' -> 
  riskStatisticsSemiVariance'_ a1'1  a1'2 a2' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 214 "./QuantLib/Math.chs" #-}


-- |Square root of 'riskStatisticsSemiVariance'.
riskStatisticsSemiDeviation :: (RealVector) -- ^sample
 -> IO ((Double))
riskStatisticsSemiDeviation a1 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  preErrorCheck $ \a2' -> 
  riskStatisticsSemiDeviation'_ a1'1  a1'2 a2' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 218 "./QuantLib/Math.chs" #-}


-- |Variance of the sample values falling below zero. Throws if fewer than two sample values
-- fall below zero.
riskStatisticsDownsideVariance :: (RealVector) -- ^sample
 -> IO ((Double))
riskStatisticsDownsideVariance a1 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  preErrorCheck $ \a2' -> 
  riskStatisticsDownsideVariance'_ a1'1  a1'2 a2' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 223 "./QuantLib/Math.chs" #-}


-- |Square root of 'riskStatisticsDownsideVariance'.
riskStatisticsDownsideDeviation :: (RealVector) -- ^sample
 -> IO ((Double))
riskStatisticsDownsideDeviation a1 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  preErrorCheck $ \a2' -> 
  riskStatisticsDownsideDeviation'_ a1'1  a1'2 a2' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 227 "./QuantLib/Math.chs" #-}


-- |Empirical @y@-th percentile of the sample; @y@ must lie in @(0.0, 1.0]@.
riskStatisticsPercentile :: (RealVector) -- ^sample
 -> (Double) -- ^y
 -> IO ((Double))
riskStatisticsPercentile a1 a2 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  riskStatisticsPercentile'_ a1'1  a1'2 a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 232 "./QuantLib/Math.chs" #-}


-- |@y@-th percentile assuming the sample is gaussian (mean\/standard deviation matched); @y@
-- must lie in @(0.0, 1.0)@.
riskStatisticsGaussianPercentile :: (RealVector) -- ^sample
 -> (Double) -- ^y
 -> IO ((Double))
riskStatisticsGaussianPercentile a1 a2 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  riskStatisticsGaussianPercentile'_ a1'1  a1'2 a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 238 "./QuantLib/Math.chs" #-}


-- |Empirical value-at-risk at the given @centile@, which must lie in @[0.9, 1.0)@ — a loss
-- (non-negative), the negative of the empirical @(1-centile)@-th percentile floored at zero.
riskStatisticsValueAtRisk :: (RealVector) -- ^sample
 -> (Double) -- ^centile
 -> IO ((Double))
riskStatisticsValueAtRisk a1 a2 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  riskStatisticsValueAtRisk'_ a1'1  a1'2 a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 244 "./QuantLib/Math.chs" #-}


-- |Value-at-risk at the given @centile@ assuming the sample is gaussian; @centile@ must lie in
-- @[0.9, 1.0)@.
riskStatisticsGaussianValueAtRisk :: (RealVector) -- ^sample
 -> (Double) -- ^centile
 -> IO ((Double))
riskStatisticsGaussianValueAtRisk a1 a2 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  riskStatisticsGaussianValueAtRisk'_ a1'1  a1'2 a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 250 "./QuantLib/Math.chs" #-}


-- |Empirical expected shortfall (conditional value-at-risk) at the given @centile@, which must
-- lie in @[0.9, 1.0)@: the average of the sample values below the value-at-risk threshold.
-- Throws if the sample is empty, or if no sample value falls below the threshold.
riskStatisticsExpectedShortfall :: (RealVector) -- ^sample
 -> (Double) -- ^centile
 -> IO ((Double))
riskStatisticsExpectedShortfall a1 a2 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  riskStatisticsExpectedShortfall'_ a1'1  a1'2 a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 257 "./QuantLib/Math.chs" #-}


-- |Expected shortfall at the given @centile@ assuming the sample is gaussian; @centile@ must
-- lie in @[0.9, 1.0)@.
riskStatisticsGaussianExpectedShortfall :: (RealVector) -- ^sample
 -> (Double) -- ^centile
 -> IO ((Double))
riskStatisticsGaussianExpectedShortfall a1 a2 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  riskStatisticsGaussianExpectedShortfall'_ a1'1  a1'2 a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 263 "./QuantLib/Math.chs" #-}


-- |Empirical potential upside (the reciprocal notion of value-at-risk, floored at zero) at the
-- given @centile@, which must lie in @[0.9, 1.0)@.
riskStatisticsPotentialUpside :: (RealVector) -- ^sample
 -> (Double) -- ^centile
 -> IO ((Double))
riskStatisticsPotentialUpside a1 a2 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  riskStatisticsPotentialUpside'_ a1'1  a1'2 a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 269 "./QuantLib/Math.chs" #-}


-- |Potential upside at the given @centile@ assuming the sample is gaussian; @centile@ must lie
-- in @[0.9, 1.0)@.
riskStatisticsGaussianPotentialUpside :: (RealVector) -- ^sample
 -> (Double) -- ^centile
 -> IO ((Double))
riskStatisticsGaussianPotentialUpside a1 a2 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  riskStatisticsGaussianPotentialUpside'_ a1'1  a1'2 a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 275 "./QuantLib/Math.chs" #-}


-- |Variance of the sample values falling below @target@ (Dembo\/Freeman regret). Throws if
-- fewer than two sample values fall below @target@.
riskStatisticsRegret :: (RealVector) -- ^sample
 -> (Double) -- ^target
 -> IO ((Double))
riskStatisticsRegret a1 a2 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  riskStatisticsRegret'_ a1'1  a1'2 a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 281 "./QuantLib/Math.chs" #-}


-- |Probability (fraction of the sample, by count) of falling below @target@. Throws if the
-- sample is empty.
riskStatisticsShortfall :: (RealVector) -- ^sample
 -> (Double) -- ^target
 -> IO ((Double))
riskStatisticsShortfall a1 a2 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  riskStatisticsShortfall'_ a1'1  a1'2 a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 287 "./QuantLib/Math.chs" #-}


-- |Average shortfall below @target@, i.e. the mean of @target - x@ over sample values @x@
-- below @target@. Throws if no sample value falls below @target@.
riskStatisticsAverageShortfall :: (RealVector) -- ^sample
 -> (Double) -- ^target
 -> IO ((Double))
riskStatisticsAverageShortfall a1 a2 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  let {a2' = realToFrac a2} in 
  preErrorCheck $ \a3' -> 
  riskStatisticsAverageShortfall'_ a1'1  a1'2 a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 293 "./QuantLib/Math.chs" #-}


toMatrixDouble :: (Word, Word, [Double]) -> Matrix Double
toMatrixDouble (r, c, d) = Matrix r c d

-- |Eigenvalues and eigenvectors of a real symmetric matrix, computed by the symmetric threshold
-- Jacobi algorithm. The eigenvalues come back in decreasing order, and the eigenvectors are the
-- /columns/ of the returned matrix: column @i@ belongs to the @i@-th eigenvalue.
symmetricSchurDecomposition :: Matrix Double -- ^symmetric matrix
  -> IO ([Double], Matrix Double) -- ^eigenvalues, eigenvectors as columns
symmetricSchurDecomposition (Matrix mr mc md) = do
  (values, r, c, vectors) <- qlSymmetricSchurDecomposition mr mc md
  pure (values, Matrix r c vectors)
qlSymmetricSchurDecomposition :: (Word) -> (Word) -> ([Double]) -> IO (([Double]), (Word), (Word), ([Double]))
qlSymmetricSchurDecomposition :: Word -> Word -> [Double] -> IO ([Double], Word, Word, [Double])
qlSymmetricSchurDecomposition Word
a1 Word
a2 [Double]
a3 =
  let {a1' :: CUInt
a1' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a1} in 
  let {a2' :: CUInt
a2' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a2} in 
  [Double]
-> (Ptr CDouble -> IO ([Double], Word, Word, [Double]))
-> IO ([Double], Word, Word, [Double])
forall b. [Double] -> (Ptr CDouble -> IO b) -> IO b
withDoubleArrayRaw [Double]
a3 ((Ptr CDouble -> IO ([Double], Word, Word, [Double]))
 -> IO ([Double], Word, Word, [Double]))
-> (Ptr CDouble -> IO ([Double], Word, Word, [Double]))
-> IO ([Double], Word, Word, [Double])
forall a b. (a -> b) -> a -> b
$ \Ptr CDouble
a3' -> 
  ((Ptr CUInt, Ptr (Ptr CDouble))
 -> IO ([Double], Word, Word, [Double]))
-> IO ([Double], Word, Word, [Double])
forall a b. ((Ptr CUInt, Ptr (Ptr a)) -> IO b) -> IO b
preArray (((Ptr CUInt, Ptr (Ptr CDouble))
  -> IO ([Double], Word, Word, [Double]))
 -> IO ([Double], Word, Word, [Double]))
-> ((Ptr CUInt, Ptr (Ptr CDouble))
    -> IO ([Double], Word, Word, [Double]))
-> IO ([Double], Word, Word, [Double])
forall a b. (a -> b) -> a -> b
$ \(Ptr CUInt
a4'1, Ptr (Ptr CDouble)
a4'2) -> 
  (Ptr CUInt -> IO ([Double], Word, Word, [Double]))
-> IO ([Double], Word, Word, [Double])
forall a b. Storable a => (Ptr a -> IO b) -> IO b
prePtr ((Ptr CUInt -> IO ([Double], Word, Word, [Double]))
 -> IO ([Double], Word, Word, [Double]))
-> (Ptr CUInt -> IO ([Double], Word, Word, [Double]))
-> IO ([Double], Word, Word, [Double])
forall a b. (a -> b) -> a -> b
$ \Ptr CUInt
a5' -> 
  (Ptr CUInt -> IO ([Double], Word, Word, [Double]))
-> IO ([Double], Word, Word, [Double])
forall a b. Storable a => (Ptr a -> IO b) -> IO b
prePtr ((Ptr CUInt -> IO ([Double], Word, Word, [Double]))
 -> IO ([Double], Word, Word, [Double]))
-> (Ptr CUInt -> IO ([Double], Word, Word, [Double]))
-> IO ([Double], Word, Word, [Double])
forall a b. (a -> b) -> a -> b
$ \Ptr CUInt
a6' -> 
  ((Ptr CUInt, Ptr (Ptr CDouble))
 -> IO ([Double], Word, Word, [Double]))
-> IO ([Double], Word, Word, [Double])
forall a b. ((Ptr CUInt, Ptr (Ptr a)) -> IO b) -> IO b
preArray (((Ptr CUInt, Ptr (Ptr CDouble))
  -> IO ([Double], Word, Word, [Double]))
 -> IO ([Double], Word, Word, [Double]))
-> ((Ptr CUInt, Ptr (Ptr CDouble))
    -> IO ([Double], Word, Word, [Double]))
-> IO ([Double], Word, Word, [Double])
forall a b. (a -> b) -> a -> b
$ \(Ptr CUInt
a7'1, Ptr (Ptr CDouble)
a7'2) -> 
  (Ptr (Ptr CChar) -> IO ([Double], Word, Word, [Double]))
-> IO ([Double], Word, Word, [Double])
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO ([Double], Word, Word, [Double]))
 -> IO ([Double], Word, Word, [Double]))
-> (Ptr (Ptr CChar) -> IO ([Double], Word, Word, [Double]))
-> IO ([Double], Word, Word, [Double])
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a8' -> 
  qlSymmetricSchurDecomposition'_ a1' a2' a3' a4'1  a4'2 a5' a6' a7'1  a7'2 a8' >>
  peekDoubleArray  a4'1  a4'2IO [Double]
-> ([Double] -> IO ([Double], Word, Word, [Double]))
-> IO ([Double], Word, Word, [Double])
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Double]
a4'' -> 
  peekWord  a5'>>= \a5'' -> 
  peekWord  a6'>>= \a6'' -> 
  peekDoubleArray  a7'1  a7'2>>= \a7'' -> 
  errorCheck  a8'>>
  return (a4'', a5'', a6'', a7'')

{-# LINE 309 "./QuantLib/Math.chs" #-}


-- |Pseudo square root @S@ of a real symmetric matrix @M@, i.e. the matrix with @S*transpose S == M@.
-- When @M@ is not positive semi-definite the given 'SalvagingAlgorithm' approximates it; with
-- 'SalvagingNone' a non-positive-semi-definite input throws instead.
pseudoSqrt :: Matrix Double -- ^symmetric matrix
  -> SalvagingAlgorithm
  -> IO (Matrix Double)
pseudoSqrt (Matrix mr mc md) salvaging = toMatrixDouble <$> qlPseudoSqrt mr mc md salvaging
qlPseudoSqrt :: (Word) -> (Word) -> ([Double]) -> (SalvagingAlgorithm) -> IO ((Word), (Word), ([Double]))
qlPseudoSqrt a1 a2 a3 a4 =
  let {a1' = fromIntegral a1} in 
  let {a2' = fromIntegral a2} in 
  withDoubleArrayRaw a3 $ \a3' -> 
  let {a4' = fromEnumC a4} in 
  prePtr $ \a5' -> 
  prePtr $ \a6' -> 
  preArray $ \(a7'1, a7'2) -> 
  preErrorCheck $ \a8' -> 
  qlPseudoSqrt'_ a1' a2' a3' a4' a5' a6' a7'1  a7'2 a8' >>
  peekWord  a5'>>= \a5'' -> 
  peekWord  a6'>>= \a6'' -> 
  peekDoubleArray  a7'1  a7'2>>= \a7'' -> 
  errorCheck  a8'>>
  return (a5'', a6'', a7'')

{-# LINE 321 "./QuantLib/Math.chs" #-}


-- |Rank-reduced pseudo square root of a real symmetric matrix: the result has rank at most
-- @maxRank@. If @maxRank@ reaches the matrix size, the given percentage of the eigenvalues' sum
-- is retained instead.
rankReducedSqrt :: Matrix Double -- ^symmetric matrix
  -> Word -- ^maxRank
  -> Double -- ^componentRetainedPercentage
  -> SalvagingAlgorithm
  -> IO (Matrix Double)
rankReducedSqrt (Matrix mr mc md) maxRank retained salvaging =
  toMatrixDouble <$> qlRankReducedSqrt mr mc md maxRank retained salvaging
qlRankReducedSqrt :: (Word) -> (Word) -> ([Double]) -> (Word) -> (Double) -> (SalvagingAlgorithm) -> IO ((Word), (Word), ([Double]))
qlRankReducedSqrt a1 a2 a3 a4 a5 a6 =
  let {a1' = fromIntegral a1} in 
  let {a2' = fromIntegral a2} in 
  withDoubleArrayRaw a3 $ \a3' -> 
  let {a4' = fromIntegral a4} in 
  let {a5' = realToFrac a5} in 
  let {a6' = fromEnumC a6} in 
  prePtr $ \a7' -> 
  prePtr $ \a8' -> 
  preArray $ \(a9'1, a9'2) -> 
  preErrorCheck $ \a10' -> 
  qlRankReducedSqrt'_ a1' a2' a3' a4' a5' a6' a7' a8' a9'1  a9'2 a10' >>
  peekWord  a7'>>= \a7'' -> 
  peekWord  a8'>>= \a8'' -> 
  peekDoubleArray  a9'1  a9'2>>= \a9'' -> 
  errorCheck  a10'>>
  return (a7'', a8'', a9'')

{-# LINE 336 "./QuantLib/Math.chs" #-}


-- |Cholesky factor @L@ of a symmetric positive-definite matrix @M@, i.e. the lower-triangular
-- matrix with @L*transpose L == M@. Pass @True@ for @flexible@ to accept a merely positive
-- /semi/-definite (rank-deficient) input, whose factor is completed with zeroes rather than
-- producing @nan@.
choleskyDecomposition :: Matrix Double -- ^symmetric matrix
  -> Bool -- ^flexible
  -> IO (Matrix Double)
choleskyDecomposition (Matrix mr mc md) flexible = toMatrixDouble <$> qlCholeskyDecomposition mr mc md flexible
qlCholeskyDecomposition :: (Word) -> (Word) -> ([Double]) -> (Bool) -> IO ((Word), (Word), ([Double]))
qlCholeskyDecomposition a1 a2 a3 a4 =
  let {a1' = fromIntegral a1} in 
  let {a2' = fromIntegral a2} in 
  withDoubleArrayRaw a3 $ \a3' -> 
  let {a4' = C2HSImp.fromBool a4} in 
  prePtr $ \a5' -> 
  prePtr $ \a6' -> 
  preArray $ \(a7'1, a7'2) -> 
  preErrorCheck $ \a8' -> 
  qlCholeskyDecomposition'_ a1' a2' a3' a4' a5' a6' a7'1  a7'2 a8' >>
  peekWord  a5'>>= \a5'' -> 
  peekWord  a6'>>= \a6'' -> 
  peekDoubleArray  a7'1  a7'2>>= \a7'' -> 
  errorCheck  a8'>>
  return (a5'', a6'', a7'')

{-# LINE 349 "./QuantLib/Math.chs" #-}


-- |Solves @M*x == b@ given the Cholesky factor @L@ of @M@ -- the first argument is the factor
-- returned by 'choleskyDecomposition', not @M@ itself.
choleskySolveFor :: Matrix Double -- ^Cholesky factor L
  -> [Double] -- ^b
  -> IO [Double]
choleskySolveFor (Matrix mr mc md) b = qlCholeskySolveFor mr mc md b
qlCholeskySolveFor :: (Word) -> (Word) -> ([Double]) -> ([Double]) -> IO (([Double]))
qlCholeskySolveFor a1 a2 a3 a4 =
  let {a1' = fromIntegral a1} in 
  let {a2' = fromIntegral a2} in 
  withDoubleArrayRaw a3 $ \a3' -> 
  withDoubleArray a4 $ \(a4'1, a4'2) -> 
  preArray $ \(a5'1, a5'2) -> 
  preErrorCheck $ \a6' -> 
  qlCholeskySolveFor'_ a1' a2' a3' a4'1  a4'2 a5'1  a5'2 a6' >>
  peekDoubleArray  a5'1  a5'2>>= \a5'' -> 
  errorCheck  a6'>>
  return (a5'')

{-# LINE 360 "./QuantLib/Math.chs" #-}


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

foreign import ccall safe "QuantLib/Math.chs.h qlRound"
  applyRounding'_ :: ((C2HSImp.Ptr (CRounding)) -> (C2HSImp.CDouble -> (IO C2HSImp.CDouble)))

foreign import ccall safe "QuantLib/Math.chs.h qlOptimize"
  optimize'_ :: ((C2HSImp.FunPtr ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> (IO C2HSImp.CDouble)))) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CConstraint)) -> ((C2HSImp.Ptr (COptimizationMethod)) -> ((C2HSImp.Ptr (CEndCriteria)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO ()))))))))))))

foreign import ccall safe "QuantLib/Math.chs.h qlTimeGrid1"
  timeGrid'_ :: (C2HSImp.CDouble -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CTimeGrid))))))

foreign import ccall safe "QuantLib/Math.chs.h qlTimeGrid2"
  timeGridFromVector'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CTimeGrid))))))

foreign import ccall safe "QuantLib/Math.chs.h qlTimeGrid3"
  timeGridFromVectorWithSteps'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CTimeGrid)))))))

foreign import ccall safe "QuantLib/Math.chs.h qlTimeGridSize"
  size'_ :: ((C2HSImp.Ptr (CTimeGrid)) -> (IO C2HSImp.CUInt))

foreign import ccall safe "QuantLib/Math.chs.h qlTimeGridAt"
  timeAt'_ :: ((C2HSImp.Ptr (CTimeGrid)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Math.chs.h qlTimeGridPoints"
  points'_ :: ((C2HSImp.Ptr (CTimeGrid)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO ())))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsMean"
  riskStatisticsMean'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsStandardDeviation"
  riskStatisticsStandardDeviation'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsVariance"
  riskStatisticsVariance'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsSkewness"
  riskStatisticsSkewness'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsKurtosis"
  riskStatisticsKurtosis'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsMin"
  riskStatisticsMin'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsMax"
  riskStatisticsMax'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsSemiVariance"
  riskStatisticsSemiVariance'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsSemiDeviation"
  riskStatisticsSemiDeviation'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsDownsideVariance"
  riskStatisticsDownsideVariance'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsDownsideDeviation"
  riskStatisticsDownsideDeviation'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsPercentile"
  riskStatisticsPercentile'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsGaussianPercentile"
  riskStatisticsGaussianPercentile'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsValueAtRisk"
  riskStatisticsValueAtRisk'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsGaussianValueAtRisk"
  riskStatisticsGaussianValueAtRisk'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsExpectedShortfall"
  riskStatisticsExpectedShortfall'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsGaussianExpectedShortfall"
  riskStatisticsGaussianExpectedShortfall'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsPotentialUpside"
  riskStatisticsPotentialUpside'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsGaussianPotentialUpside"
  riskStatisticsGaussianPotentialUpside'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsRegret"
  riskStatisticsRegret'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsShortfall"
  riskStatisticsShortfall'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsAverageShortfall"
  riskStatisticsAverageShortfall'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/Math.chs.h qlSymmetricSchurDecomposition"
  qlSymmetricSchurDecomposition'_ :: (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO ())))))))))))

foreign import ccall safe "QuantLib/Math.chs.h qlPseudoSqrt"
  qlPseudoSqrt'_ :: (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO ()))))))))))

foreign import ccall safe "QuantLib/Math.chs.h qlRankReducedSqrt"
  qlRankReducedSqrt'_ :: (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO ()))))))))))))

foreign import ccall safe "QuantLib/Math.chs.h qlCholeskyDecomposition"
  qlCholeskyDecomposition'_ :: (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO ()))))))))))

foreign import ccall safe "QuantLib/Math.chs.h qlCholeskySolveFor"
  qlCholeskySolveFor'_ :: (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO ())))))))))