never executed always true always false
    1 -- GENERATED by C->Haskell Compiler, version 0.28.8 Switcheroo, 25 November 2017 (Haskell)
    2 -- Edit the ORIGNAL .chs file instead!
    3 
    4 
    5 -- |Numeric helpers and matrix/vector value types.
    6 -- 'RealMatrix' stores dense numeric grids; boxed 'Matrix' supports small or object-valued data.
    7 module QuantLib.Math
    8   (
    9     -- * Types
   10     -- ** Matrices, vectors and grids
   11     Matrix
   12   , RealMatrix
   13   , RealVector
   14   , NonEmptyVector
   15   , TimeGrid
   16 
   17     -- ** Rounding and optimization
   18   , RoundingType(..)
   19   , Rounding(..)
   20   , EndCriteriaType(..)
   21   , EndCriteria(..)
   22   , OptimizationMethod(..)
   23   , Constraint(..)
   24 
   25     -- ** Interpolation and numerical traits
   26   , Interpolation(..)
   27   , Interpolation2D(..)
   28   , Approximation(..)
   29   , PolynomialType(..)
   30   , ComplexLogFormula(..)
   31   , SalvagingAlgorithm(..)
   32   , BinomialTree(..)
   33   , HistogramAlgorithm(..)
   34   , CmsMarketCalibrationType(..)
   35 
   36     -- ** Random sequences and statistics
   37   , RngTrait(..)
   38   , StatisticsTrait(..)
   39   , SobolDirectionIntegers(..)
   40 
   41     -- ** Finite-difference schemes
   42   , BoundaryConditionSide(..)
   43   , FdmSchemeType(..)
   44   , FdmScheme(..)
   45 
   46     -- * Constructors
   47     -- ** Matrices and vectors
   48   , boxedRealMatrix
   49   , realMatrixFromVector
   50   , objectMatrix
   51   , singletonNonEmptyVector
   52   , consNonEmptyVector
   53   , nonEmptyVector
   54     -- ** Time grids
   55   , timeGrid
   56   , timeGridFromVector
   57   , timeGridFromVectorWithSteps
   58 
   59     -- * Inspectors
   60     -- ** Rounding and optimization
   61   , applyRounding
   62   , optimize
   63     -- ** Matrix decompositions
   64   , symmetricSchurDecomposition
   65   , pseudoSqrt
   66   , rankReducedSqrt
   67   , choleskyDecomposition
   68   , choleskySolveFor
   69     -- ** Risk statistics
   70   , riskStatisticsMean
   71   , riskStatisticsStandardDeviation
   72   , riskStatisticsVariance
   73   , riskStatisticsSkewness
   74   , riskStatisticsKurtosis
   75   , riskStatisticsMin
   76   , riskStatisticsMax
   77   , riskStatisticsSemiVariance
   78   , riskStatisticsSemiDeviation
   79   , riskStatisticsDownsideVariance
   80   , riskStatisticsDownsideDeviation
   81   , riskStatisticsPercentile
   82   , riskStatisticsGaussianPercentile
   83   , riskStatisticsValueAtRisk
   84   , riskStatisticsGaussianValueAtRisk
   85   , riskStatisticsExpectedShortfall
   86   , riskStatisticsGaussianExpectedShortfall
   87   , riskStatisticsPotentialUpside
   88   , riskStatisticsGaussianPotentialUpside
   89   , riskStatisticsRegret
   90   , riskStatisticsShortfall
   91   , riskStatisticsAverageShortfall
   92     -- ** Matrices and vectors
   93   , matrixRows
   94   , matrixColumns
   95   , matrixData
   96   , realMatrixRows
   97   , realMatrixColumns
   98   , realMatrixData
   99   , nonEmptyVectorToVector
  100     -- ** Time grids
  101   , timeAt
  102   , size
  103   , points
  104   ) where
  105 import qualified Foreign.C.Types as C2HSImp
  106 import qualified Foreign.ForeignPtr as C2HSImp
  107 import qualified Foreign.Marshal.Utils as C2HSImp
  108 import qualified Foreign.Ptr as C2HSImp
  109 import qualified System.IO.Unsafe as C2HSImp
  110 
  111 
  112 import QuantLib.Internal
  113 import QuantLib.Internal.Common
  114 import QuantLib.Internal.Type
  115 import Foreign.Marshal.Alloc(alloca)
  116 
  117 
  118 
  119 
  120 
  121 
  122 
  123 data EndCriteriaType = EndNone
  124                      | MaxIterations
  125                      | StationaryPoint
  126                      | StationaryFunctionValue
  127                      | StationaryFunctionAccuracy
  128                      | ZeroGradientNorm
  129                      | Unknown
  130   deriving (Enum,Show,Eq,Read)
  131 
  132 
  133 data HistogramAlgorithm = HistogramNone
  134                         | Sturges
  135                         | FD
  136                         | Scott
  137   deriving (Enum,Show,Eq,Read)
  138 
  139 
  140 data RngTrait = PseudoRandom
  141               | PoissonPseudoRandom
  142               | LowDiscrepancy
  143               | Ziggurat
  144   deriving (Show,Eq,Read)
  145 instance Enum RngTrait where
  146   succ PseudoRandom = PoissonPseudoRandom
  147   succ PoissonPseudoRandom = LowDiscrepancy
  148   succ LowDiscrepancy = Ziggurat
  149   succ Ziggurat = error "RngTrait.succ: Ziggurat has no successor"
  150 
  151   pred PoissonPseudoRandom = PseudoRandom
  152   pred LowDiscrepancy = PoissonPseudoRandom
  153   pred Ziggurat = LowDiscrepancy
  154   pred PseudoRandom = error "RngTrait.pred: PseudoRandom has no predecessor"
  155 
  156   enumFromTo from to = go from
  157     where
  158       end = fromEnum to
  159       go v = case compare (fromEnum v) end of
  160                  LT -> v : go (succ v)
  161                  EQ -> [v]
  162                  GT -> []
  163 
  164   enumFrom from = enumFromTo from Ziggurat
  165 
  166   fromEnum PseudoRandom = 0
  167   fromEnum PoissonPseudoRandom = 1
  168   fromEnum LowDiscrepancy = 2
  169   fromEnum Ziggurat = 3
  170 
  171   toEnum 0 = PseudoRandom
  172   toEnum 1 = PoissonPseudoRandom
  173   toEnum 2 = LowDiscrepancy
  174   toEnum 3 = Ziggurat
  175   toEnum unmatched = error ("RngTrait.toEnum: Cannot match " ++ show unmatched)
  176 
  177 
  178 data StatisticsTrait = Statistics
  179                      | GaussianStatistics
  180                      | GeneralStatistics
  181                      | IncrementalStatistics
  182   deriving (Show,Eq,Read)
  183 instance Enum StatisticsTrait where
  184   succ Statistics = GaussianStatistics
  185   succ GaussianStatistics = GeneralStatistics
  186   succ GeneralStatistics = IncrementalStatistics
  187   succ IncrementalStatistics = error "StatisticsTrait.succ: IncrementalStatistics has no successor"
  188 
  189   pred GaussianStatistics = Statistics
  190   pred GeneralStatistics = GaussianStatistics
  191   pred IncrementalStatistics = GeneralStatistics
  192   pred Statistics = error "StatisticsTrait.pred: Statistics has no predecessor"
  193 
  194   enumFromTo from to = go from
  195     where
  196       end = fromEnum to
  197       go v = case compare (fromEnum v) end of
  198                  LT -> v : go (succ v)
  199                  EQ -> [v]
  200                  GT -> []
  201 
  202   enumFrom from = enumFromTo from IncrementalStatistics
  203 
  204   fromEnum Statistics = 0
  205   fromEnum GaussianStatistics = 1
  206   fromEnum GeneralStatistics = 2
  207   fromEnum IncrementalStatistics = 3
  208 
  209   toEnum 0 = Statistics
  210   toEnum 1 = GaussianStatistics
  211   toEnum 2 = GeneralStatistics
  212   toEnum 3 = IncrementalStatistics
  213   toEnum unmatched = error ("StatisticsTrait.toEnum: Cannot match " ++ show unmatched)
  214 
  215 
  216 data BinomialTree = JarrowRudd
  217                   | CoxRossRubinstein
  218                   | AdditiveEQPBinomialTree
  219                   | Trigeorgis
  220                   | Tian
  221                   | LeisenReimer
  222                   | Joshi4
  223                   | ExtendedJarrowRudd
  224                   | ExtendedCoxRossRubinstein
  225                   | ExtendedAdditiveEQPBinomialTree
  226                   | ExtendedTrigeorgis
  227                   | ExtendedTian
  228                   | ExtendedLeisenReimer
  229                   | ExtendedJoshi4
  230   deriving (Show,Eq,Read)
  231 instance Enum BinomialTree where
  232   succ JarrowRudd = CoxRossRubinstein
  233   succ CoxRossRubinstein = AdditiveEQPBinomialTree
  234   succ AdditiveEQPBinomialTree = Trigeorgis
  235   succ Trigeorgis = Tian
  236   succ Tian = LeisenReimer
  237   succ LeisenReimer = Joshi4
  238   succ Joshi4 = ExtendedJarrowRudd
  239   succ ExtendedJarrowRudd = ExtendedCoxRossRubinstein
  240   succ ExtendedCoxRossRubinstein = ExtendedAdditiveEQPBinomialTree
  241   succ ExtendedAdditiveEQPBinomialTree = ExtendedTrigeorgis
  242   succ ExtendedTrigeorgis = ExtendedTian
  243   succ ExtendedTian = ExtendedLeisenReimer
  244   succ ExtendedLeisenReimer = ExtendedJoshi4
  245   succ ExtendedJoshi4 = error "BinomialTree.succ: ExtendedJoshi4 has no successor"
  246 
  247   pred CoxRossRubinstein = JarrowRudd
  248   pred AdditiveEQPBinomialTree = CoxRossRubinstein
  249   pred Trigeorgis = AdditiveEQPBinomialTree
  250   pred Tian = Trigeorgis
  251   pred LeisenReimer = Tian
  252   pred Joshi4 = LeisenReimer
  253   pred ExtendedJarrowRudd = Joshi4
  254   pred ExtendedCoxRossRubinstein = ExtendedJarrowRudd
  255   pred ExtendedAdditiveEQPBinomialTree = ExtendedCoxRossRubinstein
  256   pred ExtendedTrigeorgis = ExtendedAdditiveEQPBinomialTree
  257   pred ExtendedTian = ExtendedTrigeorgis
  258   pred ExtendedLeisenReimer = ExtendedTian
  259   pred ExtendedJoshi4 = ExtendedLeisenReimer
  260   pred JarrowRudd = error "BinomialTree.pred: JarrowRudd has no predecessor"
  261 
  262   enumFromTo from to = go from
  263     where
  264       end = fromEnum to
  265       go v = case compare (fromEnum v) end of
  266                  LT -> v : go (succ v)
  267                  EQ -> [v]
  268                  GT -> []
  269 
  270   enumFrom from = enumFromTo from ExtendedJoshi4
  271 
  272   fromEnum JarrowRudd = 0
  273   fromEnum CoxRossRubinstein = 1
  274   fromEnum AdditiveEQPBinomialTree = 2
  275   fromEnum Trigeorgis = 3
  276   fromEnum Tian = 4
  277   fromEnum LeisenReimer = 5
  278   fromEnum Joshi4 = 6
  279   fromEnum ExtendedJarrowRudd = 7
  280   fromEnum ExtendedCoxRossRubinstein = 8
  281   fromEnum ExtendedAdditiveEQPBinomialTree = 9
  282   fromEnum ExtendedTrigeorgis = 10
  283   fromEnum ExtendedTian = 11
  284   fromEnum ExtendedLeisenReimer = 12
  285   fromEnum ExtendedJoshi4 = 13
  286 
  287   toEnum 0 = JarrowRudd
  288   toEnum 1 = CoxRossRubinstein
  289   toEnum 2 = AdditiveEQPBinomialTree
  290   toEnum 3 = Trigeorgis
  291   toEnum 4 = Tian
  292   toEnum 5 = LeisenReimer
  293   toEnum 6 = Joshi4
  294   toEnum 7 = ExtendedJarrowRudd
  295   toEnum 8 = ExtendedCoxRossRubinstein
  296   toEnum 9 = ExtendedAdditiveEQPBinomialTree
  297   toEnum 10 = ExtendedTrigeorgis
  298   toEnum 11 = ExtendedTian
  299   toEnum 12 = ExtendedLeisenReimer
  300   toEnum 13 = ExtendedJoshi4
  301   toEnum unmatched = error ("BinomialTree.toEnum: Cannot match " ++ show unmatched)
  302 
  303 
  304 data BoundaryConditionSide = BoundaryNone
  305                            | Upper
  306                            | Lower
  307   deriving (Enum,Show,Eq,Read)
  308 
  309 
  310 data PolynomialType = Monomial
  311                     | Laguerre
  312                     | Hermite
  313                     | Hyperbolic
  314                     | Legendre
  315                     | Chebyshev
  316                     | Chebyshev2nd
  317   deriving (Enum,Show,Eq,Read)
  318 
  319 
  320 
  321 -- |Characteristic-function contour/control-variate choice used by Heston integrations.
  322 data ComplexLogFormula = Gatheral
  323                        | BranchCorrection
  324                        | AndersenPiterbarg
  325                        | AndersenPiterbargOptCV
  326                        | AsymptoticChF
  327                        | AngledContour
  328                        | AngledContourNoCV
  329                        | OptimalCV
  330   deriving (Enum,Show,Eq,Read)
  331 
  332 
  333 data CmsMarketCalibrationType = OnSpread
  334                               | OnPrice
  335                               | OnForwardCmsPrice
  336   deriving (Enum,Show,Eq,Read)
  337 
  338 
  339 data SobolDirectionIntegers = Unit
  340                             | Jaeckel
  341                             | SobolLevitan
  342                             | SobolLevitanLemieux
  343                             | JoeKuoD5
  344                             | JoeKuoD6
  345                             | JoeKuoD7
  346                             | Kuo
  347                             | Kuo2
  348                             | Kuo3
  349   deriving (Enum,Show,Eq,Read)
  350 
  351 
  352 
  353 -- |Algorithm used to salvage a matrix that is not positive semi-definite before taking its
  354 -- pseudo square root. @Higham@ only works for correlation matrices.
  355 data SalvagingAlgorithm = SalvagingNone
  356                         | Spectral
  357                         | Hypersphere
  358                         | LowerDiagonal
  359                         | Higham
  360                         | Principal
  361   deriving (Enum,Show,Eq,Read)
  362 
  363 
  364 
  365 
  366 
  367 
  368 
  369 
  370 
  371 
  372 
  373 
  374 
  375 
  376 -- |rounds a value to the precision and rule carried by the given 'Rounding'
  377 applyRounding :: (Rounding) -- ^rounding
  378  -> (Double) -- ^value
  379  -> (Double)
  380 applyRounding a1 a2 =
  381   C2HSImp.unsafePerformIO $
  382   withRounding a1 $ \a1' -> 
  383   let {a2' = realToFrac a2} in 
  384   applyRounding'_ a1' a2' >>= \res ->
  385   let {res' = realToFrac res} in
  386   return (res')
  387 
  388 
  389 
  390 -- |Minimizes an arbitrary Haskell-defined cost function via QuantLib's general-purpose
  391 -- 'Problem'\/'OptimizationMethod' machinery -- unlike 'QuantLib.Model.calibrate', which drives a
  392 -- 'QuantLib.Model.CalibratedModel''s own built-in calibration error against bound
  393 -- 'QuantLib.Model.CalibrationHelper's, this takes any 'RealVector -> Double' objective. The cost
  394 -- function crosses back into Haskell once per outer optimizer iteration over the whole parameter
  395 -- vector; see 'QuantLib.Internal.Type.withCostFunction'.
  396 optimize :: (RealVector -> Double) -- ^cost function
  397  -> (RealVector) -- ^initial guess
  398  -> (Maybe Constraint) -> (OptimizationMethod) -> (EndCriteria) -> IO ((RealVector), (Double), (EndCriteriaType))
  399 optimize a1 a2 a3 a4 a5 =
  400   withCostFunction a1 $ \a1' -> 
  401   withRealVector a2 $ \(a2'1, a2'2) -> 
  402   withMaybeConstraint a3 $ \a3' -> 
  403   withOptimizationMethod a4 $ \a4' -> 
  404   withEndCriteria a5 $ \a5' -> 
  405   preDoubleArray $ \(a6'1, a6'2) -> 
  406   alloca $ \a7' -> 
  407   alloca $ \a8' -> 
  408   preErrorCheck $ \a9' -> 
  409   optimize'_ a1' a2'1  a2'2 a3' a4' a5' a6'1  a6'2 a7' a8' a9' >>
  410   peekRealVector  a6'1  a6'2>>= \a6'' -> 
  411   peekDouble  a7'>>= \a7'' -> 
  412   peekEnum  a8'>>= \a8'' -> 
  413   errorCheck  a9'>>
  414   return (a6'', a7'', a8'')
  415 
  416 
  417 
  418 -- |Regularly spaced time-grid.
  419 timeGrid :: (Double) -- ^end
  420  -> (Word) -- ^steps
  421  -> IO ((TimeGrid))
  422 timeGrid a1 a2 =
  423   let {a1' = realToFrac a1} in 
  424   let {a2' = fromIntegral a2} in 
  425   preErrorCheck $ \a3' -> 
  426   timeGrid'_ a1' a2' a3' >>= \res ->
  427   peekTimeGrid res >>= \res' ->
  428   errorCheck  a3'>>
  429   return (res')
  430 
  431 
  432 
  433 -- |Time grid with mandatory time points.
  434 -- Mandatory points are guaranteed to belong to the grid. No additional points are added.
  435 timeGridFromVector :: (NonEmptyVector Double) -- ^mandatoryTimes
  436  -> IO ((TimeGrid))
  437 timeGridFromVector a1 =
  438   withNonEmptyRealVector a1 $ \(a1'1, a1'2) -> 
  439   preErrorCheck $ \a2' -> 
  440   timeGridFromVector'_ a1'1  a1'2 a2' >>= \res ->
  441   peekTimeGrid res >>= \res' ->
  442   errorCheck  a2'>>
  443   return (res')
  444 
  445 
  446 
  447 -- |Time grid with mandatory time points.
  448 -- 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.
  449 timeGridFromVectorWithSteps :: (NonEmptyVector Double) -- ^mandatoryTimes
  450  -> (Word) -- ^steps
  451  -> IO ((TimeGrid))
  452 timeGridFromVectorWithSteps a1 a2 =
  453   withNonEmptyRealVector a1 $ \(a1'1, a1'2) -> 
  454   let {a2' = fromIntegral a2} in 
  455   preErrorCheck $ \a3' -> 
  456   timeGridFromVectorWithSteps'_ a1'1  a1'2 a2' a3' >>= \res ->
  457   peekTimeGrid res >>= \res' ->
  458   errorCheck  a3'>>
  459   return (res')
  460 
  461 
  462 
  463 -- |returns the number of times on the grid
  464 size :: (TimeGrid) -> (Word)
  465 size a1 =
  466   C2HSImp.unsafePerformIO $
  467   withTimeGrid a1 $ \a1' -> 
  468   size'_ a1' >>= \res ->
  469   let {res' = fromIntegral res} in
  470   return (res')
  471 
  472 
  473 
  474 -- |returns the time at the given index of the grid
  475 timeAt :: (TimeGrid) -- ^grid
  476  -> (Word) -- ^index
  477  -> IO ((Double))
  478 timeAt a1 a2 =
  479   withTimeGrid a1 $ \a1' -> 
  480   let {a2' = fromIntegral a2} in 
  481   preErrorCheck $ \a3' -> 
  482   timeAt'_ a1' a2' a3' >>= \res ->
  483   let {res' = realToFrac res} in
  484   errorCheck  a3'>>
  485   return (res')
  486 
  487 
  488 
  489 -- |Returns all times on the grid in contiguous storage.
  490 points :: (TimeGrid) -> IO ((RealVector))
  491 points a1 =
  492   withTimeGrid a1 $ \a1' -> 
  493   preDoubleArray $ \(a2'1, a2'2) -> 
  494   preErrorCheck $ \a3' -> 
  495   points'_ a1' a2'1  a2'2 a3' >>
  496   peekRealVector  a2'1  a2'2>>= \a2'' -> 
  497   errorCheck  a3'>>
  498   return (a2'')
  499 
  500 
  501 
  502 -- |Mean of a caller-supplied sample. Each @riskStatistics*@ call evaluates a fresh sample.
  503 riskStatisticsMean :: (RealVector) -- ^sample
  504  -> IO ((Double))
  505 riskStatisticsMean a1 =
  506   withRealVector a1 $ \(a1'1, a1'2) -> 
  507   preErrorCheck $ \a2' -> 
  508   riskStatisticsMean'_ a1'1  a1'2 a2' >>= \res ->
  509   let {res' = realToFrac res} in
  510   errorCheck  a2'>>
  511   return (res')
  512 
  513 
  514 
  515 -- |Standard deviation of the sample (square root of 'riskStatisticsVariance').
  516 riskStatisticsStandardDeviation :: (RealVector) -- ^sample
  517  -> IO ((Double))
  518 riskStatisticsStandardDeviation a1 =
  519   withRealVector a1 $ \(a1'1, a1'2) -> 
  520   preErrorCheck $ \a2' -> 
  521   riskStatisticsStandardDeviation'_ a1'1  a1'2 a2' >>= \res ->
  522   let {res' = realToFrac res} in
  523   errorCheck  a2'>>
  524   return (res')
  525 
  526 
  527 
  528 -- |Variance of the sample, @N\/(N-1)@-corrected.
  529 riskStatisticsVariance :: (RealVector) -- ^sample
  530  -> IO ((Double))
  531 riskStatisticsVariance a1 =
  532   withRealVector a1 $ \(a1'1, a1'2) -> 
  533   preErrorCheck $ \a2' -> 
  534   riskStatisticsVariance'_ a1'1  a1'2 a2' >>= \res ->
  535   let {res' = realToFrac res} in
  536   errorCheck  a2'>>
  537   return (res')
  538 
  539 
  540 
  541 -- |Skewness of the sample; 0 for a gaussian distribution.
  542 riskStatisticsSkewness :: (RealVector) -- ^sample
  543  -> IO ((Double))
  544 riskStatisticsSkewness a1 =
  545   withRealVector a1 $ \(a1'1, a1'2) -> 
  546   preErrorCheck $ \a2' -> 
  547   riskStatisticsSkewness'_ a1'1  a1'2 a2' >>= \res ->
  548   let {res' = realToFrac res} in
  549   errorCheck  a2'>>
  550   return (res')
  551 
  552 
  553 
  554 -- |Excess kurtosis of the sample; 0 for a gaussian distribution.
  555 riskStatisticsKurtosis :: (RealVector) -- ^sample
  556  -> IO ((Double))
  557 riskStatisticsKurtosis a1 =
  558   withRealVector a1 $ \(a1'1, a1'2) -> 
  559   preErrorCheck $ \a2' -> 
  560   riskStatisticsKurtosis'_ a1'1  a1'2 a2' >>= \res ->
  561   let {res' = realToFrac res} in
  562   errorCheck  a2'>>
  563   return (res')
  564 
  565 
  566 
  567 -- |Minimum sample value. Throws if the sample is empty.
  568 riskStatisticsMin :: (RealVector) -- ^sample
  569  -> IO ((Double))
  570 riskStatisticsMin a1 =
  571   withRealVector a1 $ \(a1'1, a1'2) -> 
  572   preErrorCheck $ \a2' -> 
  573   riskStatisticsMin'_ a1'1  a1'2 a2' >>= \res ->
  574   let {res' = realToFrac res} in
  575   errorCheck  a2'>>
  576   return (res')
  577 
  578 
  579 
  580 -- |Maximum sample value. Throws if the sample is empty.
  581 riskStatisticsMax :: (RealVector) -- ^sample
  582  -> IO ((Double))
  583 riskStatisticsMax a1 =
  584   withRealVector a1 $ \(a1'1, a1'2) -> 
  585   preErrorCheck $ \a2' -> 
  586   riskStatisticsMax'_ a1'1  a1'2 a2' >>= \res ->
  587   let {res' = realToFrac res} in
  588   errorCheck  a2'>>
  589   return (res')
  590 
  591 
  592 
  593 -- |Variance of the sample values falling below the sample mean (Markowitz semi-variance).
  594 -- Throws if fewer than two sample values fall below the mean.
  595 riskStatisticsSemiVariance :: (RealVector) -- ^sample
  596  -> IO ((Double))
  597 riskStatisticsSemiVariance a1 =
  598   withRealVector a1 $ \(a1'1, a1'2) -> 
  599   preErrorCheck $ \a2' -> 
  600   riskStatisticsSemiVariance'_ a1'1  a1'2 a2' >>= \res ->
  601   let {res' = realToFrac res} in
  602   errorCheck  a2'>>
  603   return (res')
  604 
  605 
  606 
  607 -- |Square root of 'riskStatisticsSemiVariance'.
  608 riskStatisticsSemiDeviation :: (RealVector) -- ^sample
  609  -> IO ((Double))
  610 riskStatisticsSemiDeviation a1 =
  611   withRealVector a1 $ \(a1'1, a1'2) -> 
  612   preErrorCheck $ \a2' -> 
  613   riskStatisticsSemiDeviation'_ a1'1  a1'2 a2' >>= \res ->
  614   let {res' = realToFrac res} in
  615   errorCheck  a2'>>
  616   return (res')
  617 
  618 
  619 
  620 -- |Variance of the sample values falling below zero. Throws if fewer than two sample values
  621 -- fall below zero.
  622 riskStatisticsDownsideVariance :: (RealVector) -- ^sample
  623  -> IO ((Double))
  624 riskStatisticsDownsideVariance a1 =
  625   withRealVector a1 $ \(a1'1, a1'2) -> 
  626   preErrorCheck $ \a2' -> 
  627   riskStatisticsDownsideVariance'_ a1'1  a1'2 a2' >>= \res ->
  628   let {res' = realToFrac res} in
  629   errorCheck  a2'>>
  630   return (res')
  631 
  632 
  633 
  634 -- |Square root of 'riskStatisticsDownsideVariance'.
  635 riskStatisticsDownsideDeviation :: (RealVector) -- ^sample
  636  -> IO ((Double))
  637 riskStatisticsDownsideDeviation a1 =
  638   withRealVector a1 $ \(a1'1, a1'2) -> 
  639   preErrorCheck $ \a2' -> 
  640   riskStatisticsDownsideDeviation'_ a1'1  a1'2 a2' >>= \res ->
  641   let {res' = realToFrac res} in
  642   errorCheck  a2'>>
  643   return (res')
  644 
  645 
  646 
  647 -- |Empirical @y@-th percentile of the sample; @y@ must lie in @(0.0, 1.0]@.
  648 riskStatisticsPercentile :: (RealVector) -- ^sample
  649  -> (Double) -- ^y
  650  -> IO ((Double))
  651 riskStatisticsPercentile a1 a2 =
  652   withRealVector a1 $ \(a1'1, a1'2) -> 
  653   let {a2' = realToFrac a2} in 
  654   preErrorCheck $ \a3' -> 
  655   riskStatisticsPercentile'_ a1'1  a1'2 a2' a3' >>= \res ->
  656   let {res' = realToFrac res} in
  657   errorCheck  a3'>>
  658   return (res')
  659 
  660 
  661 
  662 -- |@y@-th percentile assuming the sample is gaussian (mean\/standard deviation matched); @y@
  663 -- must lie in @(0.0, 1.0)@.
  664 riskStatisticsGaussianPercentile :: (RealVector) -- ^sample
  665  -> (Double) -- ^y
  666  -> IO ((Double))
  667 riskStatisticsGaussianPercentile a1 a2 =
  668   withRealVector a1 $ \(a1'1, a1'2) -> 
  669   let {a2' = realToFrac a2} in 
  670   preErrorCheck $ \a3' -> 
  671   riskStatisticsGaussianPercentile'_ a1'1  a1'2 a2' a3' >>= \res ->
  672   let {res' = realToFrac res} in
  673   errorCheck  a3'>>
  674   return (res')
  675 
  676 
  677 
  678 -- |Empirical value-at-risk at the given @centile@, which must lie in @[0.9, 1.0)@ — a loss
  679 -- (non-negative), the negative of the empirical @(1-centile)@-th percentile floored at zero.
  680 riskStatisticsValueAtRisk :: (RealVector) -- ^sample
  681  -> (Double) -- ^centile
  682  -> IO ((Double))
  683 riskStatisticsValueAtRisk a1 a2 =
  684   withRealVector a1 $ \(a1'1, a1'2) -> 
  685   let {a2' = realToFrac a2} in 
  686   preErrorCheck $ \a3' -> 
  687   riskStatisticsValueAtRisk'_ a1'1  a1'2 a2' a3' >>= \res ->
  688   let {res' = realToFrac res} in
  689   errorCheck  a3'>>
  690   return (res')
  691 
  692 
  693 
  694 -- |Value-at-risk at the given @centile@ assuming the sample is gaussian; @centile@ must lie in
  695 -- @[0.9, 1.0)@.
  696 riskStatisticsGaussianValueAtRisk :: (RealVector) -- ^sample
  697  -> (Double) -- ^centile
  698  -> IO ((Double))
  699 riskStatisticsGaussianValueAtRisk a1 a2 =
  700   withRealVector a1 $ \(a1'1, a1'2) -> 
  701   let {a2' = realToFrac a2} in 
  702   preErrorCheck $ \a3' -> 
  703   riskStatisticsGaussianValueAtRisk'_ a1'1  a1'2 a2' a3' >>= \res ->
  704   let {res' = realToFrac res} in
  705   errorCheck  a3'>>
  706   return (res')
  707 
  708 
  709 
  710 -- |Empirical expected shortfall (conditional value-at-risk) at the given @centile@, which must
  711 -- lie in @[0.9, 1.0)@: the average of the sample values below the value-at-risk threshold.
  712 -- Throws if the sample is empty, or if no sample value falls below the threshold.
  713 riskStatisticsExpectedShortfall :: (RealVector) -- ^sample
  714  -> (Double) -- ^centile
  715  -> IO ((Double))
  716 riskStatisticsExpectedShortfall a1 a2 =
  717   withRealVector a1 $ \(a1'1, a1'2) -> 
  718   let {a2' = realToFrac a2} in 
  719   preErrorCheck $ \a3' -> 
  720   riskStatisticsExpectedShortfall'_ a1'1  a1'2 a2' a3' >>= \res ->
  721   let {res' = realToFrac res} in
  722   errorCheck  a3'>>
  723   return (res')
  724 
  725 
  726 
  727 -- |Expected shortfall at the given @centile@ assuming the sample is gaussian; @centile@ must
  728 -- lie in @[0.9, 1.0)@.
  729 riskStatisticsGaussianExpectedShortfall :: (RealVector) -- ^sample
  730  -> (Double) -- ^centile
  731  -> IO ((Double))
  732 riskStatisticsGaussianExpectedShortfall a1 a2 =
  733   withRealVector a1 $ \(a1'1, a1'2) -> 
  734   let {a2' = realToFrac a2} in 
  735   preErrorCheck $ \a3' -> 
  736   riskStatisticsGaussianExpectedShortfall'_ a1'1  a1'2 a2' a3' >>= \res ->
  737   let {res' = realToFrac res} in
  738   errorCheck  a3'>>
  739   return (res')
  740 
  741 
  742 
  743 -- |Empirical potential upside (the reciprocal notion of value-at-risk, floored at zero) at the
  744 -- given @centile@, which must lie in @[0.9, 1.0)@.
  745 riskStatisticsPotentialUpside :: (RealVector) -- ^sample
  746  -> (Double) -- ^centile
  747  -> IO ((Double))
  748 riskStatisticsPotentialUpside a1 a2 =
  749   withRealVector a1 $ \(a1'1, a1'2) -> 
  750   let {a2' = realToFrac a2} in 
  751   preErrorCheck $ \a3' -> 
  752   riskStatisticsPotentialUpside'_ a1'1  a1'2 a2' a3' >>= \res ->
  753   let {res' = realToFrac res} in
  754   errorCheck  a3'>>
  755   return (res')
  756 
  757 
  758 
  759 -- |Potential upside at the given @centile@ assuming the sample is gaussian; @centile@ must lie
  760 -- in @[0.9, 1.0)@.
  761 riskStatisticsGaussianPotentialUpside :: (RealVector) -- ^sample
  762  -> (Double) -- ^centile
  763  -> IO ((Double))
  764 riskStatisticsGaussianPotentialUpside a1 a2 =
  765   withRealVector a1 $ \(a1'1, a1'2) -> 
  766   let {a2' = realToFrac a2} in 
  767   preErrorCheck $ \a3' -> 
  768   riskStatisticsGaussianPotentialUpside'_ a1'1  a1'2 a2' a3' >>= \res ->
  769   let {res' = realToFrac res} in
  770   errorCheck  a3'>>
  771   return (res')
  772 
  773 
  774 
  775 -- |Variance of the sample values falling below @target@ (Dembo\/Freeman regret). Throws if
  776 -- fewer than two sample values fall below @target@.
  777 riskStatisticsRegret :: (RealVector) -- ^sample
  778  -> (Double) -- ^target
  779  -> IO ((Double))
  780 riskStatisticsRegret a1 a2 =
  781   withRealVector a1 $ \(a1'1, a1'2) -> 
  782   let {a2' = realToFrac a2} in 
  783   preErrorCheck $ \a3' -> 
  784   riskStatisticsRegret'_ a1'1  a1'2 a2' a3' >>= \res ->
  785   let {res' = realToFrac res} in
  786   errorCheck  a3'>>
  787   return (res')
  788 
  789 
  790 
  791 -- |Probability (fraction of the sample, by count) of falling below @target@. Throws if the
  792 -- sample is empty.
  793 riskStatisticsShortfall :: (RealVector) -- ^sample
  794  -> (Double) -- ^target
  795  -> IO ((Double))
  796 riskStatisticsShortfall a1 a2 =
  797   withRealVector a1 $ \(a1'1, a1'2) -> 
  798   let {a2' = realToFrac a2} in 
  799   preErrorCheck $ \a3' -> 
  800   riskStatisticsShortfall'_ a1'1  a1'2 a2' a3' >>= \res ->
  801   let {res' = realToFrac res} in
  802   errorCheck  a3'>>
  803   return (res')
  804 
  805 
  806 
  807 -- |Average shortfall below @target@, i.e. the mean of @target - x@ over sample values @x@
  808 -- below @target@. Throws if no sample value falls below @target@.
  809 riskStatisticsAverageShortfall :: (RealVector) -- ^sample
  810  -> (Double) -- ^target
  811  -> IO ((Double))
  812 riskStatisticsAverageShortfall a1 a2 =
  813   withRealVector a1 $ \(a1'1, a1'2) -> 
  814   let {a2' = realToFrac a2} in 
  815   preErrorCheck $ \a3' -> 
  816   riskStatisticsAverageShortfall'_ a1'1  a1'2 a2' a3' >>= \res ->
  817   let {res' = realToFrac res} in
  818   errorCheck  a3'>>
  819   return (res')
  820 
  821 
  822 
  823 toMatrixDouble :: (Word, Word, [Double]) -> Matrix Double
  824 toMatrixDouble (r, c, d) = Matrix r c d
  825 
  826 -- |Eigenvalues and eigenvectors of a real symmetric matrix, computed by the symmetric threshold
  827 -- Jacobi algorithm. The eigenvalues come back in decreasing order, and the eigenvectors are the
  828 -- /columns/ of the returned matrix: column @i@ belongs to the @i@-th eigenvalue.
  829 symmetricSchurDecomposition :: Matrix Double -- ^symmetric matrix
  830   -> IO ([Double], Matrix Double) -- ^eigenvalues, eigenvectors as columns
  831 symmetricSchurDecomposition (Matrix mr mc md) = do
  832   (values, r, c, vectors) <- qlSymmetricSchurDecomposition mr mc md
  833   pure (values, Matrix r c vectors)
  834 qlSymmetricSchurDecomposition :: (Word) -> (Word) -> ([Double]) -> IO (([Double]), (Word), (Word), ([Double]))
  835 qlSymmetricSchurDecomposition a1 a2 a3 =
  836   let {a1' = fromIntegral a1} in 
  837   let {a2' = fromIntegral a2} in 
  838   withDoubleArrayRaw a3 $ \a3' -> 
  839   preDoubleArray $ \(a4'1, a4'2) -> 
  840   prePtr $ \a5' -> 
  841   prePtr $ \a6' -> 
  842   preDoubleArray $ \(a7'1, a7'2) -> 
  843   preErrorCheck $ \a8' -> 
  844   qlSymmetricSchurDecomposition'_ a1' a2' a3' a4'1  a4'2 a5' a6' a7'1  a7'2 a8' >>
  845   peekDoubleArray  a4'1  a4'2>>= \a4'' -> 
  846   peekWord  a5'>>= \a5'' -> 
  847   peekWord  a6'>>= \a6'' -> 
  848   peekDoubleArray  a7'1  a7'2>>= \a7'' -> 
  849   errorCheck  a8'>>
  850   return (a4'', a5'', a6'', a7'')
  851 
  852 
  853 
  854 -- |Pseudo square root @S@ of a real symmetric matrix @M@, i.e. the matrix with @S*transpose S == M@.
  855 -- When @M@ is not positive semi-definite the given 'SalvagingAlgorithm' approximates it; with
  856 -- 'SalvagingNone' a non-positive-semi-definite input throws instead.
  857 pseudoSqrt :: Matrix Double -- ^symmetric matrix
  858   -> SalvagingAlgorithm
  859   -> IO (Matrix Double)
  860 pseudoSqrt (Matrix mr mc md) salvaging = toMatrixDouble <$> qlPseudoSqrt mr mc md salvaging
  861 qlPseudoSqrt :: (Word) -> (Word) -> ([Double]) -> (SalvagingAlgorithm) -> IO ((Word), (Word), ([Double]))
  862 qlPseudoSqrt a1 a2 a3 a4 =
  863   let {a1' = fromIntegral a1} in 
  864   let {a2' = fromIntegral a2} in 
  865   withDoubleArrayRaw a3 $ \a3' -> 
  866   let {a4' = fromEnumC a4} in 
  867   prePtr $ \a5' -> 
  868   prePtr $ \a6' -> 
  869   preDoubleArray $ \(a7'1, a7'2) -> 
  870   preErrorCheck $ \a8' -> 
  871   qlPseudoSqrt'_ a1' a2' a3' a4' a5' a6' a7'1  a7'2 a8' >>
  872   peekWord  a5'>>= \a5'' -> 
  873   peekWord  a6'>>= \a6'' -> 
  874   peekDoubleArray  a7'1  a7'2>>= \a7'' -> 
  875   errorCheck  a8'>>
  876   return (a5'', a6'', a7'')
  877 
  878 
  879 
  880 -- |Rank-reduced pseudo square root of a real symmetric matrix: the result has rank at most
  881 -- @maxRank@. If @maxRank@ reaches the matrix size, the given percentage of the eigenvalues' sum
  882 -- is retained instead.
  883 rankReducedSqrt :: Matrix Double -- ^symmetric matrix
  884   -> Word -- ^maxRank
  885   -> Double -- ^componentRetainedPercentage
  886   -> SalvagingAlgorithm
  887   -> IO (Matrix Double)
  888 rankReducedSqrt (Matrix mr mc md) maxRank retained salvaging =
  889   toMatrixDouble <$> qlRankReducedSqrt mr mc md maxRank retained salvaging
  890 qlRankReducedSqrt :: (Word) -> (Word) -> ([Double]) -> (Word) -> (Double) -> (SalvagingAlgorithm) -> IO ((Word), (Word), ([Double]))
  891 qlRankReducedSqrt a1 a2 a3 a4 a5 a6 =
  892   let {a1' = fromIntegral a1} in 
  893   let {a2' = fromIntegral a2} in 
  894   withDoubleArrayRaw a3 $ \a3' -> 
  895   let {a4' = fromIntegral a4} in 
  896   let {a5' = realToFrac a5} in 
  897   let {a6' = fromEnumC a6} in 
  898   prePtr $ \a7' -> 
  899   prePtr $ \a8' -> 
  900   preDoubleArray $ \(a9'1, a9'2) -> 
  901   preErrorCheck $ \a10' -> 
  902   qlRankReducedSqrt'_ a1' a2' a3' a4' a5' a6' a7' a8' a9'1  a9'2 a10' >>
  903   peekWord  a7'>>= \a7'' -> 
  904   peekWord  a8'>>= \a8'' -> 
  905   peekDoubleArray  a9'1  a9'2>>= \a9'' -> 
  906   errorCheck  a10'>>
  907   return (a7'', a8'', a9'')
  908 
  909 
  910 
  911 -- |Cholesky factor @L@ of a symmetric positive-definite matrix @M@, i.e. the lower-triangular
  912 -- matrix with @L*transpose L == M@. Pass @True@ for @flexible@ to accept a merely positive
  913 -- /semi/-definite (rank-deficient) input, whose factor is completed with zeroes rather than
  914 -- producing @nan@.
  915 choleskyDecomposition :: Matrix Double -- ^symmetric matrix
  916   -> Bool -- ^flexible
  917   -> IO (Matrix Double)
  918 choleskyDecomposition (Matrix mr mc md) flexible = toMatrixDouble <$> qlCholeskyDecomposition mr mc md flexible
  919 qlCholeskyDecomposition :: (Word) -> (Word) -> ([Double]) -> (Bool) -> IO ((Word), (Word), ([Double]))
  920 qlCholeskyDecomposition a1 a2 a3 a4 =
  921   let {a1' = fromIntegral a1} in 
  922   let {a2' = fromIntegral a2} in 
  923   withDoubleArrayRaw a3 $ \a3' -> 
  924   let {a4' = C2HSImp.fromBool a4} in 
  925   prePtr $ \a5' -> 
  926   prePtr $ \a6' -> 
  927   preDoubleArray $ \(a7'1, a7'2) -> 
  928   preErrorCheck $ \a8' -> 
  929   qlCholeskyDecomposition'_ a1' a2' a3' a4' a5' a6' a7'1  a7'2 a8' >>
  930   peekWord  a5'>>= \a5'' -> 
  931   peekWord  a6'>>= \a6'' -> 
  932   peekDoubleArray  a7'1  a7'2>>= \a7'' -> 
  933   errorCheck  a8'>>
  934   return (a5'', a6'', a7'')
  935 
  936 
  937 
  938 -- |Solves @M*x == b@ given the Cholesky factor @L@ of @M@ -- the first argument is the factor
  939 -- returned by 'choleskyDecomposition', not @M@ itself.
  940 choleskySolveFor :: Matrix Double -- ^Cholesky factor L
  941   -> [Double] -- ^b
  942   -> IO [Double]
  943 choleskySolveFor (Matrix mr mc md) b = qlCholeskySolveFor mr mc md b
  944 qlCholeskySolveFor :: (Word) -> (Word) -> ([Double]) -> ([Double]) -> IO (([Double]))
  945 qlCholeskySolveFor a1 a2 a3 a4 =
  946   let {a1' = fromIntegral a1} in 
  947   let {a2' = fromIntegral a2} in 
  948   withDoubleArrayRaw a3 $ \a3' -> 
  949   withDoubleArray a4 $ \(a4'1, a4'2) -> 
  950   preDoubleArray $ \(a5'1, a5'2) -> 
  951   preErrorCheck $ \a6' -> 
  952   qlCholeskySolveFor'_ a1' a2' a3' a4'1  a4'2 a5'1  a5'2 a6' >>
  953   peekDoubleArray  a5'1  a5'2>>= \a5'' -> 
  954   errorCheck  a6'>>
  955   return (a5'')
  956 
  957 
  958 
  959 -- vim: set ff=unix ts=8 sts=2 sw=2 et:
  960 
  961 foreign import ccall safe "QuantLib/Math.chs.h qlRound"
  962   applyRounding'_ :: ((C2HSImp.Ptr (CRounding)) -> (C2HSImp.CDouble -> (IO C2HSImp.CDouble)))
  963 
  964 foreign import ccall safe "QuantLib/Math.chs.h qlOptimize"
  965   optimize'_ :: ((C2HSImp.Ptr ()) -> (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 ())) -> (IO ()))))))))))))
  966 
  967 foreign import ccall safe "QuantLib/Math.chs.h qlTimeGrid1"
  968   timeGrid'_ :: (C2HSImp.CDouble -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CTimeGrid))))))
  969 
  970 foreign import ccall safe "QuantLib/Math.chs.h qlTimeGrid2"
  971   timeGridFromVector'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CTimeGrid))))))
  972 
  973 foreign import ccall safe "QuantLib/Math.chs.h qlTimeGrid3"
  974   timeGridFromVectorWithSteps'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CTimeGrid)))))))
  975 
  976 foreign import ccall safe "QuantLib/Math.chs.h qlTimeGridSize"
  977   size'_ :: ((C2HSImp.Ptr (CTimeGrid)) -> (IO C2HSImp.CUInt))
  978 
  979 foreign import ccall safe "QuantLib/Math.chs.h qlTimeGridAt"
  980   timeAt'_ :: ((C2HSImp.Ptr (CTimeGrid)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
  981 
  982 foreign import ccall safe "QuantLib/Math.chs.h qlTimeGridPoints"
  983   points'_ :: ((C2HSImp.Ptr (CTimeGrid)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
  984 
  985 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsMean"
  986   riskStatisticsMean'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
  987 
  988 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsStandardDeviation"
  989   riskStatisticsStandardDeviation'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
  990 
  991 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsVariance"
  992   riskStatisticsVariance'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
  993 
  994 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsSkewness"
  995   riskStatisticsSkewness'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
  996 
  997 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsKurtosis"
  998   riskStatisticsKurtosis'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
  999 
 1000 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsMin"
 1001   riskStatisticsMin'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 1002 
 1003 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsMax"
 1004   riskStatisticsMax'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 1005 
 1006 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsSemiVariance"
 1007   riskStatisticsSemiVariance'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 1008 
 1009 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsSemiDeviation"
 1010   riskStatisticsSemiDeviation'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 1011 
 1012 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsDownsideVariance"
 1013   riskStatisticsDownsideVariance'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 1014 
 1015 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsDownsideDeviation"
 1016   riskStatisticsDownsideDeviation'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))
 1017 
 1018 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsPercentile"
 1019   riskStatisticsPercentile'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))
 1020 
 1021 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsGaussianPercentile"
 1022   riskStatisticsGaussianPercentile'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))
 1023 
 1024 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsValueAtRisk"
 1025   riskStatisticsValueAtRisk'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))
 1026 
 1027 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsGaussianValueAtRisk"
 1028   riskStatisticsGaussianValueAtRisk'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))
 1029 
 1030 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsExpectedShortfall"
 1031   riskStatisticsExpectedShortfall'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))
 1032 
 1033 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsGaussianExpectedShortfall"
 1034   riskStatisticsGaussianExpectedShortfall'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))
 1035 
 1036 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsPotentialUpside"
 1037   riskStatisticsPotentialUpside'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))
 1038 
 1039 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsGaussianPotentialUpside"
 1040   riskStatisticsGaussianPotentialUpside'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))
 1041 
 1042 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsRegret"
 1043   riskStatisticsRegret'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))
 1044 
 1045 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsShortfall"
 1046   riskStatisticsShortfall'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))
 1047 
 1048 foreign import ccall safe "QuantLib/Math.chs.h qlRiskStatisticsAverageShortfall"
 1049   riskStatisticsAverageShortfall'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))
 1050 
 1051 foreign import ccall safe "QuantLib/Math.chs.h qlSymmetricSchurDecomposition"
 1052   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 ())) -> (IO ())))))))))))
 1053 
 1054 foreign import ccall safe "QuantLib/Math.chs.h qlPseudoSqrt"
 1055   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 ())) -> (IO ()))))))))))
 1056 
 1057 foreign import ccall safe "QuantLib/Math.chs.h qlRankReducedSqrt"
 1058   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 ())) -> (IO ()))))))))))))
 1059 
 1060 foreign import ccall safe "QuantLib/Math.chs.h qlCholeskyDecomposition"
 1061   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 ())) -> (IO ()))))))))))
 1062 
 1063 foreign import ccall safe "QuantLib/Math.chs.h qlCholeskySolveFor"
 1064   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 ())) -> (IO ())))))))))